Java Code Examples for android.opengl.EGL14#EGL_RENDERABLE_TYPE

The following examples show how to use android.opengl.EGL14#EGL_RENDERABLE_TYPE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SurfaceTextureRenderer.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void configureEGLContext() {
    mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        throw new IllegalStateException("No EGL14 display");
    }
    int[] version = new int[2];
    if (!EGL14.eglInitialize(mEGLDisplay, version, /*offset*/ 0, version, /*offset*/ 1)) {
        throw new IllegalStateException("Cannot initialize EGL14");
    }

    int[] attribList = {
            EGL14.EGL_RED_SIZE, EGL_COLOR_BITLENGTH,
            EGL14.EGL_GREEN_SIZE, EGL_COLOR_BITLENGTH,
            EGL14.EGL_BLUE_SIZE, EGL_COLOR_BITLENGTH,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL_RECORDABLE_ANDROID, 1,
            EGL14.EGL_SURFACE_TYPE, EGL14.EGL_PBUFFER_BIT | EGL14.EGL_WINDOW_BIT,
            EGL14.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    EGL14.eglChooseConfig(mEGLDisplay, attribList, /*offset*/ 0, configs, /*offset*/ 0,
            configs.length, numConfigs, /*offset*/ 0);
    checkEglError("eglCreateContext RGB888+recordable ES2");
    mConfigs = configs[0];
    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, GLES_VERSION,
            EGL14.EGL_NONE
    };
    mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT,
            attrib_list, /*offset*/ 0);
    checkEglError("eglCreateContext");
    if(mEGLContext == EGL14.EGL_NO_CONTEXT) {
        throw new IllegalStateException("No EGLContext could be made");
    }
}
 
Example 2
Source File: EGLBase.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
@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(eglDisplay, 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];
}
 
Example 3
Source File: EglCore.java    From MockCamera with Apache License 2.0 5 votes vote down vote up
/**
 * 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];
}
 
Example 4
Source File: EglCore.java    From kickflip-android-sdk with Apache License 2.0 5 votes vote down vote up
/**
 * 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];
}
 
Example 5
Source File: GLThread.java    From android-openGL-canvas with Apache License 2.0 5 votes vote down vote up
@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];
}
 
Example 6
Source File: EGLBase.java    From Tok-Android with GNU General Public License v3.0 5 votes vote down vote up
@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
        LogUtil.i(TAG, "unable to find RGBA8888 / " + " EGLConfig");
        return null;
    }
    return configs[0];
}
 
Example 7
Source File: EglCore.java    From mobile-ar-sensor-logger with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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];
}
 
Example 8
Source File: EglCore.java    From Lassi-Android with MIT License 5 votes vote down vote up
/**
 * 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];
}
 
Example 9
Source File: EGLBase.java    From MegviiFacepp-Android-SDK with Apache License 2.0 5 votes vote down vote up
@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];
}
 
Example 10
Source File: EGLBase.java    From Fatigue-Detection with MIT License 5 votes vote down vote up
@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];
}
 
Example 11
Source File: SurfaceManager.java    From libstreaming with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares EGL.  We want a GLES 2.0 context and a surface that supports recording.
 */
private void eglSetup() {
	mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
	if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
		throw new RuntimeException("unable to get EGL14 display");
	}
	int[] version = new int[2];
	if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
		throw new RuntimeException("unable to initialize EGL14");
	}

	// Configure EGL for recording and OpenGL ES 2.0.
	int[] attribList;
	if (mEGLSharedContext == null) {
		attribList = new int[] {
				EGL14.EGL_RED_SIZE, 8,
				EGL14.EGL_GREEN_SIZE, 8,
				EGL14.EGL_BLUE_SIZE, 8,
				EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
				EGL14.EGL_NONE
		};
	} else {
		attribList = new int[] {
				EGL14.EGL_RED_SIZE, 8,
				EGL14.EGL_GREEN_SIZE, 8,
				EGL14.EGL_BLUE_SIZE, 8,
				EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
				EGL_RECORDABLE_ANDROID, 1,
				EGL14.EGL_NONE
		};	
	}
	EGLConfig[] configs = new EGLConfig[1];
	int[] numConfigs = new int[1];
	EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
			numConfigs, 0);
	checkEglError("eglCreateContext RGB888+recordable ES2");

	// Configure context for OpenGL ES 2.0.
	int[] attrib_list = {
			EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
			EGL14.EGL_NONE
	};

	if (mEGLSharedContext == null) {
		mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT, attrib_list, 0);
	} else {
		mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], mEGLSharedContext, attrib_list, 0);
	}
	checkEglError("eglCreateContext");

	// Create a window surface, and attach it to the Surface we received.
	int[] surfaceAttribs = {
			EGL14.EGL_NONE
	};
	mEGLSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], mSurface,
			surfaceAttribs, 0);
	checkEglError("eglCreateWindowSurface");

       GLES20.glDisable(GLES20.GL_DEPTH_TEST);
       GLES20.glDisable(GLES20.GL_CULL_FACE);
	
}
 
Example 12
Source File: EglUtils.java    From EasyPhotos with Apache License 2.0 4 votes vote down vote up
@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];
}
 
Example 13
Source File: ColorFade.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private boolean createEglContext() {
    if (mEglDisplay == null) {
        mEglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
        if (mEglDisplay == EGL14.EGL_NO_DISPLAY) {
            logEglError("eglGetDisplay");
            return false;
        }

        int[] version = new int[2];
        if (!EGL14.eglInitialize(mEglDisplay, version, 0, version, 1)) {
            mEglDisplay = null;
            logEglError("eglInitialize");
            return false;
        }
    }

    if (mEglConfig == null) {
        int[] eglConfigAttribList = new int[] {
                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
        };
        int[] numEglConfigs = new int[1];
        EGLConfig[] eglConfigs = new EGLConfig[1];
        if (!EGL14.eglChooseConfig(mEglDisplay, eglConfigAttribList, 0,
                eglConfigs, 0, eglConfigs.length, numEglConfigs, 0)) {
            logEglError("eglChooseConfig");
            return false;
        }
        if (numEglConfigs[0] <= 0) {
            Slog.e(TAG, "no valid config found");
            return false;
        }

        mEglConfig = eglConfigs[0];
    }

    if (mEglContext == null) {
        int[] eglContextAttribList = new int[] {
                EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
                EGL14.EGL_NONE
        };
        mEglContext = EGL14.eglCreateContext(mEglDisplay, mEglConfig,
                EGL14.EGL_NO_CONTEXT, eglContextAttribList, 0);
        if (mEglContext == null) {
            logEglError("eglCreateContext");
            return false;
        }
    }
    return true;
}
 
Example 14
Source File: InputSurface.java    From TelePlus-Android with GNU General Public License v2.0 4 votes vote down vote up
private void eglSetup() {
    mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        throw new RuntimeException("unable to get EGL14 display");
    }
    int[] version = new int[2];
    if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
        mEGLDisplay = null;
        throw new RuntimeException("unable to initialize EGL14");
    }

    int[] attribList = {
            EGL14.EGL_RED_SIZE, 8,
            EGL14.EGL_GREEN_SIZE, 8,
            EGL14.EGL_BLUE_SIZE, 8,
            EGL14.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL_RECORDABLE_ANDROID, 1,
            EGL14.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
            numConfigs, 0)) {
        throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
    }

    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };

    mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT, attrib_list, 0);
    checkEglError("eglCreateContext");
    if (mEGLContext == null) {
        throw new RuntimeException("null context");
    }

    int[] surfaceAttribs = {
            EGL14.EGL_NONE
    };
    mEGLSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], mSurface,
            surfaceAttribs, 0);
    checkEglError("eglCreateWindowSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }
}
 
Example 15
Source File: SketchUtils.java    From sketch with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private static int getOpenGLMaxTextureSizeJB1() {
    // Then get a hold of the default display, and initialize.
    // This could get more complex if you have to deal with devices that could have multiple displays,
    // but will be sufficient for a typical phone/tablet:
    android.opengl.EGLDisplay dpy = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    EGL14.eglInitialize(dpy, vers, 0, vers, 1);

    // Next, we need to find a config. Since we won't use this context for rendering,
    // the exact attributes aren't very critical:
    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
    };
    android.opengl.EGLConfig[] configs = new android.opengl.EGLConfig[1];
    int[] numConfig = new int[1];
    EGL14.eglChooseConfig(dpy, configAttr, 0,
            configs, 0, 1, numConfig, 0);
    //noinspection StatementWithEmptyBody
    if (numConfig[0] == 0) {
        // TROUBLE! No config found.
    }
    android.opengl.EGLConfig config = configs[0];

    // To make a context current, which we will need later,
    // you need a rendering surface, even if you don't actually plan to render.
    // To satisfy this requirement, create a small offscreen (Pbuffer) surface:
    int[] surfAttr = {
            EGL14.EGL_WIDTH, 64,
            EGL14.EGL_HEIGHT, 64,
            EGL14.EGL_NONE
    };
    android.opengl.EGLSurface surf = EGL14.eglCreatePbufferSurface(dpy, config, surfAttr, 0);

    // Next, create the context:
    int[] ctxAttrib = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    android.opengl.EGLContext ctx = EGL14.eglCreateContext(dpy, config, EGL14.EGL_NO_CONTEXT, ctxAttrib, 0);

    // Ready to make the context current now:
    EGL14.eglMakeCurrent(dpy, surf, surf, ctx);

    // If all of the above succeeded (error checking was omitted), you can make your OpenGL calls now:
    int[] maxSize = new int[1];
    GLES20.glGetIntegerv(GLES20.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    // Once you're all done, you can tear down everything:
    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];
}
 
Example 16
Source File: InputSurface.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares EGL.  We want a GLES 2.0 context and a surface that supports recording.
 */
private void eglSetup() {
    mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        throw new RuntimeException("unable to get EGL14 display");
    }
    int[] version = new int[2];
    if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
        mEGLDisplay = null;
        throw new RuntimeException("unable to initialize EGL14");
    }
    // Configure EGL for recordable and OpenGL ES 2.0.  We want enough RGB bits
    // to minimize artifacts from possible YUV conversion.
    int[] attribList = {
            EGL14.EGL_RED_SIZE, 8,
            EGL14.EGL_GREEN_SIZE, 8,
            EGL14.EGL_BLUE_SIZE, 8,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL_RECORDABLE_ANDROID, 1,
            EGL14.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
            numConfigs, 0)) {
        throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
    }
    // Configure context for OpenGL ES 2.0.
    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT,
            attrib_list, 0);
    checkEglError("eglCreateContext");
    if (mEGLContext == null) {
        throw new RuntimeException("null context");
    }
    // Create a window surface, and attach it to the Surface we received.
    int[] surfaceAttribs = {
            EGL14.EGL_NONE
    };
    mEGLSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], mSurface,
            surfaceAttribs, 0);
    checkEglError("eglCreateWindowSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }
}
 
Example 17
Source File: OutputSurface.java    From phoenix with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares EGL.  We want a GLES 2.0 context and a surface that supports pbuffer.
 */
private void eglSetup(int width, int height) {
    mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        throw new RuntimeException("unable to get EGL14 display");
    }
    int[] version = new int[2];
    if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
        mEGLDisplay = null;
        throw new RuntimeException("unable to initialize EGL14");
    }
    // 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 = {
            EGL14.EGL_RED_SIZE, 8,
            EGL14.EGL_GREEN_SIZE, 8,
            EGL14.EGL_BLUE_SIZE, 8,
            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[] numConfigs = new int[1];
    if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
            numConfigs, 0)) {
        throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
    }
    // Configure context for OpenGL ES 2.0.
    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT,
            attrib_list, 0);
    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 = {
            EGL14.EGL_WIDTH, width,
            EGL14.EGL_HEIGHT, height,
            EGL14.EGL_NONE
    };
    mEGLSurface = EGL14.eglCreatePbufferSurface(mEGLDisplay, configs[0], surfaceAttribs, 0);
    checkEglError("eglCreatePbufferSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }
}
 
Example 18
Source File: InputSurface.java    From talk-android with MIT License 4 votes vote down vote up
private void eglSetup() {
    mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        throw new RuntimeException("unable to get EGL14 display");
    }
    int[] version = new int[2];
    if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
        mEGLDisplay = null;
        throw new RuntimeException("unable to initialize EGL14");
    }

    int[] attribList = {
            EGL14.EGL_RED_SIZE, 8,
            EGL14.EGL_GREEN_SIZE, 8,
            EGL14.EGL_BLUE_SIZE, 8,
            EGL14.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
            EGL_RECORDABLE_ANDROID, 1,
            EGL14.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
            numConfigs, 0)) {
        throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
    }

    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };

    mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT, attrib_list, 0);
    checkEglError("eglCreateContext");
    if (mEGLContext == null) {
        throw new RuntimeException("null context");
    }

    int[] surfaceAttribs = {
            EGL14.EGL_NONE
    };
    mEGLSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], mSurface,
            surfaceAttribs, 0);
    checkEglError("eglCreateWindowSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }
}
 
Example 19
Source File: InputSurface.java    From android-transcoder with Apache License 2.0 4 votes vote down vote up
/**
 * Prepares EGL.  We want a GLES 2.0 context and a surface that supports recording.
 */
private void eglSetup() {
    mEGLDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    if (mEGLDisplay == EGL14.EGL_NO_DISPLAY) {
        throw new RuntimeException("unable to get EGL14 display");
    }
    int[] version = new int[2];
    if (!EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)) {
        mEGLDisplay = null;
        throw new RuntimeException("unable to initialize EGL14");
    }
    // Configure EGL for recordable and OpenGL ES 2.0.  We want enough RGB bits
    // to minimize artifacts from possible YUV conversion.
    int[] attribList = {
            EGL14.EGL_RED_SIZE, 8,
            EGL14.EGL_GREEN_SIZE, 8,
            EGL14.EGL_BLUE_SIZE, 8,
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,
            EGL_RECORDABLE_ANDROID, 1,
            EGL14.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
            numConfigs, 0)) {
        throw new RuntimeException("unable to find RGB888+recordable ES2 EGL config");
    }
    // Configure context for OpenGL ES 2.0.
    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 2,
            EGL14.EGL_NONE
    };
    mEGLContext = EGL14.eglCreateContext(mEGLDisplay, configs[0], EGL14.EGL_NO_CONTEXT,
            attrib_list, 0);
    checkEglError("eglCreateContext");
    if (mEGLContext == null) {
        throw new RuntimeException("null context");
    }
    // Create a window surface, and attach it to the Surface we received.
    int[] surfaceAttribs = {
            EGL14.EGL_NONE
    };
    mEGLSurface = EGL14.eglCreateWindowSurface(mEGLDisplay, configs[0], mSurface,
            surfaceAttribs, 0);
    checkEglError("eglCreateWindowSurface");
    if (mEGLSurface == null) {
        throw new RuntimeException("surface was null");
    }
}
 
Example 20
Source File: EglManager.java    From AudioVideoCodec with Apache License 2.0 4 votes vote down vote up
/**
 * EGL配置步骤1-7
 *
 * @param surface :surface
 * @param context :EGLContext
 */
public void init(Surface surface, EGLContext context) {

    eglDisplay = EGL14.eglGetDisplay(EGL14.EGL_DEFAULT_DISPLAY);
    if (eglDisplay == EGL14.EGL_NO_DISPLAY) {
        Log.d(TAG, "获取显示设备失败 ");
        return;
    }
    int[] version = new int[2];
    boolean isInit = EGL14.eglInitialize(eglDisplay, version, 0, version, 1);
    if (!isInit) {
        Log.d(TAG, "EGL14初始化失败");
        return;
    }

    //参数配置以 id - value 格式组成
    int[] attribute = new int[]{
            EGL14.EGL_BUFFER_SIZE, 32,//颜色缓冲区所有组成颜色的位数
            EGL14.EGL_ALPHA_SIZE, 8,//缓冲区透明度位数
            EGL14.EGL_RED_SIZE, 8,//缓冲区红色位数
            EGL14.EGL_BLUE_SIZE, 8,//缓冲区蓝色位数
            EGL14.EGL_GREEN_SIZE, 8,//缓冲区绿色位数
            EGL14.EGL_RENDERABLE_TYPE, EGL14.EGL_OPENGL_ES2_BIT,//渲染窗口支持的布局类型
            EGL14.EGL_SURFACE_TYPE, EGL14.EGL_WINDOW_BIT,//EGL窗口支持的类型
            EGL14.EGL_NONE//标识结尾信息
    };

    EGLConfig[] eglConfig = new EGLConfig[1];
    int[] numConfigs = new int[1];
    boolean isConfig = EGL14.eglChooseConfig(eglDisplay, attribute, 0, eglConfig,
            0, eglConfig.length, numConfigs, 0);
    if (!isConfig || numConfigs[0] < 0) {
        Log.d(TAG, "config参数配置失败");
        return;
    }

    //指定OpenGL ES 2.0版本
    int[] contextAttribute = {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};

    if (context == null) {
        eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig[0], EGL14.EGL_NO_CONTEXT,
                contextAttribute, 0);
    } else {
        //传入context,表示与其它OpenGL ES上下文共享资源
        eglContext = EGL14.eglCreateContext(eglDisplay, eglConfig[0], context,
                contextAttribute, 0);
    }
    if (eglContext == EGL14.EGL_NO_CONTEXT) {
        Log.d(TAG, "EGLContext 创建失败");
        return;
    }

    int[] attrs = {EGL14.EGL_NONE};
    eglSurface = EGL14.eglCreateWindowSurface(eglDisplay, eglConfig[0], surface, attrs, 0);
    if (eglSurface == EGL14.EGL_NO_SURFACE) {
        Log.d(TAG, "连接EGL和设备屏幕失败");
        return;
    }

    //绑定eglContext
    boolean isMakeCurrent = EGL14.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext);
    if (!isMakeCurrent) {
        Log.d(TAG, "eglContext绑定失败");
    }
}