protected virtual void DestroyFrameBuffer() { AssertValid(); AssertContext(); EAGLContext oldContext = EAGLContext.CurrentContext; if (!GraphicsContext.IsCurrent) { MakeCurrent(); } DeleteBuffers(); if (oldContext != EAGLContext) { EAGLContext.SetCurrentContext(oldContext); } else { EAGLContext.SetCurrentContext(null); } GraphicsContext.Dispose(); GraphicsContext = null; gl = null; }
protected virtual void CreateFrameBuffer() { AssertValid(); if (LayerColorFormat == null) { throw new InvalidOperationException("Set the LayerColorFormat property to an EAGLColorFormat value before calling Run()."); } CAEAGLLayer eaglLayer = (CAEAGLLayer)Layer; eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys( new NSObject [] { NSNumber.FromBoolean(LayerRetainsBacking), LayerColorFormat }, new NSObject [] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat } ); ConfigureLayer(eaglLayer); GraphicsContext = Utilities.CreateGraphicsContext(ContextRenderingApi); gl = GLCalls.GetGLCalls(ContextRenderingApi); gl.GenFramebuffers(1, ref framebuffer); gl.BindFramebuffer(All.FramebufferOes, framebuffer); gl.GenRenderbuffers(1, ref renderbuffer); gl.BindRenderbuffer(All.RenderbufferOes, renderbuffer); if (!EAGLContext.RenderBufferStorage((uint)All.RenderbufferOes, eaglLayer)) { throw new InvalidOperationException("Error with EAGLContext.RenderBufferStorage!"); } gl.FramebufferRenderbuffer(All.FramebufferOes, All.ColorAttachment0Oes, All.RenderbufferOes, renderbuffer); Size newSize = new Size( (int)Math.Round(eaglLayer.Bounds.Size.Width), (int)Math.Round(eaglLayer.Bounds.Size.Height)); Size = newSize; gl.Viewport(0, 0, newSize.Width, newSize.Height); gl.Scissor(0, 0, newSize.Width, newSize.Height); frameBufferWindow = new WeakReference(Window); frameBufferLayer = new WeakReference(Layer); }