xoreos
0.0.5
|
The shader manager. More...
#include <shader.h>
Public Member Functions | |
ShaderManager () | |
~ShaderManager () | |
void | init () |
Initialise shader management, including default shader set creation. More... | |
void | deinit () |
Deinitialise shader subsystem. More... | |
ShaderObject * | getShaderObject (const Common::UString &name, ShaderType type) |
ShaderObject * | getShaderObject (const Common::UString &name, const Common::UString &source, ShaderType type) |
void | bindShaderVariable (ShaderObject::ShaderObjectVariable &var, GLint loc, const void *data) |
void | bindShaderInstance (ShaderProgram *program, const void **vertexVariables, const void **fragmentVariables) |
ShaderProgram * | getShaderProgram (ShaderObject *vertexObject, ShaderObject *fragmentObject) |
ShaderProgram * | registerShaderProgram (ShaderObject *vertexObject, ShaderObject *fragmentObject) |
void | genShaderVariableList (ShaderObject *obj, std::vector< ShaderObject::ShaderObjectVariable > &vars) |
ShaderVariableType | shaderstringToEnum (const Common::UString &stype) |
void | genGLShader (ShaderObject *object) |
Generate GL ids for, and compile a shader object. More... | |
void | genGLProgram (ShaderProgram *program) |
Generate GL id for, and link, a shader program. More... | |
Private Member Functions | |
void | registerShaderAttachment (GLuint progid, ShaderObject *obj) |
Recursively attaches shader objects to a given program. More... | |
void | parseShaderVariables (const Common::UString &shaderString, std::vector< ShaderObject::ShaderObjectVariable > &variableList) |
Parses a given string, representing a GLSL shader, and extracts uniform variable information from it. More... | |
Private Attributes | |
uint32 | _counterVID |
uint32 | _counterFID |
std::map< Common::UString, Shader::ShaderObject * > | _shaderObjectMap |
std::vector< Shader::ShaderProgram * > | _shaderProgramArray |
Common::Mutex | _shaderMutex |
Common::Mutex | _programMutex |
Additional Inherited Members | |
Static Public Member Functions inherited from Common::Singleton< ShaderManager > | |
static ShaderManager & | instance () |
static void | destroy () |
Protected Types inherited from Common::Singleton< ShaderManager > | |
typedef ShaderManager | SingletonBaseType |
Protected Member Functions inherited from Common::Singleton< ShaderManager > | |
Singleton () | |
virtual | ~Singleton () |
Graphics::Shader::ShaderManager::ShaderManager | ( | ) |
Definition at line 79 of file shader.cpp.
Graphics::Shader::ShaderManager::~ShaderManager | ( | ) |
Definition at line 82 of file shader.cpp.
References deinit().
void Graphics::Shader::ShaderManager::bindShaderInstance | ( | ShaderProgram * | program, |
const void ** | vertexVariables, | ||
const void ** | fragmentVariables | ||
) |
Definition at line 324 of file shader.cpp.
References bindShaderVariable(), Graphics::Shader::ShaderProgram::fragmentObject, Graphics::Shader::ShaderProgram::fragmentVariableLocations, Graphics::Shader::ShaderProgram::glid, Graphics::Shader::ShaderObject::variablesCombined, Graphics::Shader::ShaderProgram::vertexObject, and Graphics::Shader::ShaderProgram::vertexVariableLocations.
void Graphics::Shader::ShaderManager::bindShaderVariable | ( | ShaderObject::ShaderObjectVariable & | var, |
GLint | loc, | ||
const void * | data | ||
) |
Definition at line 228 of file shader.cpp.
References Graphics::Shader::ShaderObject::ShaderObjectVariable::count, Graphics::Shader::SHADER_FLOAT, Graphics::Shader::SHADER_INT, Graphics::Shader::SHADER_ISAMPLER1D, Graphics::Shader::SHADER_ISAMPLER1DARRAY, Graphics::Shader::SHADER_ISAMPLER2D, Graphics::Shader::SHADER_ISAMPLER2DARRAY, Graphics::Shader::SHADER_ISAMPLER3D, Graphics::Shader::SHADER_ISAMPLERCUBE, Graphics::Shader::SHADER_IVEC2, Graphics::Shader::SHADER_IVEC3, Graphics::Shader::SHADER_IVEC4, Graphics::Shader::SHADER_MAT2, Graphics::Shader::SHADER_MAT3, Graphics::Shader::SHADER_MAT4, Graphics::Shader::SHADER_SAMPLER1D, Graphics::Shader::SHADER_SAMPLER1DARRAY, Graphics::Shader::SHADER_SAMPLER1DARRAYSHADOW, Graphics::Shader::SHADER_SAMPLER1DSHADOW, Graphics::Shader::SHADER_SAMPLER2D, Graphics::Shader::SHADER_SAMPLER2DARRAY, Graphics::Shader::SHADER_SAMPLER2DARRAYSHADOW, Graphics::Shader::SHADER_SAMPLER2DSHADOW, Graphics::Shader::SHADER_SAMPLER3D, Graphics::Shader::SHADER_SAMPLERBUFFER, Graphics::Shader::SHADER_SAMPLERCUBE, Graphics::Shader::SHADER_UNIFORM_BUFFER, Graphics::Shader::SHADER_USAMPLER1D, Graphics::Shader::SHADER_USAMPLER1DARRAY, Graphics::Shader::SHADER_USAMPLER2D, Graphics::Shader::SHADER_USAMPLER2DARRAY, Graphics::Shader::SHADER_USAMPLER3D, Graphics::Shader::SHADER_USAMPLERCUBE, Graphics::Shader::SHADER_VEC2, Graphics::Shader::SHADER_VEC3, Graphics::Shader::SHADER_VEC4, and Graphics::Shader::ShaderObject::ShaderObjectVariable::type.
Referenced by bindShaderInstance().
void Graphics::Shader::ShaderManager::deinit | ( | ) |
Deinitialise shader subsystem.
Definition at line 165 of file shader.cpp.
References _shaderObjectMap, _shaderProgramArray, and status().
Referenced by ~ShaderManager().
void Graphics::Shader::ShaderManager::genGLProgram | ( | ShaderProgram * | program | ) |
Generate GL id for, and link, a shader program.
Definition at line 564 of file shader.cpp.
References error(), Graphics::Shader::ShaderProgram::fragmentObject, Graphics::Shader::ShaderProgram::fragmentVariableLocations, genGLShader(), GfxMan, Graphics::Shader::ShaderProgram::glid, registerShaderAttachment(), Graphics::Shader::SHADER_UNIFORM_BUFFER, Graphics::Shader::UBO_BONE_MATRICES, Graphics::Shader::UBO_SCREEN_INFO, Graphics::Shader::UBO_VIEW_MATRICES, Graphics::Shader::ShaderObject::variablesCombined, Graphics::Shader::VERTEX_COLOR, Graphics::Shader::VERTEX_LOCATION, Graphics::Shader::VERTEX_NORMAL, Graphics::Shader::VERTEX_TEXCOORD0, Graphics::Shader::VERTEX_TEXCOORD1, Graphics::Shader::ShaderProgram::vertexObject, and Graphics::Shader::ShaderProgram::vertexVariableLocations.
void Graphics::Shader::ShaderManager::genGLShader | ( | ShaderObject * | object | ) |
Generate GL ids for, and compile a shader object.
Definition at line 544 of file shader.cpp.
References error(), Graphics::Shader::ShaderObject::glid, Graphics::Shader::SHADER_VERTEX, and Graphics::Shader::ShaderObject::type.
Referenced by genGLProgram().
void Graphics::Shader::ShaderManager::genShaderVariableList | ( | ShaderObject * | obj, |
std::vector< ShaderObject::ShaderObjectVariable > & | vars | ||
) |
Definition at line 408 of file shader.cpp.
References Graphics::Shader::ShaderObject::subObjects, and Graphics::Shader::ShaderObject::variablesSelf.
Referenced by getShaderObject().
ShaderObject * Graphics::Shader::ShaderManager::getShaderObject | ( | const Common::UString & | name, |
ShaderType | type | ||
) |
Definition at line 184 of file shader.cpp.
References _shaderObjectMap.
ShaderObject * Graphics::Shader::ShaderManager::getShaderObject | ( | const Common::UString & | name, |
const Common::UString & | source, | ||
ShaderType | type | ||
) |
Definition at line 197 of file shader.cpp.
References _counterFID, _counterVID, _shaderMutex, _shaderObjectMap, Common::UString::c_str(), genShaderVariableList(), Graphics::Shader::ShaderObject::glid, Graphics::Shader::ShaderObject::id, Common::Mutex::lock(), parseShaderVariables(), Graphics::Shader::SHADER_VERTEX, Graphics::Shader::ShaderObject::shaderString, status(), Graphics::Shader::ShaderObject::type, Common::Mutex::unlock(), Graphics::Shader::ShaderObject::variablesCombined, and Graphics::Shader::ShaderObject::variablesSelf.
ShaderProgram * Graphics::Shader::ShaderManager::getShaderProgram | ( | ShaderObject * | vertexObject, |
ShaderObject * | fragmentObject | ||
) |
Definition at line 335 of file shader.cpp.
References _programMutex, _shaderProgramArray, Graphics::Shader::ShaderObject::id, Common::Mutex::lock(), and Common::Mutex::unlock().
Referenced by registerShaderProgram().
void Graphics::Shader::ShaderManager::init | ( | ) |
Initialise shader management, including default shader set creation.
Definition at line 86 of file shader.cpp.
References Graphics::Shader::ShaderDescriptor::addPass(), Graphics::Shader::ShaderDescriptor::BLEND_MULTIPLY, Graphics::Shader::ShaderDescriptor::BLEND_ONE, Graphics::Shader::ShaderDescriptor::build(), Common::UString::clear(), Graphics::Shader::ShaderDescriptor::clear(), Graphics::Shader::ShaderDescriptor::COLOUR, Graphics::Shader::ShaderDescriptor::connect(), Graphics::Shader::ShaderDescriptor::declareInput(), Graphics::Shader::ShaderDescriptor::declareSampler(), Graphics::Shader::ShaderDescriptor::declareUniform(), GfxMan, Graphics::Shader::ShaderDescriptor::INPUT_COLOUR, Graphics::Shader::ShaderDescriptor::INPUT_POSITION0, Graphics::Shader::ShaderDescriptor::INPUT_UV0, Graphics::Shader::ShaderDescriptor::INPUT_UV0_MATRIX, registerShaderProgram(), Graphics::Shader::ShaderDescriptor::SAMPLER_2D, Graphics::Shader::ShaderDescriptor::SAMPLER_TEXTURE_0, Graphics::Shader::SHADER_FRAGMENT, Graphics::Shader::SHADER_VERTEX, ShaderMan, status(), Graphics::Shader::ShaderDescriptor::TEXTURE_DIFFUSE, Graphics::Shader::ShaderDescriptor::UNIFORM_F_COLOUR, and Graphics::Shader::ShaderDescriptor::X_COLOUR.
|
private |
Parses a given string, representing a GLSL shader, and extracts uniform variable information from it.
Definition at line 438 of file shader.cpp.
References Common::UString::c_str(), Graphics::Shader::SHADER_INVALID, and shaderstringToEnum().
Referenced by getShaderObject().
|
private |
Recursively attaches shader objects to a given program.
Called prior to linking.
Definition at line 366 of file shader.cpp.
References Graphics::Shader::ShaderObject::glid, and Graphics::Shader::ShaderObject::subObjects.
Referenced by genGLProgram().
ShaderProgram * Graphics::Shader::ShaderManager::registerShaderProgram | ( | ShaderObject * | vertexObject, |
ShaderObject * | fragmentObject | ||
) |
Definition at line 373 of file shader.cpp.
References _programMutex, _shaderProgramArray, Graphics::Shader::ShaderProgram::fragmentObject, getShaderProgram(), Graphics::Shader::ShaderProgram::glid, Graphics::Shader::ShaderObject::id, Graphics::Shader::ShaderProgram::id, Common::Mutex::lock(), Graphics::Shader::ShaderProgram::queue(), Common::Mutex::unlock(), Graphics::Shader::ShaderObject::usageCount, and Graphics::Shader::ShaderProgram::vertexObject.
Referenced by init().
ShaderVariableType Graphics::Shader::ShaderManager::shaderstringToEnum | ( | const Common::UString & | stype | ) |
Definition at line 701 of file shader.cpp.
References Graphics::Shader::SHADER_INVALID, and Graphics::Shader::shaderTypeChararray.
Referenced by parseShaderVariables().
|
private |
Definition at line 280 of file shader.h.
Referenced by getShaderObject().
|
private |
Definition at line 279 of file shader.h.
Referenced by getShaderObject().
|
private |
Definition at line 285 of file shader.h.
Referenced by getShaderProgram(), and registerShaderProgram().
|
private |
Definition at line 284 of file shader.h.
Referenced by getShaderObject().
|
private |
Definition at line 281 of file shader.h.
Referenced by deinit(), and getShaderObject().
|
private |
Definition at line 282 of file shader.h.
Referenced by deinit(), getShaderProgram(), and registerShaderProgram().