Search in sources :

Example 26 with EGLConfig

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

the class RenderTarget method forSurfaceHolder.

public RenderTarget forSurfaceHolder(SurfaceHolder surfaceHolder) {
    EGLConfig eglConfig = chooseEglConfig(mEgl, mDisplay);
    EGLSurface eglSurf = null;
    synchronized (mSurfaceSources) {
        eglSurf = mSurfaceSources.get(surfaceHolder);
        if (eglSurf == null) {
            eglSurf = mEgl.eglCreateWindowSurface(mDisplay, eglConfig, surfaceHolder, null);
            mSurfaceSources.put(surfaceHolder, eglSurf);
        }
    }
    checkEglError(mEgl, "eglCreateWindowSurface");
    checkSurface(mEgl, eglSurf);
    RenderTarget result = new RenderTarget(mDisplay, mContext, eglSurf, 0, false, true);
    result.addReferenceTo(eglSurf);
    result.setSurfaceSource(surfaceHolder);
    return result;
}
Also used : EGLSurface(javax.microedition.khronos.egl.EGLSurface) EGLConfig(javax.microedition.khronos.egl.EGLConfig)

Example 27 with EGLConfig

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

the class RenderTarget method forSurface.

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

Example 28 with EGLConfig

use of javax.microedition.khronos.egl.EGLConfig 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 29 with EGLConfig

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

the class AndroidConfigChooser method chooseConfig.

/**
     * Gets called by the GLSurfaceView class to return the best config
     */
@Override
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
    logger.fine("GLSurfaceView asking for egl config");
    Config requestedConfig = getRequestedConfig();
    EGLConfig[] configs = getConfigs(egl, display);
    // First try to find an exact match, but allowing a higher stencil
    EGLConfig choosenConfig = chooseConfig(egl, display, configs, requestedConfig, false, false, false, true);
    if (choosenConfig == null && requestedConfig.d > 16) {
        logger.log(Level.INFO, "EGL configuration not found, reducing depth");
        requestedConfig.d = 16;
        choosenConfig = chooseConfig(egl, display, configs, requestedConfig, false, false, false, true);
    }
    if (choosenConfig == null) {
        logger.log(Level.INFO, "EGL configuration not found, allowing higher RGB");
        choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, false, false, true);
    }
    if (choosenConfig == null && requestedConfig.a > 0) {
        logger.log(Level.INFO, "EGL configuration not found, allowing higher alpha");
        choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, true, false, true);
    }
    if (choosenConfig == null && requestedConfig.s > 0) {
        logger.log(Level.INFO, "EGL configuration not found, allowing higher samples");
        choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, true, true, true);
    }
    if (choosenConfig == null && requestedConfig.a > 0) {
        logger.log(Level.INFO, "EGL configuration not found, reducing alpha");
        requestedConfig.a = 1;
        choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, true, false, true);
    }
    if (choosenConfig == null && requestedConfig.s > 0) {
        logger.log(Level.INFO, "EGL configuration not found, reducing samples");
        requestedConfig.s = 1;
        if (requestedConfig.a > 0) {
            choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, true, true, true);
        } else {
            choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, false, true, true);
        }
    }
    if (choosenConfig == null && requestedConfig.getBitsPerPixel() > 16) {
        logger.log(Level.INFO, "EGL configuration not found, setting to RGB565");
        requestedConfig.r = 5;
        requestedConfig.g = 6;
        requestedConfig.b = 5;
        choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, false, false, true);
        if (choosenConfig == null) {
            logger.log(Level.INFO, "EGL configuration not found, allowing higher alpha");
            choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, true, false, true);
        }
    }
    if (choosenConfig == null) {
        logger.log(Level.INFO, "EGL configuration not found, looking for best config with >= 16 bit Depth");
        //failsafe, should pick best config with at least 16 depth
        requestedConfig = new Config(0, 0, 0, 0, 16, 0, 0);
        choosenConfig = chooseConfig(egl, display, configs, requestedConfig, true, false, false, true);
    }
    if (choosenConfig != null) {
        logger.fine("GLSurfaceView asks for egl config, returning: ");
        logEGLConfig(choosenConfig, display, egl, Level.FINE);
        storeSelectedConfig(egl, display, choosenConfig);
        return choosenConfig;
    } else {
        logger.severe("No EGL Config found");
        return null;
    }
}
Also used : EGLConfig(javax.microedition.khronos.egl.EGLConfig) EGLConfig(javax.microedition.khronos.egl.EGLConfig)

Example 30 with EGLConfig

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

the class GdxEglConfigChooser method chooseConfig.

public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs) {
    EGLConfig best = null;
    EGLConfig bestAA = null;
    // default back to 565 when no exact match found
    EGLConfig safe = null;
    for (EGLConfig config : configs) {
        int d = findConfigAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
        int s = findConfigAttrib(egl, display, config, EGL10.EGL_STENCIL_SIZE, 0);
        // We need at least mDepthSize and mStencilSize bits
        if (d < mDepthSize || s < mStencilSize)
            continue;
        // We want an *exact* match for red/green/blue/alpha
        int r = findConfigAttrib(egl, display, config, EGL10.EGL_RED_SIZE, 0);
        int g = findConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
        int b = findConfigAttrib(egl, display, config, EGL10.EGL_BLUE_SIZE, 0);
        int a = findConfigAttrib(egl, display, config, EGL10.EGL_ALPHA_SIZE, 0);
        // Match RGB565 as a fallback
        if (safe == null && r == 5 && g == 6 && b == 5 && a == 0) {
            safe = config;
        }
        // isn't set already.
        if (best == null && r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) {
            best = config;
            // if no AA is requested we can bail out here.
            if (mNumSamples == 0) {
                break;
            }
        }
        // now check for MSAA support
        int hasSampleBuffers = findConfigAttrib(egl, display, config, EGL10.EGL_SAMPLE_BUFFERS, 0);
        int numSamples = findConfigAttrib(egl, display, config, EGL10.EGL_SAMPLES, 0);
        // We take the first sort of matching config, thank you.
        if (bestAA == null && hasSampleBuffers == 1 && numSamples >= mNumSamples && r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) {
            bestAA = config;
            continue;
        }
        // for this to work we need to call the extension glCoverageMaskNV which is not
        // exposed in the Android bindings. We'd have to link agains the NVidia SDK and
        // that is simply not going to happen.
        // // still no luck, let's try CSAA support
        hasSampleBuffers = findConfigAttrib(egl, display, config, EGL_COVERAGE_BUFFERS_NV, 0);
        numSamples = findConfigAttrib(egl, display, config, EGL_COVERAGE_SAMPLES_NV, 0);
        // We take the first sort of matching config, thank you.
        if (bestAA == null && hasSampleBuffers == 1 && numSamples >= mNumSamples && r == mRedSize && g == mGreenSize && b == mBlueSize && a == mAlphaSize) {
            bestAA = config;
            continue;
        }
    }
    if (bestAA != null)
        return bestAA;
    else if (best != null)
        return best;
    else
        return safe;
}
Also used : EGLConfig(javax.microedition.khronos.egl.EGLConfig)

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