ClassCaseException on GL11ExtensionPack. Rendering to texture on OpenGL android

寵の児 提交于 2020-01-25 11:19:09

问题


I'm trying to render to a texture (really thought it would be easier than this!)

I found this resource: which seems to be exactly what I want

I'm getting a ClassCastException however, on GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;

Can anyone tell me why?

  public void renderToTexture(GLRenderer glRenderer, GL10 gl)
  {
    boolean checkIfContextSupportsExtension = checkIfContextSupportsExtension(gl, "GL_OES_framebuffer_object");
    if(checkIfContextSupportsExtension)
    {
      GL11ExtensionPack gl11ep = (GL11ExtensionPack) gl;

      int mFrameBuffer = createFrameBuffer(gl,texture.getWidth(), texture.getHeight(), texture.getGLID());

      gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, mFrameBuffer);

      gl.glClearColor(0f, 1f, 0f, 1f);

      gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
    }
  }

Issue fixed by removing setDebugFlags(GLSurfaceView.DEBUG_LOG_GL_CALLS);

However, its still not modifying the texture. I modified the code so all it does is clear the colour green, so the texture should become all green. Here is the createFrameBuffer method. I don't really understand everything thats going on in this :/

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 depthbuffer;
int[] renderbuffers = new int[1];
gl11ep.glGenRenderbuffersOES(1, renderbuffers, 0);
depthbuffer = renderbuffers[0];

gl11ep.glBindRenderbufferOES(GL11ExtensionPack.GL_RENDERBUFFER_OES, depthbuffer);
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, depthbuffer);

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));
  Log.v("error","Frame buffer not complete");
} else {
  gl11ep.glBindFramebufferOES(GL11ExtensionPack.GL_FRAMEBUFFER_OES, 0);
  return -1;
}
return framebuffer;

}


回答1:


Calling setDebugFlags on a GLSurfaceView to wrap the GL instance has/had the unfortunate sideeffect to not implementing all GL* interfaces. Unfortunately the issue does not state in which version this is fixed.



来源:https://stackoverflow.com/questions/9969163/classcaseexception-on-gl11extensionpack-rendering-to-texture-on-opengl-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!