0
$\begingroup$

For the old approach, generating a texture for the ImageTexture for compute shaders would look like this:

glGenTextures(1, &m_texture);
glBindTexture(GL_TEXTURE_2D, m_texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, (GLsizei)m_width, (GLsizei)m_height, 0, GL_RGBA, GL_FLOAT, nullptr);

However, in DSA, glTexImage2D is no longer a thing and we need to use glTextureStorage2D and glTextureSubImage2D to replace it. Yet, the new DSA functions don't work with ImageTextures, when I try to create texture for the ImageTextures, the texture returns black. Here is the code:

glCreateTextures(GL_TEXTURE_2D, 1, &m_texture);
glTextureStorage2D(m_texture, 0, m_internalFormat, (GLsizei)width, (GLsizei)height);

glTextureParameteri(m_texture, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTextureParameteri(m_texture, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTextureParameteri(m_texture, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTextureParameteri(m_texture, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTextureSubImage2D(m_texture, 0, 0, 0, (GLsizei)width, (GLsizei)height, m_dataFormat, GL_UNSIGNED_BYTE, nullptr);

I've read about that the new DSA functions are immutable textures and maybe that causes this problem? If that is the case, what is the DSA counterpart for creating mutable textures?

$\endgroup$
2
  • 1
    $\begingroup$ What do you mean by "image texture"? $\endgroup$ Feb 17, 2023 at 18:35
  • 1
    $\begingroup$ You cannot pass a nullptr to glTex(ture)SubImage*D. If you don't want to fill the texture with data, then just don't call it. $\endgroup$ Feb 17, 2023 at 18:36

1 Answer 1

0
$\begingroup$

The 2nd argument of glTextureStorage2D() API is mip-map levels, if you specify it as 0, it causes troubles you may have.

glTextureStorage2D(m_texture, 0, m_internalFormat, (GLsizei)width, (GLsizei)height);
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.