com.threerings.opengl.renderer.util
Class SnippetUtil

java.lang.Object
  extended by com.threerings.opengl.renderer.util.SnippetUtil

public class SnippetUtil
extends Object

Contains methods to create snippets of GLSL shader code.


Field Summary
protected static SoftCache<ArrayKey,String> _fogParams
          Cached fog param snippets.
protected static SoftCache<ArrayKey,String> _fragmentLighting
          Cached fragment lighting snippets.
protected static SoftCache<ArrayKey,String> _texCoords
          Cached tex coord snippets.
protected static SoftCache<ArrayKey,String> _vertexLighting
          Cached vertex lighting snippets.
 
Constructor Summary
SnippetUtil()
           
 
Method Summary
protected static void addDirectionalLight(int idx, String dest, String side, String eyeNormal, StringBuilder buf)
          Adds the influence of a directional light.
protected static void addPointLight(int idx, String dest, String side, String eyeVertex, String eyeNormal, StringBuilder buf)
          Adds the influence of a point light.
protected static void addSpotLight(int idx, String dest, String side, String eyeVertex, String eyeNormal, StringBuilder buf)
          Adds the influence of a spot light.
protected static boolean anySphereMapped(TextureUnit[] units)
          Determines whether any of the specified texture units use sphere-map texture coordinate generation.
protected static String createFogParamDef(String name, String eyeVertex, int mode)
          Creates and returns the definition for the supplied fog parameters.
protected static String createFragmentLightingDef(String name, String eyeVertex, String eyeNormal, Light.Type[] lights)
          Creates and returns the definition for the supplied fragment lighting parameters.
protected static String createLightingSide(String dest, String side, String eyeVertex, String eyeNormal, Light.Type[] lights)
          Creates and returns the expression for a single lit side.
protected static String createTexCoordDef(String name, String eyeVertex, String eyeNormal, TextureUnit[] units)
          Creates and returns the definition for the supplied tex coord parameters.
protected static String createTexCoordElement(int idx, char element, int mode, String eyeVertex)
          Returns the code for a single texture coordinate element.
protected static ArrayKey createTexCoordKey(String name, String eyeVertex, String eyeNormal, TextureUnit[] units)
          Creates and returns a key for the supplied tex coord parameters.
protected static void createTexCoordUnit(int idx, TextureUnit unit, String eyeVertex, StringBuilder buf)
          Appends the code for a single texture coordinate unit.
protected static String createVertexLightingDef(String name, String eyeVertex, String eyeNormal, int cullFace, boolean vertexProgramTwoSide, Light.Type[] lights)
          Creates and returns the definition for the supplied vertex lighting parameters.
static void getFogBlend(String name, RenderState[] states, List<String> defs)
          Creates a fog blend snippet.
static void getFogParam(String name, String eyeVertex, RenderState[] states, List<String> defs)
          Creates a fog parameter snippet.
static void getFragmentLighting(String name, String eyeVertex, String eyeNormal, RenderState[] states, List<String> defs)
          Creates a fragment lighting snippet.
protected static Light.Type[] getLightTypes(Light[] lights)
          Returns an array of types corresponding to each light.
static void getTexCoord(String name, String eyeVertex, String eyeNormal, RenderState[] states, List<String> defs)
          Retrieves a tex coord snippet.
static void getVertexLighting(String name, String eyeVertex, String eyeNormal, RenderState[] states, boolean vertexProgramTwoSide, List<String> defs)
          Creates a vertex lighting snippet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_fogParams

protected static SoftCache<ArrayKey,String> _fogParams
Cached fog param snippets.


_texCoords

protected static SoftCache<ArrayKey,String> _texCoords
Cached tex coord snippets.


_vertexLighting

protected static SoftCache<ArrayKey,String> _vertexLighting
Cached vertex lighting snippets.


_fragmentLighting

protected static SoftCache<ArrayKey,String> _fragmentLighting
Cached fragment lighting snippets.

Constructor Detail

SnippetUtil

public SnippetUtil()
Method Detail

getFogParam

public static void getFogParam(String name,
                               String eyeVertex,
                               RenderState[] states,
                               List<String> defs)
Creates a fog parameter snippet.


getFogBlend

public static void getFogBlend(String name,
                               RenderState[] states,
                               List<String> defs)
Creates a fog blend snippet.


getTexCoord

public static void getTexCoord(String name,
                               String eyeVertex,
                               String eyeNormal,
                               RenderState[] states,
                               List<String> defs)
Retrieves a tex coord snippet.


getVertexLighting

public static void getVertexLighting(String name,
                                     String eyeVertex,
                                     String eyeNormal,
                                     RenderState[] states,
                                     boolean vertexProgramTwoSide,
                                     List<String> defs)
Creates a vertex lighting snippet.


getFragmentLighting

public static void getFragmentLighting(String name,
                                       String eyeVertex,
                                       String eyeNormal,
                                       RenderState[] states,
                                       List<String> defs)
Creates a fragment lighting snippet.


createFogParamDef

protected static String createFogParamDef(String name,
                                          String eyeVertex,
                                          int mode)
Creates and returns the definition for the supplied fog parameters.


createTexCoordKey

protected static ArrayKey createTexCoordKey(String name,
                                            String eyeVertex,
                                            String eyeNormal,
                                            TextureUnit[] units)
Creates and returns a key for the supplied tex coord parameters.


createTexCoordDef

protected static String createTexCoordDef(String name,
                                          String eyeVertex,
                                          String eyeNormal,
                                          TextureUnit[] units)
Creates and returns the definition for the supplied tex coord parameters.


anySphereMapped

protected static boolean anySphereMapped(TextureUnit[] units)
Determines whether any of the specified texture units use sphere-map texture coordinate generation.


createTexCoordUnit

protected static void createTexCoordUnit(int idx,
                                         TextureUnit unit,
                                         String eyeVertex,
                                         StringBuilder buf)
Appends the code for a single texture coordinate unit.


createTexCoordElement

protected static String createTexCoordElement(int idx,
                                              char element,
                                              int mode,
                                              String eyeVertex)
Returns the code for a single texture coordinate element.


getLightTypes

protected static Light.Type[] getLightTypes(Light[] lights)
Returns an array of types corresponding to each light.


createVertexLightingDef

protected static String createVertexLightingDef(String name,
                                                String eyeVertex,
                                                String eyeNormal,
                                                int cullFace,
                                                boolean vertexProgramTwoSide,
                                                Light.Type[] lights)
Creates and returns the definition for the supplied vertex lighting parameters.


createFragmentLightingDef

protected static String createFragmentLightingDef(String name,
                                                  String eyeVertex,
                                                  String eyeNormal,
                                                  Light.Type[] lights)
Creates and returns the definition for the supplied fragment lighting parameters.


createLightingSide

protected static String createLightingSide(String dest,
                                           String side,
                                           String eyeVertex,
                                           String eyeNormal,
                                           Light.Type[] lights)
Creates and returns the expression for a single lit side.


addDirectionalLight

protected static void addDirectionalLight(int idx,
                                          String dest,
                                          String side,
                                          String eyeNormal,
                                          StringBuilder buf)
Adds the influence of a directional light.


addPointLight

protected static void addPointLight(int idx,
                                    String dest,
                                    String side,
                                    String eyeVertex,
                                    String eyeNormal,
                                    StringBuilder buf)
Adds the influence of a point light.


addSpotLight

protected static void addSpotLight(int idx,
                                   String dest,
                                   String side,
                                   String eyeVertex,
                                   String eyeNormal,
                                   StringBuilder buf)
Adds the influence of a spot light.