Simplify vertex data

Only x and y components are needed for shader.

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent 89df395ffc
commit 4a33be9c80

@ -199,10 +199,10 @@ public class GPUImageFilter {
runPendingOnDrawTasks(); runPendingOnDrawTasks();
GLES20.glEnableVertexAttribArray(mGLPositionIndex); GLES20.glEnableVertexAttribArray(mGLPositionIndex);
GLES20.glVertexAttribPointer(mGLPositionIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, cubeBuffer); GLES20.glVertexAttribPointer(mGLPositionIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, cubeBuffer);
GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex); GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex);
GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, textureBuffer); GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, textureBuffer);
if (textureId != OpenGlUtils.NO_TEXTURE) { if (textureId != OpenGlUtils.NO_TEXTURE) {
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
@ -232,11 +232,11 @@ public class GPUImageFilter {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]);
GLES20.glEnableVertexAttribArray(mGLPositionIndex); GLES20.glEnableVertexAttribArray(mGLPositionIndex);
GLES20.glVertexAttribPointer(mGLPositionIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLPositionIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]);
GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex); GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex);
GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0); GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0);
@ -270,11 +270,11 @@ public class GPUImageFilter {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]);
GLES20.glEnableVertexAttribArray(mGLPositionIndex); GLES20.glEnableVertexAttribArray(mGLPositionIndex);
GLES20.glVertexAttribPointer(mGLPositionIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLPositionIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]);
GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex); GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex);
GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0); GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0);
@ -311,11 +311,11 @@ public class GPUImageFilter {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]);
GLES20.glEnableVertexAttribArray(mGLPositionIndex); GLES20.glEnableVertexAttribArray(mGLPositionIndex);
GLES20.glVertexAttribPointer(mGLPositionIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLPositionIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]);
GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex); GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex);
GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0); GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0);
@ -359,11 +359,11 @@ public class GPUImageFilter {
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLCubeId[0]);
GLES20.glEnableVertexAttribArray(mGLPositionIndex); GLES20.glEnableVertexAttribArray(mGLPositionIndex);
GLES20.glVertexAttribPointer(mGLPositionIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLPositionIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]); GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mGLTextureId[0]);
GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex); GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex);
GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 4, GLES20.GL_FLOAT, false, 4 * 4, 0); GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, 0);
GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0); GLES20.glUniformMatrix4fv(mGLTextureTransformIndex, 1, false, mGLTextureTransformMatrix, 0);

@ -19,36 +19,36 @@ package com.seu.magicfilter.utils;
public class TextureRotationUtil { public class TextureRotationUtil {
public static final float TEXTURE_NO_ROTATION[] = { public static final float TEXTURE_NO_ROTATION[] = {
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
}; };
public static final float TEXTURE_ROTATED_90[] = { public static final float TEXTURE_ROTATED_90[] = {
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
}; };
public static final float TEXTURE_ROTATED_180[] = { public static final float TEXTURE_ROTATED_180[] = {
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
}; };
public static final float TEXTURE_ROTATED_270[] = { public static final float TEXTURE_ROTATED_270[] = {
0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f,
1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
}; };
public static final float CUBE[] = { public static final float CUBE[] = {
-1.0f, -1.0f, 0.0f, 1.0f, -1.0f, -1.0f,
1.0f, -1.0f, 0.0f, 1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f,
1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f,
}; };
private TextureRotationUtil() {} private TextureRotationUtil() {}
@ -73,24 +73,23 @@ public class TextureRotationUtil {
} }
if (flipHorizontal) { if (flipHorizontal) {
rotatedTex = new float[]{ rotatedTex = new float[]{
flip(rotatedTex[0]), rotatedTex[1], 0.0f, 1.0f, flip(rotatedTex[0]), rotatedTex[1],
flip(rotatedTex[4]), rotatedTex[5], 0.0f, 1.0f, flip(rotatedTex[2]), rotatedTex[3],
flip(rotatedTex[8]), rotatedTex[9], 0.0f, 1.0f, flip(rotatedTex[4]), rotatedTex[5],
flip(rotatedTex[12]), rotatedTex[13], 0.0f, 1.0f, flip(rotatedTex[6]), rotatedTex[7],
}; };
} }
if (flipVertical) { if (flipVertical) {
rotatedTex = new float[]{ rotatedTex = new float[]{
rotatedTex[0], flip(rotatedTex[1]), 0.0f, 1.0f, rotatedTex[0], flip(rotatedTex[1]),
rotatedTex[4], flip(rotatedTex[5]), 0.0f, 1.0f, rotatedTex[2], flip(rotatedTex[3]),
rotatedTex[8], flip(rotatedTex[9]), 0.0f, 1.0f, rotatedTex[4], flip(rotatedTex[5]),
rotatedTex[12], flip(rotatedTex[13]), 0.0f, 1.0f, rotatedTex[6], flip(rotatedTex[7]),
}; };
} }
return rotatedTex; return rotatedTex;
} }
private static float flip(final float i) { private static float flip(final float i) {
return i == 0.0f ? 1.0f : 0.0f; return i == 0.0f ? 1.0f : 0.0f;
} }

Loading…
Cancel
Save