我正在尝试更新TextureArray,但是在调用glTexSubImage3D()
时,它仅更新纹理的第一层。其余的仍然充满零。在此代码示例m_layerCount = 10
中。存储在Computeshader中的vec4 tmp
中的结果始终等于TextureArray中第一层的像素,因为其他层的所有像素均为零。当仅查看第一层以外的任何其他层时,也可以查看此视图。
Opengl:
// init
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &tex.handle);
glBindTexture(GL_TEXTURE_2D_ARRAY, tex.handle);
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_BORDER);
glTexParameteri(GL_TEXTURE_2D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, GL_R32F, m_res.x, m_res.y, m_layerCount);
...
// update
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_ARRAY, tex.handle);
// there is a pbo for every texture, all are filled and work!
for(unsigned int j = 0; j < m_layerCount; j++){
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo_container[j].handle);
glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, j, m_res.x, m_res.y, 1, GL_RED, GL_FLOAT, 0);
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
}
Computeshader:
layout (binding = 0, r32f) uniform image2DArray srcTex;
layout(local_size_x = 10, local_size_y = 10) in;
void main(){
ivec2 idx = ivec2(gl_GlobalInvocationID.xy);
vec4 tmp = vec4(0, 0, 0, 0);
for(int i = 0; i < 10; i++){
tmp += imageLoad(srcTex, ivec3(idx, i));
}
}