Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ACG::ShaderCache Class Reference

Cache for shaders. More...

#include <ACG/GL/ShaderCache.hh>

Classes

struct  CacheEntry
 

Public Member Functions

virtual ~ShaderCache ()
 Destructor.
 
GLSL::ProgramgetProgram (const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
 Query a dynamically generated program from cache. More...
 
GLSL::ProgramgetProgram (const ShaderGenDesc *_desc, const std::vector< unsigned int > *_mods)
 Query a dynamically generated program from cache. More...
 
GLSL::ProgramgetProgram (const ShaderGenDesc *_desc)
 Query a dynamically generated program from cache. More...
 
GLSL::ProgramgetProgram (const char *_vertexShaderFile, const char *_tessControlShaderFile, const char *_tessEvalShaderFile, const char *_geometryShaderFile, const char *_fragmentShaderFile, QStringList *_macros=0, bool _verbose=true)
 Query a static shader program from cache. More...
 
GLSL::ProgramgetProgram (const char *_vertexShaderFile, const char *_fragmentShaderFile, QStringList *_macros=0, bool _verbose=true)
 Query a static shader program from cache. More...
 
GLSL::ProgramgetComputeProgram (const char *_computeShaderFile, QStringList *_macros=0, bool _verbose=true)
 Query a static compute shader program from cache. More...
 
void clearCache ()
 Delete all cached shaders.
 
void setTimeCheck (bool _on)
 enable or disable checking of the time step of each file More...
 
bool getTimeCheck ()
 
void setDebugOutputDir (const char *_outputDir)
 Enable debug output of generated shaders to specified directory.
 

Static Public Member Functions

static ShaderCachegetInstance ()
 Return instance of the ShaderCache singleton. More...
 

Protected Types

typedef std::list< std::pair
< CacheEntry, GLSL::Program * > > 
CacheList
 

Protected Member Functions

bool compareTimeStamp (const CacheEntry *_a, const CacheEntry *_b)
 Returns true, if the shaders have the timestamp.
 
int compareShaderGenDescs (const CacheEntry *_a, const CacheEntry *_b)
 Returns true, if the shaders are not equal.
 

Protected Attributes

CacheList cache_
 cache containing dynamic shaders from ShaderProgGenerator
 
CacheList cacheStatic_
 cache containing static shaders loaded from files (separate from dynamic cache to reduce access time)
 
CacheList cacheComputeShaders_
 cache for static compute shaders
 
bool timeCheck_
 
QString dbgOutputDir_
 output directory for shaders in dynamic cache
 

Detailed Description

Cache for shaders.

This class provides a cache for shaders. You can query a GLSL::Program via getProgram by specifying a ShaderGenDesc. If the program has already been compiled, it is returned from the cache. Otherwise it will be compiled and linked, added to the cache and returned. This ensures, that the shader is not compiled and linked every time, it is used.

Note
This class is a singleton

Definition at line 72 of file ShaderCache.hh.

Member Function Documentation

GLSL::Program * ACG::ShaderCache::getComputeProgram ( const char *  _computeShaderFile,
QStringList *  _macros = 0,
bool  _verbose = true 
)

Query a static compute shader program from cache.

Can be used to load a shader and have external changes automatically applied by the timestamp watchdog. However, the program should be queried every time before using the program as it may have been deleted and recompiled in the meantime.

Parameters
_computeShaderFilerelative (from shader directory) or absolute filename of vertex shader
_macrosoptional list of glsl preprocessor macros, which are added directly after the #version directive (example: "#define USE_METHOD 1", "#define METHOD_PARAM 0"...)
_verboselog or suppress error output
Returns
The program (Either from cache or newly compiled and linked)

Definition at line 444 of file ShaderCache.cc.

ShaderCache * ACG::ShaderCache::getInstance ( )
static

Return instance of the ShaderCache singleton.

Returns
Instance

Definition at line 87 of file ShaderCache.cc.

GLSL::Program * ACG::ShaderCache::getProgram ( const ShaderGenDesc _desc,
const std::vector< unsigned int > &  _mods 
)

Query a dynamically generated program from cache.

Parameters
_descShader description
_modsCombination of active shader modifier ids
Returns
The program (Either from cache or newly compiled and linked)

Definition at line 105 of file ShaderCache.cc.

GLSL::Program* ACG::ShaderCache::getProgram ( const ShaderGenDesc _desc,
const std::vector< unsigned int > *  _mods 
)
inline

Query a dynamically generated program from cache.

Parameters
_descShader description
_modsCombination of active shader modifier ids
Returns
The program (Either from cache or newly compiled and linked)

Definition at line 100 of file ShaderCache.hh.

GLSL::Program * ACG::ShaderCache::getProgram ( const ShaderGenDesc _desc)

Query a dynamically generated program from cache.

Parameters
_descShader description
_modsCombination of active shader modifier ids
Returns
The program (Either from cache or newly compiled and linked)

Definition at line 94 of file ShaderCache.cc.

GLSL::Program * ACG::ShaderCache::getProgram ( const char *  _vertexShaderFile,
const char *  _tessControlShaderFile,
const char *  _tessEvalShaderFile,
const char *  _geometryShaderFile,
const char *  _fragmentShaderFile,
QStringList *  _macros = 0,
bool  _verbose = true 
)

Query a static shader program from cache.

Can be used to load a shader and have external changes automatically applied by the timestamp watchdog. However, the program should be queried every time before using the program as it may have been deleted and recompiled in the meantime.

Parameters
_vertexShaderFilerelative (from shader directory) or absolute filename of vertex shader
_tessControlShaderFilerelative (from shader directory) or absolute filename of tessellation control shader, null accepted
_tessEvalShaderFilerelative (from shader directory) or absolute filename of tessellation eval shader, null accepted
_geometryShaderFilerelative (from shader directory) or absolute filename of geometry shader, null accepted
_fragmentShaderFilerelative (from shader directory) or absolute filename of fragment shader
_macrosoptional list of glsl preprocessor macros, which are added directly after the #version directive (example: "#define USE_METHOD 1", "#define METHOD_PARAM 0"...)
_verboselog or suppress error output
Returns
The program (Either from cache or newly compiled and linked)

Definition at line 285 of file ShaderCache.cc.

GLSL::Program * ACG::ShaderCache::getProgram ( const char *  _vertexShaderFile,
const char *  _fragmentShaderFile,
QStringList *  _macros = 0,
bool  _verbose = true 
)

Query a static shader program from cache.

Can be used to load a shader and have external changes automatically applied by the timestamp watchdog. However, the program should be queried every time before using the program as it may have been deleted and recompiled in the meantime.

Parameters
_vertexShaderFilerelative (from shader directory) or absolute filename of vertex shader
_fragmentShaderFilerelative (from shader directory) or absolute filename of fragment shader
_macrosoptional list of glsl preprocessor macros, which are added directly after the #version directive (example: "#define USE_METHOD 1", "#define METHOD_PARAM 0"...)
_verboselog or suppress error output
Returns
The program (Either from cache or newly compiled and linked)

Definition at line 439 of file ShaderCache.cc.

void ACG::ShaderCache::setTimeCheck ( bool  _on)
inline

enable or disable checking of the time step of each file

Definition at line 170 of file ShaderCache.hh.


The documentation for this class was generated from the following files: