Skip to content

Commit

Permalink
Fix: Grouped filters with filterCount%2==0 are flipped.
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Boos committed Mar 18, 2013
1 parent a2f2d9d commit 3f573f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package jp.co.cyberagent.android.gpuimage;

import android.opengl.GLES20;
import jp.co.cyberagent.android.gpuimage.util.TextureRotationUtil;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
Expand All @@ -38,6 +39,7 @@ public class GPUImageFilterGroup extends GPUImageFilter {

private final FloatBuffer mGLCubeBuffer;
private final FloatBuffer mGLTextureBuffer;
private final FloatBuffer mGLTextureFlipBuffer;

/**
* Instantiates a new GPUImageFilterGroup with the given filters.
Expand All @@ -55,6 +57,12 @@ public GPUImageFilterGroup(final List<GPUImageFilter> filters) {
.order(ByteOrder.nativeOrder())
.asFloatBuffer();
mGLTextureBuffer.put(TEXTURE_NO_ROTATION).position(0);

float[] flipTexture = TextureRotationUtil.getRotation(Rotation.NORMAL, false, true);
mGLTextureFlipBuffer = ByteBuffer.allocateDirect(flipTexture.length * 4)
.order(ByteOrder.nativeOrder())
.asFloatBuffer();
mGLTextureFlipBuffer.put(flipTexture).position(0);
}

/*
Expand Down Expand Up @@ -151,7 +159,8 @@ public void onDraw(final int textureId, final FloatBuffer cubeBuffer,
GPUImageFilter filter = mFilters.get(i);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, mFrameBuffers[i]);
GLES20.glClearColor(0, 0, 0, 1);
filter.onDraw(previousTexture, mGLCubeBuffer, mGLTextureBuffer);
filter.onDraw(previousTexture, mGLCubeBuffer,
(i == 0 && mFilters.size() % 2 == 0) ? mGLTextureFlipBuffer : mGLTextureBuffer);
GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0);
previousTexture = mFrameBufferTextures[i];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,6 @@ public void setRotation(final Rotation rotation, final boolean flipHorizontal,
mRotation = rotation;
mFlipHorizontal = flipHorizontal;
mFlipVertical = flipVertical;

float[] rotatedTex = TextureRotationUtil.getRotation(rotation, flipHorizontal, flipVertical);

mGLTextureBuffer.clear();
mGLTextureBuffer.put(rotatedTex).position(0);

adjustImageScaling();
}

Expand Down

0 comments on commit 3f573f8

Please sign in to comment.