android.opengl.EGLConfig Java Examples

The following examples show how to use android.opengl.EGLConfig. 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: EGLSurfaceTexture.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static EGLConfig chooseEGLConfig(EGLDisplay display) {
  EGLConfig[] configs = new EGLConfig[1];
  int[] numConfigs = new int[1];
  boolean success =
      EGL14.eglChooseConfig(
          display,
          EGL_CONFIG_ATTRIBUTES,
          /* attrib_listOffset= */ 0,
          configs,
          /* configsOffset= */ 0,
          /* config_size= */ 1,
          numConfigs,
          /* num_configOffset= */ 0);
  if (!success || numConfigs[0] <= 0 || configs[0] == null) {
    throw new GlException(
        Util.formatInvariant(
            /* format= */ "eglChooseConfig failed: success=%b, numConfigs[0]=%d, configs[0]=%s",
            success, numConfigs[0], configs[0]));
  }

  return configs[0];
}
 
Example #2
Source File: EglBase14.java    From VideoCRE with MIT License 6 votes vote down vote up
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;
}
 
Example #3
Source File: EglHelper.java    From AAVT with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #4
Source File: EGLSurfaceTexture.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static EGLConfig chooseEGLConfig(EGLDisplay display) {
  EGLConfig[] configs = new EGLConfig[1];
  int[] numConfigs = new int[1];
  boolean success =
      EGL14.eglChooseConfig(
          display,
          EGL_CONFIG_ATTRIBUTES,
          /* attrib_listOffset= */ 0,
          configs,
          /* configsOffset= */ 0,
          /* config_size= */ 1,
          numConfigs,
          /* num_configOffset= */ 0);
  if (!success || numConfigs[0] <= 0 || configs[0] == null) {
    throw new GlException(
        Util.formatInvariant(
            /* format= */ "eglChooseConfig failed: success=%b, numConfigs[0]=%d, configs[0]=%s",
            success, numConfigs[0], configs[0]));
  }

  return configs[0];
}
 
Example #5
Source File: EGLSurfaceTexture.java    From MediaSDK with Apache License 2.0 6 votes vote down vote up
private static EGLContext createEGLContext(
    EGLDisplay display, EGLConfig config, @SecureMode int secureMode) {
  int[] glAttributes;
  if (secureMode == SECURE_MODE_NONE) {
    glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};
  } else {
    glAttributes =
        new int[] {
          EGL14.EGL_CONTEXT_CLIENT_VERSION,
          2,
          EGL_PROTECTED_CONTENT_EXT,
          EGL14.EGL_TRUE,
          EGL14.EGL_NONE
        };
  }
  EGLContext context =
      EGL14.eglCreateContext(
          display, config, EGL14.EGL_NO_CONTEXT, glAttributes, 0);
  if (context == null) {
    throw new GlException("eglCreateContext failed");
  }
  return context;
}
 
Example #6
Source File: EglBase14.java    From VideoCRE with MIT License 6 votes vote down vote up
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;
}
 
Example #7
Source File: EglHelper.java    From AAVT with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #8
Source File: EglBase14.java    From UltraGpuImage with MIT License 6 votes vote down vote up
private static EGLContext createEglContext(
    @Nullable 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;
}
 
Example #9
Source File: EGLSurfaceTexture.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static EGLContext createEGLContext(
    EGLDisplay display, EGLConfig config, @SecureMode int secureMode) {
  int[] glAttributes;
  if (secureMode == SECURE_MODE_NONE) {
    glAttributes = new int[] {EGL14.EGL_CONTEXT_CLIENT_VERSION, 2, EGL14.EGL_NONE};
  } else {
    glAttributes =
        new int[] {
          EGL14.EGL_CONTEXT_CLIENT_VERSION,
          2,
          EGL_PROTECTED_CONTENT_EXT,
          EGL14.EGL_TRUE,
          EGL14.EGL_NONE
        };
  }
  EGLContext context =
      EGL14.eglCreateContext(
          display, config, android.opengl.EGL14.EGL_NO_CONTEXT, glAttributes, 0);
  if (context == null) {
    throw new GlException("eglCreateContext failed");
  }
  return context;
}
 
Example #10
Source File: EglBase14Impl.java    From webrtc_android with MIT License 6 votes vote down vote up
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;
}
 
Example #11
Source File: EglBase14Impl.java    From webrtc_android with MIT License 6 votes vote down vote up
private static EGLContext createEglContext(
      EGLContext sharedContext, EGLDisplay eglDisplay, EGLConfig eglConfig) {
  if (sharedContext != null && sharedContext == 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;
  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;
}
 
Example #12
Source File: EGLSurfaceTexture.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
private static EGLConfig chooseEGLConfig(EGLDisplay display) {
  EGLConfig[] configs = new EGLConfig[1];
  int[] numConfigs = new int[1];
  boolean success =
      EGL14.eglChooseConfig(
          display,
          EGL_CONFIG_ATTRIBUTES,
          /* attrib_listOffset= */ 0,
          configs,
          /* configsOffset= */ 0,
          /* config_size= */ 1,
          numConfigs,
          /* num_configOffset= */ 0);
  if (!success || numConfigs[0] <= 0 || configs[0] == null) {
    throw new GlException(
        Util.formatInvariant(
            /* format= */ "eglChooseConfig failed: success=%b, numConfigs[0]=%d, configs[0]=%s",
            success, numConfigs[0], configs[0]));
  }

  return configs[0];
}
 
Example #13
Source File: EglBase14.java    From UltraGpuImage with MIT License 6 votes vote down vote up
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;
}
 
Example #14
Source File: EGLEnvironment.java    From EZFilter with MIT License 5 votes vote down vote up
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];
}
 
Example #15
Source File: EglCore.java    From sealrtc-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 #16
Source File: EglCore.java    From VideoRecorder 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 #17
Source File: EGLSurfaceTexture.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initializes required EGL parameters and creates the {@link SurfaceTexture}.
 *
 * @param secureMode The {@link SecureMode} to be used for EGL surface.
 */
public void init(@SecureMode int secureMode) {
  display = getDefaultDisplay();
  EGLConfig config = chooseEGLConfig(display);
  context = createEGLContext(display, config, secureMode);
  surface = createEGLSurface(display, config, context, secureMode);
  generateTextureIds(textureIdHolder);
  texture = new SurfaceTexture(textureIdHolder[0]);
  texture.setOnFrameAvailableListener(this);
}
 
Example #18
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 #19
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 #20
Source File: EGLBase.java    From In77Camera 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 #21
Source File: EglUtil.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
static EGLConfig getEglConfig(EGLDisplay eglDisplay, int version) {
    // Get an EGLConfig.
    int renderableType = EGL14.EGL_OPENGL_ES2_BIT;
    if (version == 3) {
        renderableType = EGLExt.EGL_OPENGL_ES3_BIT_KHR;
    }
    final int RED_SIZE = 8;
    final int GREEN_SIZE = 8;
    final int BLUE_SIZE = 8;
    final int ALPHA_SIZE = 8;
    final int DEPTH_SIZE = 0;
    final int STENCIL_SIZE = 0;
    final int[] DEFAULT_CONFIGURATION = new int[]{
            EGL14.EGL_RENDERABLE_TYPE, renderableType,
            EGL14.EGL_RED_SIZE, RED_SIZE,
            EGL14.EGL_GREEN_SIZE, GREEN_SIZE,
            EGL14.EGL_BLUE_SIZE, BLUE_SIZE,
            EGL14.EGL_ALPHA_SIZE, ALPHA_SIZE,
            EGL14.EGL_DEPTH_SIZE, DEPTH_SIZE,
            EGL14.EGL_STENCIL_SIZE, STENCIL_SIZE,
            EGL14.EGL_NONE};
    int[] configsCount = new int[1];
    EGLConfig[] eglConfigs = new EGLConfig[1];
    if (!EGL14.eglChooseConfig(
            eglDisplay, DEFAULT_CONFIGURATION, 0, eglConfigs, 0, 1, configsCount, 0)) {
        throw new RuntimeException("eglChooseConfig failed");
    }
    return eglConfigs[0];
}
 
Example #22
Source File: EglCore.java    From Fatigue-Detection 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 #23
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 #24
Source File: EglCore.java    From FuAgoraDemoDroid 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 #25
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 #26
Source File: RecordableSurfaceView.java    From recordablesurfaceview with Apache License 2.0 5 votes vote down vote up
EGLConfig chooseEglConfig(EGLDisplay eglDisplay) {
    int[] configsCount = new int[]{0};
    EGLConfig[] configs = new EGLConfig[1];
    EGL14.eglChooseConfig(eglDisplay, config, 0, configs, 0, configs.length, configsCount,
            0);
    return configs[0];
}
 
Example #27
Source File: EglCore.java    From PLDroidShortVideo 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 #28
Source File: EglHelper.java    From AAVT with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #29
Source File: EglHelper.java    From AAVT with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #30
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];
}