Example #1
0
 public void MakeCurrent()
 {
     if (!EAGLContext.SetCurrentContext(mgleaglContext))
     {
         throw new InvalidOperationException("Unable to change current EAGLContext.");
     }
     GLHelper.CheckGLErrors();
 }
Example #2
0
        private void CreateFramebuffer()
        {
            if (framebuffer != 0)
            {
                return;
            }
            MakeCurrent();
            framebuffer = GL.GenFramebuffer();
            GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer);
            GLHelper.CheckGLErrors();

            colorRenderbuffer = GL.GenRenderbuffer();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, colorRenderbuffer);
            GLHelper.CheckGLErrors();

            var eaglLayer = (CAEAGLLayer)Layer;

            if (!mgleaglContext.RenderBufferStorage((uint)RenderbufferTarget.Renderbuffer, eaglLayer))
            {
                Logger.Write("Failed to bind render buffer with error: {0}", GL.GetErrorCode());
                //throw new InvalidOperationException("EAGLContext.RenderBufferStorage() failed");
            }

            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, colorRenderbuffer);
            GL.Viewport(0, 0, (int)ClientSize.X, (int)ClientSize.Y);
            GL.Scissor(0, 0, (int)ClientSize.X, (int)ClientSize.Y);
            GLHelper.CheckGLErrors();

            // Create a depth renderbuffer
            depthRenderbuffer = GL.GenRenderbuffer();
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthRenderbuffer);

            // Allocate storage for the new renderbuffer
            var scale = (float)UIScreen.MainScreen.Scale;

            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, (RenderbufferInternalFormat)All.Depth24Stencil8Oes,
                                   (int)(ClientSize.X * scale), (int)(ClientSize.Y * scale));
            // Attach the renderbuffer to the framebuffer's depth attachment point
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, depthRenderbuffer);
            // Attach the renderbuffer to the framebuffer's stencil attachment point
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.StencilAttachment, RenderbufferTarget.Renderbuffer, depthRenderbuffer);

            GL.ClearStencil(0);
            GL.ClearDepth(1.0f);

            GL.DepthFunc(DepthFunction.Lequal);
            GLHelper.CheckGLErrors();
        }
Example #3
0
 private void DestroyFramebuffer()
 {
     if (framebuffer == 0)
     {
         return;
     }
     MakeCurrent();
     GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, 0);
     GL.DeleteRenderbuffer(colorRenderbuffer);
     GL.DeleteRenderbuffer(depthRenderbuffer);
     GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0);
     GL.DeleteFramebuffer(framebuffer);
     GLHelper.CheckGLErrors();
     colorRenderbuffer = 0;
     depthRenderbuffer = 0;
     framebuffer       = 0;
     EAGLContext.SetCurrentContext(null);
 }