Exemplo n.º 1
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");
            }
        }