Search in sources :

Example 21 with EGLConfig

use of javax.microedition.khronos.egl.EGLConfig in project android_frameworks_base by DirtyUnicorns.

the class RenderTarget method createSurface.

private static EGLSurface createSurface(EGL10 egl, EGLDisplay display, int width, int height) {
    EGLConfig eglConfig = chooseEglConfig(egl, display);
    int[] attribs = { EGL10.EGL_WIDTH, width, EGL10.EGL_HEIGHT, height, EGL10.EGL_NONE };
    return egl.eglCreatePbufferSurface(display, eglConfig, attribs);
}
Also used : EGLConfig(javax.microedition.khronos.egl.EGLConfig)

Example 22 with EGLConfig

use of javax.microedition.khronos.egl.EGLConfig in project android_frameworks_base by DirtyUnicorns.

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 23 with EGLConfig

use of javax.microedition.khronos.egl.EGLConfig in project jmonkeyengine by jMonkeyEngine.

the class AndroidConfigChooser method getConfigs.

/**
     * Query egl for the available configs
     * @param egl
     * @param display
     * @return
     */
private EGLConfig[] getConfigs(EGL10 egl, EGLDisplay display) {
    int[] num_config = new int[1];
    int[] configSpec = new int[] { EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL10.EGL_NONE };
    if (!egl.eglChooseConfig(display, configSpec, null, 0, num_config)) {
        RendererUtil.checkEGLError(egl);
        throw new AssertionError();
    }
    int numConfigs = num_config[0];
    EGLConfig[] configs = new EGLConfig[numConfigs];
    if (!egl.eglChooseConfig(display, configSpec, configs, numConfigs, num_config)) {
        RendererUtil.checkEGLError(egl);
        throw new AssertionError();
    }
    logger.fine("--------------Display Configurations---------------");
    for (EGLConfig eGLConfig : configs) {
        logEGLConfig(eGLConfig, display, egl, Level.FINE);
        logger.fine("----------------------------------------");
    }
    return configs;
}
Also used : EGLConfig(javax.microedition.khronos.egl.EGLConfig)

Example 24 with EGLConfig

use of javax.microedition.khronos.egl.EGLConfig in project jmonkeyengine by jMonkeyEngine.

the class AndroidConfigChooser method chooseConfig.

private EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs, Config requestedConfig, boolean higherRGB, boolean higherAlpha, boolean higherSamples, boolean higherStencil) {
    EGLConfig keptConfig = null;
    int kr = 0;
    int kg = 0;
    int kb = 0;
    int ka = 0;
    int kd = 0;
    int ks = 0;
    int kst = 0;
    // first pass through config list.  Try to find an exact match.
    for (EGLConfig config : configs) {
        int r = eglGetConfigAttribSafe(egl, display, config, EGL10.EGL_RED_SIZE);
        int g = eglGetConfigAttribSafe(egl, display, config, EGL10.EGL_GREEN_SIZE);
        int b = eglGetConfigAttribSafe(egl, display, config, EGL10.EGL_BLUE_SIZE);
        int a = eglGetConfigAttribSafe(egl, display, config, EGL10.EGL_ALPHA_SIZE);
        int d = eglGetConfigAttribSafe(egl, display, config, EGL10.EGL_DEPTH_SIZE);
        int s = eglGetConfigAttribSafe(egl, display, config, EGL10.EGL_SAMPLES);
        int st = eglGetConfigAttribSafe(egl, display, config, EGL10.EGL_STENCIL_SIZE);
        logger.log(Level.FINE, "Checking Config r: {0}, g: {1}, b: {2}, alpha: {3}, depth: {4}, samples: {5}, stencil: {6}", new Object[] { r, g, b, a, d, s, st });
        if (higherRGB && r < requestedConfig.r) {
            continue;
        }
        if (!higherRGB && r != requestedConfig.r) {
            continue;
        }
        if (higherRGB && g < requestedConfig.g) {
            continue;
        }
        if (!higherRGB && g != requestedConfig.g) {
            continue;
        }
        if (higherRGB && b < requestedConfig.b) {
            continue;
        }
        if (!higherRGB && b != requestedConfig.b) {
            continue;
        }
        if (higherAlpha && a < requestedConfig.a) {
            continue;
        }
        if (!higherAlpha && a != requestedConfig.a) {
            continue;
        }
        // always allow higher depth
        if (d < requestedConfig.d) {
            continue;
        }
        if (higherSamples && s < requestedConfig.s) {
            continue;
        }
        if (!higherSamples && s != requestedConfig.s) {
            continue;
        }
        if (higherStencil && st < requestedConfig.st) {
            continue;
        }
        if (!higherStencil && !inRange(st, 0, requestedConfig.st)) {
            continue;
        }
        //we keep the config if it is better
        if (r >= kr || g >= kg || b >= kb || a >= ka || d >= kd || s >= ks || st >= kst) {
            kr = r;
            kg = g;
            kb = b;
            ka = a;
            kd = d;
            ks = s;
            kst = st;
            keptConfig = config;
            logger.log(Level.FINE, "Keeping Config r: {0}, g: {1}, b: {2}, alpha: {3}, depth: {4}, samples: {5}, stencil: {6}", new Object[] { r, g, b, a, d, s, st });
        }
    }
    if (keptConfig != null) {
        return keptConfig;
    }
    //no match found
    logger.log(Level.SEVERE, "No egl config match found");
    return null;
}
Also used : EGLConfig(javax.microedition.khronos.egl.EGLConfig)

Example 25 with EGLConfig

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

the class RenderTarget method forSurfaceTexture.

@TargetApi(11)
public RenderTarget forSurfaceTexture(SurfaceTexture surfaceTexture) {
    EGLConfig eglConfig = chooseEglConfig(mEgl, mDisplay);
    EGLSurface eglSurf = null;
    synchronized (mSurfaceSources) {
        eglSurf = mSurfaceSources.get(surfaceTexture);
        if (eglSurf == null) {
            eglSurf = mEgl.eglCreateWindowSurface(mDisplay, eglConfig, surfaceTexture, null);
            mSurfaceSources.put(surfaceTexture, eglSurf);
        }
    }
    checkEglError(mEgl, "eglCreateWindowSurface");
    checkSurface(mEgl, eglSurf);
    RenderTarget result = new RenderTarget(mDisplay, mContext, eglSurf, 0, false, true);
    result.setSurfaceSource(surfaceTexture);
    result.addReferenceTo(eglSurf);
    return result;
}
Also used : EGLSurface(javax.microedition.khronos.egl.EGLSurface) EGLConfig(javax.microedition.khronos.egl.EGLConfig) TargetApi(android.annotation.TargetApi)

Aggregations

EGLConfig (javax.microedition.khronos.egl.EGLConfig)42 EGLSurface (javax.microedition.khronos.egl.EGLSurface)20 EGL10 (javax.microedition.khronos.egl.EGL10)12 EGLDisplay (javax.microedition.khronos.egl.EGLDisplay)12 TargetApi (android.annotation.TargetApi)9 EGLContext (javax.microedition.khronos.egl.EGLContext)8 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1 TextPaint (android.text.TextPaint)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1