簡體   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