void CreateContext() { log("CreateContext"); if (!RenderOnUIThread && Thread.CurrentThread != renderingThread) { throw new Exception("CreateContext called from wrong thread"); } GraphicsContext = AndroidGraphicsContext.CreateGraphicsContext(GraphicsMode, WindowInfo, GraphicsContext, #if OPENTK_0 GLContextVersion, #else ContextRenderingApi, #endif GraphicsContextFlags.Embedded); }
/// <summary> /// /// </summary> /// <param name="eglDisplay"></param> /// <param name="support"></param> /// <param name="fbconfig"></param> /// <param name="drawable"></param> public AndroidContext( AndroidGraphicsContext glContext, AndroidSupport support ) { _glSupport = support; //_drawable = drawable; _context = glContext; //_config = fbconfig; //_eglDisplay = eglDisplay; //Contract.Requires(_drawable != null); //GLESRenderSystem rendersystem = (GLESRenderSystem)Root.Instance.RenderSystem; //GLESContext mainContext = rendersystem.MainContext; //EGLCONTEXT shareContext = null; //if (mainContext != null) //{ // shareContext = mainContext.con; //} //if (mainContext == null) //{ // throw new AxiomException("Unable to create a suitable EGLContext"); //} // _context = _glSupport.CreateNewContext(_eglDisplay, _config, shareContext); }
internal AndroidAsyncGraphicsContext(AndroidGraphicsContext graphicsContext, AndroidWindow androidWindow, int versionMajor) { egl = EGLContext.EGL.JavaCast<IEGL10>(); var pbufferAttribList = new[] { EGL10.EglWidth, 1, EGL10.EglHeight, 1, EGL10.EglNone }; EGLDisplay = androidWindow.Display; var androidGraphicsContext = graphicsContext; var config = androidGraphicsContext.EGLConfig; var attribList = new[] { EGL10.EglSurfaceType, EGL10.EglPbufferBit, EGL10.EglRenderableType, 4, // (opengl es 2.0) EGL10.EglRedSize, graphicsContext.GraphicsMode.ColorFormat.Red, EGL10.EglGreenSize, graphicsContext.GraphicsMode.ColorFormat.Green, EGL10.EglBlueSize, graphicsContext.GraphicsMode.ColorFormat.Blue, EGL10.EglAlphaSize, graphicsContext.GraphicsMode.ColorFormat.Alpha, EGL10.EglDepthSize, graphicsContext.GraphicsMode.Depth, EGL10.EglStencilSize, graphicsContext.GraphicsMode.Stencil, //Egl.SAMPLE_BUFFERS, samples > 0 ? 1 : 0, EGL10.EglSamples, 0, EGL10.EglNone, }; // first ask the number of config available var numConfig = new int[1]; if (!egl.EglChooseConfig(EGLDisplay, attribList, null, 0, numConfig)) { throw new InvalidOperationException(string.Format("EglChooseConfig {0:x}", egl.EglGetError())); } // retrieve the available configs var configs = new EGLConfig[numConfig[0]]; if (!egl.EglChooseConfig(EGLDisplay, attribList, configs, configs.Length, numConfig)) { throw new InvalidOperationException(string.Format("EglChooseConfig {0:x}", egl.EglGetError())); } // choose the best config EGLConfig = ChooseConfigEGL(configs); // create the surface EGLSurface = egl.EglCreatePbufferSurface(EGLDisplay, EGLConfig, pbufferAttribList); if (EGLSurface == EGL10.EglNoSurface) { throw new InvalidOperationException(string.Format("EglCreatePBufferSurface {0:x}", egl.EglGetError())); } // 0x3098 is EGL_CONTEXT_CLIENT_VERSION var attribList3 = new[] { 0x3098, versionMajor, EGL10.EglNone }; EGLContext = egl.EglCreateContext(EGLDisplay, config, androidGraphicsContext.EGLContext, attribList3); if (EGLContext == EGL10.EglNoContext) { throw new InvalidOperationException(string.Format("EglCreateContext {0:x}", egl.EglGetError())); } }
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!"); } } }
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; } }
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; }