It is required to transfer some amount of int format data to the fragment shader, based on which the shader would determine which texture to use. I tried to use TBO for such purposes:
glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D,texture1); texLoc = glGetUniformLocation(ProgramId,"Tex1 "); glUniform1i(texLoc,0); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D,texture2); texLoc = glGetUniformLocation(ProgramId,"Tex2 "); glUniform1i(texLoc,1); glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D,texture3); texLoc = glGetUniformLocation(ProgramId,"Tex3"); glUniform1i(texLoc,2); glGenBuffers(1, &FTexBuffer); glBindBuffer(GL_TEXTURE_BUFFER, FTexBuffer); glBufferData(GL_TEXTURE_BUFFER, sizeof(array_id),array_id, GL_STREAM_DRAW); glGenTextures(1, &FBuffer); glBindTexture(GL_TEXTURE_BUFFER, FBuffer); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexBuffer(GL_TEXTURE_BUFFER, GL_R32I, FTexBuffer); glBindBuffer(GL_TEXTURE_BUFFER, 0); glBindTexture(GL_TEXTURE_BUFFER, 0); glActiveTexture(GL_TEXTURE3); glBindTexture(GL_TEXTURE_BUFFER,FBuffer); texLoc = glGetUniformLocation(ProgramId,"tex_id "); glUniform1i(texLoc,3);
Fragment shader:
out vec4 color; uniform sampler2D Tex1; uniform sampler2D Tex2; uniform sampler2D Tex3; uniform isamplerBuffer tex_id; in vec2 Tex_coord; void main() { if (texelFetchBuffer(tex_id,1) == 3) color = texture(tex1, tex_coord); if (texelFetchBuffer(tex_id,5) == 4) color = texture(tex2, tex_coord); if (texelFetchBuffer(tex_id,25) == 5) color = texture(tex3, tex_coord);\n"\ … }
Nothing happened. What is the problem? The contents of array_id have very little effect on the final outcome, and after several experiments with the code, the contents of the array have completely ceased to have any effect on the result. Apparently, the data is not transferred to the shader.