public void Dispose() { if (_disposed) { return; } _disposed = true; _gl.DeleteFramebuffer(_framebuffer); _gl.DeleteRenderbuffer(_depthBuffer); _gl.DeleteRenderbuffer(_renderbuffer); if (_context != EAGLContext.CurrentContext) { throw new InvalidOperationException("Associated EAGLContext is not current"); } }
public static LayerFbo TryCreate(EAGLContext context, GlInterface gl, CAEAGLLayer layer) { if (context != EAGLContext.CurrentContext) { return(null); } var rb = gl.GenRenderbuffer(); gl.BindRenderbuffer(GlConsts.GL_RENDERBUFFER, rb); context.RenderBufferStorage(GlConsts.GL_RENDERBUFFER, layer); var fb = gl.GenFramebuffer(); gl.BindFramebuffer(GlConsts.GL_FRAMEBUFFER, fb); gl.FramebufferRenderbuffer(GlConsts.GL_FRAMEBUFFER, GlConsts.GL_COLOR_ATTACHMENT0, GlConsts.GL_RENDERBUFFER, rb); gl.GetRenderbufferParameteriv(GlConsts.GL_RENDERBUFFER, GlConsts.GL_RENDERBUFFER_WIDTH, out var w); gl.GetRenderbufferParameteriv(GlConsts.GL_RENDERBUFFER, GlConsts.GL_RENDERBUFFER_HEIGHT, out var h); var db = gl.GenRenderbuffer(); //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); var frameBufferError = gl.CheckFramebufferStatus(GlConsts.GL_FRAMEBUFFER); if (frameBufferError != GlConsts.GL_FRAMEBUFFER_COMPLETE) { gl.DeleteFramebuffer(fb); gl.DeleteRenderbuffer(db); gl.DeleteRenderbuffer(rb); return(null); } return(new LayerFbo(context, gl, layer, fb, rb, db) { Width = w, Height = h }); }
void EnsureDepthBufferAttachment(GlInterface gl) { var size = GetPixelSize(); if (size == _depthBufferSize && _depthBuffer != 0) { return; } gl.GetIntegerv(GL_RENDERBUFFER_BINDING, out var oldRenderBuffer); if (_depthBuffer != 0) { gl.DeleteRenderbuffer(_depthBuffer); } _depthBuffer = gl.GenRenderbuffer(); gl.BindRenderbuffer(GL_RENDERBUFFER, _depthBuffer); gl.RenderbufferStorage(GL_RENDERBUFFER, GlVersion.Type == GlProfileType.OpenGLES ? GL_DEPTH_COMPONENT16 : GL_DEPTH_COMPONENT, size.Width, size.Height); gl.FramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, _depthBuffer); gl.BindRenderbuffer(GL_RENDERBUFFER, oldRenderBuffer); }