Пример #1
0
        protected override void CreateFrameBuffer()
        {
            Android.Util.Log.Debug("MonoGame", "AndroidGameWindow.CreateFrameBuffer");
            try
            {
                GLContextVersion = GLContextVersion.Gles2_0;
                try
                {
                    base.CreateFrameBuffer();
                }
                catch (Exception)
                {
                    // try again using a more basic mode which hopefully the device will support
                    GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);
                    base.CreateFrameBuffer();
                }
                All status = GL.CheckFramebufferStatus(All.Framebuffer);
                Android.Util.Log.Debug("MonoGame", "Framebuffer Status: " + status.ToString());
            }
            catch (Exception)
            {
                throw new NotSupportedException("Could not create OpenGLES 2.0 frame buffer");
            }
            if (_game.GraphicsDevice != null && _contextWasLost)
            {
                _game.GraphicsDevice.Initialize();

                _isResuming = true;
                if (_resumer != null)
                {
                    _resumer.LoadContent();
                }

                // Reload textures on a different thread so the resumer can be drawn
                System.Threading.Thread bgThread = new System.Threading.Thread(
                    o =>
                {
                    Android.Util.Log.Debug("MonoGame", "Begin reloading graphics content");
                    Microsoft.Xna.Framework.Content.ContentManager.ReloadGraphicsContent();
                    Android.Util.Log.Debug("MonoGame", "End reloading graphics content");

                    // DeviceReset events
                    _game.graphicsDeviceManager.OnDeviceReset(EventArgs.Empty);
                    _game.GraphicsDevice.OnDeviceReset();

                    _contextWasLost = false;
                    _isResuming     = false;
                });

                bgThread.Start();
            }

            MakeCurrent();
        }
Пример #2
0
        protected override void CreateFrameBuffer()
        {
            Android.Util.Log.Debug("MonoGame", "AndroidGameWindow.CreateFrameBuffer");
            try
            {
                GLContextVersion = GLContextVersion.Gles2_0;
                try
                {
                    int depth   = 0;
                    int stencil = 0;
                    switch (this._game.graphicsDeviceManager.PreferredDepthStencilFormat)
                    {
                    case DepthFormat.Depth16:
                        depth = 16;
                        break;

                    case DepthFormat.Depth24:
                        depth = 24;
                        break;

                    case DepthFormat.Depth24Stencil8:
                        depth   = 24;
                        stencil = 8;
                        break;

                    case DepthFormat.None: break;
                    }
                    Android.Util.Log.Debug("MonoGame", string.Format("Creating Color:Default Depth:{0} Stencil:{1}", depth, stencil));
                    GraphicsMode = new AndroidGraphicsMode(new ColorFormat(8, 8, 8, 8), depth, stencil, 0, 0, false);
                    base.CreateFrameBuffer();
                }
                catch (Exception)
                {
                    Android.Util.Log.Debug("MonoGame", "Failed to create desired format, falling back to defaults");
                    // try again using a more basic mode with a 16 bit depth buffer which hopefully the device will support
                    GraphicsMode = new AndroidGraphicsMode(new ColorFormat(0, 0, 0, 0), 16, 0, 0, 0, false);
                    try {
                        base.CreateFrameBuffer();
                    } catch (Exception) {
                        // ok we are right back to getting the default
                        GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);
                        base.CreateFrameBuffer();
                    }
                }
                Android.Util.Log.Debug("MonoGame", "Created format {0}", this.GraphicsContext.GraphicsMode);
                All status = GL.CheckFramebufferStatus(All.Framebuffer);
                Android.Util.Log.Debug("MonoGame", "Framebuffer Status: " + status.ToString());
            }
            catch (Exception)
            {
                throw new NotSupportedException("Could not create OpenGLES 2.0 frame buffer");
            }
            if (_game.GraphicsDevice != null && _contextWasLost)
            {
                _game.GraphicsDevice.Initialize();

                _isResuming = true;
                if (_resumer != null)
                {
                    _resumer.LoadContent();
                }

                // Reload textures on a different thread so the resumer can be drawn
                System.Threading.Thread bgThread = new System.Threading.Thread(
                    o =>
                {
                    Android.Util.Log.Debug("MonoGame", "Begin reloading graphics content");
                    Microsoft.Xna.Framework.Content.ContentManager.ReloadGraphicsContent();
                    Android.Util.Log.Debug("MonoGame", "End reloading graphics content");

                    // DeviceReset events
                    _game.graphicsDeviceManager.OnDeviceReset(EventArgs.Empty);
                    _game.GraphicsDevice.OnDeviceReset();

                    _contextWasLost = false;
                    _isResuming     = false;
                });

                bgThread.Start();
            }

            MakeCurrent();
        }