Skip to content

Commit 682a5ca

Browse files
hmschicbaker
authored andcommitted
Clarify GlProgram parameter name.
PiperOrigin-RevId: 434441008
1 parent fb88a4f commit 682a5ca

File tree

4 files changed

+20
-13
lines changed

4 files changed

+20
-13
lines changed

demos/gl/src/main/java/androidx/media3/demo/gl/BitmapOverlayVideoProcessor.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ public void draw(int frameTexture, long frameTimestampUs, float[] transformMatri
119119

120120
// Run the shader program.
121121
GlProgram program = checkNotNull(this.program);
122-
program.setSamplerTexIdUniform("uTexSampler0", frameTexture, /* unit= */ 0);
123-
program.setSamplerTexIdUniform("uTexSampler1", textures[0], /* unit= */ 1);
122+
program.setSamplerTexIdUniform("uTexSampler0", frameTexture, /* texUnitIndex= */ 0);
123+
program.setSamplerTexIdUniform("uTexSampler1", textures[0], /* texUnitIndex= */ 1);
124124
program.setFloatUniform("uScaleX", bitmapScaleX);
125125
program.setFloatUniform("uScaleY", bitmapScaleY);
126126
program.setFloatsUniform("uTexTransform", transformMatrix);

libraries/common/src/main/java/androidx/media3/common/util/GlProgram.java

+16-9
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,16 @@ public void setBufferAttribute(String name, float[] values, int size) {
175175
checkNotNull(attributeByName.get(name)).setBuffer(values, size);
176176
}
177177

178-
/** Sets a texture sampler type uniform. */
179-
public void setSamplerTexIdUniform(String name, int texId, int unit) {
180-
checkNotNull(uniformByName.get(name)).setSamplerTexId(texId, unit);
178+
/**
179+
* Sets a texture sampler type uniform.
180+
*
181+
* @param name The uniform's name.
182+
* @param texId The texture identifier.
183+
* @param texUnitIndex The texture unit index. Use a different index (0, 1, 2, ...) for each
184+
* texture sampler in the program.
185+
*/
186+
public void setSamplerTexIdUniform(String name, int texId, int texUnitIndex) {
187+
checkNotNull(uniformByName.get(name)).setSamplerTexId(texId, texUnitIndex);
181188
}
182189

183190
/** Sets a float type uniform. */
@@ -322,7 +329,7 @@ public static Uniform create(int programId, int index) {
322329
private final float[] value;
323330

324331
private int texId;
325-
private int unit;
332+
private int texUnitIndex;
326333

327334
private Uniform(String name, int location, int type) {
328335
this.name = name;
@@ -335,11 +342,11 @@ private Uniform(String name, int location, int type) {
335342
* Configures {@link #bind()} to use the specified {@code texId} for this sampler uniform.
336343
*
337344
* @param texId The GL texture identifier from which to sample.
338-
* @param unit The GL texture unit index.
345+
* @param texUnitIndex The GL texture unit index.
339346
*/
340-
public void setSamplerTexId(int texId, int unit) {
347+
public void setSamplerTexId(int texId, int texUnitIndex) {
341348
this.texId = texId;
342-
this.unit = unit;
349+
this.texUnitIndex = texUnitIndex;
343350
}
344351

345352
/** Configures {@link #bind()} to use the specified float {@code value} for this uniform. */
@@ -382,15 +389,15 @@ public void bind() {
382389
if (texId == 0) {
383390
throw new IllegalStateException("No call to setSamplerTexId() before bind.");
384391
}
385-
GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + unit);
392+
GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + texUnitIndex);
386393
if (type == GLES11Ext.GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT) {
387394
GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, texId);
388395
} else if (type == GLES20.GL_SAMPLER_2D) {
389396
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texId);
390397
} else {
391398
throw new IllegalStateException("Unexpected uniform type: " + type);
392399
}
393-
GLES20.glUniform1i(location, unit);
400+
GLES20.glUniform1i(location, texUnitIndex);
394401
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
395402
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
396403
GLES20.glTexParameteri(

libraries/transformer/src/main/java/androidx/media3/transformer/ExternalCopyFrameProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void initialize(int inputTexId) throws IOException {
7070
? FRAGMENT_SHADER_COPY_EXTERNAL_YUV_ES3_PATH
7171
: FRAGMENT_SHADER_COPY_EXTERNAL_PATH;
7272
glProgram = new GlProgram(context, vertexShaderFilePath, fragmentShaderFilePath);
73-
glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* unit= */ 0);
73+
glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* texUnitIndex= */ 0);
7474
// Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y.
7575
glProgram.setBufferAttribute(
7676
"aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT);

libraries/transformer/src/main/java/androidx/media3/transformer/TransformationFrameProcessor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void initialize(int inputTexId) throws IOException {
9797
// TODO(b/205002913): check the loaded program is consistent with the attributes and uniforms
9898
// expected in the code.
9999
glProgram = new GlProgram(context, VERTEX_SHADER_TRANSFORMATION_PATH, FRAGMENT_SHADER_PATH);
100-
glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* unit= */ 0);
100+
glProgram.setSamplerTexIdUniform("uTexSampler", inputTexId, /* texUnitIndex= */ 0);
101101
// Draw the frame on the entire normalized device coordinate space, from -1 to 1, for x and y.
102102
glProgram.setBufferAttribute(
103103
"aFramePosition", GlUtil.getNormalizedCoordinateBounds(), GlUtil.RECTANGLE_VERTICES_COUNT);

0 commit comments

Comments
 (0)