4
$\begingroup$

Made a new question as suggested, follow up to that one.

I was experimenting with texture declaration to find solution and thats how I done that before (unsigned int):

glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_3D, m_texture);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32UI, width, height, depth, 0, GL_RGBA_INTEGER, 
GL_UNSIGNED_INT, NULL);
glGenerateMipap(GL_TEXTURE_3D);

glGenSamplers(1, &m_sampler);
glSamplerParameteri(m_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glSamplerParameteri(m_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

And for that using imagestore for int/unsigned int didnt work despite correct binding for writing as uimage , rgba32ui, uvec4 format and for reading as usampler, uvec4 format. Of course also binding sampler object for reading.

But I added two lines:

glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_3D, m_texture);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32UI, width, height, depth, 0, GL_RGBA_INTEGER, 
GL_UNSIGNED_INT, NULL);

glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); //
glTexParameteri( GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); //

glGenerateMipmap(GL_TEXTURE_3D);

glGenSamplers(1, &m_sampler);
glSamplerParameteri(m_sampler, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glSamplerParameteri(m_sampler, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glSamplerParameteri(m_sampler, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);

And now it seems to work. Still need to bind sampler thought. But I fail to see any logic in this. I use sampler objects to set texture filtering not glTexParameteri functions.

Float textures work with sampler objects as in first block of code. Anyone can explain?

$\endgroup$
2
$\begingroup$

I use sampler objects to set texture filtering not glTexParameteri functions.

No, you do not. Image Load/Store doesn't use samplers, so you cannot be using sampler objects to set the texture's filtering, when you're using the texture with Image Load/Store.

Sure, Image Load/Store doesn't use the built-in sampler data stored in a texture object either. However, those parameters do have an effect. They can determine if a texture is complete.

And whether you're using those parameters or not, if a texture is not complete, you can't access the texture from the GPU. Among the texture completeness rules is that the texture's sampling parameters must be valid, with respect to the texture's image format.

The default filtering parameters for textures are some form of LINEAR filtering; OpenGL does not change these defaults based on the image format. Therefore, a fresh texture with an integer image format will be incomplete unless you explicitly set the mag/min filters to GL_NEAREST (or NEAREST_MIPMAP_NEAREST for min).

You can get away with what you have when using the texture with sampler objects because their parameters override the completeness check. But as previously mentioned, Image Load/Store doesn't care about the bound sampler objects. Therefore, the completeness check must look at the texture's sampling parameters.

This is regardless of the fact that Image Load/Store itself doesn't actually use those parameters. So it's pointless, but you've gotta do it.

| improve this answer | |
$\endgroup$
  • $\begingroup$ That's quite a clarified explanation for that somewhat tricky problem. $\endgroup$ – narthex Nov 14 '16 at 17:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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