javax.microedition.khronos.egl.EGLContext Java Examples

The following examples show how to use javax.microedition.khronos.egl.EGLContext. 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: EGL.java    From MyHearts with Apache License 2.0 6 votes vote down vote up
public void start() {
  mEgl = (EGL10) EGLContext.getEGL();
  mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

  if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
    throw new RuntimeException("eglGetDisplay failed");
  }

  int[] version = new int[2];
  if (!mEgl.eglInitialize(mEglDisplay, version)) {
    throw new RuntimeException("eglInitialize failed");
  }
  mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

  mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
  if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
    mEglContext = null;
    throwEglException("createContext");
  }

  mEglSurface = null;
}
 
Example #2
Source File: AndEngine.java    From tilt-game-android with MIT License 6 votes vote down vote up
private static void checkEGLConfigChooserSupport() throws DeviceNotSupportedException {
	/* Get an EGL instance. */
	final EGL10 egl = (EGL10) EGLContext.getEGL();

	/* Get to the default display. */
	final EGLDisplay eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

	/* We can now initialize EGL for that display. */
	final int[] version = new int[2];
	egl.eglInitialize(eglDisplay, version);

	final ConfigChooser configChooser = new ConfigChooser(new ConfigChooserOptions());

	try {
		configChooser.chooseConfig(egl, eglDisplay);
	} catch (final IllegalArgumentException e) {
		throw new DeviceNotSupportedException(DeviceNotSupportedCause.EGLCONFIG_NOT_FOUND, e);
	}
}
 
Example #3
Source File: ResizingSurfaceView.java    From ExoMedia with Apache License 2.0 6 votes vote down vote up
/**
 * Clears the frames from the current surface.  This should only be called when
 * the implementing video view has finished playback or otherwise released
 * the surface
 */
@Override
public void clearSurface() {
    try {
        EGL10 gl10 = (EGL10) EGLContext.getEGL();
        EGLDisplay display = gl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        gl10.eglInitialize(display, null);

        EGLConfig[] configs = new EGLConfig[1];
        gl10.eglChooseConfig(display, GL_CLEAR_CONFIG_ATTRIBUTES, configs, configs.length, new int[1]);
        EGLContext context = gl10.eglCreateContext(display, configs[0], EGL10.EGL_NO_CONTEXT, GL_CLEAR_CONTEXT_ATTRIBUTES);
        EGLSurface eglSurface = gl10.eglCreateWindowSurface(display, configs[0], this, new int[]{EGL10.EGL_NONE});

        gl10.eglMakeCurrent(display, eglSurface, eglSurface, context);
        gl10.eglSwapBuffers(display, eglSurface);
        gl10.eglDestroySurface(display, eglSurface);
        gl10.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
        gl10.eglDestroyContext(display, context);

        gl10.eglTerminate(display);
    } catch (Exception e) {
        Log.e(TAG, "Error clearing surface", e);
    }
}
 
Example #4
Source File: DeviceConfiguration.java    From android_packages_apps_GmsCore with Apache License 2.0 6 votes vote down vote up
private static void addExtensionsForConfig(EGL10 egl10, EGLDisplay egldisplay, EGLConfig eglconfig, int ai[],
                                           int ai1[], Set<String> set) {
    EGLContext eglcontext = egl10.eglCreateContext(egldisplay, eglconfig, EGL10.EGL_NO_CONTEXT, ai1);
    if (eglcontext != EGL10.EGL_NO_CONTEXT) {
        javax.microedition.khronos.egl.EGLSurface eglsurface =
                egl10.eglCreatePbufferSurface(egldisplay, eglconfig, ai);
        if (eglsurface == EGL10.EGL_NO_SURFACE) {
            egl10.eglDestroyContext(egldisplay, eglcontext);
        } else {
            egl10.eglMakeCurrent(egldisplay, eglsurface, eglsurface, eglcontext);
            String s = GLES10.glGetString(7939);
            if (s != null && !s.isEmpty()) {
                String as[] = s.split(" ");
                int i = as.length;
                for (int j = 0; j < i; j++) {
                    set.add(as[j]);
                }

            }
            egl10.eglMakeCurrent(egldisplay, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
            egl10.eglDestroySurface(egldisplay, eglsurface);
            egl10.eglDestroyContext(egldisplay, eglcontext);
        }
    }
}
 
Example #5
Source File: ShaderView.java    From ShaderEditor with MIT License 6 votes vote down vote up
@Override
public EGLContext createContext(EGL10 egl, EGLDisplay display,
		EGLConfig eglConfig) {
	EGLContext context = egl.eglCreateContext(display, eglConfig,
			EGL10.EGL_NO_CONTEXT, new int[]{
					EGL_CONTEXT_CLIENT_VERSION,
					3,
					EGL10.EGL_NONE
			});
	if (context != null && context != EGL10.EGL_NO_CONTEXT &&
			context.getGL() != null) {
		renderer.setVersion(3);
		return context;
	}
	return egl.eglCreateContext(display, eglConfig,
			EGL10.EGL_NO_CONTEXT, new int[]{
					EGL_CONTEXT_CLIENT_VERSION, 2,
					EGL10.EGL_NONE
			});
}
 
Example #6
Source File: EGL.java    From react-native-android-vitamio with MIT License 6 votes vote down vote up
public void start() {
  mEgl = (EGL10) EGLContext.getEGL();
  mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

  if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
    throw new RuntimeException("eglGetDisplay failed");
  }

  int[] version = new int[2];
  if (!mEgl.eglInitialize(mEglDisplay, version)) {
    throw new RuntimeException("eglInitialize failed");
  }
  mEglConfig = mEGLConfigChooser.chooseConfig(mEgl, mEglDisplay);

  mEglContext = mEGLContextFactory.createContext(mEgl, mEglDisplay, mEglConfig);
  if (mEglContext == null || mEglContext == EGL10.EGL_NO_CONTEXT) {
    mEglContext = null;
    throwEglException("createContext");
  }

  mEglSurface = null;
}
 
Example #7
Source File: OffScreenBlurRenderer.java    From HokoBlur with Apache License 2.0 6 votes vote down vote up
private BlurContext prepare(Bitmap bitmap) {
    EGLContext context = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext();
    if (context.equals(EGL10.EGL_NO_CONTEXT)) {
        throw new IllegalStateException("This thread has no EGLContext.");
    }

    if (mNeedRelink || mProgram == null) {
        deletePrograms();
        mProgram = ProgramFactory.create(vertexShaderCode, ShaderUtil.getFragmentShaderCode(mMode));
        mNeedRelink = false;
    }

    if (mProgram.id() == 0) {
        throw new IllegalStateException("Failed to create program.");
    }

    int w = bitmap.getWidth();
    int h = bitmap.getHeight();

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    GLES20.glViewport(0, 0, w, h);

    return new BlurContext(bitmap);

}
 
Example #8
Source File: TextureSizeUtils.java    From Moment with GNU General Public License v3.0 5 votes vote down vote up
public static int getMaxTextureSize() {
    // Safe minimum default size
    final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

    // Get EGL Display
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++) {
        // Only need to check for width since opengl textures are always squared
        egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

        // Keep track of the maximum texture size
        if (maximumTextureSize < textureSize[0])
            maximumTextureSize = textureSize[0];
    }

    // Release
    egl.eglTerminate(display);

    // Return largest texture size found, or default
    return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}
 
Example #9
Source File: TextureGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example #10
Source File: SimpleFPSDisplay.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example #11
Source File: GOSurfaceView.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void destroyContext(EGL10 arg0, EGLDisplay arg1, EGLContext arg2) {
	Log.w("gl", "Invalidating texture context");
	if(drawcontext != null) drawcontext.invalidateContext();
	AndroidTextDrawer.invalidateTextures();
	IContextDestroyedListener listener = contextDestroyedListener;
	if (listener != null) {
		listener.glContextDestroyed();
	}
	arg0.eglDestroyContext(arg1, arg2);
}
 
Example #12
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)
@Override
public android.opengl.EGLContext createContextAPI17(android.opengl.EGLDisplay display, android.opengl.EGLConfig eglConfig, android.opengl.EGLContext sharedContext) {
    int[] attrib_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, contextClientVersion,
            EGL14.EGL_NONE};
    return EGL14.eglCreateContext(display, eglConfig, sharedContext, attrib_list, 0);
}
 
Example #13
Source File: BasicGLCube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example #14
Source File: BasicGLCube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example #15
Source File: GLTextureView.java    From EZFilter with MIT License 5 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display,
                           EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
        if (LOG_THREADS) {
            Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
        }
        EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
    }
}
 
Example #16
Source File: DefaultContextFactory.java    From GPUVideo-android with MIT License 5 votes vote down vote up
@Override
public void destroyContext(final EGL10 egl, final EGLDisplay display, final EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e(TAG, "display:" + display + " context: " + context);
        throw new RuntimeException("eglDestroyContext" + egl.eglGetError());
    }
}
 
Example #17
Source File: VideoRenderThread.java    From ParsingPlayer with GNU Lesser General Public License v2.1 5 votes vote down vote up
@WorkerThread
private void initEGL() {
    egl10 = (EGL10) EGLContext.getEGL();
    eglDisplay = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
        raiseEGLInitError();
    }

    int[] majorMinorVersions = new int[2];
    if (!egl10.eglInitialize(eglDisplay, majorMinorVersions)) {
        raiseEGLInitError();
    }

    EGLConfig[] eglConfigs = new EGLConfig[1];
    int[] numOfConfigs = new int[1];
    if (!egl10.eglChooseConfig(eglDisplay, EGL_CONFIG_ATTRIBUTE_LIST, eglConfigs, 1, numOfConfigs)) {
        raiseEGLInitError();
    }
    LogUtil.v(TAG, "createWindowSurface by" + mNativeWindow.get());
    eglSurface = egl10.eglCreateWindowSurface(eglDisplay, eglConfigs[0], mNativeWindow.get(), EGL_SURFACE_ATTRIBUTE_LIST);
    if (eglSurface == EGL10.EGL_NO_SURFACE) {
        raiseEGLInitError();
    }

    eglContext = egl10.eglCreateContext(eglDisplay, eglConfigs[0], EGL10.EGL_NO_CONTEXT, EGL_CONTEXT_ATTRIBUTE_LIST);
    if (eglContext == EGL10.EGL_NO_CONTEXT) {
        raiseEGLInitError();
    }

    if (!egl10.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
        raiseEGLInitError();
    }

    LogUtil.d(TAG, "initEGL");
}
 
Example #18
Source File: TextureVideoView.java    From texturevideoview with Apache License 2.0 5 votes vote down vote up
/**
 * Clears the surface texture by attaching a GL context and clearing it.
 * Code taken from <a href="http://stackoverflow.com/a/31582209">Hugo Gresse's answer on stackoverflow.com</a>.
 */
private void clearSurface() {
    if (mSurface == null || Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        return;
    }

    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    egl.eglInitialize(display, null);

    int[] attribList = {
        EGL10.EGL_RED_SIZE, 8,
        EGL10.EGL_GREEN_SIZE, 8,
        EGL10.EGL_BLUE_SIZE, 8,
        EGL10.EGL_ALPHA_SIZE, 8,
        EGL10.EGL_RENDERABLE_TYPE, EGL10.EGL_WINDOW_BIT,
        EGL10.EGL_NONE, 0,      // placeholder for recordable [@-3]
        EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    egl.eglChooseConfig(display, attribList, configs, configs.length, numConfigs);
    EGLConfig config = configs[0];
    EGLContext context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, new int[]{
        12440, 2, EGL10.EGL_NONE
    });
    EGLSurface eglSurface = egl.eglCreateWindowSurface(display, config, mSurface, new int[]{
        EGL10.EGL_NONE
    });

    egl.eglMakeCurrent(display, eglSurface, eglSurface, context);
    GLES20.glClearColor(0, 0, 0, 1);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    egl.eglSwapBuffers(display, eglSurface);
    egl.eglDestroySurface(display, eglSurface);
    egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl.eglDestroyContext(display, context);
    egl.eglTerminate(display);
}
 
Example #19
Source File: TextureGL.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}
 
Example #20
Source File: GLTextureView.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display,
                           EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
        if (LOG_THREADS) {
            Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
        }
        EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
    }
}
 
Example #21
Source File: PixelBuffer.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
public PixelBuffer(final int width, final int height, final boolean isStereo) {
    mWidth = isStereo ? width * 2 : width;
    mHeight = height;
    mIb = IntBuffer.allocate(mWidth * mHeight);
    mBitmap = Bitmap.createBitmap(mWidth, mHeight, Bitmap.Config.ARGB_8888);

    mEGL = (EGL10) EGLContext.getEGL();
    mEGLDisplay = mEGL.eglGetDisplay(EGL_DEFAULT_DISPLAY);
    int[] version = new int[2];
    mEGL.eglInitialize(mEGLDisplay, version);
    mEGLConfigs = chooseConfigs();
    mEGLConfig = mEGLConfigs[0];
    mEGLContext = mEGL.eglCreateContext(mEGLDisplay, mEGLConfig, EGL_NO_CONTEXT, new int[] {
            0x3098, // EGL_CONTEXT_CLIENT_VERSION
            2,      // OpenGL ES 2.0
            EGL10.EGL_NONE });

    mEGLSurface = mEGL.eglCreatePbufferSurface(mEGLDisplay, mEGLConfig, new int[] {
            EGL_WIDTH, mWidth,
            EGL_HEIGHT, mHeight,
            EGL_NONE
        });

    mEGL.eglMakeCurrent(mEGLDisplay, mEGLSurface, mEGLSurface, mEGLContext);
    mGL = (GL10) mEGLContext.getGL();

    mThreadOwner = Thread.currentThread().getName();
}
 
Example #22
Source File: DefaultContextFactory.java    From CameraRecorder-android with MIT License 5 votes vote down vote up
@Override
public void destroyContext(final EGL10 egl, final EGLDisplay display, final EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e(TAG, "display:" + display + " context: " + context);
        throw new RuntimeException("eglDestroyContext" + egl.eglGetError());
    }
}
 
Example #23
Source File: GLTextureView.java    From MD360Player4Android with Apache License 2.0 5 votes vote down vote up
public void destroyContext(EGL10 egl, EGLDisplay display,
                           EGLContext context) {
    if (!egl.eglDestroyContext(display, context)) {
        Log.e("DefaultContextFactory", "display:" + display + " context: " + context);
        if (LOG_THREADS) {
            Log.i("DefaultContextFactory", "tid=" + Thread.currentThread().getId());
        }
        EglHelper.throwEglException("eglDestroyContex", egl.eglGetError());
    }
}
 
Example #24
Source File: EGLBase10.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * 現在のスレッドの既存のレンダリングコンテキストがあればそれを共有して
 * 新しいレンダリングコンテキストを生成する
 * 既存のレンダリングコンテキストが存在していなければ独立したレンダリングコンテキストを
 * 生成する
 * @param maxClientVersion
 * @param withDepthBuffer
 * @param stencilBits
 * @param isRecordable
 * @return
 */
/*package*/ static EGLBase createFromCurrentImpl(final int maxClientVersion,
	final boolean withDepthBuffer, final int stencilBits, final boolean isRecordable) {

	Context context = null;
	final EGL10 egl10 = (EGL10)EGLContext.getEGL();
	final EGLContext currentContext = egl10.eglGetCurrentContext();
	final EGLSurface currentSurface = egl10.eglGetCurrentSurface(EGL10.EGL_DRAW);
	if ((currentContext != null) && (currentSurface != null)) {
		context = wrap(currentContext);
	}
	return new EGLBase10(maxClientVersion, context, withDepthBuffer, stencilBits, isRecordable);
}
 
Example #25
Source File: Utils.java    From react-native-documentscanner-android with MIT License 5 votes vote down vote up
public static int getMaxTextureSize() {
    // Safe minimum default size
    final int IMAGE_MAX_BITMAP_DIMENSION = 2048;

    // Get EGL Display
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    // Initialise
    int[] version = new int[2];
    egl.eglInitialize(display, version);

    // Query total number of configurations
    int[] totalConfigurations = new int[1];
    egl.eglGetConfigs(display, null, 0, totalConfigurations);

    // Query actual list configurations
    EGLConfig[] configurationsList = new EGLConfig[totalConfigurations[0]];
    egl.eglGetConfigs(display, configurationsList, totalConfigurations[0], totalConfigurations);

    int[] textureSize = new int[1];
    int maximumTextureSize = 0;

    // Iterate through all the configurations to located the maximum texture size
    for (int i = 0; i < totalConfigurations[0]; i++) {
        // Only need to check for width since opengl textures are always squared
        egl.eglGetConfigAttrib(display, configurationsList[i], EGL10.EGL_MAX_PBUFFER_WIDTH, textureSize);

        // Keep track of the maximum texture size
        if (maximumTextureSize < textureSize[0])
            maximumTextureSize = textureSize[0];
    }

    // Release
    egl.eglTerminate(display);

    // Return largest texture size found, or default
    return Math.max(maximumTextureSize, IMAGE_MAX_BITMAP_DIMENSION);
}
 
Example #26
Source File: DeviceConfiguration.java    From android_packages_apps_GmsCore with Apache License 2.0 5 votes vote down vote up
private static void addEglExtensions(Set<String> glExtensions) {
    EGL10 egl10 = (EGL10) EGLContext.getEGL();
    if (egl10 != null) {
        EGLDisplay display = egl10.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        egl10.eglInitialize(display, new int[2]);
        int cf[] = new int[1];
        if (egl10.eglGetConfigs(display, null, 0, cf)) {
            EGLConfig[] configs = new EGLConfig[cf[0]];
            if (egl10.eglGetConfigs(display, configs, cf[0], cf)) {
                int[] a1 =
                        new int[]{EGL10.EGL_WIDTH, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_HEIGHT, EGL10.EGL_PBUFFER_BIT,
                                EGL10.EGL_NONE};
                int[] a2 = new int[]{12440, EGL10.EGL_PIXMAP_BIT, EGL10.EGL_NONE};
                int[] a3 = new int[1];
                for (int i = 0; i < cf[0]; i++) {
                    egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_CONFIG_CAVEAT, a3);
                    if (a3[0] != EGL10.EGL_SLOW_CONFIG) {
                        egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_SURFACE_TYPE, a3);
                        if ((1 & a3[0]) != 0) {
                            egl10.eglGetConfigAttrib(display, configs[i], EGL10.EGL_RENDERABLE_TYPE, a3);
                            if ((1 & a3[0]) != 0) {
                                addExtensionsForConfig(egl10, display, configs[i], a1, null, glExtensions);
                            }
                            if ((4 & a3[0]) != 0) {
                                addExtensionsForConfig(egl10, display, configs[i], a1, a2, glExtensions);
                            }
                        }
                    }
                }
            }
        }
        egl10.eglTerminate(display);
    }
}
 
Example #27
Source File: GLTextureView.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
    int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, mEGLContextClientVersion,
            EGL10.EGL_NONE };

    return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT,
            mEGLContextClientVersion != 0 ? attrib_list : null);
}
 
Example #28
Source File: GLTextureView.java    From alpha-movie with Apache License 2.0 5 votes vote down vote up
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
    int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, mEGLContextClientVersion,
            EGL10.EGL_NONE };

    return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT,
            mEGLContextClientVersion != 0 ? attrib_list : null);
}
 
Example #29
Source File: EGLLogWrapper.java    From android-openGL-canvas with Apache License 2.0 5 votes vote down vote up
public boolean eglMakeCurrent(EGLDisplay display, EGLSurface draw,
                              EGLSurface read, EGLContext context) {
    begin("eglMakeCurrent");
    arg("display", display);
    arg("draw", draw);
    arg("read", read);
    arg("context", context);
    end();
    boolean result = mEgl10.eglMakeCurrent(display, draw, read, context);
    returns(result);
    checkError();
    return result;
}
 
Example #30
Source File: SimpleLitGLCube.java    From opengl with Apache License 2.0 5 votes vote down vote up
public void initEGL() {
    mEGL = (EGL10) GLDebugHelper.wrap(EGLContext.getEGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD,  null);
    
    mGLDisplay = mEGL.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);

    int[] curGLVersion = new int[2];
    mEGL.eglInitialize(mGLDisplay, curGLVersion);

    Log.i("GL", "GL version = " + curGLVersion[0] + "."
            + curGLVersion[1]);

    EGLConfig[] configs = new EGLConfig[1];
    int[] num_config = new int[1];
    mEGL.eglChooseConfig(mGLDisplay, mConfigSpec, configs, 1,
            num_config);
    mGLConfig = configs[0];

    mGLSurface = mEGL.eglCreateWindowSurface(mGLDisplay, mGLConfig, sv
            .getHolder(), null);

    mGLContext = mEGL.eglCreateContext(mGLDisplay, mGLConfig,
            EGL10.EGL_NO_CONTEXT, null);

    mEGL.eglMakeCurrent(mGLDisplay, mGLSurface, mGLSurface, mGLContext);
    mGL = (GL10) GLDebugHelper.wrap(mGLContext.getGL(),
            GLDebugHelper.CONFIG_CHECK_GL_ERROR
                    | GLDebugHelper.CONFIG_CHECK_THREAD
                    | GLDebugHelper.CONFIG_LOG_ARGUMENT_NAMES, null);
}