org.proteinshader.graphics.shader
Class ShaderManager

java.lang.Object
  extended by org.proteinshader.graphics.shader.ShaderManager

public class ShaderManager
extends Object

Knows how to use a ShaderProgramFactory to compile OpenGL shader programs and has methods to enable shaders.

Shader programs are provided for Phong lighting, single-pass wireframe rendering, texture mapped text, patterns, and real-time halftoning. See ShaderEnum for a list of all shader programs.

When the compileShaders(gl) method is called, the ShaderProgramFactory will be asked to compile all of the ShaderPrograms that it can (based on the vertex and fragment shader filenames found in the ShaderEnum). Any ShaderExceptions thrown while trying to compile and linke a ShaderProgram will be saved in a list of errors that will be checked only after all ShaderPrograms that can be compiled and linked have been stored. If one or more ShaderExceptions did occur, then the very last thing the compileShaders(gl) method will do is throw a single ShaderException. If there will multiple errors, then all of the errors will be bundled into the message of the single exception that gets thrown. For any shaders that are missing, the built-in OpenGL lighting will be used instead.


Constructor Summary
ShaderManager()
          Constructs a ShaderManager.
 
Method Summary
 void compileShaders(GL gl)
          Compiles the OpenGL Shading Language vertex and fragment shaders needed for Phong lighting, text label mapping, and real-time hafltoning.
 void deleteShaders(GL gl)
          Frees graphics card memory for all shaders.
 void enableFPSShaders(GL gl, int texture)
          Calls on glUseProgram() to make the fps (frames per second label) shader pair the active shader program.
 int enableGrayscaleShaders(GL gl)
          Calls on glUseProgram() to make the grayscale shader pair the active shader program.
 void enablePatternsShaders(GL gl, int texture)
          Calls on glUseProgram() to make the patterns shader pair the active shader program.
 int enablePhongShaders(GL gl)
          Calls on glUseProgram() to make the Phong shader pair the active shader program.
 void enableRibbonHalftoningShaders(GL gl, int halftoningTexture, int bendTexture, float bendFactor, boolean startLine, boolean endLine, float sCoordStart, float sCoordEnd)
          Calls on glUseProgram() to make the ribbon halftoning shader pair the active shader program.
 int enableSilhouetteShaders(GL gl, boolean startLine, boolean endLine)
          Calls on glUseProgram() to make the silhouette shader pair the active shader program.
 int enableTextLabelShaders(GL gl)
          Calls on glUseProgram() to make the text-label shader pair the active shader program.
 void enableTubeCapHalftoningShaders(GL gl, int texture)
          Calls on glUseProgram() to make the tube cap halftoning shader pair the active shader program.
 int enableTubeCapWireframeShaders(GL gl)
          Calls on glUseProgram() to make the tube cap wireframe shader pair the active shader program.
 void enableTubeHalftoningShaders(GL gl, int halftoningTexture, int bendTexture, float bendFactor, boolean startLine, boolean endLine)
          Calls on glUseProgram() to make the tube halftoning shader pair the active shader program.
 int enableWireframeShaders(GL gl, float sMin, float sDelta, float tDelta)
          Calls on glUseProgram() to make the wireframe shader pair the active shader program.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ShaderManager

public ShaderManager()
Constructs a ShaderManager.

Method Detail

compileShaders

public void compileShaders(GL gl)
                    throws ShaderException
Compiles the OpenGL Shading Language vertex and fragment shaders needed for Phong lighting, text label mapping, and real-time hafltoning.

Parameters:
gl - the current GL object.
Throws:
ShaderException - if a shader program object cannot be obtained.

deleteShaders

public void deleteShaders(GL gl)
Frees graphics card memory for all shaders.

Parameters:
gl - the current GL object.

enablePhongShaders

public int enablePhongShaders(GL gl)
Calls on glUseProgram() to make the Phong shader pair the active shader program.

Parameters:
gl - the current GL object.
Returns:
The name (an integer) of the OpenGL shader pair that was set.

enableWireframeShaders

public int enableWireframeShaders(GL gl,
                                  float sMin,
                                  float sDelta,
                                  float tDelta)
Calls on glUseProgram() to make the wireframe shader pair the active shader program.

The texture t-coordinate for a segment always starts at 0.0 and ends at 1.0, so only the spacing between lines along the t-axis is needed. For s-coordinates, however, the minimum s-coordinate is not always zero, so the minimum s-coordinate must be given (in addition to the spacing between lines along the s-axis).

Parameters:
gl - the current GL object.
sMin - the minimum s-coordinate for texture mapping.
sDelta - the spacing of lines along the s-coordinate axis.
tDelta - the spacing of lines along the t-coordinate axis.
Returns:
The name (an integer) of the OpenGL shader pair that was set.

enableTubeCapWireframeShaders

public int enableTubeCapWireframeShaders(GL gl)
Calls on glUseProgram() to make the tube cap wireframe shader pair the active shader program.

The tube caps are expected to have texture coordinates based on a unit circle with its origin at (s, t) = (0.5, 0.5).

Parameters:
gl - the current GL object.
Returns:
The name (an integer) of the OpenGL shader pair that was set.

enableTextLabelShaders

public int enableTextLabelShaders(GL gl)
Calls on glUseProgram() to make the text-label shader pair the active shader program.

Parameters:
gl - the current GL object.
Returns:
The name (an integer) of the OpenGL shader pair that was set.

enablePatternsShaders

public void enablePatternsShaders(GL gl,
                                  int texture)
Calls on glUseProgram() to make the patterns shader pair the active shader program.

Before calling this method, the texture name (an integer) should be checked to make sure it is valid.

Parameters:
gl - the current GL object.
texture - the name (an integer) of an OpenGL texture object.

enableTubeHalftoningShaders

public void enableTubeHalftoningShaders(GL gl,
                                        int halftoningTexture,
                                        int bendTexture,
                                        float bendFactor,
                                        boolean startLine,
                                        boolean endLine)
Calls on glUseProgram() to make the tube halftoning shader pair the active shader program.

If startLine if true, the fragment shader will draw a line near the beginning of the segment, where the t-coordinate of the texture is close to zero. If endLine is true, the fragment shader will draw a line near the end of the segment, where the t-coordinate of the texture is close to one.

Before calling this method, the glIsTexture() method should be used to verify that the texture name (an integer) is valid.

Parameters:
gl - the current GL object.
halftoningTexture - the name of the halftoning texture.
bendTexture - the name of the bend texture.
bendFactor - factor from 0 (no bend) to 1.0 (max bend).
startLine - determines if a start line is drawn.
endLine - determines if an end line is drawn.

enableTubeCapHalftoningShaders

public void enableTubeCapHalftoningShaders(GL gl,
                                           int texture)
Calls on glUseProgram() to make the tube cap halftoning shader pair the active shader program.

In addition to halftoning, the fragment shader draws a line based on the equation of a circle with texture coordinates (0.5, 0.5) as its center and a radius of 0.5.

Before calling this method, the glIsTexture() method should be used to verify that the texture name (an integer) is valid.

Parameters:
gl - the current GL object.
texture - the name (an integer) of an OpenGL texture object.

enableRibbonHalftoningShaders

public void enableRibbonHalftoningShaders(GL gl,
                                          int halftoningTexture,
                                          int bendTexture,
                                          float bendFactor,
                                          boolean startLine,
                                          boolean endLine,
                                          float sCoordStart,
                                          float sCoordEnd)
Calls on glUseProgram() to make the ribbon halftoning shader pair the active shader program.

If startLine if true, the fragment shader will draw a line near the beginning of the segment, where the t-coordinate of the texture is close to zero. If endLine is true, the fragment shader will draw a line near the end of the segment, where the t-coordinate of the texture is close to one.

Before calling this method, the glIsTexture() method should be used to verify that the texture name (an integer) is valid.

Parameters:
gl - the current GL object.
halftoningTexture - the name of the halftoning texture.
bendTexture - the name of the bend texture.
bendFactor - factor from 0 (no bend) to 1.0 (max bend).
startLine - determines if a start line should be drawn.
endLine - determines if an end line should be drawn.
sCoordStart - the min value of the texture s-coordinate.
sCoordEnd - the max value of the texture s-coordinate.

enableGrayscaleShaders

public int enableGrayscaleShaders(GL gl)
Calls on glUseProgram() to make the grayscale shader pair the active shader program.

Parameters:
gl - the current GL object.
Returns:
The name (an integer) of the OpenGL shader pair that was set.

enableFPSShaders

public void enableFPSShaders(GL gl,
                             int texture)
Calls on glUseProgram() to make the fps (frames per second label) shader pair the active shader program.

Before calling this method, the glIsTexture() method should be used to verify that the texture name (an integer) is valid.

Parameters:
gl - the current GL object.
texture - the name (an integer) of an OpenGL texture object.

enableSilhouetteShaders

public int enableSilhouetteShaders(GL gl,
                                   boolean startLine,
                                   boolean endLine)
Calls on glUseProgram() to make the silhouette shader pair the active shader program.

Parameters:
gl - the current GL object.
startLine - determines if a start line is drawn.
endLine - determines if an end line is drawn.
Returns:
The name (an integer) of the OpenGL shader pair that was set.


Copyright © 2007-2008