I'm currently facing an issue with OpenGL samplers. I have a running fragment shader which uses a isampler2DArray variable to sample a stack of 2D images and an integer index which is used to retrieve the desired slice from the stack.
The fragment shader looks like this:
#version 430
/* Per Fragment Input Attributes */
in vec2 texCoord;
/* Per Fragment Uniform Attributes */
layout (binding = 0) uniform isampler2DArray textureSampler;
/* Per Fragment Output Values */
layout (location = 0) out vec3 out_color;
uniform float windowCenter;
uniform float windowWidth;
uniform int texIndex;
void main()
{
float value = float(texture(textureSampler, vec3(texCoord, texIndex)).r);
float min = windowCenter - windowWidth / 2;
value = (value - min) / windowWidth;
out_color = vec3(value);
}
When I tried to change the sampler to sampler2DArray and the uniform variable to retrieve the data to float, I only get a black screen instead of the sampled texture. Similar for a sampler3D.
The texture setup code looks as follows:
m_texture= std::make_unique<Texture>(GL_TEXTURE_2D_ARRAY, nullptr, sequence->width(), sequence->height(), sequence->images().size(), GL_R16I, GL_RED_INTEGER, 1, 0, GL_SHORT);
glPixelStorei(GL_UNPACK_ROW_LENGTH, sequence->width());
for (int i = 0; i < sequence->images().size(); i++)
{
m_texture->UpdateTexture(sequence->images()[i]->data(), 0, sequence->images()[i]->width(), 0, sequence->images()[i]->height(), i, 1);
}
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
For sampler2DArray and sampler3D, I uploaded my float uniform the following way, according to this stackoverflow question (OpenGL 3D Texture Coordinates):
prg_texture3D->SetUniform("currentSliceTexCoord", (1.0f + 2.0f * currentSlice) / (2.0f * sequence->images().size()));
I'm puzzled why the program runs with the isampler2DArray and not with the other two. Can you please make clear to me the difference between them, especially between isampler2DArray and sampler2DArray?
GL_LINEAR.