Search code examples
c++openglglsltextures

OpenGL Cubemap Can only write to one face


I have a cubemap texture like this:

uint32_t skyboxTextureUnfiltered = -1;
glGenTextures(1, &skyboxTextureUnfiltered);
glBindTexture(GL_TEXTURE_CUBE_MAP, skyboxTextureUnfiltered);
glTexStorage2D(GL_TEXTURE_CUBE_MAP, 6, GL_RGBA32F, m_SkyboxSize, m_SkyboxSize);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

I run a compute shader on it like:

glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
glUseProgram(m_EquirectToCubeID);
glDispatchCompute(m_SkyboxSize, m_SkyboxSize, 6);

And my compute shader looks like :

layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
layout(binding = 0, rgba32f) uniform imageCube outputTexture;

void main(void)
{
    imageStore(outputTexture, ivec3(gl_GlobalInvocationID), vec4(1.0f));
}

And after all this when I try to see its contents in RenderDoc, I only see the +X Face is white rest all are black.

Why is this happenning?


Solution

  • glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_FALSE, 0, GL_READ_WRITE, GL_RGBA32F);
    

    Here you pass GL_FALSE to the layered parameter. It means that only a single layer (here layer 0) will be bound. For cube-map textures, every face is a single layer.

    You should pass GL_TRUE instead:

    glBindImageTexture(0, skyboxTextureUnfiltered, 0, GL_TRUE, 0, GL_READ_WRITE, GL_RGBA32F);