Results 1 to 3 of 3

Thread: Loading assets in a background thread?

  1. #1

    Default Loading assets in a background thread?

    Just wondering how I would go about achieving this. I was thinking of doing this either;
    • through a shared context and a runnable object
    • mapping opengl buffers into memory, loading in the background thread (then unmapped in the main thread)
    • loaded/decompressed in the background thread (from files) then uploaded piecemeal each frame in the main thread.

  2. #2
    ClanLib Developer
    Join Date
    May 2007


    I have not done this. Another developer has, but I'm not sure how he achieved it, but this is my guess (if he reads this I'm sure that he'll correct me )

    He loads the assets in a separate thread:
    1) Main thread, create new window that is hidden (for use by the worker thread)
    2) Main thread contains graphics using the clan::Resource<> template. For example "clan::Resource<clan::Image>" (this can be initialised with a stock object)
    3) Main thread requests the worker thread to load an image. (To load into "clan::Resource<clan::Image>")
    4) Worker thread uses this hidden window's graphic context (and canvas) to load the Texture's, Images and Sprites
    5) When worker thread has completed, "set" is called on "clan::Resource<clan::Image>" that now contains the new image
    6) Main thread will automatically use this loaded object. Or you can use "updated()" to determine if a loading stage is complete

    Note, only create worker windows in the main thread. Else you'll run into problems (I.E. Only works on some gpu's)

    Again, I have personally not done this. So I could be wrong!

    An additional note. The clan:: DisplayCache ( ) uses this clan::Resource<> template.
    If you create your own DisplayCache to use worker threads, you can load fonts, sprites, images and textures in your own loader, and call (for example)
    static Resource<Image> Image::resource(Canvas &canvas, const std::string &id, const ResourceManager &resources);
    This is useful if you want clanGUI to load graphics in an external thread (why? !!! )
    Last edited by rombust; 11-14-2013 at 08:31 AM.

  3. #3


    As a particular project grows bigger, I want to implement a loading screen so I don't block the main thread whilst loading all assets needed by a scene file.

    So I will want to load the entire world in the background thread, then signal when we're done.

Similar Threads

  1. How to loading .x in zip file
    By feelthat in forum Proton SDK
    Replies: 2
    Last Post: 08-05-2013, 09:28 AM
  2. Replies: 17
    Last Post: 05-28-2013, 03:05 PM
  3. Loading
    By Cobra in forum Novashell Game Creation System
    Replies: 2
    Last Post: 06-26-2008, 09:43 AM



Posting Permissions

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