@@ -175,9 +175,16 @@ public void setBufferAttribute(String name, float[] values, int size) {
175
175
checkNotNull (attributeByName .get (name )).setBuffer (values , size );
176
176
}
177
177
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 );
181
188
}
182
189
183
190
/** Sets a float type uniform. */
@@ -322,7 +329,7 @@ public static Uniform create(int programId, int index) {
322
329
private final float [] value ;
323
330
324
331
private int texId ;
325
- private int unit ;
332
+ private int texUnitIndex ;
326
333
327
334
private Uniform (String name , int location , int type ) {
328
335
this .name = name ;
@@ -335,11 +342,11 @@ private Uniform(String name, int location, int type) {
335
342
* Configures {@link #bind()} to use the specified {@code texId} for this sampler uniform.
336
343
*
337
344
* @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.
339
346
*/
340
- public void setSamplerTexId (int texId , int unit ) {
347
+ public void setSamplerTexId (int texId , int texUnitIndex ) {
341
348
this .texId = texId ;
342
- this .unit = unit ;
349
+ this .texUnitIndex = texUnitIndex ;
343
350
}
344
351
345
352
/** Configures {@link #bind()} to use the specified float {@code value} for this uniform. */
@@ -382,15 +389,15 @@ public void bind() {
382
389
if (texId == 0 ) {
383
390
throw new IllegalStateException ("No call to setSamplerTexId() before bind." );
384
391
}
385
- GLES20 .glActiveTexture (GLES20 .GL_TEXTURE0 + unit );
392
+ GLES20 .glActiveTexture (GLES20 .GL_TEXTURE0 + texUnitIndex );
386
393
if (type == GLES11Ext .GL_SAMPLER_EXTERNAL_OES || type == GL_SAMPLER_EXTERNAL_2D_Y2Y_EXT ) {
387
394
GLES20 .glBindTexture (GLES11Ext .GL_TEXTURE_EXTERNAL_OES , texId );
388
395
} else if (type == GLES20 .GL_SAMPLER_2D ) {
389
396
GLES20 .glBindTexture (GLES20 .GL_TEXTURE_2D , texId );
390
397
} else {
391
398
throw new IllegalStateException ("Unexpected uniform type: " + type );
392
399
}
393
- GLES20 .glUniform1i (location , unit );
400
+ GLES20 .glUniform1i (location , texUnitIndex );
394
401
GLES20 .glTexParameteri (GLES20 .GL_TEXTURE_2D , GLES20 .GL_TEXTURE_MAG_FILTER , GLES20 .GL_LINEAR );
395
402
GLES20 .glTexParameteri (GLES20 .GL_TEXTURE_2D , GLES20 .GL_TEXTURE_MIN_FILTER , GLES20 .GL_LINEAR );
396
403
GLES20 .glTexParameteri (
0 commit comments