Ejemplo n.º 1
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 ()
		{
			ContextRenderingApi = GLVersion.ES1;

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

				// if you don't call this, the context won't be created
				base.CreateFrameBuffer ();
				return;
			} 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 ();
				return;
			} catch (Exception ex) {
				Log.Verbose ("GLCube", "{0}", ex);
			}
			throw new Exception ("Can't load egl, aborting");
		}
Ejemplo n.º 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 ();
		}
Ejemplo n.º 3
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 ("TexturedCube", "Loading with default settings");

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

            // this is a slightly lower setting that disables depth buffers and sets buffers to 0,
            // which is invalid in OpenTK itself by default but allowed in some devices on
            // Android
            try {
                Log.Verbose ("TexturedCube", "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) {
                Log.Verbose ("TexturedCube", "{0}", ex);
            }
            throw new Exception ("Can't load egl, aborting");
        }
        // 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();
        }
Ejemplo n.º 5
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");
		}
Ejemplo n.º 6
0
        protected override void CreateFrameBuffer()
        {
            if (GraphicsMode != null && !(GraphicsMode is AndroidGraphicsMode))
#if OPENTK_0
            { GraphicsMode = new AndroidGraphicsMode(windowInfo.Display, (int)GLContextVersion - 1, GraphicsMode); }
#else
            { GraphicsMode = new AndroidGraphicsMode(windowInfo.Display, (int)ContextRenderingApi, GraphicsMode); }
#endif
            if (Mode == null)
#if OPENTK_0
            { GraphicsMode = new AndroidGraphicsMode(windowInfo.Display, (int)GLContextVersion - 1, new GraphicsMode()); }
            Mode.Initialize(windowInfo.Display, (int)GLContextVersion - 1);
#else
            { GraphicsMode = new AndroidGraphicsMode(windowInfo.Display, (int)ContextRenderingApi, new GraphicsMode()); }
            Mode.Initialize(windowInfo.Display, (int)ContextRenderingApi);
#endif
            windowInfo.CreateSurface(Mode.Config);
            hasSurface = true;

            if (RenderOnUIThread)
            {
                MakeCurrent();
            }
        }
Ejemplo n.º 7
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 ()
		{
			ContextRenderingApi = GLVersion.ES3;

			try {
				Log.Verbose ("TexturedCube", "Loading with high quality settings");

				GraphicsMode = new GraphicsMode (new ColorFormat (32), 24, 0, 0); 
				// if you don't call this, the context won't be created
				base.CreateFrameBuffer ();
				return;
			} catch (Exception ex) {
				Log.Verbose ("TexturedCube", "{0}", ex);
			}

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

				// if you don't call this, the context won't be created
				base.CreateFrameBuffer ();
				return;
			} catch (Exception ex) {
				Log.Verbose ("TexturedCube", "{0}", 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 {
				Log.Verbose ("TexturedCube", "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) {
				Log.Verbose ("TexturedCube", "{0}", 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 {
				Log.Verbose ("TexturedCube", "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) {
				Log.Verbose ("TexturedCube", "{0}", ex);
			}
			throw new Exception ("Can't load egl, aborting");
		}
Ejemplo n.º 8
0
		void Init (GraphicsMode mode, IWindowInfo win, IGraphicsContext sharedContext,
										int major, int minor, GraphicsContextFlags flags)
		{
			window = win as AndroidWindow;
			if (window == null)
				throw new ArgumentException ("win");

			AndroidGraphicsContext shared = sharedContext as AndroidGraphicsContext;

			egl = EGLContext.EGL.JavaCast<IEGL10> ();

			window.InitializeDisplay ();

			if (mode == null)
				mode = new GraphicsMode ();

			if (mode is AndroidGraphicsMode) {
				GraphicsMode = mode;
			} else {
				GraphicsMode = new AndroidGraphicsMode (window.Display, major, mode);
			}

			if (shared != null && !PBufferSupported)
				throw new EglException ("Multiple Context's are not supported by this device");

			if (Mode.Config == null)
				Mode.Initialize (window.Display, major);

			/*
			 * Create an OpenGL ES context. We want to do this as rarely as possible, an
			 * OpenGL context is a somewhat heavy object.
			 */
			int EglContextClientVersion = 0x3098;
			int EglContextMinorVersion = 0x30fb;
			int[] attribList = null;
			if (major >= 2) {
				string extensions = egl.EglQueryString (window.Display, Egl.Egl.EXTENSIONS);
				if (minor > 0 && !string.IsNullOrEmpty (extensions) && extensions.Contains ("EGL_KHR_create_context")) {
					attribList = new int [] { EglContextClientVersion, major,
						EglContextMinorVersion, minor,
						EGL10.EglNone
					};
				} else {
					attribList = new int [] { EglContextClientVersion, major,
						EGL10.EglNone
					};
				}
			}

			EGLContext = egl.EglCreateContext (window.Display,
						EGLConfig,
						shared != null && shared.EGLContext != null ? shared.EGLContext : EGL10.EglNoContext,
						attribList);

			if (EGLContext == EGL10.EglNoContext)
				throw EglException.GenerateException ("EglCreateContext == EGL10.EglNoContext", egl, null);

			if (shared != null && shared.EGLContext != null) {
				egl.EglMakeCurrent (window.Display, EGL10.EglNoSurface, EGL10.EglNoSurface, EGL10.EglNoContext);
				int[] pbufferAttribList = new int [] { EGL10.EglWidth, 64, EGL10.EglHeight, 64, EGL10.EglNone };
				surface = window.CreatePBufferSurface (EGLConfig, pbufferAttribList);
				if (surface == EGL10.EglNoSurface)
					throw new EglException ("Could not create PBuffer for shared context!");
			}
		}
Ejemplo n.º 9
0
        // Copied from GLTriangle20 example
        protected override void CreateFrameBuffer()
        {
            GLContextVersion = GLContextVersion.Gles3_0;

            // the default GraphicsMode that is set consists of (16, 16, 0, 0, 2, false)
            try
            {
                Log.Verbose("RAVC", "Loading with default settings");
                GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);
                base.CreateFrameBuffer();
                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("RAVC", "{0}", ex);
            }

            try
            {
                Log.Verbose("RAVC", "Loading with custom Android settings (low mode)");
                GraphicsMode = new AndroidGraphicsMode(0, 0, 0, 0, 0, false);
                base.CreateFrameBuffer();
                return;
            }
            catch (Exception ex)
            {
                Log.Verbose("GLTriangle", "{0}", ex);
            }
            throw new Exception("Can't load egl, aborting");
        }
Ejemplo n.º 10
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();
		}
Ejemplo n.º 11
0
        void Init(GraphicsMode mode, IWindowInfo win, IGraphicsContext sharedContext,
                  int major, int minor, GraphicsContextFlags flags)
        {
            window = win as AndroidWindow;
            if (window == null)
            {
                throw new ArgumentException("win");
            }

            AndroidGraphicsContext shared = sharedContext as AndroidGraphicsContext;

            egl = EGLContext.EGL.JavaCast <IEGL10> ();

            window.InitializeDisplay();

            if (mode == null)
            {
                mode = new GraphicsMode();
            }

            if (mode is AndroidGraphicsMode)
            {
                GraphicsMode = mode;
            }
            else
            {
                GraphicsMode = new AndroidGraphicsMode(window.Display, major, mode);
            }

            if (shared != null && !PBufferSupported)
            {
                throw new EglException("Multiple Context's are not supported by this device");
            }

            if (Mode.Config == null)
            {
                Mode.Initialize(window.Display, major);
            }

            /*
             * Create an OpenGL ES context. We want to do this as rarely as possible, an
             * OpenGL context is a somewhat heavy object.
             */
            int EglContextClientVersion = 0x3098;
            int EglContextMinorVersion  = 0x30fb;

            int[] attribList = null;
            if (major >= 2)
            {
                string extensions = egl.EglQueryString(window.Display, Egl.Egl.EXTENSIONS);
                if (minor > 0 && !string.IsNullOrEmpty(extensions) && extensions.Contains("EGL_KHR_create_context"))
                {
                    attribList = new int [] { EglContextClientVersion, major,
                                              EglContextMinorVersion, minor,
                                              EGL10.EglNone };
                }
                else
                {
                    attribList = new int [] { EglContextClientVersion, major,
                                              EGL10.EglNone };
                }
            }

            EGLContext = egl.EglCreateContext(window.Display,
                                              EGLConfig,
                                              shared != null && shared.EGLContext != null ? shared.EGLContext : EGL10.EglNoContext,
                                              attribList);

            if (EGLContext == EGL10.EglNoContext)
            {
                throw EglException.GenerateException("EglCreateContext == EGL10.EglNoContext", egl, null);
            }

            if (shared != null && shared.EGLContext != null)
            {
                egl.EglMakeCurrent(window.Display, EGL10.EglNoSurface, EGL10.EglNoSurface, EGL10.EglNoContext);
                int[] pbufferAttribList = new int [] { EGL10.EglWidth, 64, EGL10.EglHeight, 64, EGL10.EglNone };
                surface = window.CreatePBufferSurface(EGLConfig, pbufferAttribList);
                if (surface == EGL10.EglNoSurface)
                {
                    throw new EglException("Could not create PBuffer for shared context!");
                }
            }
        }
Ejemplo n.º 12
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);

                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;
            }
        }
Ejemplo n.º 13
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();
                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;
            }

            MakeCurrent();
		}
Ejemplo n.º 14
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();
        }
Ejemplo n.º 15
0
        private GraphicsProfile GetMaximumSupportedProfile()
        {
            var profile = GraphicsProfile.Level_9_1;

            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);

                var versionVendorText = GL.GetString(StringName.Version);
                var match = MatchOpenGLVersion.Match(versionVendorText);
                if (match.Success)
                {
                    var versionText = match.Groups[1].Value;
                    if (versionText.StartsWith("2"))
                    {
                        profile = GraphicsProfile.Level_9_1;
                    }
                    else if (versionText.StartsWith("3.1"))
                    {
                        profile = GraphicsProfile.Level_10_0;
                    }
                    else if (versionText.StartsWith("3"))
                    {
                        profile = GraphicsProfile.Level_10_0;
                    }
                }

                context.MakeCurrent(null);
                window.DestroySurface();
            }
            return profile;
        }