Results 1 to 3 of 3

Thread: Is it safe to load data into CL_TextureGroup in another thread while drawing it?

  1. #1
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default Is it safe to load data into CL_TextureGroup in another thread while drawing it?

    Hello again,
    Now I have another task to implement - something like a movie, large number of frames that should be shown in the certain sequence. The number of frames isn't that much, actually, and the frames themselves are just small gray-scaled images so the whole thing could be loaded in memory at once without any drawbacks. But while I'm at it why not to try and implement a loading via buffer
    So I need a construction that would load new images in one thread while showing already loaded in another. This could be done by collection of textures or sprites but I found this class CL_TextureGroup and was thinking if I could use it for my purpose. But as far as I understand, it contains only one texture and delivers subtextures to use. So, if I use it to draw current frames and at the same time add a new images to it in another thread? Is it safe to use it like this?

  2. #2
    ClanLib Developer
    Join Date
    May 2007
    Posts
    1,824

    Default

    (I have not actually tried this, but I believe it is correct)

    You cannot use an OpenGL context in different threads.

    There are 2 options.
    1) Load into a CL_PixelBuffer object in the second thread.
    The primary thread uploads to the CL_Texture.
    The "Thread" example does this.

    2) Create a new display window that is hidden.
    This is your secondary graphic context.
    Note that CL_Textures are shared between graphic contexts.
    In the second thead, you can upload data to a new CL_Texture to this graphic context.
    When completed uploading, pass control of this CL_Texture to the primary thread.
    Be very careful to not use the same CL_Texture in both threads at the same time.
    You MIGHT need to call glFinish() in the second thread to ensure the CL_Texture upload is complete.



    I do not know how to handle CL_TextureGroup with this. Personally, I would avoid using it.

  3. #3
    Lesser Knight
    Join Date
    Jul 2011
    Posts
    57

    Default

    Thanks for the reply, I did it like this already.
    I've created an array of the textures and load new frames in one thread while showing current frame in another.
    All working fine so far, only one thing confusing me a little - I don't quite understand what exactly happens when I load a new image to the texture with existing one. There is no methods for unloading image data from texture object(as it has no meaning, of course) and I'm not quite sure if texture recreated or pixel data just replaced by new and if previous data properly discarded.
    So, is it safe to upload pixel data to texture object many times? It wouldn't cause memory leaks?

Similar Threads

  1. Dictionary Additions Thread
    By Seth in forum Dungeon Scroll for PC and iPhone
    Replies: 39
    Last Post: 04-29-2016, 09:43 AM
  2. Simple question about CL_Texture and CL_TextureGroup
    By Flav in forum Official ClanLib SDK Forums
    Replies: 6
    Last Post: 08-07-2009, 09:51 AM
  3. Novashell won't load
    By Ainiaria in forum Novashell Game Creation System
    Replies: 11
    Last Post: 07-13-2009, 11:10 PM
  4. detect thread support
    By gergo in forum Official ClanLib SDK Forums
    Replies: 5
    Last Post: 02-13-2009, 10:12 AM
  5. Can't load Dinkedit
    By cathadink in forum Dink Smallwood HD
    Replies: 2
    Last Post: 12-10-2006, 02:19 AM

Bookmarks

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
  •