Пример #1
0
        private bool ElgInitialize()
        {
            prevEglContext     = EGL14.EglGetCurrentContext();
            prevEglDisplay     = EGL14.EglGetCurrentDisplay();
            prevEglSurfaceRead = EGL14.EglGetCurrentSurface(EGL14.EglRead);
            prevEglSurfaceDraw = EGL14.EglGetCurrentSurface(EGL14.EglDraw);

            eglDisplay = EGL14.EglGetDisplay(EGL14.EglDefaultDisplay);
            if (eglDisplay == EGL14.EglNoDisplay)
            {
                return(false);
            }

            int[] version = new int[2];
            if (!EGL14.EglInitialize(eglDisplay, version, 0, version, 1))
            {
                return(false);
            }

            // Configure EGL for recording and OpenGL ES 2.0.
            int[] attribList =
            {
                EGL14.EglRedSize,                           8,
                EGL14.EglGreenSize,                         8,
                EGL14.EglBlueSize,                          8,
                EGL14.EglAlphaSize,                         8,
                EGL14.EglRenderableType, EGL14.EglOpenglEsBit,
                EGL_RECORDABLE_ANDROID,                     1,
                EGL14.EglNone
            };
            EGLConfig[] configs    = new EGLConfig[1];
            int[]       numConfigs = new int[1];
            EGL14.EglChooseConfig(eglDisplay, attribList, 0, configs, 0, configs.Length, numConfigs, 0);
            CheckEglError();

            // Configure context for OpenGL ES 2.0.
            int[] attrib_list =
            {
                EGL14.EglContextClientVersion, 1,
                EGL14.EglNone
            };
            eglContext = EGL14.EglCreateContext(eglDisplay, configs[0], EGL14.EglNoContext, attrib_list, 0);
            CheckEglError();

            int[] surfaceAttribs = { EGL14.EglNone };
            eglSurface = EGL14.EglCreateWindowSurface(eglDisplay, configs[0], surface, surfaceAttribs, 0);
            CheckEglError();

            EGL14.EglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
            CheckEglError();

            return(true);
        }
Пример #2
0
        /**
         * Discard all resources held by this class, notably the EGL context. Also releases the
         * Surface that was passed to our constructor.
         */
        public void Release()
        {
            if (EGL14.EglGetCurrentContext().Equals(_EGLContext))
            {
                // Clear the current context and surface to ensure they are discarded immediately.
                EGL14.EglMakeCurrent(_EGLDisplay, EGL14.EglNoSurface, EGL14.EglNoSurface,
                                     EGL14.EglNoContext);
            }

            EGL14.EglDestroySurface(_EGLDisplay, _EGLSurface);
            EGL14.EglDestroyContext(_EGLDisplay, _EGLContext);

            //EGL14.eglTerminate(mEGLDisplay);
            _surface.Release();

            // null everything out so future attempts to use this object will cause an NPE
            _EGLDisplay = null;
            _EGLContext = null;
            _EGLSurface = null;
            _surface    = null;
        }