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 4 of 4

Thread: textures and threads

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2006
    Location
    Ottawa, Canada.
    Posts
    3

    textures and threads

    Hi all;

    I have a threaded application that I would like to change so that textures are created in 1 thread, and used in another.

    It kind of works, but, although the texture info appears correct for both threads (glGetTexLevelParameteriv calls), the texture appears to not be.

    Main thread, which "consumes" textures, has:
    XInitThreads();
    ...
    GLcx = glXCreateContext(Xdpy, Xvi, 0, GL_FALSE);

    The creator thread does:

    textureContext = glXCreateContext(Xdpy, Xvi, GLcx, GL_FALSE);
    ...
    glBindTexture (texnum);
    glTexParameteri(...)
    glTexImage2D(GL_TEXTURE_2D...)
    then signals that the texture is ok.

    This method, according to what I can see on-line, should be thread safe.

    The textures are kind of written; but both Linux and OS X show the textures incorrect; if they come in as images of say 128x128, RGB, then they are displayed, if not, then the image is "skewed" or some other corruption.

    The application is FreeWRL - an X3D/VRML Browser; the major threading code is old; the producer used to read data to a malloc'd bit of code to be glTexImaged (etc) in the consumer thread.

    Any thoughts??

  2. #2
    Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    302

    Re: textures and threads

    Not that I expect this to solve the problem, but what if you explicitly bind texture zero (aka none) after uploading the texture data but before signalling the main thread "Go ahead, use it"?

  3. #3
    Junior Member Newbie
    Join Date
    Feb 2006
    Location
    Ottawa, Canada.
    Posts
    3

    Re: textures and threads

    glBindTexture to 0 after uploading, but before telling the main thread that the texture is there does not affect anything on Linux or OS X.

    Thanks for the thought, though...

    More investigation:
    ok; TEXTURE_INTERNAL_FORMAT on OS X is 0x8058, which is GL_RGBA8 (linux returns "3" which does not make much sense...) in both one-context-thread code, and in my multithreaded example.

    If I send in a 4 element PixelTexture (VRML-code) it "kind of" works better on OS X and Linux - the colors are off, but at least
    it displays better.

    I can understand storing textures as RGBA8; but why would the glTexImage2D that works when only one OpenGL context is there, fail when the contexts are shared?

  4. #4
    Junior Member Newbie
    Join Date
    Feb 2006
    Location
    Ottawa, Canada.
    Posts
    3

    Re: textures and threads

    I think I found it...

    On my second context, I had not set glPixelStorei(GL_PACK_ALIGNMENT,1), etc.

    I don't know whether to say "sigh" or "arrrgh". I have spent a couple of days at this; at least my knowledge of OpenGL and texturing is *much* better than it was beforehand.

    I'm off to thoroughly test this on a few platforms, with quite a few textures.

Posting Permissions

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