I am new at this particular site in the SE ecosystem, but not to computer graphics in general. If I'm in the wrong spot feel free to redirect me.

My question regards glsl programming and binding two different layers from the same GL_TEXTURE_ARRAY for use in a compute shader.

I am not sure if this is possible or if I am doing it correctly.

What I have tried is to first create an array of 2D textures for

glGenTextures(1,&im_mvs); glActiveTexture(GL_TEXTURE0+1);  
// setting various parameters here
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1 , GL_RGBA32F, lMatDims[0]/lSSFact, lMatDims[1]/lSSFact, NMVS);
glBindImageTexture(1, im_mvs, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);

Then when setting up the shader call I do something like:

glUseProgram(convProgram); // Now try to convolve.
glUniform1i(p4ImIn,1); glActiveTexture(GL_TEXTURE0+1); glBindImageTexture(1, im_mvs, 0, GL_FALSE, 0, GL_READ_ONLY,GL_RGBA32F);
glUniform1i(p4Filt,4); glActiveTexture(GL_TEXTURE0+4); glBindImageTexture(4, im_filt,0, GL_FALSE, 0, GL_READ_ONLY,GL_RGBA32F);
glUniform1i(p4ImOut,1); glActiveTexture(GL_TEXTURE0+1); glBindImageTexture(1, im_mvs, 0, GL_FALSE, 1, GL_WRITE_ONLY,GL_RGBA32F);

I currently can't get it to work, but as I still am quite new to opengl and glsl there is a fair chance that I may have made a mistake somewhere else.

The behavior that I am hoping for is to be able to select which layer of the array should be used in in-image and out-image respectively. This would make it very convenient to construct automated sequences of filterings by just changing the pointing with glBindImageTexture command like above.

I wonder if this is supposed to be possible or if I need to alter it somehow ?

Edit: Just as Nicol mentioned in the answer there were several issues with my code. The most important was that I had mixed up texture units and image units.

Inside my shader which defines uniform data like this :

layout(rgba32f, binding = 0) uniform image2D im_in;
layout(rgba32f, binding = 1) uniform image2D filt;
layout(rgba32f, binding = 2) uniform image2D im_out;

The "binding" numbers there should correspond to the first argument in the call to glBindImageTexture as the types "image2D" is an image type. The glActiveTexture command is superflous as the variables im_mvs, im_filt already are tied to the texture(array)s which the image will be gotten from. I had them there previously to be able to transfer data.

I changed to

glUniform1i(p4ImIn,0); glBindImageTexture(0, im_mvs, ...
glUniform1i(p4Filt,1); glBindImageTexture(1, im_filt,...
glUniform1i(p4ImOut,2); glBindImageTexture(2, im_mvs, ...

and now the code works as I had hoped. I will now go ahead to investigate various ways to filter my MVs. Thank you for the help.

  • 1
    $\begingroup$ glActiveTexture(GL_TEXTURE0+1); What do you think these calls are doing? $\endgroup$ Commented Jan 31, 2023 at 22:44

1 Answer 1


There is no such thing as an "in image" and an "out image". There are just images used for load/store operations. A particular image can be write-only or read-only, but what "a particular image" means is defined by the binding index used in the shader. That is, there is exactly and only one image bound to index 1 at any time, with exactly and only one set of properties (readable, writeable, etc). If you bind another image to index 1, then you have unbound the previous image, and you have changed the properties of the binding.

Whatever p4ImIn and p4ImOut represent in your shader, they should have different binding indices. And therefore, you should be binding those images to different indices.

  • $\begingroup$ Thank you Nicol. Of course you are right. Sorry for the messy code. I just have the convention of naming targets for writing or store operations for "out" and targets for reading or load for "in". I realized just 1 hour ago I had mixed up image units and texture units. $\endgroup$ Commented Jan 31, 2023 at 23:53

Your Answer

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

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