private void CreateFramebuffer() { AssertNotDisposed(); AssertValidContext(); if (PreserveFrameBuffer) { return; } __renderbuffergraphicsContext.MakeCurrent(null); // HACK: GraphicsDevice itself should be calling // glViewport, so we shouldn't need to do it // here and then force the state into // GraphicsDevice. However, that change is a // ways off, yet. int unscaledViewportHeight = (int)Math.Round(Layer.Bounds.Size.Height); int unscaledViewportWidth = (int)Math.Round(Layer.Bounds.Size.Width); int previousRenderbuffer = 0; _glapi.GetInteger(All.RenderbufferBinding, ref previousRenderbuffer); _glapi.GenFramebuffers(1, ref _framebuffer); _glapi.BindFramebuffer(All.Framebuffer, _framebuffer); // Create our Depth buffer. Color buffer must be the last one bound GL.GenRenderbuffers(1, ref _depthbuffer); GL.BindRenderbuffer(All.Renderbuffer, _depthbuffer); GL.RenderbufferStorage(All.Renderbuffer, All.DepthComponent16, unscaledViewportWidth * (int)Layer.ContentsScale, unscaledViewportHeight * (int)Layer.ContentsScale); GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, _depthbuffer); _glapi.GenRenderbuffers(2, ref _colorbuffer); _glapi.BindRenderbuffer(All.Renderbuffer, _colorbuffer); var ctx = ((IGraphicsContextInternal)__renderbuffergraphicsContext).Implementation as iPhoneOSGraphicsContext; // TODO: EAGLContext.RenderBufferStorage returns false // on all but the first call. Nevertheless, it // works. Still, it would be nice to know why it // claims to have failed. ctx.EAGLContext.RenderBufferStorage((uint)All.Renderbuffer, Layer); _glapi.FramebufferRenderbuffer(All.Framebuffer, All.ColorAttachment0, All.Renderbuffer, _colorbuffer); var status = GL.CheckFramebufferStatus(All.Framebuffer); if (status != All.FramebufferComplete) { throw new InvalidOperationException( "Framebuffer was not created correctly: " + status); } _glapi.Viewport(0, 0, unscaledViewportWidth, unscaledViewportHeight); _glapi.Scissor(0, 0, unscaledViewportWidth, unscaledViewportHeight); var gds = (IGraphicsDeviceService)_platform.Game.Services.GetService( typeof(IGraphicsDeviceService)); if (gds != null && gds.GraphicsDevice != null) { var pp = gds.GraphicsDevice.PresentationParameters; int height = (int)(unscaledViewportHeight * Layer.ContentsScale); int width = (int)(unscaledViewportWidth * Layer.ContentsScale); if (this.NextResponder is iOSGameViewController) { DisplayOrientation supportedOrientations = OrientationConverter.Normalize((this.NextResponder as iOSGameViewController).SupportedOrientations); if ((supportedOrientations & DisplayOrientation.LandscapeRight) != 0 || (supportedOrientations & DisplayOrientation.LandscapeLeft) != 0) { height = (int)(Math.Min(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale); width = (int)(Math.Max(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale); } else { height = (int)(Math.Max(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale); width = (int)(Math.Min(unscaledViewportHeight, unscaledViewportWidth) * Layer.ContentsScale); } } pp.BackBufferHeight = height; pp.BackBufferWidth = width; gds.GraphicsDevice.Viewport = new Viewport( 0, 0, pp.BackBufferWidth, pp.BackBufferHeight); // FIXME: These static methods on GraphicsDevice need // to go away someday. gds.GraphicsDevice.glFramebuffer = _framebuffer; } if (Threading.BackgroundContext == null) { Threading.BackgroundContext = new MonoTouch.OpenGLES.EAGLContext(ctx.EAGLContext.API, ctx.EAGLContext.ShareGroup); } }
private void CreateFramebuffer() { AssertNotDisposed(); AssertValidContext(); _graphicsContext.MakeCurrent(null); int previousRenderbuffer = 0; _glapi.GetInteger(All.RenderbufferBinding, ref previousRenderbuffer); _glapi.GenRenderbuffers(1, ref _renderbuffer); _glapi.BindRenderbuffer(All.Renderbuffer, _renderbuffer); var ctx = ((IGraphicsContextInternal)_graphicsContext).Implementation as iPhoneOSGraphicsContext; // TODO: EAGLContext.RenderBufferStorage returns false // on all but the first call. Nevertheless, it // works. Still, it would be nice to know why it // claims to have failed. ctx.EAGLContext.RenderBufferStorage((uint)All.Renderbuffer, Layer); _glapi.GenFramebuffers(1, ref _framebuffer); _glapi.BindFramebuffer(All.Framebuffer, _framebuffer); _glapi.FramebufferRenderbuffer( All.Framebuffer, All.ColorAttachment0, All.Renderbuffer, _renderbuffer); // HACK: GraphicsDevice itself should be calling // glViewport, so we shouldn't need to do it // here and then force the state into // GraphicsDevice. However, that change is a // ways off, yet. int unscaledViewportWidth = (int)Math.Round(Layer.Bounds.Size.Width); int unscaledViewportHeight = (int)Math.Round(Layer.Bounds.Size.Height); _glapi.Viewport(0, 0, unscaledViewportWidth, unscaledViewportHeight); _glapi.Scissor(0, 0, unscaledViewportWidth, unscaledViewportHeight); var gds = (IGraphicsDeviceService)_platform.Game.Services.GetService( typeof(IGraphicsDeviceService)); if (gds != null && gds.GraphicsDevice != null) { gds.GraphicsDevice.Viewport = new Viewport( 0, 0, (int)(Layer.Bounds.Width * Layer.ContentsScale), (int)(Layer.Bounds.Height * Layer.ContentsScale)); } var status = _glapi.CheckFramebufferStatus(All.Framebuffer); if (status != All.FramebufferComplete) { throw new InvalidOperationException( "Framebuffer was not created correctly: " + status); } // FIXME: These static methods on GraphicsDevice need // to go away someday. GraphicsDevice.FrameBufferScreen = _framebuffer; }