Add new setIntsUniform for setting ivec uniforms in shaders.
PiperOrigin-RevId: 567102956
This commit is contained in:
parent
bfd4b6a188
commit
2052be0f51
@ -189,6 +189,11 @@ public final class GlProgram {
|
|||||||
checkNotNull(uniformByName.get(name)).setInt(value);
|
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. */
|
/** Sets a {@code float} type uniform. */
|
||||||
public void setFloatUniform(String name, float value) {
|
public void setFloatUniform(String name, float value) {
|
||||||
checkNotNull(uniformByName.get(name)).setFloat(value);
|
checkNotNull(uniformByName.get(name)).setFloat(value);
|
||||||
@ -296,7 +301,11 @@ public final class GlProgram {
|
|||||||
*/
|
*/
|
||||||
private static final class Uniform {
|
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.
|
||||||
|
*
|
||||||
|
* <p>See https://docs.gl/es2/glGetActiveUniform for more information.
|
||||||
|
*/
|
||||||
public static Uniform create(int programId, int index) {
|
public static Uniform create(int programId, int index) {
|
||||||
int[] length = new int[1];
|
int[] length = new int[1];
|
||||||
GLES20.glGetProgramiv(
|
GLES20.glGetProgramiv(
|
||||||
@ -329,8 +338,8 @@ public final class GlProgram {
|
|||||||
private final int location;
|
private final int location;
|
||||||
private final int type;
|
private final int type;
|
||||||
private final float[] floatValue;
|
private final float[] floatValue;
|
||||||
|
private final int[] intValue;
|
||||||
|
|
||||||
private int intValue;
|
|
||||||
private int texIdValue;
|
private int texIdValue;
|
||||||
private int texUnitIndex;
|
private int texUnitIndex;
|
||||||
|
|
||||||
@ -338,7 +347,8 @@ public final class GlProgram {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.type = type;
|
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}. */
|
/** Configures {@link #bind()} to use the specified {@code int} {@code value}. */
|
||||||
public void setInt(int 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}. */
|
/** 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 {
|
public void bind() throws GlUtil.GlException {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case GLES20.GL_INT:
|
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;
|
break;
|
||||||
case GLES20.GL_FLOAT:
|
case GLES20.GL_FLOAT:
|
||||||
GLES20.glUniform1fv(location, /* count= */ 1, floatValue, /* offset= */ 0);
|
GLES20.glUniform1fv(location, /* count= */ 1, floatValue, /* offset= */ 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user