Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Sharing textures between contexts

  1. #1
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    2

    Sharing textures between contexts

    Is there a way to share textures between several contexts? I want to load textures in the background with a "loader" thread while rendering continues in the main rendering thread (rendering without the textures that are not available yet, obviously). Since an OpenGL context cannot be shared by other threads, I tried to create a loader context using the "sharing" feature mentioned in the context creation documentation but this does not seem to work. It doesn't even work in a single-thread design -- textures loaded in one context are not available to the other context. Any working example using either glx or wxwidgets would be most appreciated!

    Thanks.

  2. #2
    Junior Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    153
    AFAIK context sharing is the best/easiest/most portable way to acomplish this and textures should be shareable among contexts.

    I used this in an applicaton several years ago, where a resource loading thread loaded (among other things) textures while the main rendering thread kept rendering, but unfortunately I no longer have access to that source code. However, I can confirm that this works (after a bit of tinkering, especially for shaders).

    How do you diagnose that it does not work for you? Do you get a gl error or is the texture blank? Could you post a few source code snippets of how you try to do this?

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2012
    Posts
    15
    Here's how to do it with GLX:

    In main thread Init function :

    Code :
    XInitThreads();
    ...
     
     
    ...
    renderingContext = glXCreateContext( Display*, XVisualInfo*, NULL, True);
     
    workerContext = glXCreateContext( Display*, XVisualInfo*, renderingContext, True );
     
    glXMakeCurrent(Display*, GLXDrawable, renderingContext);

    In worker thread init function :

    Code :
    glXMakeCurrent(Display*, GLXDrawable, workerContext);

    Finally, don't forget to call glFinish() before using the loaded resources in the main thread

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,224
    Also while you're studying up, be sure to read up on the new GL extension:

    * {GL|GLX|WGL}_ARB_context_flush_control

    just released. Good to know about this even if you decide you don't need it.

  5. #5
    Newbie Newbie
    Join Date
    Aug 2014
    Posts
    2
    Thanks a lot! Turns out that this is pretty much what I did, my problems where mostly threads-related. Also forgot to call XInitThreads().

Posting Permissions

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