In my android application I have texture with mipmap array
final int[] textureHandle = new int[1];
GLES20.glGenTextures(1, textureHandle, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureHandle);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, filter);
GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
Initial size of texture is 1024x1024. I need get textures:
- 512x512 (level 1)
- 256x256 (level 2)
- 128x128 (level 3)
Has OpenGL
any api to access textures from mipmap array?
Full OpenGL has a
glGetTexImage()
call for this purpose. But it's not available in any version of OpenGL ES, up to the current ES 3.1.Without having this call, you can set the texture as an FBO attachment, and then read the content with
glReadPixels()
. To read levellev
:This approach is somewhat restricted because it will only work for texture formats that are color-renderable. Other formats will not be valid as FBO attachments. The only formats guaranteed to be color-renderable in ES 2.0 are
RGBA4444
,RGB5_A1
andRGB565
. Many devices have extensions that add support for formats likeRGB8
andRGBA8
.The next best approach is to render a quad with the texture, and then read the result with
glReadPixels()
. But you would have the same restrictions on the format of the render target. For example if your texture isRGBA8
, and your device does not support rendering toRGBA8
surfaces, you would lose precision with this approach.