1
votes

We are developing a C++ plug-in within an OpenGL application. The application will call a "render" method on our plug-in as necessary. While rendering our textures, we noticed that sometimes some of the textures are drawn completely white even though they are created with valid data. It appears to be random about which texture and when. While investigating what could cause some of the textures to render white, I noticed that simply trying to retrieve the size of a texture (even for the ones that render correctly) doesn't work. Here is the simple code to create the texture and retrieve its size:

GLuint textureId;
glGenTextures(1, &textureId);
glBindTexture(GL_TEXTURE_2D, textureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, imageWidth, imageHeight, 0,
             GL_BGRA, GL_UNSIGNED_BYTE, imageDdata);

// try to lookup the size of the texture
int textureWidth = 0, textureHeight = 0;
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &textureWidth);
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT, &textureHeight);

glBindTexture(GL_TEXTURE_2D, 0);

The image width and height input to glTexImage2D are 1536 x 1536, however the values returned from glGetTexLevelParameter are 16384 x 256. In fact, any width and height image that I pass to glTexImage2D result in an output of 16384 x 256. If I pass a width and height of 64 x 64, I still get back 16384 x 256.

I am using the same simple texture load/render code in another standalone test application and it works correctly all the time. However, I get these white textures when I use the code within this larger application. I have also verified that glGetError() returns 0.

I am assuming the containing application is setting some OpenGL state that is causing problems when we try to render our textures. Do you have any suggestions for things to check that could cause these white textures OR invalid texture dimensions?

Update
Both my test application that renders correctly and the integrated application that doesn't render correctly are running within a VM on Windows 7 with Accelerated 3D Graphics enabled. Here is the VM environment:
CentOS 7.0
OpenGL 2.1 Mesa 9.2.5

2
Which platform are you using, and what is GL's context version when you get the error? - MuertoExcobito
Who the f*** did vote to close this perfectly fine question? - datenwolf
@MuertoExcobito CentOS 7.0 and OpenGL 2.1 via Mesa 9.2.5 - dewald
Are these calls executed directly in this sequence? Meaning, glGetTexLevelParameteriv() is called immediately after glTexImage2D()? Or is there anything between these calls that was omitted for brevity? - Reto Koradi
Build a small test for this and check that there is not just a bug in your application. This shouldn't be difficult. If the test fails run it on a native graphics card with up to date drivers. If this still fails, your test is probably wrong. If the native card works fine, then there could be a bug in Mesa. I honestly don't know how Mesa works with regard to emulated 3d acceleration in a VM host, but I don't think that is a primary use case so I would say you are now the lead developer in that area. - djgandy

2 Answers

0
votes

Did you check that you've got a valid OpenGL context being active when this code is called? The values you get back may be uninitialized garbage left in the variables, which values don't get modified if glGetTexLevelParameter fails for some reason. Note that glGetErrors may return GL_NO_ERROR if there's no OpenGL context active.

To check if there's a OpenGL context use wglGetCurrentContext (Windows), glXGetCurrentContext (X11 / GLX) or CGLGetCurrentContext (MacOS X CGL) to query the active OpenGL context; if there's none active all of these functions will return NULL.


Just FYI: You should use GLint for retrieval of integer values from OpenGL, the reason for that is, the the OpenGL types have very specific sizes, which may differ from the primitive C types of the same name. For example a C unsigned int may vary between 16 to 64 bits in size, while a OpenGL GLuint always is fixed to 32 bits.

0
votes

https://www.opengl.org/sdk/docs/man/docbook4/xhtml/glGetTexLevelParameter.xml

glGetTexLevelParameter returns the texture level parameters for the active texture unit.

Try glActiveTexture on all the units. See if you are getting default values.