private int setupRenderTextureAndRenderbuffer(int width, int height) { if (mTextureId != -1) { GLES20.GlDeleteTextures(1, new int[] { mTextureId }, 0); } if (mRenderbufferId != -1) { GLES20.GlDeleteRenderbuffers(1, new int[] { mRenderbufferId }, 0); } if (mFramebufferId != -1) { GLES20.GlDeleteFramebuffers(1, new int[] { mFramebufferId }, 0); } mTextureId = createTexture(width, height); checkGlError("setupRenderTextureAndRenderbuffer: create texture"); int[] renderbufferIds = new int[1]; GLES20.GlGenRenderbuffers(1, renderbufferIds, 0); GLES20.GlBindRenderbuffer(36161, renderbufferIds[0]); GLES20.GlRenderbufferStorage(36161, 33189, width, height); mRenderbufferId = renderbufferIds[0]; checkGlError("setupRenderTextureAndRenderbuffer: create renderbuffer"); int[] framebufferIds = new int[1]; GLES20.GlGenFramebuffers(1, framebufferIds, 0); GLES20.GlBindFramebuffer(36160, framebufferIds[0]); mFramebufferId = framebufferIds[0]; GLES20.GlFramebufferTexture2D(36160, 36064, 3553, mTextureId, 0); GLES20.GlFramebufferRenderbuffer(36160, 36096, 36161, renderbufferIds[0]); int status = GLES20.GlCheckFramebufferStatus(36160); if (status != 36053) { throw new Java.Lang.RuntimeException("Framebuffer is not complete: " + Java.Lang.Integer.ToHexString(status)); } GLES20.GlBindFramebuffer(36160, 0); return(framebufferIds[0]); }
private void create(int width, int height) { // FBO int[] ret = new int[1]; // frame buffer GLES20.GlGenFramebuffers(1, ret, 0); FBO = ret[0]; GLES20.GlBindFramebuffer(GLES20.GlFramebuffer, FBO); // depth buffer GLES20.GlGenRenderbuffers(1, ret, 0); RBOD = ret[0]; GLES20.GlBindRenderbuffer(GLES20.GlFramebuffer, RBOD); GLES20.GlRenderbufferStorage(GLES20.GlRenderbuffer, GLES20.GlDepthComponent16, width, height); GLES20.GlFramebufferRenderbuffer(GLES20.GlFramebuffer, GLES20.GlDepthAttachment, GLES20.GlRenderbuffer, RBOD); // color buffer (is texture) GLES20.GlPixelStorei(GLES20.GlUnpackAlignment, 1); GLES20.GlGenTextures(1, ret, 0); RBOC = ret[0]; GLES20.GlBindTexture(GLES20.GlTexture2d, RBOC); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapS, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureWrapT, GLES20.GlClampToEdge); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMagFilter, GLES20.GlLinear); GLES20.GlTexParameteri(GLES20.GlTexture2d, GLES20.GlTextureMinFilter, GLES20.GlLinear); GLES20.GlTexImage2D(GLES20.GlTexture2d, 0, GLES20.GlRgba, width, height, 0, GLES20.GlRgba, GLES20.GlUnsignedByte, null); GLES20.GlFramebufferTexture2D(GLES20.GlFramebuffer, GLES20.GlColorAttachment0, GLES20.GlTexture2d, RBOC, 0); if (GLES20.GlCheckFramebufferStatus(GLES20.GlFramebuffer) != GLES20.GlFramebufferComplete) { Log.Debug(TAG, "Fail to create FBO."); FBO = 0; RBOD = 0; RBOC = 0; } }
public virtual void Bind() { GLES20.GlBindRenderbuffer(GLES20.GlRenderbuffer, id); }