// This method is called everytime the context needs
        // to be recreated. Use it to set any egl-specific settings
        // prior to context creation
        //
        // In this particular case, we demonstrate how to set
        // the graphics mode and fallback in case the device doesn't
        // support the defaults
        protected override void CreateFrameBuffer()
        {
            ContextRenderingApi = GLVersion.ES2;
            // the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
            try {
                Log.Verbose("GLSharedContext20", "Loading with default settings");

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
                return;
            } catch (Exception ex) {
                Log.Verbose("GLSharedContext20", "{0}", ex);
            }

            // this is a graphics setting that sets everything to the lowest mode possible so
            // the device returns a reliable graphics setting.
            try {
                Log.Verbose("GLSharedContext20", "Loading with custom Android settings (low mode)");
                GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
                return;
            } catch (Exception ex) {
                Log.Verbose("GLSharedContext20", "{0}", ex);
            }
            throw new Exception("Can't load egl, aborting");
        }
Exemple #2
0
        // This method is called everytime the context needs
        // to be recreated. Use it to set any egl-specific settings
        // prior to context creation
        //
        // In this particular case, we demonstrate how to set
        // the graphics mode and fallback in case the device doesn't
        // support the defaults
        protected override void CreateFrameBuffer()
        {
            ContextRenderingApi = GLVersion.ES3;
            // the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
            try {
                Log.Verbose("GLCube", "Loading with default settings");

                // use multisample if possible
                GraphicsMode = new AndroidGraphicsMode(new ColorFormat(32), 16, 0, 4, 2, false);
                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
            } catch (Exception ex) {
                Log.Verbose("GLCube", "{0}", ex);
                // this is a graphics setting that sets everything to the lowest mode possible so
                // the device returns a reliable graphics setting.
                try {
                    Log.Verbose("GLCube", "Loading with custom Android settings (low mode)");
                    GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);

                    // if you don't call this, the context won't be created
                    base.CreateFrameBuffer();
                } catch (Exception ex1) {
                    Log.Verbose("GLCube", "{0}", ex1);
                    throw new Exception("Can't load egl, aborting");
                }
            }

            Console.WriteLine("OpenGL version: {0} GLSL version: {1}", GL.GetString(StringName.Version), GL.GetString(StringName.ShadingLanguageVersion));
            keys.LoadShaders();
            SetupProjection();
        }
Exemple #3
0
        private GLVersion GetMaximumSupportedProfile()
        {
            var window = ((AndroidWindow)this.WindowInfo);
            var mode   = new AndroidGraphicsMode(window.Display, (int)this.ContextRenderingApi, new GraphicsMode(32, 0, 0));

            using (var context = new AndroidGraphicsContext(mode, window, this.GraphicsContext, GLVersion.ES2, GraphicsContextFlags.Embedded))
            {
                mode.Initialize(window.Display, (int)this.ContextRenderingApi);
                window.CreateSurface(mode.Config);

                context.MakeCurrent(window);

                PlatformConfigurations.RendererName = GL.GetString(StringName.Renderer);

                int versionMajor, versionMinor;
                if (!OpenGLUtils.GetCurrentGLVersion(out versionMajor, out versionMinor))
                {
                    versionMajor = 2;
                    versionMinor = 0;
                }

                context.MakeCurrent(null);
                window.DestroySurface();

                if (versionMajor == 3)
                {
                    return((versionMinor >= 1) ? GLVersion.ES31 : GLVersion.ES3);
                }
                return(GLVersion.ES2);
            }
        }
Exemple #4
0
        protected override void CreateFrameBuffer()
        {
            ContextRenderingApi = GLVersion.ES3;

            // The default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
            try {
                base.CreateFrameBuffer();
                return;
            } catch {
                //Console.WriteLine("GLView.CreateFrameBuffer() threw an exception: " + ex);
            }

            // This is a graphics setting that sets everything to the lowest mode possible so
            // the device returns a reliable graphics setting.
            try {
                GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);

                base.CreateFrameBuffer();
                return;
            } catch {
                //Console.WriteLine("GLView.CreateFrameBuffer() threw an exception: " + ex);
            }

            throw new BackendException("Cannot initialize OpenGL ES 3.0 device");
        }
Exemple #5
0
        protected override void CreateFrameBuffer()
        {
            try
            {
                Log.Verbose("MonoNX", "Loading with default settings");

                base.CreateFrameBuffer();
                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("MonoNX", ex.ToString());
            }

            try
            {
                Log.Verbose("MonoNX", "Loading with custom Android settings (low mode)");
                GraphicsMode = new AndroidGraphicsMode();

                base.CreateFrameBuffer();
                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("MonoNX", ex.ToString());
            }

            throw new Exception("Can't load EGL, aborting");
        }
Exemple #6
0
        // This method is called everytime the context needs
        // to be recreated. Use it to set any egl-specific settings
        // prior to context creation
        protected override void CreateFrameBuffer()
        {
            // the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
            try
            {
                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();

                return;
            } catch (Exception ex)
            {
                Logger.Error(ex);
            }

            // Fallback modes
            // If the first attempt at initializing the surface with a default graphics
            // mode fails, then the app can try different configurations. Devices will
            // support different modes, and what is valid for one might not be valid for
            // another. If all options fail, you can set all values to 0, which will
            // ask for the first available configuration the device has without any
            // filtering.
            // After a successful call to base.CreateFrameBuffer(), the GraphicsMode
            // object will have its values filled with the actual values that the
            // device returned.


            // This is a setting that asks for any available 16-bit color mode with no
            // other filters. It passes 0 to the buffers parameter, which is an invalid
            // setting in the default OpenTK implementation but is valid in some
            // Android implementations, so the AndroidGraphicsMode object allows it.
            try
            {
                Logger.Debug("Loading with custom Android settings (low mode)");
                GraphicsMode = new AndroidGraphicsMode(16, 0, 0, 0, 0, false);

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
                return;
            } catch (Exception ex)
            {
                Logger.Error(ex);
            }

            // this is a setting that doesn't specify any color values. Certain devices
            // return invalid graphics modes when any color level is requested, and in
            // those cases, the only way to get a valid mode is to not specify anything,
            // even requesting a default value of 0 would return an invalid mode.
            try {
                Logger.Debug("Loading with no Android settings");
                GraphicsMode = new AndroidGraphicsMode(0, 4, 0, 0, 0, false);

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
                return;
            } catch (Exception ex)
            {
                Logger.Error(ex);
            }
            throw new Exception("Context create error, aborting");
        }
Exemple #7
0
 protected override void CreateFrameBuffer()
 {
     ContextRenderingApi = GLVersion.ES2;
     // the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
     try {
         Debug.Write("Creating framebuffer with default settings");
         // Enable stencil buffer
         GraphicsMode = new AndroidGraphicsMode(16, 16, 8, 0, 2, false);
         base.CreateFrameBuffer();
         return;
     } catch (Exception ex) {
         Debug.Write("{0}", ex);
     }
     // this is a graphics setting that sets everything to the lowest mode possible so
     // the device returns a reliable graphics setting.
     try {
         Debug.Write("Creating framebuffer with custom Android settings (low mode)");
         GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);
         base.CreateFrameBuffer();
         return;
     } catch (Exception ex) {
         Debug.Write("{0}", ex);
     }
     throw new Lime.Exception("Can't create framebuffer, aborting");
 }
Exemple #8
0
        protected override void CreateFrameBuffer()
        {
            Android.Util.Log.Debug("MonoGame", "MonoGameAndroidGameView.CreateFrameBuffer");
            try
            {
                GLContextVersion = GLContextVersion.Gles2_0;
                try
                {
                    int depth   = 0;
                    int stencil = 0;
                    switch (_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}", 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");
            }

            MakeCurrent();
        }
        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();
        }
        // This method is called everytime the context needs to be recreated.
        protected override void CreateFrameBuffer()
        {
            Log.Verbose("Sparrow", "AndroidGameWindow.CreateFrameBuffer");
            try
            {
                ContextRenderingApi = GLVersion.ES3;
                try
                {
                    GraphicsMode = new AndroidGraphicsMode(new ColorFormat(8, 8, 8, 8), 24, 0, 0, 0, false);
                    base.CreateFrameBuffer();
                }
                catch (Exception)
                {
                    Log.Verbose("Sparrow", "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();
                    }
                }
                Log.Verbose("Sparrow", "Created format " + GraphicsContext.GraphicsMode);
                FramebufferErrorCode status = GL.CheckFramebufferStatus(FramebufferTarget.Framebuffer);
                Log.Verbose("Sparrow", "Framebuffer Status: " + status);
            }
            catch (Exception)
            {
                throw new NotSupportedException("Could not create OpenGLES 3.0 frame buffer");
            }
            GL.Disable(EnableCap.CullFace);
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Dither);
            GL.Enable(EnableCap.Blend);

            MakeCurrent();
        }
Exemple #11
0
        protected override void CreateFrameBuffer()
        {
            GLContextVersion = GLContextVersion.Gles2_0;

            try {
                Log.Verbose("AndroidUI", "Loading with default settings");
                base.CreateFrameBuffer();
                return;
            } catch (Exception ex) {
                Log.Verbose("AndroidUI", "{0}", ex);
            }

            try {
                Log.Verbose("AndroidUI", "Loading with custom Android settings (low mode)");
                GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);
                base.CreateFrameBuffer();
                return;
            } catch (Exception ex) {
                Log.Verbose("AndroidUI", "{0}", ex);
            }
            throw new Exception("Can't load egl, aborting");
        }
Exemple #12
0
        // This method is called everytime the context needs
        // to be recreated. Use it to set any egl-specific settings
        // prior to context creation
        protected override void CreateFrameBuffer()
        {
            GLContextVersion = GLContextVersion.Gles2_0;

            // the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
            try
            {
                Log.Verbose("AxiomSampleBrowser", "Loading with default settings");
                //GraphicsMode = new AndroidGraphicsMode( new ColorFormat(8,8,8,8), 24, 8, 0, 2, false );

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();

                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("AxiomSampleBrowser", "{0}", ex);
            }

            // this is a graphics setting that sets everything to the lowest mode possible so
            // the device returns a reliable graphics setting.
            try
            {
                Log.Verbose("AxiomSampleBrowser", "Loading with custom Android settings (low mode)");
                GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("AxiomSampleBrowser", "{0}", ex);
            }
            throw new Exception("Can't load egl, aborting");
        }
Exemple #13
0
        // This method is called everytime the context needs
        // to be recreated. Use it to set any egl-specific settings
        // prior to context creation
        protected override void CreateFrameBuffer()
        {
            //essential, from https://github.com/xamarin/monodroid-samples/blob/master/GLTriangle20-1.0/PaintingView.cs
            ContextRenderingApi = GLVersion.ES2;

            // the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
            try
            {
                Log.Verbose("GLTriangle", "Loading with default settings");

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("GLTriangle", "{0}", ex);
            }

            // this is a graphics setting that sets everything to the lowest mode possible so
            // the device returns a reliable graphics setting.
            try
            {
                Log.Verbose("GLTriangle", "Loading with custom Android settings (low mode)");
                GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);

                // if you don't call this, the context won't be created
                base.CreateFrameBuffer();
                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("GLTriangle", "{0}", ex);
            }
            throw new Exception("Can't load egl, aborting");
        }
Exemple #14
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();
        }