Search in sources :

Example 11 with EGL10

use of javax.microedition.khronos.egl.EGL10 in project android_frameworks_base by crdroidandroid.

the class RenderTarget method focusNone.

public static void focusNone() {
    EGL10 egl = (EGL10) EGLContext.getEGL();
    egl.eglMakeCurrent(egl.eglGetCurrentDisplay(), EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    mCurrentTarget.set(null);
    checkEglError(egl, "eglMakeCurrent");
}
Also used : EGL10(javax.microedition.khronos.egl.EGL10)

Example 12 with EGL10

use of javax.microedition.khronos.egl.EGL10 in project platform_frameworks_base by android.

the class SingleFrameTextureViewTestActivity method onSurfaceTextureAvailable.

@Override
public void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height) {
    Log.d(LOG_TAG, "onSurfaceAvailable");
    mGLThread = new Thread() {

        static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;

        static final int EGL_OPENGL_ES2_BIT = 4;

        private EGL10 mEgl;

        private EGLDisplay mEglDisplay;

        private EGLConfig mEglConfig;

        private EGLContext mEglContext;

        private EGLSurface mEglSurface;

        @Override
        public void run() {
            initGL();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
            for (int i = 0; i < 2; i++) {
                if (i == 0) {
                    glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
                } else {
                    glClearColor(0.0f, 1.0f, 0.0f, 1.0f);
                }
                glClear(GL_COLOR_BUFFER_BIT);
                Log.d(LOG_TAG, "eglSwapBuffers");
                if (!mEgl.eglSwapBuffers(mEglDisplay, mEglSurface)) {
                    throw new RuntimeException("Cannot swap buffers");
                }
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                }
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
            }
            finishGL();
        }

        private void finishGL() {
            mEgl.eglDestroyContext(mEglDisplay, mEglContext);
            mEgl.eglDestroySurface(mEglDisplay, mEglSurface);
        }

        private void initGL() {
            mEgl = (EGL10) EGLContext.getEGL();
            mEglDisplay = mEgl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
            if (mEglDisplay == EGL10.EGL_NO_DISPLAY) {
                throw new RuntimeException("eglGetDisplay failed " + GLUtils.getEGLErrorString(mEgl.eglGetError()));
            }
            int[] version = new int[2];
            if (!mEgl.eglInitialize(mEglDisplay, version)) {
                throw new RuntimeException("eglInitialize failed " + GLUtils.getEGLErrorString(mEgl.eglGetError()));
            }
            mEglConfig = chooseEglConfig();
            if (mEglConfig == null) {
                throw new RuntimeException("eglConfig not initialized");
            }
            mEglContext = createContext(mEgl, mEglDisplay, mEglConfig);
            mEglSurface = mEgl.eglCreateWindowSurface(mEglDisplay, mEglConfig, surface, null);
            if (mEglSurface == null || mEglSurface == EGL10.EGL_NO_SURFACE) {
                int error = mEgl.eglGetError();
                if (error == EGL10.EGL_BAD_NATIVE_WINDOW) {
                    Log.e(LOG_TAG, "createWindowSurface returned EGL_BAD_NATIVE_WINDOW.");
                    return;
                }
                throw new RuntimeException("createWindowSurface failed " + GLUtils.getEGLErrorString(error));
            }
            if (!mEgl.eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, mEglContext)) {
                throw new RuntimeException("eglMakeCurrent failed " + GLUtils.getEGLErrorString(mEgl.eglGetError()));
            }
        }

        EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
            int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
            return egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
        }

        private EGLConfig chooseEglConfig() {
            int[] configsCount = new int[1];
            EGLConfig[] configs = new EGLConfig[1];
            int[] configSpec = getConfig();
            if (!mEgl.eglChooseConfig(mEglDisplay, configSpec, configs, 1, configsCount)) {
                throw new IllegalArgumentException("eglChooseConfig failed " + GLUtils.getEGLErrorString(mEgl.eglGetError()));
            } else if (configsCount[0] > 0) {
                return configs[0];
            }
            return null;
        }

        private int[] getConfig() {
            return new int[] { EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_RED_SIZE, 8, EGL10.EGL_GREEN_SIZE, 8, EGL10.EGL_BLUE_SIZE, 8, EGL10.EGL_ALPHA_SIZE, 8, EGL10.EGL_DEPTH_SIZE, 0, EGL10.EGL_STENCIL_SIZE, 0, EGL10.EGL_NONE };
        }
    };
    mGLThread.start();
}
Also used : EGLSurface(javax.microedition.khronos.egl.EGLSurface) EGL10(javax.microedition.khronos.egl.EGL10) EGLDisplay(javax.microedition.khronos.egl.EGLDisplay) EGLContext(javax.microedition.khronos.egl.EGLContext) EGLConfig(javax.microedition.khronos.egl.EGLConfig)

Example 13 with EGL10

use of javax.microedition.khronos.egl.EGL10 in project libgdx by libgdx.

the class AndroidGraphics method logConfig.

private void logConfig(EGLConfig config) {
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int r = getAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0);
    int g = getAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
    int b = getAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0);
    int a = getAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0);
    int d = getAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
    int s = getAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
    int samples = Math.max(getAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0), getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0));
    boolean coverageSample = getAttrib(egl, display, config, GdxEglConfigChooser.EGL_COVERAGE_SAMPLES_NV, 0) != 0;
    Gdx.app.log(LOG_TAG, "framebuffer: (" + r + ", " + g + ", " + b + ", " + a + ")");
    Gdx.app.log(LOG_TAG, "depthbuffer: (" + d + ")");
    Gdx.app.log(LOG_TAG, "stencilbuffer: (" + s + ")");
    Gdx.app.log(LOG_TAG, "samples: (" + samples + ")");
    Gdx.app.log(LOG_TAG, "coverage sampling: (" + coverageSample + ")");
    bufferFormat = new BufferFormat(r, g, b, a, d, s, samples, coverageSample);
}
Also used : EGL10(javax.microedition.khronos.egl.EGL10) EGLDisplay(javax.microedition.khronos.egl.EGLDisplay)

Example 14 with EGL10

use of javax.microedition.khronos.egl.EGL10 in project libgdx by libgdx.

the class AndroidGraphics method checkGL20.

protected boolean checkGL20() {
    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] version = new int[2];
    egl.eglInitialize(display, version);
    int EGL_OPENGL_ES2_BIT = 4;
    int[] configAttribs = { EGL10.EGL_RED_SIZE, 4, EGL10.EGL_GREEN_SIZE, 4, EGL10.EGL_BLUE_SIZE, 4, EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE };
    EGLConfig[] configs = new EGLConfig[10];
    int[] num_config = new int[1];
    egl.eglChooseConfig(display, configAttribs, configs, 10, num_config);
    egl.eglTerminate(display);
    return num_config[0] > 0;
}
Also used : EGL10(javax.microedition.khronos.egl.EGL10) EGLDisplay(javax.microedition.khronos.egl.EGLDisplay) EGLConfig(javax.microedition.khronos.egl.EGLConfig)

Example 15 with EGL10

use of javax.microedition.khronos.egl.EGL10 in project uCrop by Yalantis.

the class EglUtils method getMaxTextureEgl10.

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private static int getMaxTextureEgl10() {
    EGL10 egl = (EGL10) javax.microedition.khronos.egl.EGLContext.getEGL();
    javax.microedition.khronos.egl.EGLDisplay dpy = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    int[] vers = new int[2];
    egl.eglInitialize(dpy, vers);
    int[] configAttr = { EGL10.EGL_COLOR_BUFFER_TYPE, EGL10.EGL_RGB_BUFFER, EGL10.EGL_LEVEL, 0, EGL10.EGL_SURFACE_TYPE, EGL10.EGL_PBUFFER_BIT, EGL10.EGL_NONE };
    javax.microedition.khronos.egl.EGLConfig[] configs = new javax.microedition.khronos.egl.EGLConfig[1];
    int[] numConfig = new int[1];
    egl.eglChooseConfig(dpy, configAttr, configs, 1, numConfig);
    if (numConfig[0] == 0) {
        return 0;
    }
    javax.microedition.khronos.egl.EGLConfig config = configs[0];
    int[] surfAttr = { EGL10.EGL_WIDTH, 64, EGL10.EGL_HEIGHT, 64, EGL10.EGL_NONE };
    javax.microedition.khronos.egl.EGLSurface surf = egl.eglCreatePbufferSurface(dpy, config, surfAttr);
    // missing in EGL10
    final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
    int[] ctxAttrib = { EGL_CONTEXT_CLIENT_VERSION, 1, EGL10.EGL_NONE };
    javax.microedition.khronos.egl.EGLContext ctx = egl.eglCreateContext(dpy, config, EGL10.EGL_NO_CONTEXT, ctxAttrib);
    egl.eglMakeCurrent(dpy, surf, surf, ctx);
    int[] maxSize = new int[1];
    GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0);
    egl.eglMakeCurrent(dpy, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_CONTEXT);
    egl.eglDestroySurface(dpy, surf);
    egl.eglDestroyContext(dpy, ctx);
    egl.eglTerminate(dpy);
    return maxSize[0];
}
Also used : EGL10(javax.microedition.khronos.egl.EGL10) EGLConfig(android.opengl.EGLConfig) TargetApi(android.annotation.TargetApi)

Aggregations

EGL10 (javax.microedition.khronos.egl.EGL10)22 EGLDisplay (javax.microedition.khronos.egl.EGLDisplay)16 EGLConfig (javax.microedition.khronos.egl.EGLConfig)12 EGLContext (javax.microedition.khronos.egl.EGLContext)9 EGLSurface (javax.microedition.khronos.egl.EGLSurface)8 SuppressLint (android.annotation.SuppressLint)1 TargetApi (android.annotation.TargetApi)1 Paint (android.graphics.Paint)1 EGLConfig (android.opengl.EGLConfig)1 TextPaint (android.text.TextPaint)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ConfigChooser (org.andengine.opengl.view.ConfigChooser)1 DeviceNotSupportedException (org.andengine.util.exception.DeviceNotSupportedException)1