Page 5 of 5 FirstFirst ... 345
Results 41 to 46 of 46

Thread: Multithreaded resource loading

  1. #41
    PGD Staff code_glitch's Avatar
    Join Date
    Oct 2009
    Location
    UK (England, the bigger bit)
    Posts
    933
    Blog Entries
    45
    works 100% on both graphics cards (I have stretchable) with this spec:
    windows 7 Hp 64 bit
    4gb ddr3 ram
    ATI 4330HD and GMA 4500MHD
    SU4100 @ 1.3ghz

    loaded great, and wuite fast. Cpu tops out at around 7-8% with a few megs of ram.
    I once tried to change the world. But they wouldn't give me the source code. Damned evil cunning.

  2. #42
    I was able to make my ImageViewer work with separate thread properly.

    Execute doesn't free on exit but it sets Finished variable true. Main application loop checks in its start if Finished is set and then do the Finish; to bind texture and fill the data in with glTexImage2D().
    Code:
      TLoadThread = class(TThread)
      private
        fn: string;
        texIndex: integer;
        finished: boolean;
      public
        constructor Create(_texIndex: integer; _fn: string);
        procedure Execute; override;
        procedure Finish;
      end;
    
    constructor TLoadThread.Create(_texIndex: integer; _fn: string);
    begin
      inherited Create(False);
      texIndex:=_texIndex; fn:=_fn;
      finished:=false;
      FreeOnTerminate:=True;
    end;
    
    procedure TLoadThread.Execute;
    begin
      tex.LoadTextureData(@tex.texture[texIndex],fn);
      if terminated then exit;
      finished:=true;
    end;
    
    procedure TLoadThread.Finish;
    begin
      tex.Restore(texIndex);
      form1.loader:=nil;
      form1.MakeDispList;
      Terminate;
    end;
    ps. missing pascal tags...
    Last edited by User137; 07-10-2010 at 09:57 PM.

  3. #43
    Quote Originally Posted by User137
    Execute doesn't free on exit but it sets Finished variable true. Main application loop checks in its start if Finished is set and then do the Finish; to bind texture and fill the data in with glTexImage2D().
    Yeah, this is one of solution, but this is not so interesting as two independent threads And if I get a fail, I will use this method to load the resources(decoding in separate thread and uploading to videocard in main thread).

  4. #44
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    Hey guys, sorry been very busy lately. I'm going to be releasing JUI within the next month or so. It has a fully working multi-threaded resource loader, which does have an option for loading data (images, vertex etc) directly into an OpenGL context. But while you can do this, you really shouldn't, it's basically a waste of time. Since the render thread can't switch to back the context until the data has been uploaded, it's a lot simpler and more elegant to load data into system memory first, then copy the data across to the card in the render thread when it's ready. My resource loader is tied in with a generic scene-graph allowing you to do things like a streaming world AKA the Grand Theft Auto Series. A much better area of focus for your multi-threaded musings would be path finding and steering algorithms. Since both of these require simultaneous access to data along with the render thread, it's a lot more challenging and fun to solve
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

  5. #45
    phibermon
    Quote Originally Posted by phibermon
    t's a lot simpler and more elegant to load data into system memory first, then copy the data across to the card in the render thread when it's ready
    There is no fun if it simple, so... I will waste my time with fun first
    Last edited by WILL; 09-10-2010 at 10:05 PM. Reason: General housekeeping. Moved portion of dialog to other thread.

  6. #46
    PGD Staff / News Reporter phibermon's Avatar
    Join Date
    Sep 2009
    Location
    England
    Posts
    524
    It's not just simpler, it's the only rational solution. You can't load data to the card and render at the same time with OpenGL, at least not with version < 3.2. On higher versions you can use fence sync objects (http://www.opengl.org/registry/doc/g...e.20100725.pdf - section 5.3). With your current method, you may be loading the data in seperate thread, but your main thread will be locking on GL calls until this load is complete and the context is switched back.

    Your method will crash a PS3 and most older ATI cards too. Sorry I'm really not trying to be a killjoy but you're quite clearly a good developer and I feel your time would be better spent on learning about fence syncing, it was designed exactly for what you're trying to do.

    EDIT : But I do agree, sometimes the best solution isn't the most fun
    Last edited by phibermon; 09-10-2010 at 01:50 PM.
    When the moon hits your eye like a big pizza pie - that's an extinction level impact event.

Page 5 of 5 FirstFirst ... 345

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •