繁体   English   中英

OpenGL ES 用于 Android 需要 3.0 上下文的 2.0 命令?

[英]OpenGL ES for Android requires 2.0 commands for 3.0 context?

我正在使用渲染视频

glTexSubImage2D(GL_TEXTURE_2D,
                            0,
                            0,
                            0,
                            decodedFrame.width[j],
                            decodedFrame.height[j],
                            GL_LUMINANCE,
                            GL_UNSIGNED_BYTE,
                            null);

我使用GL_RED代替GL_LUMINANCE因为我认为,因为我在我的着色器中使用 OpenGL #version 320 es ,我需要使用 OpenGL 3.x 命令,如 GL_RED。 但是 GL_RED 不起作用,只有 GL_LUMINANCE 起作用。

这是我创建上下文的方式:

        eglDisplay = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
        if (eglDisplay == EGL10.EGL_NO_DISPLAY) {
            throw new RuntimeException("eglGetDisplay failed");
        }

        int[] version = new int[2];
        if (!egl.eglInitialize(eglDisplay, version)) {
            throw new RuntimeException("eglInitialize failed");
        }

        EGLConfig eglConfig = chooseEglConfig();
        eglContext = createContext(egl, eglDisplay, eglConfig);

        eglSurface = egl.eglCreateWindowSurface(eglDisplay, eglConfig, surfaceTexture, null);

        if (eglSurface == null || eglSurface == EGL10.EGL_NO_SURFACE) {
            throw new RuntimeException("GL Error: " + GLUtils.getEGLErrorString(egl.eglGetError()));
        }

        if (!egl.eglMakeCurrent(eglDisplay, eglSurface, eglSurface, eglContext)) {
            throw new RuntimeException("GL make current error: " + GLUtils.getEGLErrorString(egl.eglGetError()));
        }

private EGLContext createContext(EGL10 egl, EGLDisplay eglDisplay, EGLConfig eglConfig) {
        int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
        int[] attribList = {EGL_CONTEXT_CLIENT_VERSION, 3, EGL10.EGL_NONE};
        return egl.eglCreateContext(eglDisplay, eglConfig, EGL10.EGL_NO_CONTEXT, attribList);
    }

    private EGLConfig chooseEglConfig() {
        int[] configsCount = new int[1];
        EGLConfig[] configs = new EGLConfig[1];
        int[] configSpec = getConfig();

        if (!egl.eglChooseConfig(eglDisplay, configSpec, configs, 1, configsCount)) {
            throw new IllegalArgumentException("Failed to choose config: " + GLUtils.getEGLErrorString(egl.eglGetError()));
        } else if (configsCount[0] > 0) {
            return configs[0];
        }

        return null;
    }

如您所见,我正在使用EGL_CONTEXT_CLIENT_VERSION 3

我还从 GLES30 导入了所有内容:

    import static android.opengl.GLES30.GL_TRIANGLE_STRIP;
    import static android.opengl.GLES30.glDrawArrays;
    import static android.opengl.GLES30.GL_CLAMP_TO_EDGE;
    import static android.opengl.GLES30.GL_LINEAR;
    import static android.opengl.GLES30.GL_STREAM_DRAW;
    import static android.opengl.GLES30.GL_TEXTURE0;
    import static android.opengl.GLES30.GL_TEXTURE_2D;
    import static android.opengl.GLES30.GL_TEXTURE_MAG_FILTER;
    import static android.opengl.GLES30.GL_TEXTURE_MIN_FILTER;
    import static android.opengl.GLES30.GL_TEXTURE_WRAP_S;
    import static android.opengl.GLES30.GL_TEXTURE_WRAP_T;
    import static android.opengl.GLES30.glActiveTexture;
    import static android.opengl.GLES30.glBindBuffer;
    import static android.opengl.GLES30.glBindTexture;
    import static android.opengl.GLES30.glBufferData;
    import static android.opengl.GLES30.glBufferSubData;
    import static android.opengl.GLES30.glGenBuffers;
    import static android.opengl.GLES30.glGenTextures;
    import static android.opengl.GLES30.glGetUniformLocation;
    import static android.opengl.GLES30.glTexImage2D;
    import static android.opengl.GLES30.glTexParameteri;
    import static android.opengl.GLES30.glTexSubImage2D;
    import static android.opengl.GLES30.glUniform1f;
    import static android.opengl.GLES30.glUniform1i;
    import static android.opengl.GLES30.GL_PIXEL_UNPACK_BUFFER;

但我需要从 GLES20 导入GL_LUMINANCE才能正常工作

那么为什么我需要使用GL_LUMINANCE呢? 这是我创建和使用纹理的方式:

    if (!initiatedTextures)
        {
            //LOG << "initiatedTextures";
            Log.d(LOG_TAG, "initiating textures");
            //TODO: delete these textures
            glGenTextures(1, textureId);


            glBindTexture(GL_TEXTURE_2D, textureId.get(0));
            glTexImage2D(GL_TEXTURE_2D,
                    0,
                    GL_LUMINANCE,
                    2304,
                    1296,
                    0,
                    GL_LUMINANCE,
                    GL_UNSIGNED_BYTE,
                    null);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

            initiatedTextures = true;
        }

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, textureId.get(0));

        glTexSubImage2D(GL_TEXTURE_2D,
                0,
                0,
                0,
                2304,
                1296,
                GL_LUMINANCE,
                GL_UNSIGNED_BYTE,
                buffer);

如果我只是用GL_RED GL_LUMINANCE则根本不会填充纹理。

在 OpenGL ES 中,您使用的内部格式需要与您使用的像素传输格式相匹配。 您在定义纹理时使用了GL_LUMINANCE内部格式。 因此,所有进出该纹理的像素传输都必须使用GL_LUMINANCE像素传输格式。

如果您使用GL_RED作为内部格式,您可能/将需要使用GL_RED像素传输格式。 GL_RED作为内部格式是 ES 3.0 的特性,在 ES 2.0 中不可用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM