Android OpenGL combination of SurfaceTexture (external image) and ordinary texture

前端 未结 8 588
深忆病人
深忆病人 2020-12-28 10:09

I would like to mix camera preview SurfaceTexture with some overlay texture. I am using these shaders for processing:

private final String vss =          


        
8条回答
  •  忘掉有多难
    2020-12-28 10:41

    I imagine you have this problem because you are not setting the correct texture id on your code. This is a tipical error on assumptions which seem logical, but is actually not defined so on the documentation. If you check the documentation of this extension you see the following (edited) TEXT:

    Each TEXTURE_EXTERNAL_OES texture object may require up to 3 texture image units for each texture unit to which it is bound. When is set to TEXTURE_EXTERNAL_OES this value will be between 1 and 3 (inclusive). For other valid texture targets this value will always be 1. Note that, when a TEXTURE_EXTERNAL_OES texture object is bound, the number of texture image units required by a single texture unit may be 1, 2, or 3, while for other texture objects each texture unit requires exactly 1 texture image unit.

    This means that at leas one additional will work, provided that you use id 0 for it. In your case:

    GLES20.glUniform1i(sTextureHandle, 1);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES,
            sTextureId);
    

    For your 2D texture:

    GLES20.glUniform1i(filterTextureHandle, 0);
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, filterTextureID);
    

    I'm sure this will workout for you.

提交回复
热议问题