I just want know how many video memory I have on android device. For this I create many times opengl texture and check glGetError() but always have no error, but I don't belive that this is possible have so many textures in memory. So here code:
int COUNT = 100500;
int[] textureHandle = new int[COUNT];
Bitmap bitmap = BitmapFactory.decodeResource(m_activity.getResources(), R.drawable.space);
for(int i = 0; i < COUNT; i++)
{
GLES20.glGenTextures(1, textureHandle, i);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureHandle[i]);
GLES20.glActiveTexture(textureHandle[i]);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmap, 0);
System.out.println("Error code " + GLES20.glGetError());
}
Why I can't get opengl OutOfMemory? Or maybe there is another way know how many VRAM I have on my Android device.
There's really no good way of doing this. The ES 2.0 spec says about the error condition (emphasis added):
This means that you can't rely on getting
GL_OUT_OF_MEMORY
.Mobile devices don't typically have VRAM in the same way desktop graphics cards do. But even if they did, VRAM for the texture would most likely not be allocated until you use the texture for rendering the first time. So while the posted loop is running, the driver would most likely not allocate any VRAM at all.
This is very much related to why reporting and handling out of memory conditions is so tricky in OpenGL. Like almost everything else OpenGL does, memory allocations can, and often do, happen asynchronously to the API calls. When for example a
glTexImage2D()
call returns, at least some of the memory that will be used for the texture may not have been allocated yet. This means that reporting allocation errors in a synchronous way is pretty much impossible.This is part of the reason why developers are interested in lower level APIs that allow them to have more control over memory management.
You could try the GL_KHR_debug extension if your device supports it. I don't have personal experience with it, but it looks like it might be able to tell you when you run out of memory.