hmi.graphics.opengl
Class GLShader

java.lang.Object
  extended by hmi.graphics.opengl.GLShader
All Implemented Interfaces:
GLRenderObject

public class GLShader
extends Object
implements GLRenderObject

A wrapper for OpenGL shaders, in the form of an GLRenderObject. In fact a wrapper around the GLShaderProgram, with added functionality for defining and setting uniforms. A GLShader can share the same GLShaderProgram with some other GLShader, yet it can set its own individual uniform values.


Field Summary
(package private)  ArrayList<String> declaredTypes
           
static int F
           
private  float[] floatValue
           
static int FV
           
static int I
           
private  int[] intValue
           
static int IV
           
private  int nrOfUniforms
           
private  GLShaderProgram prog
           
private  int progId
           
private  String shaderProgName
           
static int U1B
           
static int U1F
           
static int U1I
           
static int U2B
           
static int U2F
           
static int U2I
           
static int U3B
           
static int U3F
           
static int U3I
           
static int U4B
           
static int U4F
           
static int U4I
           
private  int[] uBaseType
           
private  int[] uLocation
           
private  String[] uName
           
private  int[] uOffset
           
private  int[] uSize
           
private  int[] uType
           
 
Constructor Summary
GLShader(String shaderProg, String... uniformNamesAndTypes)
          Creates a new GLShader, with specified shader program name, and shader uniform names and parameter types.
 
Method Summary
 void glInit(GLRenderContext gl)
          OpenGL initialization: the shader program is initialized, activated, and current uniform values are passed on to the OpenGL shader.
 void glRender(GLRenderContext gl)
          OpenGL rendering: the shader is activated, and current uniform values are passed on to the OpenGL shader.
private  void glSetUniformValue(GLRenderContext gl, int i)
           
private  void init(String[] uniformNames, int[] uniformTypes)
          Initializes the GLShader object, where the shader program name, and shader uniforms and types are specified.
 void setValue(String uniformName, Object... vals)
          Sets the value(s) for a single uniform, referenced by name
 void setValues(int[] intVals, float[] floatVals)
          Obsolete setValues method
 void setValues(Object... vals)
          Sets uniform values, specified by an array of value Objects, which should match the uniform types for this GLShader
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

prog

private GLShaderProgram prog

shaderProgName

private String shaderProgName

progId

private int progId

nrOfUniforms

private int nrOfUniforms

uName

private String[] uName

uType

private int[] uType

uBaseType

private int[] uBaseType

uSize

private int[] uSize

uLocation

private int[] uLocation

uOffset

private int[] uOffset

intValue

private int[] intValue

floatValue

private float[] floatValue

I

public static final int I
See Also:
Constant Field Values

F

public static final int F
See Also:
Constant Field Values

IV

public static final int IV
See Also:
Constant Field Values

FV

public static final int FV
See Also:
Constant Field Values

U1I

public static final int U1I
See Also:
Constant Field Values

U2I

public static final int U2I
See Also:
Constant Field Values

U3I

public static final int U3I
See Also:
Constant Field Values

U4I

public static final int U4I
See Also:
Constant Field Values

U1F

public static final int U1F
See Also:
Constant Field Values

U2F

public static final int U2F
See Also:
Constant Field Values

U3F

public static final int U3F
See Also:
Constant Field Values

U4F

public static final int U4F
See Also:
Constant Field Values

U1B

public static final int U1B
See Also:
Constant Field Values

U2B

public static final int U2B
See Also:
Constant Field Values

U3B

public static final int U3B
See Also:
Constant Field Values

U4B

public static final int U4B
See Also:
Constant Field Values

declaredTypes

ArrayList<String> declaredTypes
Constructor Detail

GLShader

public GLShader(String shaderProg,
                String... uniformNamesAndTypes)
Creates a new GLShader, with specified shader program name, and shader uniform names and parameter types. The names and types are Strings are specified one after another, and should alternate. Allowed parameter types: int, float, bool, vec2, vec3, sampler1D, sampler2D etc. or, alternatively: 1i, 2i, 3i, 4i, 1f, 2f, 3f, 4f The uniform parameter is optional; when absent, the vertex shader and fragment shader texts are used to extract uniform definitions. The order of uniforms (used for the setValues method) is the order of declaration within the shader texts, where the unifoms from the vertex shader precede those of the fragment shader.

Method Detail

init

private void init(String[] uniformNames,
                  int[] uniformTypes)
Initializes the GLShader object, where the shader program name, and shader uniforms and types are specified. The shader program is loaded (by means of GLShaderProgramLoader).


toString

public String toString()
Overrides:
toString in class Object

setValue

public void setValue(String uniformName,
                     Object... vals)
Sets the value(s) for a single uniform, referenced by name


setValues

public void setValues(Object... vals)
Sets uniform values, specified by an array of value Objects, which should match the uniform types for this GLShader


setValues

public void setValues(int[] intVals,
                      float[] floatVals)
Obsolete setValues method


glSetUniformValue

private void glSetUniformValue(GLRenderContext gl,
                               int i)

glInit

public void glInit(GLRenderContext gl)
OpenGL initialization: the shader program is initialized, activated, and current uniform values are passed on to the OpenGL shader.

Specified by:
glInit in interface GLRenderObject

glRender

public final void glRender(GLRenderContext gl)
OpenGL rendering: the shader is activated, and current uniform values are passed on to the OpenGL shader.

Specified by:
glRender in interface GLRenderObject