From 682a5ca77bfc20548ac63f0ea6e0405b253d08d0 Mon Sep 17 00:00:00 2001 From: hschlueter Date: Mon, 14 Mar 2022 12:52:16 +0000 Subject: [PATCH] Clarify GlProgram parameter name. PiperOrigin-RevId: 434441008 --- .../demo/gl/BitmapOverlayVideoProcessor.java | 4 +-- .../media3/common/util/GlProgram.java | 25 ++++++++++++------- .../ExternalCopyFrameProcessor.java | 2 +- .../TransformationFrameProcessor.java | 2 +- 4 files changed, 20 insertions(+), 13 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 33e44323a3..a9329b5343 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 @@ -119,8 +119,8 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; // Run the shader program. GlProgram program = checkNotNull(this.program); - program.setSamplerTexIdUniform("uTexSampler0", frameTexture, /* unit= */ 0); - program.setSamplerTexIdUniform("uTexSampler1", textures[0], /* unit= */ 1); + program.setSamplerTexIdUniform("uTexSampler0", frameTexture, /* texUnitIndex= */ 0); + program.setSamplerTexIdUniform("uTexSampler1", textures[0], /* texUnitIndex= */ 1); program.setFloatUniform("uScaleX", bitmapScaleX); program.setFloatUniform("uScaleY", bitmapScaleY); program.setFloatsUniform("uTexTransform", transformMatrix); diff --git a/libraries/common/src/main/java/androidx/media3/common/util/GlProgram.java b/libraries/common/src/main/java/androidx/media3/common/util/GlProgram.java index 681ec57433..ecddad5c71 100644 --- a/libraries/common/src/main/java/androidx/media3/common/util/GlProgram.java +++ b/libraries/common/src/main/java/androidx/media3/common/util/GlProgram.java @@ -175,9 +175,16 @@ public final class GlProgram { checkNotNull(attributeByName.get(name)).setBuffer(values, size); } - /** Sets a texture sampler type uniform. */ - public void setSamplerTexIdUniform(String name, int texId, int unit) { - checkNotNull(uniformByName.get(name)).setSamplerTexId(texId, unit); + /** + * Sets a texture sampler type uniform. + * + * @param name The uniform's name. + * @param texId The texture identifier. + * @param texUnitIndex The texture unit index. Use a different index (0, 1, 2, ...) for each + * texture sampler in the program. + */ + public void setSamplerTexIdUniform(String name, int texId, int texUnitIndex) { + checkNotNull(uniformByName.get(name)).setSamplerTexId(texId, texUnitIndex); } /** Sets a float type uniform. */ @@ -322,7 +329,7 @@ public final class GlProgram { private final float[] value; private int texId; - private int unit; + private int texUnitIndex; private Uniform(String name, int location, int type) { this.name = name; @@ -335,11 +342,11 @@ public final class GlProgram { * Configures {@link #bind()} to use the specified {@code texId} for this sampler uniform. * * @param texId The GL texture identifier from which to sample. - * @param unit The GL texture unit index. + * @param texUnitIndex The GL texture unit index. */ - public void setSamplerTexId(int texId, int unit) { + public void setSamplerTexId(int texId, int texUnitIndex) { this.texId = texId; - this.unit = unit; + this.texUnitIndex = texUnitIndex; } /** Configures {@link #bind()} to use the specified float {@code value} for this uniform. */ @@ -382,7 +389,7 @@ public final class GlProgram { if (texId == 0) { throw new IllegalStateException("No call to setSamplerTexId() before bind."); } - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + unit); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texUnitIndex); if (type == GLES11Ext.GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT) { GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texId); } else if (type == GLES20.GL_SAMPLER_2D) { @@ -390,7 +397,7 @@ public final class GlProgram { } else { throw new IllegalStateException("Unexpected uniform type: " + type); } - GLES20.glUniform1i(location, unit); + GLES20.glUniform1i(location, texUnitIndex); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri( 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 05cd6dbf64..4356d24e74 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/ExternalCopyFrameProcessor.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/ExternalCopyFrameProcessor.java @@ -70,7 +70,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ? FRAGMENT_SHADER_COPY_EXTERNAL_YUV_ES3_PATH : FRAGMENT_SHADER_COPY_EXTERNAL_PATH; glProgram = new GlProgram(context, vertexShaderFilePath, fragmentShaderFilePath); - glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* unit= */ 0); + 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); diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationFrameProcessor.java b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationFrameProcessor.java index 576fc74d96..6081075ac8 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationFrameProcessor.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/TransformationFrameProcessor.java @@ -97,7 +97,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; // TODO(b/205002913): check the loaded program is consistent with the attributes and uniforms // expected in the code. glProgram = new GlProgram(context, VERTEX_SHADER_TRANSFORMATION_PATH, FRAGMENT_SHADER_PATH); - glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* unit= */ 0); + 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);