xoreos  0.0.5
Classes | Namespaces | Macros | Enumerations
shader.h File Reference

The global shader manager. More...

#include <vector>
#include <map>
#include "src/common/ustring.h"
#include "src/common/singleton.h"
#include "src/common/mutex.h"
#include "src/graphics/texture.h"
#include "src/graphics/aurora/texturehandle.h"
#include "src/graphics/shader/shaderbuilder.h"
Include dependency graph for shader.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Graphics::Shader::ShaderUBO
 
struct  Graphics::Shader::ShaderSampler
 Shader sampler is used to bind a texture to a texture unit. More...
 
class  Graphics::Shader::ShaderObject
 
struct  Graphics::Shader::ShaderObject::ShaderObjectVariable
 
class  Graphics::Shader::ShaderProgram
 
class  Graphics::Shader::ShaderManager
 The shader manager. More...
 

Namespaces

 Graphics
 
 Graphics::Shader
 

Macros

#define ShaderMan   Graphics::Shader::ShaderManager::instance()
 Shortcut for accessing the shader manager. More...
 

Enumerations

enum  Graphics::Shader::ShaderVariableType {
  Graphics::Shader::SHADER_FLOAT = 0, Graphics::Shader::SHADER_VEC2, Graphics::Shader::SHADER_VEC3, Graphics::Shader::SHADER_VEC4,
  Graphics::Shader::SHADER_INT, Graphics::Shader::SHADER_IVEC2, Graphics::Shader::SHADER_IVEC3, Graphics::Shader::SHADER_IVEC4,
  Graphics::Shader::SHADER_UINT, Graphics::Shader::SHADER_UVEC2, Graphics::Shader::SHADER_UVEC3, Graphics::Shader::SHADER_UVEC4,
  Graphics::Shader::SHADER_BOOL, Graphics::Shader::SHADER_BVEC2, Graphics::Shader::SHADER_BVEC3, Graphics::Shader::SHADER_BVEC4,
  Graphics::Shader::SHADER_MAT2, Graphics::Shader::SHADER_MAT2X2, Graphics::Shader::SHADER_MAT2X3, Graphics::Shader::SHADER_MAT2X4,
  Graphics::Shader::SHADER_MAT3, Graphics::Shader::SHADER_MAT3X2, Graphics::Shader::SHADER_MAT3X3, Graphics::Shader::SHADER_MAT3X4,
  Graphics::Shader::SHADER_MAT4, Graphics::Shader::SHADER_MAT4X2, Graphics::Shader::SHADER_MAT4X3, Graphics::Shader::SHADER_MAT4X4,
  Graphics::Shader::SHADER_SAMPLER1D, Graphics::Shader::SHADER_SAMPLER2D, Graphics::Shader::SHADER_SAMPLER3D, Graphics::Shader::SHADER_SAMPLERCUBE,
  Graphics::Shader::SHADER_SAMPLER1DSHADOW, Graphics::Shader::SHADER_SAMPLER2DSHADOW, Graphics::Shader::SHADER_SAMPLER1DARRAY, Graphics::Shader::SHADER_SAMPLER2DARRAY,
  Graphics::Shader::SHADER_SAMPLER1DARRAYSHADOW, Graphics::Shader::SHADER_SAMPLER2DARRAYSHADOW, Graphics::Shader::SHADER_SAMPLERBUFFER, Graphics::Shader::SHADER_ISAMPLER1D,
  Graphics::Shader::SHADER_ISAMPLER2D, Graphics::Shader::SHADER_ISAMPLER3D, Graphics::Shader::SHADER_ISAMPLERCUBE, Graphics::Shader::SHADER_ISAMPLER1DARRAY,
  Graphics::Shader::SHADER_ISAMPLER2DARRAY, Graphics::Shader::SHADER_USAMPLER1D, Graphics::Shader::SHADER_USAMPLER2D, Graphics::Shader::SHADER_USAMPLER3D,
  Graphics::Shader::SHADER_USAMPLERCUBE, Graphics::Shader::SHADER_USAMPLER1DARRAY, Graphics::Shader::SHADER_USAMPLER2DARRAY, Graphics::Shader::SHADER_UNIFORM_BUFFER,
  Graphics::Shader::SHADER_INVALID
}
 Enum of all supported shader variable parsing and automatic binding. More...
 
enum  Graphics::Shader::ShaderType { Graphics::Shader::SHADER_VERTEX = 0, Graphics::Shader::SHADER_FRAGMENT }
 
enum  Graphics::Shader::ShaderVertexAttrib {
  Graphics::Shader::VERTEX_LOCATION = 0, Graphics::Shader::VERTEX_NORMAL = 1, Graphics::Shader::VERTEX_COLOR = 2, Graphics::Shader::VERTEX_TEXCOORD0 = 3,
  Graphics::Shader::VERTEX_TEXCOORD1 = 4
}
 
enum  Graphics::Shader::ShaderUBOIndex { Graphics::Shader::UBO_VIEW_MATRICES = 0, Graphics::Shader::UBO_BONE_MATRICES = 1, Graphics::Shader::UBO_SCREEN_INFO = 2 }
 

Detailed Description

The global shader manager.

Developer's Notes: This form of shader handling is absolute overkill for xoreos. It's based upon code developed for a different project, then plugged into xoreos to save some wheel reinvention. It is, however, rather flexible and should be able to cleanly handle any quirks from any of the particular engines.

The basic idea:

Uniform Buffer Objects UBO's are parsed out and treated as a single variable, similar to a texture sampler. The user themselves must specify both the UBO id to attach, and the attachment location. Index binding within the shader is possible, but discouraged here. It's an OpenGL >=4.2 feature, and while it would cut down on a little bit of overhead, the target version for xoreos is OpenGL 3.2 (maybe 3.3).

To anyone thinking that program introspection would replace much of this, well yes and no. Again, the original idea behind this code involved knowing what uniforms would be available prior to the program linker stage. Uniforms stripped out during the linker phase are pretty much ignored when binding a shader here, so that's not a worry. The methods here also allow a common shader object instance (e.g fragment shader) to be bound across multiple programs (this is where unused uniforms being ignored comes in).

Definition in file shader.h.

Macro Definition Documentation

◆ ShaderMan