void SetupBuffers() { GL.Disable(EnableCap.DepthTest); GL.EnableVertexAttribArray((int)AttributeIndex.Vertex); GL.VertexAttribPointer((int)AttributeIndex.Vertex, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0); GL.EnableVertexAttribArray((int)AttributeIndex.TextureCoordinates); GL.VertexAttribPointer((int)AttributeIndex.TextureCoordinates, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0); GL.GenFramebuffers(1, out frameBufferHandle); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBufferHandle); GL.GenRenderbuffers(1, out colorBufferHandle); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, colorBufferHandle); context.RenderBufferStorage((int)RenderbufferTarget.Renderbuffer, this); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferWidth, out backingWidth); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferHeight, out backingHeight); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, colorBufferHandle); if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete) { Console.WriteLine("Failed to make complete framebuffer object"); } }
private void PrepareGLContexts() { // create GL context glContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2); EAGLContext.SetCurrentContext(glContext); // create render buffer Gles.glGenRenderbuffers(1, ref renderBuffer); Gles.glBindRenderbuffer(Gles.GL_RENDERBUFFER, renderBuffer); glContext.RenderBufferStorage(Gles.GL_RENDERBUFFER, this); // create frame buffer Gles.glGenFramebuffers(1, ref framebuffer); Gles.glBindFramebuffer(Gles.GL_FRAMEBUFFER, framebuffer); Gles.glFramebufferRenderbuffer(Gles.GL_FRAMEBUFFER, Gles.GL_COLOR_ATTACHMENT0, Gles.GL_RENDERBUFFER, renderBuffer); // get the bits for SkiaSharp var glInterface = GRGlInterface.Create(); context = GRContext.CreateGl(glInterface); // finished EAGLContext.SetCurrentContext(null); recreateSurface = true; }
public override void LayoutSubviews() { // ISSUE: reference to a compiler-generated method base.LayoutSubviews(); if (GraphicsContext == null) { return; } var bounds = Bounds; if (Math.Round(bounds.Width) == Size.Width && Math.Round(bounds.Height) == Size.Height) { return; } if (!GraphicsContext.IsCurrent) { MakeCurrent(); } Size = new Size((int)bounds.Width, (int)bounds.Height); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderBuffer); if (!EAGLContext.RenderBufferStorage((uint)RenderbufferTarget.Renderbuffer, (CAEAGLLayer)Layer)) { throw new InvalidOperationException("Error with RenderbufferStorage()!"); } GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, RenderbufferTarget.Renderbuffer, frameBuffer); }
private void CreateFrameBuffer(CAEAGLLayer eaglLayer) { int oldRenderbuffer = 1; gl.GetInteger(All.RenderbufferBindingOes, out oldRenderbuffer); gl.GenRenderbuffers(1, out renderbuffer); gl.BindRenderbuffer(All.RenderbufferOes, renderbuffer); if (!EAGLContext.RenderBufferStorage((uint)All.RenderbufferOes, eaglLayer)) { gl.DeleteRenderbuffers(1, ref renderbuffer); renderbuffer = 0; gl.BindRenderbuffer(All.RenderbufferBindingOes, oldRenderbuffer); throw new InvalidOperationException("Error with EAGLContext.RenderBufferStorage!"); } gl.BindFramebuffer(All.FramebufferOes, framebuffer); 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); }
private bool CreateFrameBuffer() { var success = true; GL.Disable(EnableCap.DepthTest); GL.GenFramebuffers(1, out frameBuffer); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); GL.GenRenderbuffers(1, out colorBuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, colorBuffer); context.RenderBufferStorage((uint)All.Renderbuffer, (CAEAGLLayer)Layer); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferWidth, out renderBufferWidth); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferHeight, out renderBufferHeight); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, colorBuffer); if (GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer) != FramebufferErrorCode.FramebufferComplete) { Console.WriteLine("Failure with framebuffer generation"); success = false; } // Create a new CVOpenGLESTexture Cache videoTextureCache = CVOpenGLESTextureCache.FromEAGLContext(context); glProgram = CreateProgram(); return(success && (glProgram != 0)); }
/// <summary> /// ICreate an ES 2.0 context /// </summary> /// <param name='context'> /// Context. /// </param> /// <param name='drawable'> /// Drawable. /// </param> public void InitWithContext(EAGLContext context, CAEAGLLayer drawable) { GL.GenFramebuffers(1, out m_defaultFBOName); // Create default framebuffer object. The backing will be allocated for the current layer in resizeFromLayer GL.GenRenderbuffers(1, out m_colorRenderbuffer); GL.BindFramebuffer(FramebufferTarget.Framebuffer, m_defaultFBOName); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, m_colorRenderbuffer); m_context = context; // This call associates the storage for the current render buffer with the EAGLDrawable (our CAEGLLAyer) // allowing us to draw into a buffer that will later be rendered to the screen wherever the layer is //(which correspondes with our) view. m_context.RenderBufferStorage((uint)All.Renderbuffer, drawable); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, m_colorRenderbuffer); int backingWidth; int backingHeight; GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferWidth, out backingWidth); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferHeight, out backingHeight); GL.GenRenderbuffers(1, out m_depthRenderbuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, m_depthRenderbuffer); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, backingWidth, backingHeight); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, m_depthRenderbuffer); var frameBufferError = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer); if(frameBufferError != FramebufferErrorCode.FramebufferComplete) { throw new ApplicationException("Failed to make complete framebuffer object: " + frameBufferError); } InitWithDefaultFBO(m_defaultFBOName); }
private void ResizeGLContexts() { // nuke old buffers Gles.glDeleteRenderbuffers(1, ref renderBuffer); // re-create render buffer Gles.glGenRenderbuffers(1, ref renderBuffer); Gles.glBindRenderbuffer(Gles.GL_RENDERBUFFER, renderBuffer); glContext.RenderBufferStorage(Gles.GL_RENDERBUFFER, this); // re-link Gles.glFramebufferRenderbuffer(Gles.GL_FRAMEBUFFER, Gles.GL_COLOR_ATTACHMENT0, Gles.GL_RENDERBUFFER, renderBuffer); }
private void ResizeGLContexts() { // nuke old buffers GL.DeleteRenderbuffers(1, ref renderBuffer); // re-create render buffer GL.GenRenderbuffers(1, out renderBuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderBuffer); glContext.RenderBufferStorage((uint)RenderbufferTarget.Renderbuffer, this); // re-link GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, renderBuffer); }
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); int oldFramebuffer = 0, oldRenderbuffer = 1; gl.GetInteger(All.FramebufferBindingOes, ref oldFramebuffer); gl.GetInteger(All.RenderbufferBindingOes, ref oldRenderbuffer); gl.GenRenderbuffers(1, ref renderbuffer); gl.BindRenderbuffer(All.RenderbufferOes, renderbuffer); if (!EAGLContext.RenderBufferStorage((uint)All.RenderbufferOes, eaglLayer)) { gl.DeleteRenderbuffers(1, ref renderbuffer); renderbuffer = 0; gl.BindRenderbuffer(All.RenderbufferBindingOes, oldRenderbuffer); throw new InvalidOperationException("Error with EAGLContext.RenderBufferStorage!"); } gl.GenFramebuffers(1, ref framebuffer); gl.BindFramebuffer(All.FramebufferOes, framebuffer); 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); }
public IOSWindow(IOSAppDelegate appDelegate) { _displaySize = new Vector2Int( (int)UIScreen.MainScreen.NativeBounds.Size.Width, (int)UIScreen.MainScreen.NativeBounds.Size.Height ); _stopwatch = new Stopwatch(); _stopwatch2 = new Stopwatch(); // Create the window Window = new UIWindow(UIScreen.MainScreen.Bounds); Window.RootViewController = new NozNavigationController(); Window.BackgroundColor = UIColor.White; Window.MakeKeyAndVisible(); appDelegate.Window = Window; // Create GL context GLContext = new EAGLContext(EAGLRenderingAPI.OpenGLES3); EAGLContext.SetCurrentContext(GLContext); // Create teh view _view = new NozView(this, Window.Bounds); _view.MultipleTouchEnabled = true; _view.UserInteractionEnabled = true; Window.AddSubview(_view); Graphics.Driver = OpenGLDriver.Create(); // Create render buffer.. _renderBufferId = GL.GenRenderBuffer(); GL.BindRenderBuffer(_renderBufferId); GLContext.RenderBufferStorage((uint)GL.Imports.GL_RENDERBUFFER, (CAEAGLLayer)_view.Layer); // Create frame buffer _frameBufferId = GL.GenFrameBuffer(); GL.BindFrameBuffer(_frameBufferId); GL.FrameBufferRenderBuffer(_renderBufferId); var link = CADisplayLink.Create(() => { Application.Step(); }); link.PreferredFramesPerSecond = 60; link.AddToRunLoop(NSRunLoop.Main, NSRunLoopMode.Default); }
void createBuffers() { GL.GenFramebuffers(1, out frameBuffer); GL.GenRenderbuffers(1, out renderBuffer); GL.BindFramebuffer(FramebufferTarget.Framebuffer, frameBuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderBuffer); context.RenderBufferStorage((uint)All.Renderbuffer, (CAEAGLLayer)Layer); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, renderBuffer); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferWidth, out backingWidth); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferHeight, out backingHeight); GL.GenRenderbuffers(1, out depthBuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthBuffer); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, backingWidth, backingHeight); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, depthBuffer); }
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] }); }
public override void LayoutSubviews() { // Called when the dimensions of our view change // E.g. When rotating the device and autoresizing var newSize = new System.Drawing.Size( (int)Math.Round(Layer.Bounds.Size.Width * Layer.ContentsScale), (int)Math.Round(Layer.Bounds.Size.Height * Layer.ContentsScale)); if (newSize.Width == 0 || newSize.Height == 0) { return; } CreateFrameBuffer(); if ((Framebuffer + depthbuffer + Renderbuffer == 0) || EAGLContext == null) { return; } Size = newSize; var eaglLayer = Layer as CAEAGLLayer; // Do not call base because iPhoneOSGameView:LayoutSubviews // destroys our graphics context // Instead we will manually rejig our buffer storage MakeCurrent(); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, Renderbuffer); EAGLContext.RenderBufferStorage((uint)All.Renderbuffer, eaglLayer); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, Renderbuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, depthbuffer); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, newSize.Width, newSize.Height); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, depthbuffer); platformInitialised = true; LoadGame(); }
private void PrepareGLContexts() { // create GL context glContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2); EAGLContext.SetCurrentContext(glContext); // create render buffer GL.GenRenderbuffers(1, out renderBuffer); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, renderBuffer); glContext.RenderBufferStorage((uint)RenderbufferTarget.Renderbuffer, this); // create frame buffer GL.GenFramebuffers(1, out framebuffer); GL.BindFramebuffer(FramebufferTarget.Framebuffer, framebuffer); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, renderBuffer); // get the bits for SkiaSharp var glInterface = GRGlInterface.CreateNativeGlInterface(); context = GRContext.Create(GRBackend.OpenGL, glInterface); // finished EAGLContext.SetCurrentContext(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); int major = 0, minor = 0; switch (ContextRenderingApi) { case EAGLRenderingAPI.OpenGLES1: major = 1; minor = 1; break; case EAGLRenderingAPI.OpenGLES2: major = 2; minor = 0; break; case EAGLRenderingAPI.OpenGLES3: major = 3; minor = 0; break; default: throw new ArgumentException("Unsupported EAGLRenderingAPI version: " + ContextRenderingApi); } GraphicsContext = new GraphicsContext(GraphicsMode.Default, WindowInfo, major, minor, GraphicsContextFlags.Embedded); GraphicsContext.MakeCurrent(WindowInfo); gl = GLCalls.GetGLCalls(ContextRenderingApi); int oldFramebuffer = 0, oldRenderbuffer = 1; gl.GetInteger(All.FramebufferBindingOes, out oldFramebuffer); gl.GetInteger(All.RenderbufferBindingOes, out oldRenderbuffer); gl.GenRenderbuffers(1, out renderbuffer); gl.BindRenderbuffer(All.RenderbufferOes, renderbuffer); if (!EAGLContext.RenderBufferStorage((uint)All.RenderbufferOes, eaglLayer)) { gl.DeleteRenderbuffers(1, ref renderbuffer); renderbuffer = 0; gl.BindRenderbuffer(All.RenderbufferBindingOes, oldRenderbuffer); throw new InvalidOperationException("Error with EAGLContext.RenderBufferStorage!"); } gl.GenFramebuffers(1, out framebuffer); gl.BindFramebuffer(All.FramebufferOes, framebuffer); 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); }
void Initialize(bool isNewContext) { MultipleTouchEnabled = true; // set layer to 32-bit RGBA var layer = (CAEAGLLayer)this.Layer; if (!isNewContext) { GL.DeleteRenderbuffers(1, ref _db); GL.DeleteRenderbuffers(1, ref _cb); } else { layer.Opaque = true; var layerProps = new NSDictionary( EAGLDrawableProperty.ColorFormat, EAGLColorFormat.RGBA8); layer.DrawableProperties = layerProps; // configure context _glContext = new EAGLContext(EAGLRenderingAPI.OpenGLES2); EAGLContext.SetCurrentContext(_glContext); this.ContentScaleFactor = this.Layer.ContentsScale = UIScreen.MainScreen.Scale; // set up framebuffer GL.GenFramebuffers(1, out _fb); _size = new Vector2(this.Bounds.Width, this.Bounds.Height); _threadPaused = true; } GL.BindFramebuffer(FramebufferTarget.Framebuffer, _fb); // set up color render buffer and bind storage GL.GenRenderbuffers(1, out _cb); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _cb); _glContext.RenderBufferStorage((uint)RenderbufferTarget.Renderbuffer, layer); // get the surface size in pixels, not points int width, height; GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferWidth, out width); GL.GetRenderbufferParameter(RenderbufferTarget.Renderbuffer, RenderbufferParameterName.RenderbufferHeight, out height); // set up depth render buffer and bind storage GL.GenRenderbuffers(1, out _db); GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _db); GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, width, height); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.ColorAttachment0, RenderbufferTarget.Renderbuffer, _cb); GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, _db); // set up viewport GL.Viewport(0, 0, width, height); if (isNewContext) { _alContext = new AudioContext(); _alContext.MakeCurrent(); this.MultipleTouchEnabled = false; _frame = new FrameArgs(); _events = new ConcurrentQueue <EventBase>(); _events.Enqueue(new Start(_size, PixelScale)); _events.Enqueue(new Resize(_size, PixelScale)); } Assets.PixelScale = PixelScale; }
private void CreateFrameBuffer() { // Setup layer eaglLayer = (CAEAGLLayer)this.Layer; eaglLayer.Opaque = false; bool layerRetainsBacking = false; NSString layerColorFormat = EAGLColorFormat.RGBA8; eaglLayer.DrawableProperties = NSDictionary.FromObjectsAndKeys(new NSObject[] { NSNumber.FromBoolean(layerRetainsBacking), layerColorFormat }, new NSObject[] { EAGLDrawableProperty.RetainedBacking, EAGLDrawableProperty.ColorFormat }); // Create OpenGL drawing context EAGLRenderingAPI api = EAGLRenderingAPI.OpenGLES2; context = new EAGLContext(api); if (context == null) { throw new InvalidOperationException("Failed to initialize OpenGLES 2.0 context"); } if (!EAGLContext.SetCurrentContext(context)) { throw new InvalidOperationException("Failed to set current OpenGL context"); } // Create render buffer and assign it to the context GL.GenRenderbuffers(1, ref colorRenderBuffer); GL.BindRenderbuffer(All.Renderbuffer, colorRenderBuffer); context.RenderBufferStorage((uint)All.Renderbuffer, eaglLayer); // Create frame buffer uint frameBuffer = 0; GL.GenFramebuffers(1, ref frameBuffer); GL.BindFramebuffer(All.Framebuffer, frameBuffer); GL.FramebufferRenderbuffer(All.Framebuffer, All.ColorAttachment0, All.Renderbuffer, colorRenderBuffer); // Set viewport Size size = new Size((int)Math.Round((double)eaglLayer.Bounds.Size.Width), (int)Math.Round((double)eaglLayer.Bounds.Size.Height)); GL.Viewport(0, 0, size.Width, size.Height); // Create CADisplayLink for animation loop displayLink = CADisplayLink.Create(this, new Selector("render")); displayLink.FrameInterval = 1; displayLink.AddToRunLoop(NSRunLoop.Current, NSRunLoop.NSDefaultRunLoopMode); }