OpenGL(大)图片用绿线画出

时间:2016-12-14 10:58:19

标签: android opengl-es

我使用OpenGL在Android屏幕上显示YUV420P帧。 有了一些分辨率,我的画面看起来不错,但是分辨率很高(在同一个屏幕上),它仍然看起来像我的原始画面(带有颜色和所有画面),但有一些绿线画出它(取决于方向,4行, 30行?)。

以下是一个示例(1080x607帧):

enter image description here

这是对齐问题吗?纹理绑定问题?这是我的代码:

private final short[] INDICES_DATA = {0, 1, 2, 0, 2, 3};

private final float[] VERTICES_DATA = new float[] {
    -1f, 1f, 0f,
    0f, 0f,
    -1f, -1f, 0f,
    0f, 1f,
    1f, -1f, 0f,
    1f, 1f,
    1f, 1f, 0f,
    1f, 0f
};

private final String szVertexShaderCode =
        "attribute vec4 aPosition;\n" +
        "attribute vec2 aTexCoord;\n" +
        "varying vec2 vTexCoord;\n" +

        "void main() {\n" +
        "   gl_Position = aPosition;\n" +
        "   vTexCoord = aTexCoord;\n" +
        "}\n";

private final String szYUV420PFragmentShaderCode =
        "#ifdef GL_FRAGMENT_PRECISION_HIGH\n" +
        "   precision highp float;\n" +
        "#else\n" +
        "   precision mediump float;\n" +
        "#endif\n" +

        "varying vec2 vTexCoord;\n" +
        "uniform sampler2D yTexture;\n" +
        "uniform sampler2D uTexture;\n" +
        "uniform sampler2D vTexture;\n" +

        "void main() {\n" +
        "   float r, g, b, y, u, v;\n" +

        "   y = texture2D(yTexture, vTexCoord).r;\n" +
        "   u = texture2D(uTexture, vTexCoord).r - 0.5;\n" +
        "   v = texture2D(vTexture, vTexCoord).r - 0.5;\n" +

        "   r = y + (1.13983 * v);\n" +
        "   g = y - (0.39465 * u) - (0.58060 * v);\n" +
        "   b = y + (2.03211 * u);\n" +

        "   gl_FragColor = vec4(r, g, b, 1.0);\n" +
        "}\n";

创建曲面上的函数:

    //initShadersAndProgram();

    iPositionLoc = GLES20.glGetAttribLocation(iProgram, "aPosition");
    iTexCoordLoc = GLES20.glGetAttribLocation(iProgram, "aTexCoord");

    // Is this line useful?
    GLES20.glPixelStorei(GLES20.GL_UNPACK_ALIGNMENT, 1);

    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    iYTexture = GLES20.glGetUniformLocation(iProgram, "yTexture");
    int[] yTextureNames = new int[1];
    GLES20.glGenTextures(1, yTextureNames, 0);
    int iYTextureName = yTextureNames[0];
    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, iYTextureName);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    iUTexture = GLES20.glGetUniformLocation(iProgram, "uTexture");
    int[] uTextureNames = new int[1];
    GLES20.glGenTextures(1, uTextureNames, 0);
    int iUTextureName = uTextureNames[0];
    GLES20.glActiveTexture(GLES20.GL_TEXTURE2);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, iUTextureName);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    iVTexture = GLES20.glGetUniformLocation(iProgram, "vTexture");
    int[] vTextureNames = new int[1];
    GLES20.glGenTextures(1, vTextureNames, 0);
    int iVTextureName = vTextureNames[0];
    GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, iVTextureName);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);

    GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

并条机上的功能:

GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

GLES20.glUseProgram(iProgram);

verticesBuffer.position(0);
GLES20.glVertexAttribPointer(iPositionLoc, 3, GLES20.GL_FLOAT, false, 5 * 4, verticesBuffer);

verticesBuffer.position(3);
GLES20.glVertexAttribPointer(iTexCoordLoc, 2, GLES20.GL_FLOAT, false, 5 * 4, verticesBuffer);

GLES20.glEnableVertexAttribArray(iPositionLoc);
GLES20.glEnableVertexAttribArray(iTexCoordLoc);

GLES20.glActiveTexture(GLES20.GL_TEXTURE1);

GLES20.glUniform1i(iYTexture, 1);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D,
        0,
        GLES20.GL_LUMINANCE,
        pixmap.getWidth(),
        pixmap.getHeight(),
        0,
        GLES20.GL_LUMINANCE,
        GLES20.GL_UNSIGNED_BYTE,
        /* buffer Y */);

GLES20.glActiveTexture(GLES20.GL_TEXTURE2);

GLES20.glUniform1i(iUTexture, 2);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D,
        0,
        GLES20.GL_LUMINANCE,
        pixmap.getWidth() / 2,
        pixmap.getHeight() / 2,
        0,
        GLES20.GL_LUMINANCE,
        GLES20.GL_UNSIGNED_BYTE,
        /* buffer U */);

GLES20.glActiveTexture(GLES20.GL_TEXTURE3);

GLES20.glUniform1i(iVTexture, 3);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D,
        0,
        GLES20.GL_LUMINANCE,
        pixmap.getWidth() / 2,
        pixmap.getHeight() / 2,
        0,
        GLES20.GL_LUMINANCE,
        GLES20.GL_UNSIGNED_BYTE,
        /* buffer V */);

GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, indicesBuffer);

我想念什么?

编辑:框架由两个不同的解码器提供,所有作品都可以通过其他渲染过程找到。

EDIT2:我只显示了Y平面,结果是一个灰色的框架(正如预期的那样),但是没有阴影线!!

enter image description here

我刚刚在片段着色器中替换了这些行以显示它:

" r = texture2D(yTexture, vTexCoord).r;\n" +
" g = texture2D(yTexture, vTexCoord).g;\n" +
" b = texture2D(yTexture, vTexCoord).b;\n" +

问题来自U / V飞机?

0 个答案:

没有答案