Esempio n. 1
0
 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");
     }
 }
Esempio n. 2
0
        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
            });
        }