TextureView无法获取EGL3 for Emulator

时间:2018-10-11 16:31:27

标签: android opengl-es android-textureview

仅在Android模拟器上尝试初始化EGLContext时遇到问题。

出于一个奇怪的原因,当我尝试获取EGL3 Config时,它什么也没找到...

这是我使用的逻辑:

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;
    }
}

这是getConfig方法

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

该模拟器已经与EGL3兼容;因为我收到以下日志:D/EGL_emulation: eglMakeCurrent: 0xe7205360: ver 3 0 (tinfo 0xe72031f0)

我在这里没主意...

1 个答案:

答案 0 :(得分:0)

最后!我能够获得有效的配置。因此问题是由以下a = np.array([[1,np.nan,3],[np.nan, 0, np.nan]]) a=np.insert(a, a.shape[0],[[1, np.nan, 1]], axis=0) a array([[ 1., nan, 3.], [nan, 0., nan], [ 1., nan, 1.]]) np.nan_to_num(a) array([[1., 0., 3.], [0., 0., 0.], [1., 0., 1.]])

引起的
if

仅在仿真器if (!EGL14.eglChooseConfig(mEGLDisplay, attribList, 0, configs, 0, configs.length, numConfigs, 0)) { Log.w(TAG, "unable to find RGB8888 / " + version + " EGLConfig"); return null; } 上,即使找到有效的配置,也始终会返回false ...

所以我最终得到以下逻辑:

eglChooseConfig

我知道这有点麻烦,但暂时是“有效”