I’m writing an Android app that is using a proprietary rendering engine written for OpenGL ES 1.1. The engine makes heavy use of the stencil buffer. We have tested our code on various devices using the nvidia Tegra 2 chipset and everything works wonderful. However, we came across a device which uses the Adreno 220 which doesn’t support a standalone stencil buffer. It does support a packed buffer combining the 24 bit depth buffer with an 8 bit stencil buffer in one construct. How can I create a valid FBO using OpenGL ES 1.1 with the needed extention? I can’t get the example from here http://www.khronos.org/registry/gles/extensions/OES/OES_packed_depth_stencil.txt to work, because javax.microedition.khronos.opengles.GL11ExtensionPack does not include GL_DEPTH_STENCIL_OES.
Here is the code that is working for hardware with standalone stencil buffer support:
private int createFrameBuffer(GL10 gl, int width, int height, int targetTextureId) {
GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;
int framebuffer;
int[] framebuffers = new int[1];
gl11ep.glGenFramebuffersOES(1, framebuffers, 0);
framebuffer = framebuffers[0];
gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, framebuffer);
int stencilBuffer;
int[] renderbuffers = new int[1];
gl11ep.glGenRenderbuffersOES(1, renderbuffers, 0);
stencilBuffer = renderbuffers[0];
gl11ep.glBindRenderbufferOES(GL11ExtensionPack.GL_RENDERBUFFER_OES, stencilBuffer);
if(mContextSupportsStencilBuffer) {
gl11ep.glRenderbufferStorageOES(GL11ExtensionPack.GL_RENDERBUFFER_OES, GL11ExtensionPack.GL_STENCIL_INDEX8_OES, width, height);
gl11ep.glFramebufferRenderbufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, GL11ExtensionPack.GL_STENCIL_ATTACHMENT_OES, GL11ExtensionPack.GL_RENDERBUFFER_OES, stencilBuffer);
}
else {
gl11ep.glRenderbufferStorageOES(GL11ExtensionPack.GL_RENDERBUFFER_OES, GL11ExtensionPack.GL_DEPTH_COMPONENT16, width, height);
gl11ep.glFramebufferRenderbufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES,GL11ExtensionPack.GL_DEPTH_ATTACHMENT_OES, GL11ExtensionPack.GL_RENDERBUFFER_OES, stencilBuffer);
}
gl11ep.glFramebufferTexture2DOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, GL11ExtensionPack.GL_COLOR_ATTACHMENT0_OES,GL10.GL_TEXTURE_2D, targetTextureId, 0);
int status = gl11ep.glCheckFramebufferStatusOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES);
if (status != GL11ExtensionPack.GL_FRAMEBUFFER_COMPLETE_OES) {
throw new RuntimeException("Framebuffer is not complete: " + Integer.toHexString(status));
}
gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
return framebuffer;
}