android.opengl.GLES11Ext.glGenFramebuffersOES抛出UnsupportedOperationException

时间:2012-02-15 23:30:04

标签: android opengl-es framebuffer

我正在尝试在Honeycomb中使用静态android.opengl.GLES11Ext,但在尝试生成FBO时不断出现异常。下面的代码在使用khronus软件包的多个设备上运行良好,但无法使用android.opengl:

  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;
}

我想使用android.opengl包的原因是因为它暴露了我在某些设备上需要的GL_DEPTH24_STENCIL8_OES扩展。使用NVidea Tegra 2芯片组的设备可以正常使用上述代码。然而,来自AT& T的三星8.9“4g设备使用不支持GL_STENCIL_INDEX8_OES的Adreno 220芯片。但是它支持使用FBO支持GL_DEPTH24_STENCIL8_OES。我依靠专有的渲染引擎,目前只支持OpenGL ES 1.1。所以转向2.0并不容易或快。我如何使用扩展名为GL_DEPTH24_STENCIL8_OES的android.opengl包和OpenGL ES 1.1中的FBO?我已经谷歌搜索了几天,但还没有找到解决方案。

如果有人使用android.opengl包而不是khronos从Goolge实现了FrameBufferObjectActivity示例,那将会有很大帮助。

0 个答案:

没有答案