private bool CheckFramebufferStatus(GlInterface gl) { var status = gl.CheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) { int code; while ((code = gl.GetError()) != 0) { Logger.TryGet(LogEventLevel.Error, "OpenGL")?.Log("OpenGlControlBase", "Unable to initialize OpenGL FBO: {code}", code); } return(false); } return(true); }
public static LayerFbo TryCreate(EAGLContext context, GlInterface gl, CAEAGLLayer layer) { if (context != EAGLContext.CurrentContext) { return(null); } var fb = new int[2]; var rb = new int[2]; var db = new int[2]; gl.GenRenderbuffers(1, rb); gl.BindRenderbuffer(GlConsts.GL_RENDERBUFFER, rb[0]); context.RenderBufferStorage(GlConsts.GL_RENDERBUFFER, layer); gl.GenFramebuffers(1, fb); gl.BindFramebuffer(GlConsts.GL_FRAMEBUFFER, fb[0]); gl.FramebufferRenderbuffer(GlConsts.GL_FRAMEBUFFER, GlConsts.GL_COLOR_ATTACHMENT0, GlConsts.GL_RENDERBUFFER, rb[0]); int[] w = new int[1]; int[] h = new int[1]; gl.GetRenderbufferParameteriv(GlConsts.GL_RENDERBUFFER, GlConsts.GL_RENDERBUFFER_WIDTH, w); gl.GetRenderbufferParameteriv(GlConsts.GL_RENDERBUFFER, GlConsts.GL_RENDERBUFFER_HEIGHT, h); gl.GenRenderbuffers(1, db); //GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBuffer); //GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, w, h); gl.FramebufferRenderbuffer(GlConsts.GL_FRAMEBUFFER, GlConsts.GL_DEPTH_ATTACHMENT, GlConsts.GL_RENDERBUFFER, db[0]); var frameBufferError = gl.CheckFramebufferStatus(GlConsts.GL_FRAMEBUFFER); if (frameBufferError != GlConsts.GL_FRAMEBUFFER_COMPLETE) { gl.DeleteFramebuffers(1, fb); gl.DeleteRenderbuffers(1, db); gl.DeleteRenderbuffers(1, rb); return(null); } return(new LayerFbo(context, gl, layer, fb, rb, db) { Width = w[0], Height = h[0] }); }