com.threerings.opengl.util
Class ShaderCache

java.lang.Object
  extended by com.threerings.opengl.util.ResourceCache
      extended by com.threerings.opengl.util.ShaderCache

public class ShaderCache
extends ResourceCache

Caches loaded shaders and shader programs.


Nested Class Summary
protected static class ShaderCache.ProgramKey
          Identifies a linked shader program.
protected static class ShaderCache.ShaderKey
          Identifies a loaded shader.
 
Nested classes/interfaces inherited from class com.threerings.opengl.util.ResourceCache
ResourceCache.CachedResource<T>, ResourceCache.Subcache<K,V>
 
Field Summary
protected  SoftCache<ShaderCache.ProgramKey,Program> _programs
          The set of linked shader programs.
protected  ResourceCache.Subcache<ShaderCache.ShaderKey,Shader> _shaders
          The shader cache.
protected  ResourceCache.Subcache<String,String> _source
          The source file cache.
protected static HashMap<String,Integer> _types
          Maps file extensions to shader types.
protected static boolean CHECK_LOGS
          Whether or not we should check the logs even if the shader compiles/links successfully.
 
Fields inherited from class com.threerings.opengl.util.ResourceCache
_checkTimestamps, _ctx
 
Constructor Summary
ShaderCache(GlContext ctx, boolean checkTimestamps)
          Creates a new shader cache.
 
Method Summary
 Program getProgram(Shader vertex, Shader fragment)
          Returns an instance of a program with the supplied vertex and fragment shaders.
 Shader getShader(String path, String... defs)
          Loads and returns the shader at the specified path with the supplied preprocessor definitions.
 Shader getShader(String path, String[] defs, String[] ddefs)
          Loads and returns the shader at the specified path with the supplied preprocessor definitions as well as a set of derived definitions (not used to find the shader, but included if the shader is compiled).
 String getSource(String path)
          Retrieves the shader source at the specified path.
protected static void maybeCheckLog(ShaderObject object, Object... args)
          If so configured, checks the specified log for the dreaded "software" keyword.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_shaders

protected ResourceCache.Subcache<ShaderCache.ShaderKey,Shader> _shaders
The shader cache.


_source

protected ResourceCache.Subcache<String,String> _source
The source file cache.


_programs

protected SoftCache<ShaderCache.ProgramKey,Program> _programs
The set of linked shader programs.


_types

protected static final HashMap<String,Integer> _types
Maps file extensions to shader types.


CHECK_LOGS

protected static final boolean CHECK_LOGS
Whether or not we should check the logs even if the shader compiles/links successfully.

See Also:
Constant Field Values
Constructor Detail

ShaderCache

public ShaderCache(GlContext ctx,
                   boolean checkTimestamps)
Creates a new shader cache.

Parameters:
checkTimestamps - if true, check the last-modified timestamp of each resource file when we retrieve it from the cache, reloading the resource if the file has been modified externally.
Method Detail

getShader

public Shader getShader(String path,
                        String... defs)
Loads and returns the shader at the specified path with the supplied preprocessor definitions.


getShader

public Shader getShader(String path,
                        String[] defs,
                        String[] ddefs)
Loads and returns the shader at the specified path with the supplied preprocessor definitions as well as a set of derived definitions (not used to find the shader, but included if the shader is compiled).


getSource

public String getSource(String path)
Retrieves the shader source at the specified path.


getProgram

public Program getProgram(Shader vertex,
                          Shader fragment)
Returns an instance of a program with the supplied vertex and fragment shaders.


maybeCheckLog

protected static void maybeCheckLog(ShaderObject object,
                                    Object... args)
If so configured, checks the specified log for the dreaded "software" keyword.