Results 1 to 10 of 46

Thread: Multithreaded resource loading

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #36
    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.

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
  •