GL_REPEAT无法用于video.mp4,但对于image.png可以

时间:2018-07-03 00:14:14

标签: android opengl-es opengl-es-2.0 mp4

对于使用GL_TEXTURE_2D的图像,GL_REPEAT可以正常工作,但是对于使用GL_TEXTURE_EXTERNAL_OES的mp4而言,GL_REPEAT不能正常工作。我需要这样做,以便创建无限类型的滚动效果来移动像素并导出更改。

在片段着色器中,可以通过以下方式实现无限的水平滚动效果:

println(s"Weighted precision: ${metrics.weightedPrecision}")
println(s"Weighted recall: ${metrics.weightedRecall}")
println(s"Weighted F1 score: ${metrics.weightedFMeasure}")
println(s"Weighted false positive rate: ${metrics.weightedFalsePositiveRate}")

在我的GlSurface中,我的几何形状和初始gl设置定义如下:

uniform float scroll;
void main() {
    vec2 coord = vec2(v_TexCoordinate.x + scroll, v_TexCoordinate.y);
    gl_FragColor = texture2D(u_Texture, coord);
}

和onDrawFame():

private static final float squareVertices[] = {
    -1.0f, 1.0f,    // top left
    -1.0f, -1.0f,   // bottom left
    1.0f, -1.0f,    // bottom right
    1.0f, 1.0f      // top right
};

private static final float textureVertices[] = {                // in counterclockwise order:
    0.0f, 0.0f,
    1.0f, 0.0f,
    1.0f, 1.0f,
    0.0f, 1.0f
};

private void glSetup() {
    final String vertexShader = Utils.readTextFileFromRawResource(mMainActivity,
            R.raw.media_vertex_shader);
    String fragmentShader = null;

    if (isVideo) {
        fragmentShader = Utils.readTextFileFromRawResource(mMainActivity,
                R.raw.media_fragment_shader_video);
    } else {
        fragmentShader = Utils.readTextFileFromRawResource(mMainActivity,
                R.raw.media_fragment_shader_image);
    }

    final int vertexShaderHandle = ShaderHelper.compileShader(GLES20.GL_VERTEX_SHADER,
            vertexShader);
    final int fragmentShaderHandle = ShaderHelper.compileShader(GLES20.GL_FRAGMENT_SHADER,
            fragmentShader);

    int[] textures = new int[1];
    GLES20.glGenTextures(1, textures, 0);
    mTextureId = textures[0];

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    if (isVideo) {
        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, mTextureId);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MAG_FILTER,
                GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_MIN_FILTER,
                GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_S,
                GLES20.GL_REPEAT);
        GLES20.glTexParameteri(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, GLES20.GL_TEXTURE_WRAP_T,
                GLES20.GL_REPEAT);

        mSurfaceTexture = new SurfaceTexture(mTextureId);
        mMediaPlayer.setSurface(mSurfaceTexture);
        mSurfaceTexture.setOnFrameAvailableListener(this);
    } else {                        //image
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureId);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER,
                GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER,
                GLES20.GL_LINEAR);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
                GLES20.GL_REPEAT);
        GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
                GLES20.GL_REPEAT);
    }

    mScrollHandle = GLES20.glGetUniformLocation(mProgramHandle, "scroll");

    Matrix.setIdentityM(mSTMatrix, 0);
}

登录GLES20.glGetError()时看到GL_INVALID_ENUM

我尝试做的事情:

  1. 使用ffmpeg将视频的大小调整为POT(2的幂,2048 x 1024)
  2. 使用GLES30 / GLES31 / GLES32进行所有绑定,参数等调用
  3. 将textureVertices和squareVertices更改为> 1.0f
  4. 使用GL31.glGetTexLevelParameteriv()打印纹理的宽度/高度,该宽度对于视频的宽度和高度都打印为0,但对于图像来说则是适当的尺寸

不确定GL_Repeat是否应在mp4文件的目标GL_Texture_External_OES上运行。根据{{​​3}}

听起来应该是可重复的

欢迎尝试其他建议!

1 个答案:

答案 0 :(得分:0)

不支持。参见规范“问题2”:

Crase et al (2012)

特别是:

  
      
  1. 是否应该将外部纹理的环绕模式设置为CLAMP_TO_EDGE以外的其他模式?

    dismo
  2.