/**
  * Discard all resources held by this class, notably the EGL context.
  */
 public void Release()
 {
     if (mEGL != null)
     {
         if (mEGL.EglGetCurrentContext().Equals(mEGLContext))
         {
             // Clear the current context and surface to ensure they are discarded immediately.
             mEGL.EglMakeCurrent(mEGLDisplay, EGL10.EglNoSurface, EGL10.EglNoSurface,
                                 EGL10.EglNoContext);
         }
         mEGL.EglDestroySurface(mEGLDisplay, mEGLSurface);
         mEGL.EglDestroyContext(mEGLDisplay, mEGLContext);
         //mEGL.eglTerminate(mEGLDisplay);
     }
     _surface.Release();
     // this causes a bunch of warnings that appear harmless but might confuse someone:
     // W BufferQueue: [unnamed-3997-2] cancelBuffer: BufferQueue has been abandoned!
     //mSurfaceTexture.release();
     // null everything out so future attempts to use this object will cause an NPE
     mEGLDisplay     = null;
     mEGLContext     = null;
     mEGLSurface     = null;
     mEGL            = null;
     _textureRender  = null;
     _surface        = null;
     _surfaceTexture = null;
 }
Пример #2
0
        /**
         * Prepares EGL. We want a GLES 2.0 context and a surface that supports pbuffer.
         */

        private void eglSetup(int width, int height)
        {
            mEGL        = (IEGL10)EGLContext.EGL;
            mEGLDisplay = mEGL.EglGetDisplay(EGL10.EglDefaultDisplay);
            if (!mEGL.EglInitialize(mEGLDisplay, null))
            {
                throw new RuntimeException("unable to initialize EGL10");
            }
            // Configure EGL for pbuffer and OpenGL ES 2.0. We want enough RGB bits
            // to be able to tell if the frame is reasonable.
            int[] attribList =
            {
                EGL10.EglRedSize,                         16,
                EGL10.EglGreenSize,                       16,
                EGL10.EglBlueSize,                        16,
                EGL10.EglAlphaSize,                       16,
                EGL10.EglSurfaceType,    EGL10.EglPbufferBit,
                EGL10.EglRenderableType, EGL_OPENGL_ES2_BIT,
                EGL10.EglNone
            };
            EGLConfig[] configs    = new EGLConfig[1];
            int[]       numConfigs = new int[1];
            if (!mEGL.EglChooseConfig(mEGLDisplay, attribList, configs, 1, numConfigs))
            {
                throw new RuntimeException("unable to find RGB888+pbuffer EGL config");
            }
            // Configure context for OpenGL ES 2.0.
            int[] attrib_list =
            {
                EGL14.EglContextClientVersion, 2,
                EGL10.EglNone
            };
            mEGLContext = mEGL.EglCreateContext(mEGLDisplay, configs[0], EGL10.EglNoContext,
                                                attrib_list);
            CheckEglError("eglCreateContext");
            if (mEGLContext == null)
            {
                throw new RuntimeException("null context");
            }
            // Create a pbuffer surface. By using this for output, we can use glReadPixels
            // to test values in the output.
            int[] surfaceAttribs =
            {
                EGL10.EglWidth,  width,
                EGL10.EglHeight, height,
                EGL10.EglNone
            };
            mEGLSurface = mEGL.EglCreatePbufferSurface(mEGLDisplay, configs[0], surfaceAttribs);
            CheckEglError("eglCreatePbufferSurface");
            if (mEGLSurface == null)
            {
                throw new RuntimeException("surface was null");
            }
        }