0

我正在尝试使用 opengles 2.0 比较 2 个纹理 [希望它们完全相同]。这是为了分析我的后期处理的结果。

所以,基本上,我使用了两次以下片段着色器(一次绑定到帧缓冲区,然后再次渲染到屏幕)。

precision lowp float;

uniform sampler2D u_Texture0;
uniform vec2 u_sizeVideo;

varying vec3 v_texCoord;

void main()
{
    vec2 vCoord = gl_FragCoord.st/ u_sizeVideo.st;

    gl_FragColor = texture2D(u_Texture0,vCoord);
}

我正在渲染的图片的大小与我的 GLSurfaceView 相同(即:1280*720)。然后我使用 glReadPixels 读取结果并创建相应的位图。然后我再次创建位图,但这次使用原始图片

        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inDensity=320; //i have double checked that this is the same density as from the bmpGPU
        options.inMutable=true; //same here, trying to manually set all options so the 2 bmp are identical
        final int resourceId=R.drawable.mypic;

        final Bitmap bmpCPU = BitmapFactory.decodeResource(mActivityContext.getResources(), resourceId, options);
        ByteBuffer buff1=ByteBuffer.allocateDirect(imgWidth * imgHeight * 4).order(ByteOrder.LITTLE_ENDIAN);;
        bmpCPU.copyPixelsToBuffer(buff1);
        buff1.rewind();

        final Bitmap bmpGPU = Bitmap.createBitmap(imgWidth, imgHeight,Config.ARGB_8888); 
        ByteBuffer buff2=ByteBuffer.allocateDirect(imgWidth * imgHeight * 4).order(ByteOrder.LITTLE_ENDIAN);
        GLES20.glReadPixels(0, 0, imgWidth, imgHeight, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE,buff2);
        buff2.rewind();
        bmpGPU.copyPixelsFromBuffer(flipByteBuffer(buff2));// the flip function works as expected

        storeImage(bmpGPU,"gpu");
        storeImage(bmpCPU,"cpu");

所以值得注意的是,尽管 2 个位图看起来相同,但它们的大小并不相同。原始的为 40Kb,而 GPU 的为 45Kb。

顺便说一句,我还将过滤设置为我认为最合适的:

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);
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);

任何建议都将受到欢迎。

4

0 回答 0