0

以下是GPUImageFilterGroup.java中的onDraw方法。

// GPUImageFilterGroup.java
public void onDraw(final int textureId, final FloatBuffer cubeBuffer,
                   final FloatBuffer textureBuffer) {
    runPendingOnDrawTasks();
    if (!isInitialized() || mFrameBuffers == null || mFrameBufferTextures == null) {
        return;
    }
    if (mMergedFilters != null) {
        int size = mMergedFilters.size();
        int previousTexture = textureId;
        for (int i = 0; i < size; i++) {
            GPUImageFilter filter = mMergedFilters.get(i);
            boolean isNotLast = i < size - 1;
            if (isNotLast) {
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[i]);
                GLES20.glClearColor(1, 0, 0, 0);
            }

            if (i == 0) {
                filter.onDraw(previousTexture, cubeBuffer, textureBuffer);
            } else if (i == size - 1) {
                filter.onDraw(previousTexture, mGLCubeBuffer, (size % 2 == 0) ? mGLTextureFlipBuffer : mGLTextureBuffer);
            } else {
                filter.onDraw(previousTexture, mGLCubeBuffer, mGLTextureBuffer);
            }

            if (isNotLast) {
                GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
                previousTexture = mFrameBufferTextures[i];
            }
        }
    }
 }

mGLTextureBuffer存储纹理的位置。

public static final float TEXTURE_NO_ROTATION[] = {
        0.0f, 1.0f,
        1.0f, 1.0f,
        0.0f, 0.0f,
        1.0f, 0.0f,
};

mGLTextureFlipBuffermGLTextureBuffer在垂直方向上的倒置。

只是无法弄清楚为什么偶数过滤器奇数过滤器使用不同的缓冲区如下行?

else if (i == size - 1)
    filter.onDraw(previousTexture, mGLCubeBuffer, (size % 2 == 0) ? mGLTextureFlipBuffer : mGLTextureBuffer);
4

1 回答 1

0

当你打电话时GPUImage.setupCamera(),你会通过flipHorizontaland flipVertical。因此,如果您应用偶数(或奇数)个过滤器,纹理将被翻转偶数(或奇数)次。如果你不喜欢这个,像我一样修改这个:

    if (i == size - 1) {// the last filter
      filter.onDraw(previousTexture, mGLCubeBuffer, textureBuffer);
    } else {
    //normalTextureBuffer is the not-clipped version of textureBuffer
      filter.onDraw(previousTexture, mGLCubeBuffer, normalTextureBuffer);
    }

使用上面的代码,每当您向组中添加一个过滤器时,您将获得一个 90 度旋转的纹理,因此 4 个过滤器用于 360 度旋转(与输入纹理相同的旋转)纹理。mGLCubeBuffer并且textureBuffer有不同的旋转90度。
愿这有帮助。

于 2016-10-21T05:43:34.390 回答