Avoid releasing location pointers

pull/535/head
Mattia Iavarone 6 years ago
parent 5caddd3d74
commit e8356bb751
  1. 19
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/BaseFilter.java
  2. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/filters/Filter.java
  3. 2
      cameraview/src/main/java/com/otaliastudios/cameraview/internal/egl/EglViewport.java
  4. 2
      demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java

@ -65,23 +65,21 @@ public abstract class BaseFilter implements Filter {
+ " gl_FragColor = texture2D(sTexture, "+fragmentTextureCoordinateName+");\n"
+ "}\n";
}
// When the model/view/projection matrix is identity, this will exactly cover the viewport.
private static final FloatBuffer VERTEX_POSITION = GlUtils.floatBuffer(new float[]{
private FloatBuffer vertexPosition = GlUtils.floatBuffer(new float[]{
-1.0f, -1.0f, // 0 bottom left
1.0f, -1.0f, // 1 bottom right
-1.0f, 1.0f, // 2 top left
1.0f, 1.0f, // 3 top right
});
private static final FloatBuffer TEXTURE_COORDINATES = GlUtils.floatBuffer(new float[]{
private FloatBuffer textureCoordinates = GlUtils.floatBuffer(new float[]{
0.0f, 0.0f, // 0 bottom left
1.0f, 0.0f, // 1 bottom right
0.0f, 1.0f, // 2 top left
1.0f, 1.0f // 3 top right
});
private int vertexModelViewProjectionMatrixLocation = -1;
private int vertexTranformMatrixLocation = -1;
private int vertexPositionLocation = -1;
@ -127,11 +125,8 @@ public abstract class BaseFilter implements Filter {
}
@Override
public void onDestroy() {
vertexModelViewProjectionMatrixLocation = -1;
vertexTranformMatrixLocation = -1;
vertexTextureCoordinateLocation = -1;
vertexPositionLocation = -1;
public void onDestroy(int programHandle) {
// Do nothing.
}
@NonNull
@ -165,15 +160,15 @@ public abstract class BaseFilter implements Filter {
// Enable the "aPosition" vertex attribute.
// Connect vertexBuffer to "aPosition".
GLES20.glEnableVertexAttribArray(vertexPositionLocation);
GlUtils.checkError("glEnableVertexAttribArray");
GLES20.glVertexAttribPointer(vertexPositionLocation, 2, GLES20.GL_FLOAT, false, 8, VERTEX_POSITION);
GlUtils.checkError("glEnableVertexAttribArray: " + vertexPositionLocation);
GLES20.glVertexAttribPointer(vertexPositionLocation, 2, GLES20.GL_FLOAT, false, 8, vertexPosition);
GlUtils.checkError("glVertexAttribPointer");
// Enable the "aTextureCoord" vertex attribute.
// Connect texBuffer to "aTextureCoord".
GLES20.glEnableVertexAttribArray(vertexTextureCoordinateLocation);
GlUtils.checkError("glEnableVertexAttribArray");
GLES20.glVertexAttribPointer(vertexTextureCoordinateLocation, 2, GLES20.GL_FLOAT, false, 8, TEXTURE_COORDINATES);
GLES20.glVertexAttribPointer(vertexTextureCoordinateLocation, 2, GLES20.GL_FLOAT, false, 8, textureCoordinates);
GlUtils.checkError("glVertexAttribPointer");
}

@ -7,7 +7,7 @@ public interface Filter {
void onCreate(int programHandle);
void onDestroy();
void onDestroy(int programHandle);
void draw(float[] transformMatrix);

@ -42,7 +42,7 @@ public class EglViewport {
public void release() {
if (mProgramHandle != -1) {
mFilter.onDestroy();
mFilter.onDestroy(mProgramHandle);
GLES20.glDeleteProgram(mProgramHandle);
mProgramHandle = -1;
}

@ -332,7 +332,7 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
} else {
mCurrentFilter = 0;
}
camera.setFilter(mAllFilters[mCurrentFilter]);
camera.setFilter(mAllFilters[mCurrentFilter].newInstance());
}
@Override

Loading…
Cancel
Save