com.neovisionaries.android.opengl
Class Uniform

java.lang.Object
  extended by com.neovisionaries.android.opengl.Uniform

public class Uniform
extends Object

A class to manipulate a uniform variable in OpenGL Shader Language.

 // E X A M P L E

 // Get a program from somewhere.
 Program program = ...;

 // Get an accessor to a uniform variable.
 Uniform pos = program.getUniform("pos");

 // Set a value to the uniform variable.
 // It is assumed here that pos is a vec2 variable.
 pos.set(1.0f, 1.0f);
 

Author:
Takahiko Kawasaki

Constructor Summary
Uniform(Program program, String name)
          A constructor.
 
Method Summary
 float[] get(Program program, float[] params)
          Get the value of a uniform variable.
 float[] get(Program program, float[] params, int offset)
          Get the value of a uniform variable.
 FloatBuffer get(Program program, FloatBuffer params)
          Get the value of a uniform variable.
 int[] get(Program program, int[] params)
          Get the value of a uniform variable.
 int[] get(Program program, int[] params, int offset)
          Get the value of a uniform variable.
 IntBuffer get(Program program, IntBuffer params)
          Get the value of a uniform variable.
 int getLocation()
          Get the location of this uniform.
 void set(float x)
          This method is an alias of set1(float).
 void set(float[] values)
          Set a value to a non-array uniform variable.
 void set(float x, float y)
          This method is an alias of set2(float, float).
 void set(float x, float y, float z)
          This method is an alias of set3(float, float, float).
 void set(float x, float y, float z, float w)
          This method is an alias of set4(float, float, float, float).
 void set(int x)
          This method is an alias of set1(int).
 void set(int[] values)
          Set a value to a non-array uniform variable.
 void set(int x, int y)
          This method is an alias of set2(int, int).
 void set(int x, int y, int z)
          This method is an alias of set3(int, int, int).
 void set(int x, int y, int z, int w)
          This method is an alias of set4(int, int, int, int).
 void set1(float x)
          Set a value to a uniform variable (float).
 void set1(float[] values)
          Set a value to a uniform variable (float array).
 void set1(int x)
          Set a value to a uniform variable (int).
 void set1(int[] values)
          Set a value to a uniform variable (int array).
 void set1(int count, float[] values, int offset)
          Set a value to a uniform variable (float array).
 void set1(int count, FloatBuffer values)
          Set a value to a uniform variable (float array).
 void set1(int count, int[] values, int offset)
          Set a value to a uniform variable (int array).
 void set1(int count, IntBuffer values)
          Set a value to a uniform variable (int array).
 void set2(float[] values)
          Set a value to a uniform variable (float vec2 array).
 void set2(float x, float y)
          Set a value to a uniform variable (float vec2).
 void set2(int[] values)
          Set a value to a uniform variable (int vec2 array).
 void set2(int count, float[] values, int offset)
          Set a value to a uniform variable (float vec2 array).
 void set2(int count, FloatBuffer values)
          Set a value to a uniform variable (float vec2 array).
 void set2(int x, int y)
          Set a value to a uniform variable (int vec2).
 void set2(int count, int[] values, int offset)
          Set a value to a uniform variable (int vec2 array).
 void set2(int count, IntBuffer values)
          Set a value to a uniform variable (int vec2 array).
 void set3(float[] values)
          Set a value to a uniform variable (float vec3 array).
 void set3(float x, float y, float z)
          Set a value to a uniform variable (float vec3).
 void set3(int[] values)
          Set a value to a uniform variable (int vec3 array).
 void set3(int count, float[] values, int offset)
          Set a value to a uniform variable (float vec3 array).
 void set3(int count, FloatBuffer values)
          Set a value to a uniform variable (float vec3 array).
 void set3(int count, int[] values, int offset)
          Set a value to a uniform variable (int vec3 array).
 void set3(int count, IntBuffer values)
          Set a value to a uniform variable (int vec3 array).
 void set3(int x, int y, int z)
          Set a value to a uniform variable (int vec3).
 void set4(float[] values)
          Set a value to a uniform variable (float vec4 array).
 void set4(float x, float y, float z, float w)
          Set a value to a uniform variable (float vec4).
 void set4(int[] values)
          Set a value to a uniform variable (int vec4 array).
 void set4(int count, float[] values, int offset)
          Set a value to a uniform variable (float vec4 array).
 void set4(int count, FloatBuffer values)
          Set a value to a uniform variable (float vec4 array).
 void set4(int count, int[] values, int offset)
          Set a value to a uniform variable (int vec4 array).
 void set4(int count, IntBuffer values)
          Set a value to a uniform variable (int vec4 array).
 void set4(int x, int y, int z, int w)
          Set a value to a uniform variable (int vec4).
 void setMatrix(float[] values)
          Set a value to a non-array, matrix uniform variable.
 void setMatrix2(float[] values)
          Set a value to a uniform variable (mat2 array).
 void setMatrix2(int count, float[] values, int offset)
          Set a value to a uniform variable (mat2 array).
 void setMatrix2(int count, FloatBuffer values)
          Set a value to a uniform variable (mat2 array).
 void setMatrix3(float[] values)
          Set a value to a uniform variable (mat3 array).
 void setMatrix3(int count, float[] values, int offset)
          Set a value to a uniform variable (mat3 array).
 void setMatrix3(int count, FloatBuffer values)
          Set a value to a uniform variable (mat3 array).
 void setMatrix4(float[] values)
          Set a value to a uniform variable (mat4 array).
 void setMatrix4(int count, float[] values, int offset)
          Set a value to a uniform variable (mat4 array).
 void setMatrix4(int count, FloatBuffer values)
          Set a value to a uniform variable (mat4 array).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Uniform

public Uniform(Program program,
               String name)
        throws GLESException
A constructor.

Parameters:
program -
name -
Throws:
IllegalArgumentException - Either or both of the arguments are null.
GLESException - There is no such a uniform variable having the specified name.
See Also:
glGetUniformLocation, Program.getUniform(String)
Method Detail

getLocation

public int getLocation()
Get the location of this uniform.

Returns:
The location of this uniform.
See Also:
glGetUniformLocation

get

public FloatBuffer get(Program program,
                       FloatBuffer params)
Get the value of a uniform variable.

Parameters:
program -
params -
Returns:
The given 'params' object.
Throws:
IllegalArgumentException - Either or both of the arguments are null.
IllegalStateException - The state of the program is not LINKED.
See Also:
glGetUniformfv

get

public float[] get(Program program,
                   float[] params,
                   int offset)
Get the value of a uniform variable.

Parameters:
program -
params -
offset -
Returns:
The given 'params' object.
Throws:
IllegalArgumentException - Either or both of the arguments are null, or 'offset' is equal to or greater than the length of 'params'.
IllegalStateException - The state of the program is not LINKED.
See Also:
glGetUniformfv

get

public float[] get(Program program,
                   float[] params)
Get the value of a uniform variable. This method calls get(program, params, 0).

Parameters:
program -
params -
Returns:
The given 'params' object.
Throws:
IllegalArgumentException - Either or both of the arguments are null, or the length of 'params' is 0.
See Also:
get(Program, float[], int)

get

public IntBuffer get(Program program,
                     IntBuffer params)
Get the value of a uniform variable.

Parameters:
program -
params -
Returns:
The given 'params' object.
Throws:
IllegalArgumentException - Either or both of the arguments are null.
IllegalStateException - The state of the program is not LINKED.
See Also:
glGetUniformiv

get

public int[] get(Program program,
                 int[] params,
                 int offset)
Get the value of a uniform variable.

Parameters:
program -
params -
offset -
Returns:
The given 'params' object.
Throws:
IllegalArgumentException - Either or both of the arguments are null, or 'offset' is equal to or greater than the length of 'params'.
IllegalStateException - The state of the program is not LINKED.
See Also:
glGetUniformiv

get

public int[] get(Program program,
                 int[] params)
Get the value of a uniform variable. This method calls get(program, params, 0).

Parameters:
program -
params -
Returns:
The given 'params' object.
Throws:
IllegalArgumentException - Either or both of the arguments are null, or the length of 'params' is 0.
See Also:
get(Program, int[], int)

set1

public void set1(float x)
Set a value to a uniform variable (float).

Parameters:
x -
See Also:
glUniform1f

set1

public void set1(int count,
                 FloatBuffer values)
Set a value to a uniform variable (float array).

Parameters:
count -
values -
See Also:
glUniform1fv

set1

public void set1(int count,
                 float[] values,
                 int offset)
Set a value to a uniform variable (float array).

Parameters:
count -
values -
offset -
See Also:
glUniform1fv

set1

public void set1(float[] values)
Set a value to a uniform variable (float array). This method calls set1(values.length, values, 0).

Parameters:
values -
See Also:
set1(int, float[], int)

set1

public void set1(int x)
Set a value to a uniform variable (int).

Parameters:
x -
See Also:
glUniform1i

set1

public void set1(int count,
                 IntBuffer values)
Set a value to a uniform variable (int array).

Parameters:
count -
values -
See Also:
glUniform1iv

set1

public void set1(int count,
                 int[] values,
                 int offset)
Set a value to a uniform variable (int array).

Parameters:
count -
values -
offset -
See Also:
glUniform1iv

set1

public void set1(int[] values)
Set a value to a uniform variable (int array). This method calls set1(values.length, values, 0).

Parameters:
values -
See Also:
set1(int, int[], int)

set2

public void set2(float x,
                 float y)
Set a value to a uniform variable (float vec2).

Parameters:
x -
y -
See Also:
glUniform2f

set2

public void set2(int count,
                 FloatBuffer values)
Set a value to a uniform variable (float vec2 array).

Parameters:
count -
values -
See Also:
glUniform2fv

set2

public void set2(int count,
                 float[] values,
                 int offset)
Set a value to a uniform variable (float vec2 array).

Parameters:
count -
values -
offset -
See Also:
glUniform2fv

set2

public void set2(float[] values)
Set a value to a uniform variable (float vec2 array). This method calls set2(values.length / 2, values, 0).

Parameters:
values -
See Also:
set2(int, float[], int)

set2

public void set2(int x,
                 int y)
Set a value to a uniform variable (int vec2).

Parameters:
x -
y -
See Also:
glUniform2i

set2

public void set2(int count,
                 IntBuffer values)
Set a value to a uniform variable (int vec2 array).

Parameters:
count -
values -
See Also:
glUniform2iv

set2

public void set2(int count,
                 int[] values,
                 int offset)
Set a value to a uniform variable (int vec2 array).

Parameters:
count -
values -
offset -
See Also:
glUniform2iv

set2

public void set2(int[] values)
Set a value to a uniform variable (int vec2 array). This method calls set2(values.length / 2, values, 0).

Parameters:
values -
See Also:
set2(int, int[], int)

set3

public void set3(float x,
                 float y,
                 float z)
Set a value to a uniform variable (float vec3).

Parameters:
x -
y -
z -
See Also:
glUniform3f

set3

public void set3(int count,
                 FloatBuffer values)
Set a value to a uniform variable (float vec3 array).

Parameters:
count -
values -
See Also:
glUniform3fv

set3

public void set3(int count,
                 float[] values,
                 int offset)
Set a value to a uniform variable (float vec3 array).

Parameters:
count -
values -
offset -
See Also:
glUniform3fv

set3

public void set3(float[] values)
Set a value to a uniform variable (float vec3 array). This method calls set3(values.length / 3, values, 0).

Parameters:
values -
See Also:
set3(int, float[], int)

set3

public void set3(int x,
                 int y,
                 int z)
Set a value to a uniform variable (int vec3).

Parameters:
x -
y -
z -
See Also:
glUniform3i

set3

public void set3(int count,
                 IntBuffer values)
Set a value to a uniform variable (int vec3 array).

Parameters:
count -
values -
See Also:
glUniform3iv

set3

public void set3(int count,
                 int[] values,
                 int offset)
Set a value to a uniform variable (int vec3 array).

Parameters:
count -
values -
offset -
See Also:
glUniform3iv

set3

public void set3(int[] values)
Set a value to a uniform variable (int vec3 array). This method calls set3(values.length / 3, values, 0).

Parameters:
values -
See Also:
set3(int, int[], int)

set4

public void set4(float x,
                 float y,
                 float z,
                 float w)
Set a value to a uniform variable (float vec4).

Parameters:
x -
y -
z -
w -
See Also:
glUniform4f

set4

public void set4(int count,
                 FloatBuffer values)
Set a value to a uniform variable (float vec4 array).

Parameters:
count -
values -
See Also:
glUniform4fv

set4

public void set4(int count,
                 float[] values,
                 int offset)
Set a value to a uniform variable (float vec4 array).

Parameters:
count -
values -
offset -
See Also:
glUniform4fv

set4

public void set4(float[] values)
Set a value to a uniform variable (float vec4 array). This method calls set4(values.lenth / 4, values, 0).

Parameters:
values -
See Also:
set4(int, float[], int)

set4

public void set4(int x,
                 int y,
                 int z,
                 int w)
Set a value to a uniform variable (int vec4).

Parameters:
x -
y -
z -
w -
See Also:
glUniform4i

set4

public void set4(int count,
                 IntBuffer values)
Set a value to a uniform variable (int vec4 array).

Parameters:
count -
values -
See Also:
glUniform4iv

set4

public void set4(int count,
                 int[] values,
                 int offset)
Set a value to a uniform variable (int vec4 array).

Parameters:
count -
values -
offset -
See Also:
glUniform4iv

set4

public void set4(int[] values)
Set a value to a uniform variable (int vec4 array). This method calls set4(values.lenth / 4, values, 0).

Parameters:
values -
See Also:
set4(int, int[], int)

setMatrix2

public void setMatrix2(int count,
                       FloatBuffer values)
Set a value to a uniform variable (mat2 array).

Parameters:
count -
values -
See Also:
glUniformMatrix2fv

setMatrix2

public void setMatrix2(int count,
                       float[] values,
                       int offset)
Set a value to a uniform variable (mat2 array).

Parameters:
count -
values -
offset -
See Also:
glUniformMatrix2fv

setMatrix2

public void setMatrix2(float[] values)
Set a value to a uniform variable (mat2 array). This method calls setMatrix2(values.length / (2 * 2), values, 0).

Parameters:
values -
See Also:
setMatrix2(int, float[], int)

setMatrix3

public void setMatrix3(int count,
                       FloatBuffer values)
Set a value to a uniform variable (mat3 array).

Parameters:
count -
values -
See Also:
glUniformMatrix3fv

setMatrix3

public void setMatrix3(int count,
                       float[] values,
                       int offset)
Set a value to a uniform variable (mat3 array).

Parameters:
count -
values -
offset -
See Also:
glUniformMatrix3fv

setMatrix3

public void setMatrix3(float[] values)
Set a value to a uniform variable (mat3 array). This method calls setMatrix3(values.length / (3 * 3), values, 0).

Parameters:
values -
See Also:
setMatrix3(int, float[], int)

setMatrix4

public void setMatrix4(int count,
                       FloatBuffer values)
Set a value to a uniform variable (mat4 array).

Parameters:
count -
values -
See Also:
glUniformMatrix4fv

setMatrix4

public void setMatrix4(int count,
                       float[] values,
                       int offset)
Set a value to a uniform variable (mat4 array).

Parameters:
count -
values -
offset -
See Also:
glUniformMatrix4fv

setMatrix4

public void setMatrix4(float[] values)
Set a value to a uniform variable (mat4 array). This method calls setMatrix4(values.length / (4 * 4), values, 0).

Parameters:
values -
See Also:
setMatrix4(int, float[], int)

set

public void set(float x)
This method is an alias of set1(float).

Parameters:
x -
See Also:
set1(float)

set

public void set(int x)
This method is an alias of set1(int).

Parameters:
x -
See Also:
set1(int)

set

public void set(float x,
                float y)
This method is an alias of set2(float, float).

Parameters:
x -
y -
See Also:
set2(float, float)

set

public void set(int x,
                int y)
This method is an alias of set2(int, int).

Parameters:
x -
y -
See Also:
set2(int, int)

set

public void set(float x,
                float y,
                float z)
This method is an alias of set3(float, float, float).

Parameters:
x -
y -
z -
See Also:
set3(float, float, float)

set

public void set(int x,
                int y,
                int z)
This method is an alias of set3(int, int, int).

Parameters:
x -
y -
z -
See Also:
set3(int, int, int)

set

public void set(float x,
                float y,
                float z,
                float w)
This method is an alias of set4(float, float, float, float).

Parameters:
x -
y -
z -
w -
See Also:
set4(float, float, float, float)

set

public void set(int x,
                int y,
                int z,
                int w)
This method is an alias of set4(int, int, int, int).

Parameters:
x -
y -
z -
w -
See Also:
set4(int, int, int, int)

set

public void set(float[] values)
Set a value to a non-array uniform variable. This method calls another setter method depending on the size of the given values. The following table shows pairs of size and method.

values.length Method to call
1 set1(values[0])
2 set2(values[0], values[1])
3 set3(values[0], values[1], values[2])
4 set4(values[0], values[1], values[2], values[3])

Parameters:
values -
Throws:
IllegalArgumentException - The argument is null, or its length is none of the ones listed in the above table.

set

public void set(int[] values)
Set a value to a non-array uniform variable. This method calls another setter method depending on the size of the given values. The following table shows pairs of size and method.

values.length Method to call
1 set1(values[0])
2 set2(values[0], values[1])
3 set3(values[0], values[1], values[2])
4 set4(values[0], values[1], values[2], values[3])

Parameters:
values -
Throws:
IllegalArgumentException - The argument is null, or its length is none of the ones listed in the above table.

setMatrix

public void setMatrix(float[] values)
Set a value to a non-array, matrix uniform variable. This method calls another setter method depending on the size of the given values. The following table shows pairs of size and method.

values.length Method to call
4 setMatrix2(values)
9 setMatrix3(values)
16 setMatrix4(values)

Parameters:
values -
Throws:
IllegalArgumentException - The argument is null, or its length is none of the ones listed in the above table.