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.

  • What you are doing in this shader is a very lousy idea. Collect all your textures into one big picture (texture atlas) with the MAXRECTS algorithm with BL heuristics and use the recalculated UV coordinates to navigate through it, so there will be no need to switch anything in the shader and you will get your animated texture simply by selecting the necessary data from VBO to which stores the texture coordinates. - igumnov
  • "Collect all your textures in one big picture" I just would not want this. Textures can be of different sizes, they are not so easy to combine into one. For my tasks, this is not at all necessary, although, as an option, it has long been left for stock. I don’t need animated textures .... The question should still be focused on transferring arrays of data to the shader, since in any case it is necessary for my tasks. - prog333
  • Here you have four OpenGLs, it looks like I'm working with ES 2.0, but it seems they are not much different. To transfer something directly to the fragment shader, you need to use a texture whose pixel color is your data, or send a vertex output to the pixel (fragmentary) input, and send a uniform or attribute (in) input to the vertex input what you need after caching in VBO . - igumnov
  • To transfer the texture, you need to bring it to the appropriate form, which is not very convenient. For such purposes, it seems, TBO was created - to transfer a one-dimensional array to the shader. But something is not working ... all the code rummaged. - prog333
  • Yes, I read about TBO in ES. I don’t have this feature at all. It can be easier to fill it simply through the uniform array if the volume is not very large. - igumnov

0