Add Texture.use

egloo2
Mattia Iavarone 5 years ago
parent f95c11cab9
commit d9cd288abb
  1. 1
      cameraview/src/main/java/com/otaliastudios/cameraview/filter/MultiFilter.java
  2. 17
      cameraview/src/main/java/com/otaliastudios/cameraview/internal/GlTextureDrawer.java
  3. 10
      demo/src/main/java/com/otaliastudios/cameraview/demo/CameraActivity.java

@ -63,7 +63,6 @@ public class MultiFilter implements Filter, OneParameterFilter, TwoParameterFilt
* Creates a new group with the given filters.
* @param filters children
*/
@SuppressWarnings("WeakerAccess")
public MultiFilter(@NonNull Filter... filters) {
this(Arrays.asList(filters));
}

@ -63,11 +63,12 @@ public class GlTextureDrawer {
mTextureTransform = textureTransform;
}
public void draw(long timestampUs) {
public void draw(final long timestampUs) {
if (mPendingFilter != null) {
release();
mFilter = mPendingFilter;
mPendingFilter = null;
}
if (mProgramHandle == -1) {
@ -75,20 +76,16 @@ public class GlTextureDrawer {
mFilter.getVertexShader(),
mFilter.getFragmentShader());
mFilter.onCreate(mProgramHandle);
Egloo.checkGlError("program creation");
}
Egloo.checkGlError("draw start");
// Select the program and the active texture.
GLES20.glUseProgram(mProgramHandle);
Egloo.checkGlError("glUseProgram");
GLES20.glActiveTexture(mTexture.getUnit());
GLES20.glBindTexture(mTexture.getTarget(), mTexture.getId());
// Draw and release.
Egloo.checkGlError("glUseProgram(handle)");
mTexture.bind();
mFilter.draw(timestampUs, mTextureTransform);
GLES20.glBindTexture(mTexture.getTarget(), 0);
mTexture.unbind();
GLES20.glUseProgram(0);
Egloo.checkGlError("draw end");
Egloo.checkGlError("glUseProgram(0)");
}
public void release() {

@ -372,13 +372,13 @@ public class CameraActivity extends AppCompatActivity implements View.OnClickLis
message(filter.toString(), false);
// Normal behavior:
camera.setFilter(filter.newInstance());
// camera.setFilter(filter.newInstance());
// To test MultiFilter:
// DuotoneFilter duotone = new DuotoneFilter();
// duotone.setFirstColor(Color.RED);
// duotone.setSecondColor(Color.GREEN);
// camera.setFilter(new MultiFilter(duotone, filter.newInstance()));
DuotoneFilter duotone = new DuotoneFilter();
duotone.setFirstColor(Color.RED);
duotone.setSecondColor(Color.GREEN);
camera.setFilter(new MultiFilter(duotone, filter.newInstance()));
}
@Override

Loading…
Cancel
Save