我正在使用GL_TEXTURE_2D_ARRAY将多个纹理发送到片段着色器。
int width, height;
unsigned char* image1 = SOIL_load_image("border_small.png",&width, &height,0,SOIL_LOAD_RGBA);
unsigned char* image2 = SOIL_load_image("tile1_small.png", &width, &height,0,SOIL_LOAD_RGBA);
glActiveTexture(GL_TEXTURE1);
GLuint textures;
glGenTextures(1, &textures);
glBindTexture(GL_TEXTURE_2D_ARRAY, textures);
glUniform1i(glGetUniformLocation(p_myGLSL->getProgramID(),"baseTextures"), 1);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_RGBA, width, height, 2);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
0,
0,0,
1,
width, height,
1,
GL_RGBA,
GL_UNSIGNED_BYTE,
image1);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY,
0,
0,0,
2,
width, height,
1,
GL_RGBA,
GL_UNSIGNED_BYTE,
image2);
glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D_ARRAY,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE);
片段着色器:
layout (binding = 1) uniform sampler2DArray baseTextures;
FragColor = texture(baseTextures, vec3(TexCoord.xy, 0));
代码生成一个空白屏幕。我该如何解决这个问题?
答案 0 :(得分:1)
您似乎正在复制纹理单元的offset = 1 and 2
中的数据,但是在片段着色器中读取offset = 0
。