private int[] filterConfigSpec(int[] configSpec) { if (mEGLContextClientVersion != 2 && mEGLContextClientVersion != 3) { return configSpec; } /* We know none of the subclasses define EGL_RENDERABLE_TYPE. * And we know the configSpec is well formed. */ int len = configSpec.length; int[] newConfigSpec = new int[len + 2]; System.arraycopy(configSpec, 0, newConfigSpec, 0, len - 1); newConfigSpec[len - 1] = EGL10.EGL_RENDERABLE_TYPE; if (mEGLContextClientVersion == 2) { newConfigSpec[len] = EGL14.EGL_OPENGL_ES2_BIT; /* EGL_OPENGL_ES2_BIT */ } else { newConfigSpec[len] = EGLExt.EGL_OPENGL_ES3_BIT_KHR; /* EGL_OPENGL_ES3_BIT_KHR */ } newConfigSpec[len + 1] = EGL10.EGL_NONE; return newConfigSpec; }
private int[] filterConfigSpec(int[] configSpec) { if (contextClientVersion != 2 && contextClientVersion != 3) { return configSpec; } /* We know none of the subclasses define EGL_RENDERABLE_TYPE. * And we know the configSpec is well formed. */ int len = configSpec.length; int[] newConfigSpec = new int[len + 2]; System.arraycopy(configSpec, 0, newConfigSpec, 0, len - 1); newConfigSpec[len - 1] = EGL10.EGL_RENDERABLE_TYPE; if (contextClientVersion == 2) { newConfigSpec[len] = EGL14.EGL_OPENGL_ES2_BIT; /* EGL_OPENGL_ES2_BIT */ } else { newConfigSpec[len] = EGLExt.EGL_OPENGL_ES3_BIT_KHR; /* EGL_OPENGL_ES3_BIT_KHR */ } newConfigSpec[len + 1] = EGL10.EGL_NONE; return newConfigSpec; }
private int[] filterConfigSpec(int[] configSpec) { int majorGLVersion = eglContextGLESVersion.getMajorVersion(); if (majorGLVersion != 2 && majorGLVersion != 3) { return configSpec; } /* We know none of the subclasses define EGL_RENDERABLE_TYPE. * And we know the configSpec is well formed. */ int len = configSpec.length; int[] newConfigSpec = new int[len + 2]; System.arraycopy(configSpec, 0, newConfigSpec, 0, len - 1); newConfigSpec[len - 1] = EGL14.EGL_RENDERABLE_TYPE; if (majorGLVersion == 2) { newConfigSpec[len] = EGL14.EGL_OPENGL_ES2_BIT; /* EGL_OPENGL_ES2_BIT */ } else { newConfigSpec[len] = EGLExt.EGL_OPENGL_ES3_BIT_KHR; /* EGL_OPENGL_ES3_BIT_KHR */ } newConfigSpec[len + 1] = EGL14.EGL_NONE; return newConfigSpec; }
/** * 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]; }
/** * Sends the presentation time stamp to EGL. * @param display an EGL display connection instance * @param surface an EGL rendering surface * @param nSecs time is expressed in nanoseconds. */ public static void setPresentationTime(@NonNull EGLDisplay display, @NonNull EGLSurface surface, long nSecs) { //noinspection StatementWithEmptyBody if (!EGLExt.eglPresentationTimeANDROID(display, surface, nSecs)) { logError(); throw new RuntimeException("Unable to set presentation time (" + nSecs +"ns)." + getDisplayString(display) + "; " + getSurfaceString(surface)); } else {/* logDebug("Set presentation time (" + nSecs +"ns)." + getDisplayString(display) + "; " + getSurfaceString(surface));*/ } }
@Override public void swapBuffers(long timeStampNs) { checkIsNotReleased(); if (eglSurface == EGL14.EGL_NO_SURFACE) { throw new RuntimeException("No EGLSurface - can't swap buffers"); } synchronized (EglBase.lock) { // See // https://android.googlesource.com/platform/frameworks/native/+/tools_r22.2/opengl/specs/EGL_ANDROID_presentation_time.txt EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, timeStampNs); EGL14.eglSwapBuffers(eglDisplay, eglSurface); } }
public void swapBuffers(long timeStampNs) { checkIsNotReleased(); if (eglSurface == EGL14.EGL_NO_SURFACE) { throw new RuntimeException("No EGLSurface - can't swap buffers"); } synchronized (EglBase.lock) { // See // https://android.googlesource.com/platform/frameworks/native/+/tools_r22.2/opengl/specs/EGL_ANDROID_presentation_time.txt EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, timeStampNs); EGL14.eglSwapBuffers(eglDisplay, eglSurface); } }
@Override public void swapBuffers(long timestampNs) { checkIsNotReleased(); if (eglSurface == EGL14.EGL_NO_SURFACE) { throw new RuntimeException("No EGLSurface - can't swap buffers"); } synchronized (EglBase.lock) { // See // https://android.googlesource.com/platform/frameworks/native/+/tools_r22.2/opengl/specs/EGL_ANDROID_presentation_time.txt if (timestampNs != -1) { EGLExt.eglPresentationTimeANDROID(eglDisplay, eglSurface, timestampNs); } EGL14.eglSwapBuffers(eglDisplay, eglSurface); } }
/** * Sends the presentation time stamp to EGL. * * @param nsecs Timestamp, in nanoseconds. */ @Override public void setPresentationTime(long nsecs) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2 && nsecs != 0) { EGLExt.eglPresentationTimeANDROID(mEglDisplay, mEglSurface, nsecs); } }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1) public android.opengl.EGLConfig chooseConfig(android.opengl.EGLDisplay display, boolean recordable) { int renderableType = EGL14.EGL_OPENGL_ES2_BIT; if (contextClientVersion >= 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 (recordable) { attribList[attribList.length - 3] = EGL_RECORDABLE_ANDROID; attribList[attribList.length - 2] = 1; } android.opengl.EGLConfig[] configs = new android.opengl.EGLConfig[1]; int[] numConfigs = new int[1]; if (!EGL14.eglChooseConfig(display, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w("GLThread", "unable to find RGB8888 / " + contextClientVersion + " EGLConfig"); return null; } return configs[0]; }
private int swap(final EGLSurface surface, final long presentationTimeNs) { // if (DEBUG) Log.v(TAG, "swap:"); EGLExt.eglPresentationTimeANDROID(mEglDisplay, surface, presentationTimeNs); if (!EGL14.eglSwapBuffers(mEglDisplay, surface)) { final int err = EGL14.eglGetError(); // if (DEBUG) Log.w(TAG, "swap:err=" + err); return err; } return EGL14.EGL_SUCCESS; }
/** * 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(eGLDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig"); return null; } return configs[0]; }
private static void checkGLVersion() { // Get an EGL context and display final EGL10 egl = (EGL10) EGLContext.getEGL(); final EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY); final int[] version = new int[2]; if (!egl.eglInitialize(display, version)) throw new IllegalStateException("Failed to initialize and EGL context while getting device capabilities."); mEGLMajorVersion = version[0]; mEGLMinorVersion = version[1]; // RajLog.d("Device EGL Version: " + version[0] + "." + version[1]); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { // The API for GLES3 doesnt exist on this device // RajLog.d("Device is API level cannot support OpenGL ES 3."); mGLESMajorVersion = 2; } else { // The API for GLES3 might exist, we need to check // RajLog.d("Attempting to get an OpenGL ES 3 config."); final int[] configAttribs = {EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE, EGLExt.EGL_OPENGL_ES3_BIT_KHR, EGL10.EGL_NONE}; final EGLConfig[] configs = new EGLConfig[10]; final int[] num_config = new int[1]; egl.eglChooseConfig(display, configAttribs, configs, 10, num_config); egl.eglTerminate(display); mGLESMajorVersion = num_config[0] > 0 ? 3 : 2; } // RajLog.d("Determined GLES Major version to be: " + mGLESMajorVersion); sGLChecked = true; }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public void setPresentationTime(EGLSurface surface, long time){ EGLExt.eglPresentationTimeANDROID(mEGLDisplay,surface,time); }
void setPresentationTime(long nsecs) { EGLExt.eglPresentationTimeANDROID(mEGLDisplay, mEGLSurface, nsecs); }
public void setPresentationTime(long nsecs) { EGLExt.eglPresentationTimeANDROID(mEGLDisplay, mEGLSurface, nsecs); }
/** * Sends the presentation time stamp to EGL. Time is expressed in nanoseconds. */ public void setPresentationTime(long nsecs) { EGLExt.eglPresentationTimeANDROID(mEGLDisplay, mEGLSurface, nsecs); }
/** * Sends the presentation time stamp to EGL. Time is expressed in nanoseconds. */ public void setPresentationTime(EGLSurface eglSurface, long nsecs) { EGLExt.eglPresentationTimeANDROID(mEGLDisplay, eglSurface, nsecs); }
public void setPresentationTime(EGLSurface eglSurface, long nsecs) { EGLExt.eglPresentationTimeANDROID(mEGLDisplay, eglSurface, nsecs); }