From 2e544224c253aa78f326aa7e3b4d0e0b9de0a543 Mon Sep 17 00:00:00 2001 From: hschlueter Date: Mon, 9 May 2022 11:33:52 +0100 Subject: [PATCH] Fix GlUtil vector size constant name. This constant is used for https://docs.gl/es2/glVertexAttribPointer which takes the number of components per generic vertex attribute (meaning the size of the individual coordinate vectors here) not the number of attributes (the number of vertices that the old constant name referred to). PiperOrigin-RevId: 447427241 --- .../media3/demo/gl/BitmapOverlayVideoProcessor.java | 8 ++++++-- .../demo/transformer/BitmapOverlayFrameProcessor.java | 4 +++- .../demo/transformer/PeriodicVignetteFrameProcessor.java | 4 +++- .../media3/demo/transformer/MediaPipeFrameProcessor.java | 2 +- .../src/main/java/androidx/media3/common/util/GlUtil.java | 4 ++-- .../media3/transformer/ExternalCopyFrameProcessor.java | 4 +++- .../transformer/MatrixTransformationFrameProcessor.java | 4 +++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/demos/gl/src/main/java/androidx/media3/demo/gl/BitmapOverlayVideoProcessor.java b/demos/gl/src/main/java/androidx/media3/demo/gl/BitmapOverlayVideoProcessor.java index a9329b5343..735abf4cfa 100644 --- a/demos/gl/src/main/java/androidx/media3/demo/gl/BitmapOverlayVideoProcessor.java +++ b/demos/gl/src/main/java/androidx/media3/demo/gl/BitmapOverlayVideoProcessor.java @@ -87,9 +87,13 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; throw new IllegalStateException(e); } program.setBufferAttribute( - "aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT); + "aFramePosition", + GlUtil.getNormalizedCoordinateBounds(), + GlUtil.HOMOGENEOUS_COORDINATE_VECTOR_SIZE); program.setBufferAttribute( - "aTexCoords", GlUtil.getTextureCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT); + "aTexCoords", + GlUtil.getTextureCoordinateBounds(), + GlUtil.HOMOGENEOUS_COORDINATE_VECTOR_SIZE); GLES20.glGenTextures(1, textures, 0); GLES20.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]); GLES20.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_NEAREST); diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/BitmapOverlayFrameProcessor.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/BitmapOverlayFrameProcessor.java index c6cd2c39ec..e4eba6e3bf 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/BitmapOverlayFrameProcessor.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/BitmapOverlayFrameProcessor.java @@ -101,7 +101,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; glProgram = new GlProgram(context, VERTEX_SHADER_PATH, FRAGMENT_SHADER_PATH); // Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y. glProgram.setBufferAttribute( - "aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT); + "aFramePosition", + GlUtil.getNormalizedCoordinateBounds(), + GlUtil.HOMOGENEOUS_COORDINATE_VECTOR_SIZE); glProgram.setSamplerTexIdUniform("uTexSampler0", inputTexId, /* texUnitIndex= */ 0); glProgram.setSamplerTexIdUniform("uTexSampler1", bitmapTexId, /* texUnitIndex= */ 1); glProgram.setFloatUniform("uScaleX", bitmapScaleX); diff --git a/demos/transformer/src/main/java/androidx/media3/demo/transformer/PeriodicVignetteFrameProcessor.java b/demos/transformer/src/main/java/androidx/media3/demo/transformer/PeriodicVignetteFrameProcessor.java index 6d4ff4289c..760c681d97 100644 --- a/demos/transformer/src/main/java/androidx/media3/demo/transformer/PeriodicVignetteFrameProcessor.java +++ b/demos/transformer/src/main/java/androidx/media3/demo/transformer/PeriodicVignetteFrameProcessor.java @@ -87,7 +87,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; glProgram.setFloatsUniform("uOuterRadius", new float[] {outerRadius}); // Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y. glProgram.setBufferAttribute( - "aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT); + "aFramePosition", + GlUtil.getNormalizedCoordinateBounds(), + GlUtil.HOMOGENEOUS_COORDINATE_VECTOR_SIZE); } @Override diff --git a/demos/transformer/src/withMediaPipe/java/androidx/media3/demo/transformer/MediaPipeFrameProcessor.java b/demos/transformer/src/withMediaPipe/java/androidx/media3/demo/transformer/MediaPipeFrameProcessor.java index 08e069fbd9..163fa91cad 100644 --- a/demos/transformer/src/withMediaPipe/java/androidx/media3/demo/transformer/MediaPipeFrameProcessor.java +++ b/demos/transformer/src/withMediaPipe/java/androidx/media3/demo/transformer/MediaPipeFrameProcessor.java @@ -144,7 +144,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; glProgram.setBufferAttribute( "aFramePosition", GlUtil.getNormalizedCoordinateBounds(), - GlUtil.RECTANGLE_VERTICES_COUNT); + GlUtil.HOMOGENEOUS_COORDINATE_VECTOR_SIZE); glProgram.bindAttributesAndUniforms(); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, /* first= */ 0, /* count= */ 4); GlUtil.checkGlError(); diff --git a/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java b/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java index b3f55812fb..a28bca30f0 100644 --- a/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java +++ b/libraries/common/src/main/java/androidx/media3/common/util/GlUtil.java @@ -53,8 +53,8 @@ public final class GlUtil { /** Whether to throw a {@link GlException} in case of an OpenGL error. */ public static boolean glAssertionsEnabled = false; - /** Number of vertices in a rectangle. */ - public static final int RECTANGLE_VERTICES_COUNT = 4; + /** Number of elements in a 3d homogeneous coordinate vector describing a vertex. */ + public static final int HOMOGENEOUS_COORDINATE_VECTOR_SIZE = 4; /** Length of the normalized device coordinate (NDC) space, which spans from -1 to 1. */ public static final float LENGTH_NDC = 2f; diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/ExternalCopyFrameProcessor.java b/libraries/transformer/src/main/java/androidx/media3/transformer/ExternalCopyFrameProcessor.java index dcd5bcb463..05b291512e 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/ExternalCopyFrameProcessor.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/ExternalCopyFrameProcessor.java @@ -77,7 +77,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* texUnitIndex= */ 0); // Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y. glProgram.setBufferAttribute( - "aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT); + "aFramePosition", + GlUtil.getNormalizedCoordinateBounds(), + GlUtil.HOMOGENEOUS_COORDINATE_VECTOR_SIZE); if (enableExperimentalHdrEditing) { // In HDR editing mode the decoder output is sampled in YUV. glProgram.setFloatsUniform("uColorTransform", MATRIX_YUV_TO_BT2020_COLOR_TRANSFORM); diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/MatrixTransformationFrameProcessor.java b/libraries/transformer/src/main/java/androidx/media3/transformer/MatrixTransformationFrameProcessor.java index b81dd74da8..48f53dbcc6 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/MatrixTransformationFrameProcessor.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/MatrixTransformationFrameProcessor.java @@ -86,7 +86,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* texUnitIndex= */ 0); // Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y. glProgram.setBufferAttribute( - "aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT); + "aFramePosition", + GlUtil.getNormalizedCoordinateBounds(), + GlUtil.HOMOGENEOUS_COORDINATE_VECTOR_SIZE); } @Override