3
$\begingroup$

When I set up a texture as float it works (color is written - BTW I'm doing voxelization):

glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F, width, height, depth, 0, GL_RGBA,GL_FLOAT,NULL);

then setting filtering...

then binding:

glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);

writing:

layout(rgba32f ,binding = 0) uniform image3D geometryGrid;
...
imageStore(geometryGrid, index, ivec4(1.0)); //ivec4 or vec4, it works

reading:

uniform sampler3D geometryTexture;
...
vec4 g = texture(geometryTexture, geomCoords);

But I want to use an integer texture (so in future I can do binary voxelization and bitwise operations - each bit = slice in z direction). I set it up like that:

glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);

then setting filtering...

then binding:

glBindImageTexture(0, textureID, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32I);

writing:

layout(rgba32i ,binding = 0) uniform iimage3D geometryGrid;
...
imageStore(geometryGrid, index, ivec4(1.0));

reading (same as float):

uniform sampler3D geometryTexture;
...
vec4 g = texture(geometryTexture, geomCoords);

Then it's black. Whats wrong with that? There is sparse documentation about it. BTW The info that iimage is for integer texture, uimage is for unsigned int is actually nowhere to be found.

$\endgroup$
3

2 Answers 2

3
$\begingroup$
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_INT, NULL);

This is not an integer image format. It's an unsigned, normalized, fixed-point image format. For those, you use floating-point image/sampler variables. So for a 3D texture, you would use image3D, not iimage3D.

If you want a true signed integer format, you would do this:

glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32I, width, height, depth, 0, GL_RGBA_INTEGER, GL_INT, NULL);

Note two changes. First, the internal format is GL_RGBA32I, which specifies a 32-bit-per-channel signed integer format. The second is the use of GL_RGBA_INTEGER for the pixel transfer format. Even though you're not actually performing a pixel transfer (since you're passing NULL), you still must use an appropriate format and type. And the _INTEGER formats must be used if you're transferring to/from a texture with an integer format.

When you do this, you must of course use the iimage3D and isampler3D types in your shaders.

$\endgroup$
1
  • $\begingroup$ Thanks for hints. I corrected glTexImage3D function as you pointed but the problem seem to persist. What I noticed is that when I setup texture as RGBA32F, RGBA, GL_FLOAT and then bind it as RGBA32I image and use iimage in shader it works. But if I setup texture as RGBA32I, RGBA_INTEGER, GL_INT is is empty. So it is something with texture setup still. But it is correct and glGetError returns 0... I updated my nvidia drivers but this is not driver fault. $\endgroup$
    – mdkdy
    Nov 1, 2016 at 11:40
1
$\begingroup$

Instead of sampler3D, you should use isampler3D to sample integer formats as described in the GLSL documentation.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.