コード例 #1
0
ファイル: iOSGameView.cs プロジェクト: play3577/PixelVision8
        private void CreateFramebuffer()
        {
            this.MakeCurrent();

            // 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 viewportHeight = (int)Math.Round(Layer.Bounds.Size.Height * Layer.ContentsScale);
            int viewportWidth  = (int)Math.Round(Layer.Bounds.Size.Width * Layer.ContentsScale);

            _glapi.GenFramebuffers(1, ref _framebuffer);
            _glapi.BindFramebuffer(FramebufferTarget.Framebuffer, _framebuffer);

            // Create our Depth buffer. Color buffer must be the last one bound
            var gdm = _platform.Game.Services.GetService(
                typeof(IGraphicsDeviceManager)) as GraphicsDeviceManager;

//            if (gdm != null)
//            {
//                var preferredDepthFormat = gdm.PreferredDepthStencilFormat;
//                if (preferredDepthFormat != DepthFormat.None)
//                {
//                    GL.GenRenderbuffers(1, out _depthbuffer);
//                    GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _depthbuffer);
//                    var internalFormat = RenderbufferStorage.DepthComponent16;
//                    if (preferredDepthFormat == DepthFormat.Depth24)
//                        internalFormat = RenderbufferStorage.DepthComponent24Oes;
//                    else if (preferredDepthFormat == DepthFormat.Depth24Stencil8)
//                        internalFormat = RenderbufferStorage.Depth24Stencil8Oes;
//                    GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, internalFormat, viewportWidth, viewportHeight);
//                    GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.DepthAttachment, RenderbufferTarget.Renderbuffer, _depthbuffer);
//                    if (preferredDepthFormat == DepthFormat.Depth24Stencil8)
//                        GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.StencilAttachment, RenderbufferTarget.Renderbuffer, _depthbuffer);
//                }
//            }

            _glapi.GenRenderbuffers(1, ref _colorbuffer);
            _glapi.BindRenderbuffer(RenderbufferTarget.Renderbuffer, _colorbuffer);

            var ctx = __renderbuffergraphicsContext as GraphicsContext;

            // 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.Context.RenderBufferStorage((uint)RenderbufferTarget.Renderbuffer, Layer);

            _glapi.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, RenderbufferTarget.Renderbuffer, _colorbuffer);

            var status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);

            if (status != FramebufferErrorCode.FramebufferComplete)
            {
                throw new InvalidOperationException(
                          "Framebuffer was not created correctly: " + status);
            }

            _glapi.Viewport(0, 0, viewportWidth, viewportHeight);
            _glapi.Scissor(0, 0, viewportWidth, viewportHeight);

            var gds = _platform.Game.Services.GetService(
                typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;

            if (gds != null && gds.GraphicsDevice != null)
            {
                var pp     = gds.GraphicsDevice.PresentationParameters;
                int height = viewportHeight;
                int width  = viewportWidth;

                if (this.NextResponder is iOSGameViewController)
                {
                    var displayOrientation = _platform.Game.Window.CurrentOrientation;
                    if (displayOrientation == DisplayOrientation.LandscapeLeft || displayOrientation == DisplayOrientation.LandscapeRight)
                    {
                        height = Math.Min(viewportHeight, viewportWidth);
                        width  = Math.Max(viewportHeight, viewportWidth);
                    }
                    else
                    {
                        height = Math.Max(viewportHeight, viewportWidth);
                        width  = Math.Min(viewportHeight, viewportWidth);
                    }
                }

                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 OpenGLES.EAGLContext(ctx.Context.API, ctx.Context.ShareGroup);
            }
        }
コード例 #2
0
ファイル: iOSGameView.cs プロジェクト: DrPandemic/EraParadox
        private void CreateFramebuffer()
        {
            AssertNotDisposed();
            AssertValidContext();

            __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 viewportHeight = (int)Math.Round(Layer.Bounds.Size.Height * Layer.ContentsScale);
            int viewportWidth  = (int)Math.Round(Layer.Bounds.Size.Width * Layer.ContentsScale);

            _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, viewportWidth, viewportHeight);
            GL.FramebufferRenderbuffer(All.Framebuffer, All.DepthAttachment, All.Renderbuffer, _depthbuffer);

            _glapi.GenRenderbuffers(1, 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, viewportWidth, viewportHeight);
            _glapi.Scissor(0, 0, viewportWidth, viewportHeight);

            var gds = _platform.Game.Services.GetService(
                typeof(IGraphicsDeviceService)) as IGraphicsDeviceService;

            if (gds != null && gds.GraphicsDevice != null)
            {
                var pp     = gds.GraphicsDevice.PresentationParameters;
                int height = viewportHeight;
                int width  = viewportWidth;

                if (this.NextResponder is iOSGameViewController)
                {
                    var displayOrientation = _platform.Game.Window.CurrentOrientation;
                    if (displayOrientation == DisplayOrientation.LandscapeLeft || displayOrientation == DisplayOrientation.LandscapeRight)
                    {
                        height = Math.Min(viewportHeight, viewportWidth);
                        width  = Math.Max(viewportHeight, viewportWidth);
                    }
                    else
                    {
                        height = Math.Max(viewportHeight, viewportWidth);
                        width  = Math.Min(viewportHeight, viewportWidth);
                    }
                }

                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);
            }
        }
コード例 #3
0
        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;
        }