Hi,
I am trying to make my shader work with a read-only image3D uniform.
This is the way I create my image:
// 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:
// 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:
#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?
Fred
NB: I also tried GL_LUMINANCE instead of GL_RED in the glTexImage3D call, with no luck