/** * 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; }
// =========================================================== // Methods // =========================================================== private int findConfigAttrib(EGL10 pEGL, EGLDisplay pEGLDisplay, EGLConfig pEGLConfig, int pAttribute, int pDefaultValue) { if (pEGL.EglGetConfigAttrib(pEGLDisplay, pEGLConfig, pAttribute, this.mValue)) { return(this.mValue[0]); } return(pDefaultValue); }
// =========================================================== // Methods // =========================================================== private int findConfigAttrib(EGL10 pEGL, EGLDisplay pEGLDisplay, EGLConfig pEGLConfig, int pAttribute, int pDefaultValue) { if (pEGL.EglGetConfigAttrib(pEGLDisplay, pEGLConfig, pAttribute, this.mValue)) { return this.mValue[0]; } return pDefaultValue; }
/** * 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"); } }
public EGLConfig chooseConfig(EGL10 pEGL, EGLDisplay pEGLDisplay) { int[] num_config = new int[1]; pEGL.EglChooseConfig(pEGLDisplay, this.mConfigSpec, null, 0, num_config); int numConfigs = num_config[0]; if (numConfigs <= 0) { throw new IllegalArgumentException("No configs match configSpec"); } EGLConfig[] configs = new EGLConfig[numConfigs]; pEGL.EglChooseConfig(pEGLDisplay, this.mConfigSpec, configs, numConfigs, num_config); EGLConfig config = this.chooseConfig(pEGL, pEGLDisplay, configs); if (config == null) { throw new IllegalArgumentException("No config chosen"); } return config; }
public EGLConfig chooseConfig(EGL10 pEGL, EGLDisplay pEGLDisplay) { int[] num_config = new int[1]; pEGL.EglChooseConfig(pEGLDisplay, this.mConfigSpec, null, 0, num_config); int numConfigs = num_config[0]; if (numConfigs <= 0) { throw new IllegalArgumentException("No configs match configSpec"); } EGLConfig[] configs = new EGLConfig[numConfigs]; pEGL.EglChooseConfig(pEGLDisplay, this.mConfigSpec, configs, numConfigs, num_config); EGLConfig config = this.chooseConfig(pEGL, pEGLDisplay, configs); if (config == null) { throw new IllegalArgumentException("No config chosen"); } return(config); }
// =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== public override EGLConfig chooseConfig(EGL10 pEGL, EGLDisplay pEGLDisplay, EGLConfig[] pEGLConfigs) { EGLConfig closestConfig = null; int closestDistance = 1000; //for(final EGLConfig config : pEGLConfigs) { foreach (EGLConfig config in pEGLConfigs) { int r = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglRedSize, 0); int g = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglGreenSize, 0); int b = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglBlueSize, 0); int a = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglAlphaSize, 0); int d = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglDepthSize, 0); int s = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglStencilSize, 0); int distance = Math.Abs(r - this.mRedSize) + Math.Abs(g - this.mGreenSize) + Math.Abs(b - this.mBlueSize) + Math.Abs(a - this.mAlphaSize) + Math.Abs(d - this.mDepthSize) + Math.Abs(s - this.mStencilSize); if (distance < closestDistance) { closestDistance = distance; closestConfig = config; } } return closestConfig; }
// =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== public override EGLConfig chooseConfig(EGL10 pEGL, EGLDisplay pEGLDisplay, EGLConfig[] pEGLConfigs) { EGLConfig closestConfig = null; int closestDistance = 1000; //for(final EGLConfig config : pEGLConfigs) { foreach (EGLConfig config in pEGLConfigs) { int r = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglRedSize, 0); int g = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglGreenSize, 0); int b = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglBlueSize, 0); int a = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglAlphaSize, 0); int d = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglDepthSize, 0); int s = this.findConfigAttrib(pEGL, pEGLDisplay, config, EGL10Consts.EglStencilSize, 0); int distance = Math.Abs(r - this.mRedSize) + Math.Abs(g - this.mGreenSize) + Math.Abs(b - this.mBlueSize) + Math.Abs(a - this.mAlphaSize) + Math.Abs(d - this.mDepthSize) + Math.Abs(s - this.mStencilSize); if (distance < closestDistance) { closestDistance = distance; closestConfig = config; } } return(closestConfig); }
// =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== public abstract EGLConfig chooseConfig(EGL10 pEGL, EGLDisplay pEGLDisplay, EGLConfig[] pEGLConfigs);
// =========================================================== // Getter & Setter // =========================================================== // =========================================================== // Methods for/from SuperClass/Interfaces // =========================================================== public abstract EGLConfig chooseConfig(EGL10 pEGL, EGLDisplay pEGLDisplay, EGLConfig[] pEGLConfigs);