How to determine if texture loading was successful in OpenGL ES 2?

In the good old days of regular OpenGL, it was pretty easy to determine if the texture load was successful - after calling glTexImage2D, you can use glGetTexLevelParameteriv with GL_TEXTURE_WIDTH and GL_TEXTURE_HEIGHT as parameters. However, GLES does not seem to allow this, and as far as I can tell, it does not have a mechanism for determining whether the texture was really provided to the map (for example, glGetError is set only for things that will not succeed, unlike things that did not succeed).

The application I'm working on always limits the barrier between having enough VRAM available and (and often a lot of dynamically allocated FBOs, etc. flies, which complicates the situation even more), and if the important texture loading failed, I need to know Do I need to clear the non-essential texture and try again.

+4
source share
1 answer

I am afraid that at the moment this is not possible. All OpenGL state containing texture size has now been removed (according to GLES 2.0.25 specifications). As you correctly stated, there is no error loading the texture (this is sad in design). Proxy texts were deleted, and people reported that they were often not supported / interrupted on a PC class GPU. So what now?

You can try and read the contents of the texture back through the framebuffer object (maybe not the whole texture, but only corner points / every 32nd pixel / ...). It would not be very fast, but it should work. You might also be able to use frame fullness checking with an attached texture (but this, apparently, is limited only by the internal image format, which may or may not be installed if texture loading fails due to low memory - you will have to check this) .

You can (theoretically) determine the amount of available memory by creating a renderbuffer object, the specification states that glRenderbufferStorage () will end with GL_OUT_OF_MEMORY, so this should be fairly reliable.

It would be fairly easy to test the free space before distributing the texture, and then remove the rendering buffer (if successful), and then select the texture itself. Keep in mind that with mipmaps, the texture will take a little more than 1.33x for the base layer.

It would be even better to determine the available memory at application startup (perhaps after compiling shaders and allocating other objects where it is not easy to estimate the amount of memory) and monitor the distribution of objects to see how much memory is left. This seems complicated, but if OpenGL objects are wrapped in classes, it should be pretty easy.

+3
source

All Articles