public void MakeCurrent(IWindowInfo window) { if (window != null) { if (!egl.EglMakeCurrent(EGLDisplay, EGLSurface, EGLSurface, EGLContext)) { throw new InvalidOperationException(); } } else { if (!egl.EglMakeCurrent(EGLDisplay, EGL10.EglNoSurface, EGL10.EglNoSurface, EGL10.EglNoContext)) { throw new InvalidOperationException(); } } }
public void MakeCurrent(IWindowInfo win) { if (win == null) { ClearCurrent(); return; } var w = win as AndroidWindow; if (w == null) { w = window; } var surf = surface == null ? w.Surface : surface; var ctx = EGLContext; if (win == null) { surf = EGL10.EglNoSurface; ctx = EGL10.EglNoContext; } if (!egl.EglMakeCurrent(window.Display, surf, surf, ctx)) { int err = egl.EglGetError(); switch (err) { case EGL11.EglContextLost: throw EglContextLostException.GenerateException("MakeCurrent", egl, err); case EGL11.EglBadAlloc: throw EglBadAllocException.GenerateException("MakeCurrent", egl, err); default: throw EglException.GenerateException("MakeCurrent", egl, err); } } }
/* * public void CreatePixmapSurface (EGLConfig config) * { * Surface = egl.EglCreatePixmapSurface (Display, config, null ,null); * if (Surface == null || Surface == EGL10.EglNoSurface) * throw EglException.GenerateException ("EglCreatePixmapSurface", egl, null); * } */ public void DestroySurface() { if (eglSurface != EGL10.EglNoSurface) { IEGL10 egl = EGLContext.EGL.JavaCast <IEGL10> (); try { egl.EglMakeCurrent(eglDisplay, EGL10.EglNoSurface, EGL10.EglNoSurface, EGL10.EglNoContext); if (!egl.EglDestroySurface(eglDisplay, eglSurface)) { Log.Warn("AndroidWindow", "Failed to destroy surface {0}.", eglSurface); } } catch (Java.Lang.IllegalArgumentException) { Log.Warn("AndroidWindow", "Failed to destroy surface {0}. Illegal Argument", eglSurface); } eglSurface = null; } }
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!"); } }
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!"); } } }