From 53f0736bf08667c291b51ddcc2e3cf41b3a2e25a Mon Sep 17 00:00:00 2001 From: MediaPipe Team Date: Fri, 9 Jun 2023 13:40:14 -0700 Subject: [PATCH] Add an option to disable explicit CPU sync for ExternalTextureRenderer PiperOrigin-RevId: 539166965 --- .../glutil/ExternalTextureRenderer.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/mediapipe/java/com/google/mediapipe/glutil/ExternalTextureRenderer.java b/mediapipe/java/com/google/mediapipe/glutil/ExternalTextureRenderer.java index 4dd35f865..381864484 100644 --- a/mediapipe/java/com/google/mediapipe/glutil/ExternalTextureRenderer.java +++ b/mediapipe/java/com/google/mediapipe/glutil/ExternalTextureRenderer.java @@ -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(); + } } /**