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!");
			}
		}
예제 #2
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!");
                }
            }
        }