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); glBindTexture(GL_TEXTURE_2D_ARRAY,im_mvs); // setting various parameters here glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1 , GL_RGBA32F, lMatDims/lSSFact, lMatDims/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.