0

I'm having issues when trying to initialize the EGLContext only on Android emulators.

For a strange reason, when I try to get the EGL3 Config it doesn't find anything...

This is the logic that I'm using:

EGL14.eglInitialize(mEGLDisplay, version, 0, version, 1)
EGLConfig config = getConfig(flags, 3);
if (config != null) {
    int[] attrib3_list = {
            EGL14.EGL_CONTEXT_CLIENT_VERSION, 3,
            EGL14.EGL_NONE
    };
    EGLContext context = EGL14.eglCreateContext(mEGLDisplay, config, sharedContext,
            attrib3_list, 0);


    if (EGL14.eglGetError() == EGL14.EGL_SUCCESS) {
        //Log.d(TAG, "Got GLES 3 config");
        mEGLConfig = config;
        mEGLContext = context;
        mGlVersion = 3;
    }
}

And here is the getConfig method

/**
 * 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_SAMPLES, 4,
            //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];
}

The emulator it's already compatible with EGL3; since I'm getting the following log: D/EGL_emulation: eglMakeCurrent: 0xe7205360: ver 3 0 (tinfo 0xe72031f0)

I'm out of ideas here...

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
vicmns
  • 724
  • 1
  • 8
  • 20

1 Answers1

0

Finally! I was able to get a valid configuration. So the problem was given by the following if

if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
        numConfigs, 0)) {
    Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig");
    return null;
}

Only on emulators eglChooseConfig will always return false, even if it found a valid configuration...

So I ended up with the following logic:

EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length,
        numConfigs, 0);
if (EGL14.eglGetError() != EGL14.EGL_SUCCESS) {
    Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig " + EGL14.eglGetError());
    return null;
}

I know it's a bit of a Hack, but for the time being "it works"

vicmns
  • 724
  • 1
  • 8
  • 20