Sogartar
Sogartar

Reputation: 2175

OpenGL: does a texture have storage?

In OpenGL, after a texture name is generated, the texture does not have storage. With glTexImage2D you can create storage for the texture.

How can you determine if a texture has storage?

Upvotes: 1

Views: 85

Answers (2)

Reto Koradi
Reto Koradi

Reputation: 54642

You can't do exactly that in ES 2.0. In ES 3.1 and later, you can call:

GLint width = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);
if (width > 0) {
    // texture has storage
}

The glIsTexture() call that is available in ES 2.0 may give you the desired information depending on what exactly your requirements are. While it will not tell you if the texture has storage, it will tell you if the given id is valid, and if it was ever bound as a texture. For example:

GLuint texId = 0;
GLboolean isTex = glIsTexture(texId);
// Result is GL_FALSE because texId is not a valid texture name.

glGenTextures(1, &texId);
isTex = glIsTexture(texId);
// Result is GL_FALSE because, while texId is a valid name, it was never
// bound yet, so the texture object has not been created.

glBindTexture(GL_TEXTURE_2D, texId);
glBindTexture(GL_TEXTURE_2D, 0);
isTex = glIsTexture(texId);
// Result is GL_TRUE because the texture object was created when the
// texture was previously bound.

Upvotes: 2

Roy T.
Roy T.

Reputation: 9648

I believe you can use glGetTexLevelParameterfv to get the height (or width) of the texture. A value of zero for either of these parameters means the texture name represents the null texture.

Note I haven't tested this!

Upvotes: 1

Related Questions