Add an option to disable explicit CPU sync for ExternalTextureRenderer

PiperOrigin-RevId: 539166965
This commit is contained in:
MediaPipe Team 2023-06-09 13:40:14 -07:00 committed by Copybara-Service
parent 67c5d8d224
commit 53f0736bf0

View File

@ -67,6 +67,7 @@ public class ExternalTextureRenderer {
private float[] textureTransformMatrix = new float[16];
private boolean flipY;
private int rotation = Surface.ROTATION_0;
private boolean doExplicitCpuSync = true;
/** Call this to setup the shader program before rendering. */
public void setup() {
@ -101,6 +102,14 @@ public class ExternalTextureRenderer {
this.rotation = rotation;
}
/**
* Configures whether the renderer should do an explicit CPU synchronization using glFinish upon
* each {@link #render} call. Defaults to true.
*/
public void setDoExplicitCpuSync(boolean doExplicitCpuSync) {
this.doExplicitCpuSync = doExplicitCpuSync;
}
/**
* Renders the surfaceTexture to the framebuffer with optional vertical flip.
*
@ -150,8 +159,11 @@ public class ExternalTextureRenderer {
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
ShaderUtil.checkGlError("glBindTexture");
// TODO: add sync and go back to glFlush()
GLES20.glFinish();
if (doExplicitCpuSync) {
// TODO: add sync and go back to glFlush()
GLES20.glFinish();
}
}
/**