Developer Documentation

Classes | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
ACG::ShaderCache Class Reference

Cache for shaders. More...

`#include <OpenFlipper/libs_required/ACG/GL/ShaderCache.hh>`

## Classes
struct | CacheEntry

## Public Member Functions
virtual | ~ShaderCache ()
| Destructor.
GLSL::Program * | getProgram (const ShaderGenDesc *_desc, const std::vector< unsigned int > &_mods)
| Query a dynamically generated program from cache. More...
GLSL::Program * | getProgram (const ShaderGenDesc *_desc, const std::vector< unsigned int > *_mods)
| Query a dynamically generated program from cache. More...
GLSL::Program * | getProgram (const ShaderGenDesc *_desc)
| Query a dynamically generated program from cache. More...
GLSL::Program * | 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. More...
GLSL::Program * | getProgram (const char *_vertexShaderFile, const char *_fragmentShaderFile, QStringList *_macros=0, bool _verbose=true)
| Query a static shader program from cache. More...
GLSL::Program * | getComputeProgram (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 ShaderCache * | getInstance ()
| 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 73 of file ShaderCache.hh.

## Member Function Documentation

## ◆ getComputeProgram()

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

  _computeShaderFile | relative (from shader directory) or absolute filename of vertex shader
  _macros | optional list of glsl preprocessor macros, which are added directly after the #version directive (example: "#define USE_METHOD 1", "#define METHOD_PARAM 0"...)
  _verbose | log or suppress error output

Returns
  The program (Either from cache or newly compiled and linked)

Definition at line 441 of file ShaderCache.cc.

## ◆ getInstance()

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

Return instance of the ShaderCache singleton.

Returns
  Instance

Definition at line 84 of file ShaderCache.cc.

## ◆ getProgram() [1/5]

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

Query a dynamically generated program from cache.

Parameters

  _desc | Shader description
  _mods | Combination of active shader modifier ids

Returns
  The program (Either from cache or newly compiled and linked)

Definition at line 102 of file ShaderCache.cc.

## ◆ getProgram() [2/5]

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

Query a dynamically generated program from cache.

Parameters

  _desc | Shader description
  _mods | Combination of active shader modifier ids

Returns
  The program (Either from cache or newly compiled and linked)

Definition at line 101 of file ShaderCache.hh.

## ◆ getProgram() [3/5]

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

Query a dynamically generated program from cache.

Parameters

  _desc | Shader description
  _mods | Combination of active shader modifier ids

Returns
  The program (Either from cache or newly compiled and linked)

Definition at line 91 of file ShaderCache.cc.

## ◆ getProgram() [4/5]

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

  _vertexShaderFile | relative (from shader directory) or absolute filename of vertex shader
  _tessControlShaderFile | relative (from shader directory) or absolute filename of tessellation control shader, null accepted
  _tessEvalShaderFile | relative (from shader directory) or absolute filename of tessellation eval shader, null accepted
  _geometryShaderFile | relative (from shader directory) or absolute filename of geometry shader, null accepted
  _fragmentShaderFile | relative (from shader directory) or absolute filename of fragment shader
  _macros | optional list of glsl preprocessor macros, which are added directly after the #version directive (example: "#define USE_METHOD 1", "#define METHOD_PARAM 0"...)
  _verbose | log or suppress error output

Returns
  The program (Either from cache or newly compiled and linked)

Definition at line 282 of file ShaderCache.cc.

## ◆ getProgram() [5/5]

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

  _vertexShaderFile | relative (from shader directory) or absolute filename of vertex shader
  _fragmentShaderFile | relative (from shader directory) or absolute filename of fragment shader
  _macros | optional list of glsl preprocessor macros, which are added directly after the #version directive (example: "#define USE_METHOD 1", "#define METHOD_PARAM 0"...)
  _verbose | log or suppress error output

Returns
  The program (Either from cache or newly compiled and linked)

Definition at line 436 of file ShaderCache.cc.

## ◆ setTimeCheck()

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

enable or disable checking of the time step of each file

Definition at line 171 of file ShaderCache.hh.

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

- OpenFlipper/libs_required/ACG/GL/ShaderCache.hh
- OpenFlipper/libs_required/ACG/GL/ShaderCache.cc