com.threerings.opengl.renderer
Class Program

java.lang.Object
  extended by com.threerings.opengl.renderer.ShaderObject
      extended by com.threerings.opengl.renderer.Program

public class Program
extends ShaderObject

Contains a shader program.


Nested Class Summary
static class Program.FloatUniform
          A uniform containing a float.
static class Program.IntegerUniform
          A uniform containing an integer.
static class Program.Matrix4fUniform
          A uniform containing a 4x4 matrix.
static class Program.Uniform
          Contains the location and value of a uniform variable.
static class Program.Vector2fUniform
          A uniform containing a two-element vector.
static class Program.Vector3fUniform
          A uniform containing a three-element vector.
static class Program.Vector4fUniform
          A uniform containing a four-element vector.
 
Field Summary
protected  HashMap<String,Integer> _attribLocations
          Maps attribute names to their locations.
protected  Shader _fragment
          The fragment shader.
protected  HashMap<String,Integer> _uniformLocations
          Maps uniform names to their locations.
protected  HashIntMap<Program.Uniform> _uniforms
          Maps uniform locations to their current values.
protected static FloatBuffer _vbuf
          Used to set values.
protected  Shader _vertex
          The vertex shader.
 
Fields inherited from class com.threerings.opengl.renderer.ShaderObject
_id, _renderer, ASCII_CHARSET
 
Constructor Summary
protected Program()
          Creates an invalid program (used by the renderer to force reapplication).
  Program(Renderer renderer)
          Creates a new shader program.
 
Method Summary
 int getAttribLocation(String name)
          Returns the location of the identified attribute.
 Shader getFragmentShader()
          Returns a reference to the fragment shader.
 int getUniformLocation(String name)
          Returns the location of the identified uniform variable.
 Shader getVertexShader()
          Returns a reference to the vertex shader.
 boolean relink()
          Relinks the program with its current vertex and fragment shaders.
 void setAttribLocation(String name, int index)
          Binds an attribute to the specified location.
 boolean setShaders(Shader vertex, Shader fragment)
          Sets the shaders for this program and links it.
 void setUniforms(Program.Uniform[] uniforms)
          Sets the values of the shader's uniform variables.
protected static ByteBuffer toBuffer(String string)
          Creates a new byte buffer containing the specified string in null-terminated ASCII format.
 
Methods inherited from class com.threerings.opengl.renderer.ShaderObject
delete, finalize, getId, getInfoLog
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_vertex

protected Shader _vertex
The vertex shader.


_fragment

protected Shader _fragment
The fragment shader.


_uniformLocations

protected HashMap<String,Integer> _uniformLocations
Maps uniform names to their locations.


_attribLocations

protected HashMap<String,Integer> _attribLocations
Maps attribute names to their locations.


_uniforms

protected HashIntMap<Program.Uniform> _uniforms
Maps uniform locations to their current values.


_vbuf

protected static FloatBuffer _vbuf
Used to set values.

Constructor Detail

Program

public Program(Renderer renderer)
Creates a new shader program.


Program

protected Program()
Creates an invalid program (used by the renderer to force reapplication).

Method Detail

relink

public boolean relink()
Relinks the program with its current vertex and fragment shaders.

Returns:
true if the program linked successfully, false if there was an error.

setShaders

public boolean setShaders(Shader vertex,
                          Shader fragment)
Sets the shaders for this program and links it. If linkage fails (or even if it succeeds), ShaderObject.getInfoLog() can be used to return more information.

Returns:
true if the program linked successfully, false if there was an error.

getVertexShader

public Shader getVertexShader()
Returns a reference to the vertex shader.


getFragmentShader

public Shader getFragmentShader()
Returns a reference to the fragment shader.


getUniformLocation

public int getUniformLocation(String name)
Returns the location of the identified uniform variable.


setUniforms

public void setUniforms(Program.Uniform[] uniforms)
Sets the values of the shader's uniform variables.


setAttribLocation

public void setAttribLocation(String name,
                              int index)
Binds an attribute to the specified location.


getAttribLocation

public int getAttribLocation(String name)
Returns the location of the identified attribute.


toBuffer

protected static ByteBuffer toBuffer(String string)
Creates a new byte buffer containing the specified string in null-terminated ASCII format.