public boolean createGLESWithSurface(EGLConfigAttrs attrs,EGLContextAttrs ctxAttrs,Object surface){ EGLConfig config=getConfig(attrs.surfaceType(EGL14.EGL_WINDOW_BIT).makeDefault(true)); if(config==null){ log("getConfig failed : "+EGL14.eglGetError()); return false; } mEGLContext=createContext(config,EGL14.EGL_NO_CONTEXT,ctxAttrs.makeDefault(true)); if(mEGLContext==EGL14.EGL_NO_CONTEXT){ log("createContext failed : "+EGL14.eglGetError()); return false; } mEGLSurface=createWindowSurface(surface); if(mEGLSurface==EGL14.EGL_NO_SURFACE){ log("createWindowSurface failed : "+EGL14.eglGetError()); return false; } if(!EGL14.eglMakeCurrent(mEGLDisplay,mEGLSurface,mEGLSurface,mEGLContext)){ log("eglMakeCurrent failed : "+EGL14.eglGetError()); return false; } return true; }
public EGLSurface createGLESWithPBuffer(EGLConfigAttrs attrs,EGLContextAttrs ctxAttrs,int width,int height){ EGLConfig config=getConfig(attrs.surfaceType(EGL14.EGL_PBUFFER_BIT)); if(config==null){ log("getConfig failed : "+EGL14.eglGetError()); return null; } EGLContext eglContext=createContext(config,EGL14.EGL_NO_CONTEXT,ctxAttrs); if(eglContext==EGL14.EGL_NO_CONTEXT){ log("createContext failed : "+EGL14.eglGetError()); return null; } EGLSurface eglSurface=createPBufferSurface(config,width,height); if(eglSurface==EGL14.EGL_NO_SURFACE){ log("createWindowSurface failed : "+EGL14.eglGetError()); return null; } if(!EGL14.eglMakeCurrent(mEGLDisplay,eglSurface,eglSurface,eglContext)){ log("eglMakeCurrent failed : "+EGL14.eglGetError()); return null; } return eglSurface; }
/** Constructs a new {@link InputSurface} */ private InputSurface(@NonNull Builder builder) { checkState(); mAutoSwap = builder.autoSwap; mWidth = builder.width; mHeight = builder.height; mByteBuffer = builder.byteBuffer; mEglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(mEglDisplay, false); mEglContext = GLTools.newContext(mEglDisplay, eglConfig); mEglSurface = GLTools.newSurface(mEglDisplay, eglConfig, builder.surface); if (mAutoSwap) GLTools.makeCurrent(mEglDisplay, mEglSurface, mEglContext); GLTools.newShader(mShader); mTexture = GLTools.newTexture(TEXTURE_LEVEL); logv("Input surface created"); }
/** * Test for {@link GLTools#setPresentationTime(EGLDisplay, EGLSurface, long)} . * @throws Exception by some fails */ @Test public final void testSetPresentationTime() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true); final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig); final EGLSurface eglSurface = GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE); GLTools.makeCurrent(eglDisplay, eglSurface, eglContext); final int txt = GLTools.newTexture(TEXTURE_LEVEL); final SurfaceTexture surfaceTexture = new SurfaceTexture(txt, true); final Surface surface = new Surface(surfaceTexture); final EGLSurface window = GLTools.newSurface(eglDisplay, eglConfig, surface); GLTools.setPresentationTime(eglDisplay, window, PRESENTATION_TIME); GLTools.closeSurface(eglDisplay, window); surface.release(); surfaceTexture.release(); GLTools.closeTexture(txt, TEXTURE_LEVEL); GLTools.closeSurface(eglDisplay, eglSurface); GLTools.closeContext(eglDisplay, eglContext); GLTools.closeDisplay(eglDisplay); }
/** * Test for {@link GLTools#newTexture(int)} and {@link GLTools#closeTexture(int, int)}. * @throws Exception by some fails */ @Test public final void testTexture() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true); final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig); final EGLSurface eglSurface = GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE); GLTools.makeCurrent(eglDisplay, eglSurface, eglContext); GLTools.closeTexture(GLTools.newTexture(TEXTURE_LEVEL), TEXTURE_LEVEL); GLTools.closeSurface(eglDisplay, eglSurface); GLTools.closeContext(eglDisplay, eglContext); GLTools.closeDisplay(eglDisplay); }
/** * Test for {@link GLTools#newShader(int[])} and {@link GLTools#closeShader(int[])}. * @throws Exception by some fails */ @Test public final void testShader() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true); final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig); final EGLSurface eglSurface = GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE); GLTools.makeCurrent(eglDisplay, eglSurface, eglContext); final int[] attrs = new int[5]; GLTools.newShader(attrs); GLTools.closeShader(attrs); GLTools.closeSurface(eglDisplay, eglSurface); GLTools.closeContext(eglDisplay, eglContext); GLTools.closeDisplay(eglDisplay); }
private static EGLConfig getEglConfig(EGLDisplay eglDisplay, int[] configAttributes) { EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig( eglDisplay, configAttributes, 0, configs, 0, configs.length, numConfigs, 0)) { throw new RuntimeException( "eglChooseConfig failed: 0x" + Integer.toHexString(EGL14.eglGetError())); } if (numConfigs[0] <= 0) { throw new RuntimeException("Unable to find any matching EGL config"); } final EGLConfig eglConfig = configs[0]; if (eglConfig == null) { throw new RuntimeException("eglChooseConfig returned null"); } return eglConfig; }
private static EGLContext createEglContext( EglBase14.Context sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) { if (sharedContext != null && sharedContext.egl14Context == EGL14.EGL_NO_CONTEXT) { throw new RuntimeException("Invalid sharedContext"); } int[] contextAttributes = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE}; EGLContext rootContext = sharedContext == null ? EGL14.EGL_NO_CONTEXT : sharedContext.egl14Context; final EGLContext eglContext; synchronized (EglBase.lock) { eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig, rootContext, contextAttributes, 0); } if (eglContext == EGL14.EGL_NO_CONTEXT) { throw new RuntimeException( "Failed to create EGL context: 0x" + Integer.toHexString(EGL14.eglGetError())); } return eglContext; }
@Override public void onSurfaceCreated(GL10 gl, javax.microedition.khronos.egl.EGLConfig config) { // Set the background frame color GLES20.glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // initialize a triangle mAxis = new Axis(squareCoords); mAxis2 = new Axis(squareCoords2); mLine = new Line(new PointVector(0.0f, 0.0f, -0.5f), new PointVector(0.0f, 0.0f, 0.5f), color); firstQuadrant = new ImportModel(new FirstQuadrantModel()); secondQuadrant = new ImportModel(new SecondQuadrantModel()); thirdQuadrant = new ImportModel(new ThirdQuadrantModel()); fourthQuadrant = new ImportModel(new FourthQuadrantModel()); }
private EGLConfig getConfig(boolean with_depth_buffer) { final int[] attribList = { EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, //EGL14.EGL_STENCIL_SIZE, 8, EGL_RECORDABLE_ANDROID, 1, // this flag need to recording of MediaCodec with_depth_buffer ? EGL14.EGL_DEPTH_SIZE : EGL14.EGL_NONE, with_depth_buffer ? 16 : 0, EGL14.EGL_NONE }; final EGLConfig[] configs = new EGLConfig[1]; final int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEglDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { // XXX it will be better to fallback to RGB565 Log.w(TAG, "unable to find RGBA8888 / " + " EGLConfig"); return null; } return configs[0]; }
public EGLSurface createWindowSurface(EGLDisplay display, EGLConfig config, Object nativeWindow) { EGLSurface result = null; try { result = EGL14.eglCreateWindowSurface(display, config, nativeWindow, s_DEFAULT_SURFACE_ATTRIBS, 0); } catch (IllegalArgumentException e) { // This exception indicates that the surface flinger surface // is not valid. This can happen if the surface flinger surface has // been torn down, but the application has not yet been // notified via SurfaceHolder.Callback.surfaceDestroyed. // In theory the application should be notified first, // but in practice sometimes it is not. See b/4588890 Log.e(s_TAG, "eglCreateWindowSurface", e); } return result; }
@Override public EGLConfig chooseConfig(EGLDisplay display, EGLConfig[] configs) { for (EGLConfig config : configs) { int d = findConfigAttrib(display, config, EGL14.EGL_DEPTH_SIZE, 0); int s = findConfigAttrib(display, config, EGL14.EGL_STENCIL_SIZE, 0); if ((d >= depthSize) && (s >= stencilSize)) { int r = findConfigAttrib(display, config, EGL14.EGL_RED_SIZE, 0); int g = findConfigAttrib(display, config, EGL14.EGL_GREEN_SIZE, 0); int b = findConfigAttrib(display, config, EGL14.EGL_BLUE_SIZE, 0); int a = findConfigAttrib(display, config, EGL14.EGL_ALPHA_SIZE, 0); if ((r == redSize) && (g == greenSize) && (b == blueSize) && (a == alphaSize)) { return config; } } } return null; }
public EGLConfig getConfig(EGLConfigAttrs attrs){ EGLConfig[] configs = new EGLConfig[1]; int[] configNum = new int[1]; EGL14.eglChooseConfig(mEGLDisplay,attrs.build(),0,configs,0,1,configNum,0); //选择的过程可能出现多个,也可能一个都没有,这里只用一个 if(configNum[0]>0){ if(attrs.isDefault()){ mEGLConfig=configs[0]; } return configs[0]; } return null; }
public EGLContext createContext(EGLConfig config,EGLContext share,EGLContextAttrs attrs){ EGLContext context= EGL14.eglCreateContext(mEGLDisplay,config,share,attrs.build(),0); if(attrs.isDefault()){ mEGLContext=context; } return context; }
@SuppressWarnings("unused") private EGLConfig getConfig(final boolean with_depth_buffer, final boolean isRecordable) { final int[] attribList = { EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, EGL14.EGL_NONE, EGL14.EGL_NONE, //EGL14.EGL_STENCIL_SIZE, 8, EGL14.EGL_NONE, EGL14.EGL_NONE, //EGL_RECORDABLE_ANDROID, 1, // this flag need to recording of MediaCodec EGL14.EGL_NONE, EGL14.EGL_NONE, // with_depth_buffer ? EGL14.EGL_DEPTH_SIZE : EGL14.EGL_NONE, // with_depth_buffer ? 16 : 0, EGL14.EGL_NONE }; int offset = 10; if (false) { // ステンシルバッファ(常時未使用) attribList[offset++] = EGL14.EGL_STENCIL_SIZE; attribList[offset++] = 8; } if (with_depth_buffer) { // デプスバッファ attribList[offset++] = EGL14.EGL_DEPTH_SIZE; attribList[offset++] = 16; } if (isRecordable && (Build.VERSION.SDK_INT >= 18)) {// MediaCodecの入力用Surfaceの場合 attribList[offset++] = EGL_RECORDABLE_ANDROID; attribList[offset++] = 1; } for (int i = attribList.length - 1; i >= offset; i--) { attribList[i] = EGL14.EGL_NONE; } final EGLConfig[] configs = new EGLConfig[1]; final int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEglDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { // XXX it will be better to fallback to RGB565 Log.w(TAG, "unable to find RGBA8888 / " + " EGLConfig"); return null; } return configs[0]; }
/** * Finds a suitable EGLConfig. * * @param flags Bit flags from constructor. * @param version Must be 2 or 3. */ private EGLConfig getConfig(int flags, int version) { int renderableType = EGL14.EGL_OPENGL_ES2_BIT; if (version >= 3) { renderableType |= EGLExt.EGL_OPENGL_ES3_BIT_KHR; } // The actual surface is generally RGBA or RGBX, so situationally omitting alpha // doesn't really help. It can also lead to a huge performance hit on glReadPixels() // when reading into a GL_RGBA buffer. int[] attribList = { EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, //EGL14.EGL_DEPTH_SIZE, 16, //EGL14.EGL_STENCIL_SIZE, 8, EGL14.EGL_RENDERABLE_TYPE, renderableType, EGL14.EGL_NONE, 0, // placeholder for recordable [@-3] EGL14.EGL_NONE }; if ((flags & FLAG_RECORDABLE) != 0) { attribList[attribList.length - 3] = EGL_RECORDABLE_ANDROID; attribList[attribList.length - 2] = 1; } EGLConfig[] configs = new EGLConfig[1]; int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig"); return null; } return configs[0]; }
/** * @param display an EGL display connection instance * @param usePBuffer do not accept rendering through the native window system * @return frame buffer configuration that defines the frame buffer resource available to the * rendering context. **/ @NonNull public static EGLConfig newConfig(@NonNull EGLDisplay display, boolean usePBuffer) { final int surfaceTypeKey = usePBuffer ? EGL14.EGL_SURFACE_TYPE : RECORDABLE_ANDROID; final int surfaceTypeValue = usePBuffer ? EGL14.EGL_PBUFFER_BIT : 1; final EGLConfig[] configs = new EGLConfig[1]; final int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(display, new int[] { EGL14.EGL_RED_SIZE, 5, EGL14.EGL_GREEN_SIZE, 6, EGL14.EGL_BLUE_SIZE, 5, /*EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8,*/ EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, surfaceTypeKey, surfaceTypeValue, EGL14.EGL_NONE }, 0, configs, 0, configs.length, numConfigs, 0) && numConfigs[0] == 1) { logError(); throw new RuntimeException("Unable to from EGL14 config"); } else { final EGLConfig result = configs[0]; logDebug(getConfigString(result) + " created"); return result; } }
/** * @param config EGL config * @return the EGL config handle */ private static long getConfigHandle(@NonNull EGLConfig config) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return getConfigHandleLollipop(config); } else { return getConfigHandleBase(config); } }
/** * @param display an EGL display connection instance * @return a new EGL rendering context **/ @NonNull public static EGLContext newContext(@NonNull EGLDisplay display, @NonNull EGLConfig config) { final EGLContext result = EGL14.eglCreateContext (display, config, EGL14.EGL_NO_CONTEXT, new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE }, 0); if (result == EGL14.EGL_NO_CONTEXT) { logError(); throw new RuntimeException("Unable to from EGL14 context"); } else { logDebug(getContextString(result) + " created"); return result; } }
/** * @param display an EGL display connection instance * @param width horizontal size of virtual surface * @param height vertical size of virtual surface * @param config a frame buffer configuration * @return a new EGL window surface **/ @NonNull public static EGLSurface newSurface(@NonNull EGLDisplay display, @NonNull EGLConfig config, int width, int height) { final EGLSurface result = EGL14.eglCreatePbufferSurface(display, config, new int[] {EGL14.EGL_WIDTH, width, EGL14.EGL_HEIGHT, height, EGL14.EGL_NONE}, 0); if (result == EGL14.EGL_NO_SURFACE) { logError(); throw new RuntimeException("Unable to from EGL14 context"); } else { logDebug(getSurfaceString(result) + " created"); return result; } }
/** * @param display an EGL display connection instance * @param surface a native window. * @param config a frame buffer configuration * @return a new EGL window surface **/ @NonNull public static EGLSurface newSurface(@NonNull EGLDisplay display, @NonNull EGLConfig config, @NonNull Surface surface) { final EGLSurface result = EGL14.eglCreateWindowSurface(display, config, surface, new int[] {EGL14.EGL_NONE}, 0); if (result == EGL14.EGL_NO_SURFACE) { logError(); throw new RuntimeException("Unable to from EGL14 context"); } else { logDebug(getSurfaceString(result) + " created"); return result; } }
/** Common "before" functionality. */ @Before public final void setUp() throws Exception { mEglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(mEglDisplay, true); mEglContext = GLTools.newContext(mEglDisplay, eglConfig); mEglSurface = GLTools.newSurface(mEglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE); GLTools.makeCurrent(mEglDisplay, mEglSurface, mEglContext); mTexture = GLTools.newTexture(TEXTURE_LEVEL); mSurfaceTexture = new SurfaceTexture(mTexture, true); mSurface = new Surface(mSurfaceTexture); }
/** * Test for {@link GLTools#newContext(EGLDisplay, EGLConfig)} and * {@link GLTools#closeContext(EGLDisplay, EGLContext)}. * @throws Exception by some fails */ @Test public final void testContextWindow() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, false); GLTools.closeContext(eglDisplay, GLTools.newContext(eglDisplay, eglConfig)); GLTools.closeDisplay(eglDisplay); }
/** * Test for {@link GLTools#newContext(EGLDisplay, EGLConfig)} and * {@link GLTools#closeContext(EGLDisplay, EGLContext)}. * @throws Exception by some fails */ @Test public final void testContextPBuffer() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true); GLTools.closeContext(eglDisplay, GLTools.newContext(eglDisplay, eglConfig)); GLTools.closeDisplay(eglDisplay); }
/** * Test for {@link GLTools#newSurface(EGLDisplay, EGLConfig, int, int)} and * {@link GLTools#closeSurface(EGLDisplay, EGLSurface)}. * @throws Exception by some fails */ @Test public final void testSurface() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true); final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig); GLTools.closeSurface(eglDisplay, GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE)); GLTools.closeContext(eglDisplay, eglContext); GLTools.closeDisplay(eglDisplay); }
/** * Test for {@link GLTools#makeCurrent(EGLDisplay, EGLSurface, EGLContext)}. * @throws Exception by some fails */ @Test public final void testMakeCurrent() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true); final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig); final EGLSurface eglSurface = GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE); GLTools.makeCurrent(eglDisplay, eglSurface, eglContext); GLTools.closeSurface(eglDisplay, eglSurface); GLTools.closeContext(eglDisplay, eglContext); GLTools.closeDisplay(eglDisplay); }
/** * Test for {@link GLTools#swapBuffers(EGLDisplay, EGLSurface)}. * @throws Exception by some fails */ @Test public final void testSwapBuffers() throws Exception { final EGLDisplay eglDisplay = GLTools.newDisplay(); final EGLConfig eglConfig = GLTools.newConfig(eglDisplay, true); final EGLContext eglContext = GLTools.newContext(eglDisplay, eglConfig); final EGLSurface eglSurface = GLTools.newSurface(eglDisplay, eglConfig, FRAME_SIZE, FRAME_SIZE); GLTools.makeCurrent(eglDisplay, eglSurface, eglContext); try { GLTools.swapBuffers(eglDisplay, eglSurface); } catch (RuntimeException exception) { final int txt = GLTools.newTexture(TEXTURE_LEVEL); final SurfaceTexture surfaceTexture = new SurfaceTexture(txt, true); final Surface surface = new Surface(surfaceTexture); final EGLSurface window = GLTools.newSurface(eglDisplay, eglConfig, surface); GLTools.makeCurrent(eglDisplay, window, eglContext); GLTools.swapBuffers(eglDisplay, window); GLTools.closeSurface(eglDisplay, window); surface.release(); surfaceTexture.release(); GLTools.closeTexture(txt, TEXTURE_LEVEL); } GLTools.closeSurface(eglDisplay, eglSurface); GLTools.closeContext(eglDisplay, eglContext); GLTools.closeDisplay(eglDisplay); }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) private static int getMaxTextureEgl14() { EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY); int[] vers = new int[2]; EGL14.eglInitialize(dpy, vers, 0, vers, 1); int[] configAttr = { EGL14.EGL_COLOR_BUFFER_TYPE, EGL14.EGL_RGB_BUFFER, EGL14.EGL_LEVEL, 0, EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT, EGL14.EGL_NONE }; EGLConfig[] configs = new EGLConfig[1]; int[] numConfig = new int[1]; EGL14.eglChooseConfig(dpy, configAttr, 0, configs, 0, 1, numConfig, 0); if (numConfig[0] == 0) { return 0; } EGLConfig config = configs[0]; int[] surfAttr = { EGL14.EGL_WIDTH, 64, EGL14.EGL_HEIGHT, 64, EGL14.EGL_NONE }; EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0); int[] ctxAttrib = { EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE }; EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0); EGL14.eglMakeCurrent(dpy, surf, surf, ctx); int[] maxSize = new int[1]; GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0); EGL14.eglMakeCurrent(dpy, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_SURFACE, EGL14.EGL_NO_CONTEXT); EGL14.eglDestroySurface(dpy, surf); EGL14.eglDestroyContext(dpy, ctx); EGL14.eglTerminate(dpy); return maxSize[0]; }
private EGLConfig getConfig(final boolean withDepthBuffer) { final int[] attributes = { EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT, EGL14.EGL_RED_SIZE, 8, EGL14.EGL_GREEN_SIZE, 8, EGL14.EGL_BLUE_SIZE, 8, EGL14.EGL_ALPHA_SIZE, 8, EGL14.EGL_NONE, EGL14.EGL_NONE, // EGL_DEPTH_SIZE占位,下面再进行设置 EGL14.EGL_NONE, EGL14.EGL_NONE, // EGL_RECORDABLE_ANDROID占位,下面再进行设置 EGL14.EGL_NONE }; int offset = 10; if (withDepthBuffer) { attributes[offset++] = EGL14.EGL_DEPTH_SIZE; attributes[offset++] = 16; } if (Build.VERSION.SDK_INT >= 18) { attributes[offset++] = EGL_RECORDABLE_ANDROID; attributes[offset++] = 1; } for (int i = attributes.length - 1; i >= offset; i--) { attributes[i] = EGL14.EGL_NONE; } final EGLConfig[] configs = new EGLConfig[1]; final int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(mEglDisplay, attributes, 0, configs, 0, configs.length, numConfigs, 0)) { return null; } return configs[0]; }