Results 1 to 6 of 6

Thread: Can't make imageLoad(image3D) to work (texture(sampler3D) or imageLoad(image2D) OK)

  1. #1
    Senior Member Regular Contributor
    Join Date
    Jul 2010

    Can't make imageLoad(image3D) to work (texture(sampler3D) or imageLoad(image2D) OK)


    I am trying to make my shader work with a read-only image3D uniform.

    This is the way I create my image:

    Code :
    // Creation
    glGenTextures(1, &tex);
    glBindTexture(GL_TEXTURE_3D, tex);
    float data[sx*sy*sz] = 1.0f everywhere;
    glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, sx,sy,sz, 0, GL_RED, GL_FLOAT, data);
    glBindTexture(GL_TEXTURE_3D, 0);

    Code that binds the image and performs the rendering:
    Code :
    // Render time
    #define SLOT 0
    glUniform1iARB(tex, SLOT);
    glBindImageTexture(SLOT, tex, 0, GL_FALSE, 0, GL_READ_ONLY, GL_R32F);
    glUseProgram and draw call.

    And now the shader code:
    Code :
    #version 420
    layout(r32f) uniform image3D tex;
    void main()
      float result = imageLoad(tex, ivec3(0,0,0)).x; // always 0.0f - why?
      gl_FragColor = vec4(result, 0, 0, 1);

    Tried on both nVidia and AMD GL4 hardware, with latest drivers - same result: imageLoad().x always returns 0.0f.

    If I change my code to use a sampler3D instead of image3D (and use texture() in the shader of course), things work fine. If I use an image2D, things are also fine (imageLoad(tex, ivec2) instead of ivec3).

    There is something that I am missing in the 3D case for images, but what?


    NB: I also tried GL_LUMINANCE instead of GL_RED in the glTexImage3D call, with no luck

  2. #2
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Watford, UK
    glBindImageTexture(..., GLboolean layered, ) // this must be GL_TRUE for 3D textures or 2D arrays, to use them with 3 coords (sampler3D).

    Also, there's possible texture-incompleteness creeping-in. When creating the texture, try adding:
    Code :

  3. #3
    Senior Member Regular Contributor
    Join Date
    Jul 2010
    Hi Ilian,

    I did try layered=GL_TRUE already, and it doesn't work. All read values are 0.0f.
    Also MIN and MAG FILTER are at GL_NEAREST.

    Tried to generate mipmaps - same result. Tried setting WRAP_R, S and T to GL_CLAMP_TO_EDGE, MIN and MAX_LOD to 0.

    Tried dozens of things in two days, to no avail.

  4. #4
    Senior Member Regular Contributor
    Join Date
    Oct 2009
    Is your line:
    Code :
    glUniform1iARB(tex, SLOT);
    a forum post typo?
    If not, tex should instead be the uniform location, rather than the texture id.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Jul 2010
    Hi Dan,

    Yes it is a forum post typo, I'm doing result = glGetUniformLocationARB(prog, "tex"); then glUniform1iARB(result, SLOT);
    result is valid and no GL error.

  6. #6
    Senior Member Regular Contributor
    Join Date
    Jul 2010
    I figured it out. As things weren't working, I switched to a smaller prototype application that we are using. I changed the value of layered to GL_TRUE in this prototype, and things were still not working. I posted the message to the forum after that. I realized later that the prototype was doing bad things. So I switched back to my main application code and changed the value of layered to GL_TRUE. Worked. Too bad I got mixed up so badly.
    Thanks both of you for your help.

Similar Threads

  1. imageLoad/imageStore VERY slow
    By JasonRay in forum OpenGL: GLSL
    Replies: 6
    Last Post: 12-17-2015, 09:15 AM
  2. Replies: 3
    Last Post: 10-21-2015, 10:26 AM
  3. imageLoad addressing past 1gb boundary
    By imported_sleap in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 02-03-2015, 10:36 PM
  4. imageload/store() very slow, any tricks?
    By robotech_er in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 07-07-2012, 10:27 AM
  5. Difference(s) between texelFetch and imageLoad ?
    By _blitz in forum OpenGL: GLSL
    Replies: 2
    Last Post: 01-15-2012, 06:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean