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 34667faf3e..4dd2b16e39 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 @@ -189,6 +189,11 @@ public final class GlProgram { checkNotNull(uniformByName.get(name)).setInt(value); } + /** Sets a {@code int[]} type uniform. */ + public void setIntsUniform(String name, int[] value) { + checkNotNull(uniformByName.get(name)).setInts(value); + } + /** Sets a {@code float} type uniform. */ public void setFloatUniform(String name, float value) { checkNotNull(uniformByName.get(name)).setFloat(value); @@ -296,7 +301,11 @@ public final class GlProgram { */ private static final class Uniform { - /** Returns the uniform at the given index in the program. */ + /** + * Returns the uniform at the given index in the program. + * + *

See https://docs.gl/es2/glGetActiveUniform for more information. + */ public static Uniform create(int programId, int index) { int[] length = new int[1]; GLES20.glGetProgramiv( @@ -329,8 +338,8 @@ public final class GlProgram { private final int location; private final int type; private final float[] floatValue; + private final int[] intValue; - private int intValue; private int texIdValue; private int texUnitIndex; @@ -338,7 +347,8 @@ public final class GlProgram { this.name = name; this.location = location; this.type = type; - this.floatValue = new float[16]; + this.floatValue = new float[16]; // Allocate 16 for mat4 + this.intValue = new int[4]; // Allocate 4 for ivec4 } /** @@ -354,7 +364,12 @@ public final class GlProgram { /** Configures {@link #bind()} to use the specified {@code int} {@code value}. */ public void setInt(int value) { - this.intValue = value; + this.intValue[0] = value; + } + + /** Configures {@link #bind()} to use the specified {@code int[]} {@code value}. */ + public void setInts(int[] value) { + System.arraycopy(value, /* srcPos= */ 0, this.intValue, /* destPos= */ 0, value.length); } /** Configures {@link #bind()} to use the specified {@code float} {@code value}. */ @@ -376,7 +391,20 @@ public final class GlProgram { public void bind() throws GlUtil.GlException { switch (type) { case GLES20.GL_INT: - GLES20.glUniform1i(location, intValue); + GLES20.glUniform1iv(location, /* count= */ 1, intValue, /* offset= */ 0); + GlUtil.checkGlError(); + break; + case GLES20.GL_INT_VEC2: + GLES20.glUniform2iv(location, /* count= */ 1, intValue, /* offset= */ 0); + GlUtil.checkGlError(); + break; + case GLES20.GL_INT_VEC3: + GLES20.glUniform3iv(location, /* count= */ 1, intValue, /* offset= */ 0); + GlUtil.checkGlError(); + break; + case GLES20.GL_INT_VEC4: + GLES20.glUniform4iv(location, /* count= */ 1, intValue, /* offset= */ 0); + GlUtil.checkGlError(); break; case GLES20.GL_FLOAT: GLES20.glUniform1fv(location, /* count= */ 1, floatValue, /* offset= */ 0);