xoreos
0.0.5
|
#include <shaderbuilder.h>
Classes | |
struct | Connector |
struct | InputDescriptor |
struct | Pass |
struct | SamplerDescriptor |
struct | UniformDescriptor |
Public Types | |
enum | Input { INPUT_POSITION0, INPUT_POSITION1, INPUT_POSITION2, INPUT_POSITION3, INPUT_NORMAL0, INPUT_NORMAL1, INPUT_NORMAL2, INPUT_NORMAL3, INPUT_UV0, INPUT_UV1, INPUT_UV0_MATRIX, INPUT_UV1_MATRIX, INPUT_UV_CUBE, INPUT_UV_SPHERE, INPUT_COLOUR } |
< Vertex shader input data. Each should have a corresponding output. More... | |
enum | Sampler { SAMPLER_TEXTURE_0, SAMPLER_TEXTURE_1, SAMPLER_TEXTURE_2, SAMPLER_TEXTURE_3, SAMPLER_TEXTURE_4, SAMPLER_TEXTURE_5, SAMPLER_TEXTURE_6, SAMPLER_TEXTURE_7, SAMPLER_TEXTURE_NONE } |
enum | SamplerType { SAMPLER_1D, SAMPLER_2D, SAMPLER_3D, SAMPLER_CUBE } |
enum | Uniform { UNIFORM_V_OBJECT_MODELVIEW_MATRIX, UNIFORM_V_PROJECTION_MATRIX, UNIFOM_V_MODELVIEW_MATRIX, UNIFORM_F_ALPHA, UNIFORM_F_COLOUR } |
enum | Action { ENV_CUBE, ENV_SPHERE, COLOUR, X_COLOUR, TEXTURE_DIFFUSE, TEXTURE_LIGHTMAP, TEXTURE_BUMPMAP, FORCE_OPAQUE, NOOP } |
enum | Blend { BLEND_SRC_ALPHA, BLEND_DST_ALPHA, BLEND_ZERO, BLEND_ONE, BLEND_MULTIPLY, BLEND_IGNORED } |
Public Member Functions | |
ShaderDescriptor () | |
~ShaderDescriptor () | |
void | declareInput (ShaderDescriptor::Input input) |
void | declareSampler (ShaderDescriptor::Sampler sampler, ShaderDescriptor::SamplerType type) |
void | declareUniform (ShaderDescriptor::Uniform uniform) |
void | connect (ShaderDescriptor::Sampler sampler, ShaderDescriptor::Input input, ShaderDescriptor::Action action) |
Connect an input to a sampler and an action. More... | |
void | addPass (ShaderDescriptor::Action action, ShaderDescriptor::Blend blend) |
void | build (bool isGL3, Common::UString &v_string, Common::UString &f_string) |
void | clear () |
Clear shader descriptor information. More... | |
void | genName (Common::UString &n_string) |
Generate a name to asscoiate with the current description. More... | |
Private Attributes | |
std::vector< Input > | _inputDescriptors |
std::vector< SamplerDescriptor > | _samplerDescriptors |
std::vector< UniformDescriptor > | _uniformDescriptors |
std::vector< Connector > | _connectors |
std::vector< Pass > | _passes |
Definition at line 46 of file shaderbuilder.h.
Enumerator | |
---|---|
ENV_CUBE | |
ENV_SPHERE | |
COLOUR | Uniform variable colour information. |
X_COLOUR | Per-vertex colour information. |
TEXTURE_DIFFUSE | |
TEXTURE_LIGHTMAP | |
TEXTURE_BUMPMAP | |
FORCE_OPAQUE | |
NOOP |
Definition at line 99 of file shaderbuilder.h.
Enumerator | |
---|---|
BLEND_SRC_ALPHA | |
BLEND_DST_ALPHA | |
BLEND_ZERO | |
BLEND_ONE | |
BLEND_MULTIPLY | Not really blending, but component-wise multiply. |
BLEND_IGNORED | Blending not applicable to the component. |
Definition at line 112 of file shaderbuilder.h.
< Vertex shader input data. Each should have a corresponding output.
Definition at line 50 of file shaderbuilder.h.
Enumerator | |
---|---|
SAMPLER_TEXTURE_0 | |
SAMPLER_TEXTURE_1 | |
SAMPLER_TEXTURE_2 | |
SAMPLER_TEXTURE_3 | |
SAMPLER_TEXTURE_4 | |
SAMPLER_TEXTURE_5 | |
SAMPLER_TEXTURE_6 | |
SAMPLER_TEXTURE_7 | |
SAMPLER_TEXTURE_NONE |
Definition at line 69 of file shaderbuilder.h.
Enumerator | |
---|---|
SAMPLER_1D | |
SAMPLER_2D | |
SAMPLER_3D | |
SAMPLER_CUBE |
Definition at line 82 of file shaderbuilder.h.
Enumerator | |
---|---|
UNIFORM_V_OBJECT_MODELVIEW_MATRIX | |
UNIFORM_V_PROJECTION_MATRIX | |
UNIFOM_V_MODELVIEW_MATRIX | |
UNIFORM_F_ALPHA | |
UNIFORM_F_COLOUR |
Definition at line 90 of file shaderbuilder.h.
Graphics::Shader::ShaderDescriptor::ShaderDescriptor | ( | ) |
Definition at line 36 of file shaderbuilder.cpp.
Graphics::Shader::ShaderDescriptor::~ShaderDescriptor | ( | ) |
Definition at line 39 of file shaderbuilder.cpp.
void Graphics::Shader::ShaderDescriptor::addPass | ( | ShaderDescriptor::Action | action, |
ShaderDescriptor::Blend | blend | ||
) |
Definition at line 67 of file shaderbuilder.cpp.
Referenced by Graphics::Aurora::ModelNode_Witcher::buildMaterial(), Graphics::Aurora::ModelNode::buildMaterial(), and Graphics::Shader::ShaderManager::init().
void Graphics::Shader::ShaderDescriptor::build | ( | bool | isGL3, |
Common::UString & | v_string, | ||
Common::UString & | f_string | ||
) |
Extra uniform declarations. These will go into either vertex or fragment headers as appropriate.
Vertex shader input declarations.
First of all, the speceified inputs need declaring. If they're not actually used, then it doesn't matter - shader compiler will include the reference for binding purposes, but won't do anything with the data. Re-declarations will cause everything to fail, but that's the caller's problem.
Vertex shaders have an easier time of it, as nothing complicated is really done. So a good deal of the vertex shader body can be added while going over the input descriptors now, rather than having to loop over them again later on.
Below may need tweaking later. It would be better to be able to map an input to an action, such as texture transform, with the output from that action fed into an appropriate shader output. Of course, what's being written here is essentially a "null action" (map input directly to output), with some hard coded exceptions. Everything later can be an action: input to view modification transform input to texture transform etc...
Fragment shader sampler declarations.
Now declare samplers. Actually this needs to be done as part of the connection phase because the sampler type is attached there, and generic sampler declaration isn't supported. Instead, prepare a string for the declaration now, and prepend the appropriate type later.
Fragment shader sampler uv coordinate mapping.
Inputs and sampler declared. Now they need to be connected. Essentially this next step just maps an input name to something the sampler can assume exists, by using some simple macro definitions. So sample_0_id will always use sample_0_coords for sampling, but that name can map to any input. The same input can be used for multiple samplers, but the same sampler cannot use multiple inputs (which makes sense if you think about it hard enough).
Samplers (which have known macro names)
All declarations should now be in place.
Wrap up the shaders.
So now there are strings for vertex and fragment shaders, header and body. Shaders, transform and rollout.
Definition at line 74 of file shaderbuilder.cpp.
References _connectors, _inputDescriptors, _passes, _samplerDescriptors, _uniformDescriptors, BLEND_DST_ALPHA, BLEND_IGNORED, BLEND_MULTIPLY, BLEND_ONE, BLEND_SRC_ALPHA, BLEND_ZERO, COLOUR, ENV_CUBE, ENV_SPHERE, FORCE_OPAQUE, INPUT_COLOUR, INPUT_NORMAL0, INPUT_NORMAL1, INPUT_NORMAL2, INPUT_NORMAL3, INPUT_POSITION0, INPUT_POSITION1, INPUT_POSITION2, INPUT_POSITION3, INPUT_UV0, INPUT_UV0_MATRIX, INPUT_UV1, INPUT_UV1_MATRIX, INPUT_UV_CUBE, INPUT_UV_SPHERE, NOOP, SAMPLER_1D, SAMPLER_2D, SAMPLER_3D, SAMPLER_CUBE, SAMPLER_TEXTURE_0, SAMPLER_TEXTURE_1, SAMPLER_TEXTURE_2, SAMPLER_TEXTURE_3, SAMPLER_TEXTURE_4, SAMPLER_TEXTURE_5, SAMPLER_TEXTURE_6, SAMPLER_TEXTURE_7, SAMPLER_TEXTURE_NONE, TEXTURE_BUMPMAP, TEXTURE_DIFFUSE, TEXTURE_LIGHTMAP, UNIFOM_V_MODELVIEW_MATRIX, UNIFORM_F_ALPHA, UNIFORM_F_COLOUR, UNIFORM_V_OBJECT_MODELVIEW_MATRIX, UNIFORM_V_PROJECTION_MATRIX, and X_COLOUR.
Referenced by Graphics::Aurora::ModelNode_Witcher::buildMaterial(), Graphics::Aurora::ModelNode::buildMaterial(), and Graphics::Shader::ShaderManager::init().
void Graphics::Shader::ShaderDescriptor::clear | ( | ) |
Clear shader descriptor information.
Reset everything to default state.
Definition at line 596 of file shaderbuilder.cpp.
References _connectors, _inputDescriptors, _passes, _samplerDescriptors, and _uniformDescriptors.
Referenced by Graphics::Shader::ShaderManager::init().
void Graphics::Shader::ShaderDescriptor::connect | ( | ShaderDescriptor::Sampler | sampler, |
ShaderDescriptor::Input | input, | ||
ShaderDescriptor::Action | action | ||
) |
Connect an input to a sampler and an action.
sampler | Sampler to associate with the input and the action. Use SAMPLER_TEXTURE_NONE if this is to be ignored. |
input | Associate a sampler with an input to be used for UVW coordinates. |
action | Associate the connection to an action to be performed with them. |
Definition at line 59 of file shaderbuilder.cpp.
References _connectors, Graphics::Shader::ShaderDescriptor::Connector::action, Graphics::Shader::ShaderDescriptor::Connector::input, and Graphics::Shader::ShaderDescriptor::Connector::sampler.
Referenced by Graphics::Aurora::ModelNode_Witcher::buildMaterial(), Graphics::Aurora::ModelNode::buildMaterial(), and Graphics::Shader::ShaderManager::init().
void Graphics::Shader::ShaderDescriptor::declareInput | ( | ShaderDescriptor::Input | input | ) |
Definition at line 42 of file shaderbuilder.cpp.
References _inputDescriptors.
Referenced by Graphics::Aurora::ModelNode_Witcher::buildMaterial(), Graphics::Aurora::ModelNode::buildMaterial(), and Graphics::Shader::ShaderManager::init().
void Graphics::Shader::ShaderDescriptor::declareSampler | ( | ShaderDescriptor::Sampler | sampler, |
ShaderDescriptor::SamplerType | type | ||
) |
Definition at line 46 of file shaderbuilder.cpp.
References _samplerDescriptors, Graphics::Shader::ShaderDescriptor::SamplerDescriptor::sampler, and Graphics::Shader::ShaderDescriptor::SamplerDescriptor::type.
Referenced by Graphics::Aurora::ModelNode_Witcher::buildMaterial(), Graphics::Aurora::ModelNode::buildMaterial(), and Graphics::Shader::ShaderManager::init().
void Graphics::Shader::ShaderDescriptor::declareUniform | ( | ShaderDescriptor::Uniform | uniform | ) |
Definition at line 53 of file shaderbuilder.cpp.
References _uniformDescriptors, and Graphics::Shader::ShaderDescriptor::UniformDescriptor::uniform.
Referenced by Graphics::Shader::ShaderManager::init().
void Graphics::Shader::ShaderDescriptor::genName | ( | Common::UString & | n_string | ) |
Generate a name to asscoiate with the current description.
Does not require building first.
n_string | String name of description. |
Definition at line 604 of file shaderbuilder.cpp.
References _connectors, _inputDescriptors, _passes, _samplerDescriptors, BLEND_DST_ALPHA, BLEND_IGNORED, BLEND_MULTIPLY, BLEND_ONE, BLEND_SRC_ALPHA, BLEND_ZERO, COLOUR, ENV_CUBE, ENV_SPHERE, FORCE_OPAQUE, INPUT_COLOUR, INPUT_NORMAL0, INPUT_NORMAL1, INPUT_NORMAL2, INPUT_NORMAL3, INPUT_POSITION0, INPUT_POSITION1, INPUT_POSITION2, INPUT_POSITION3, INPUT_UV0, INPUT_UV0_MATRIX, INPUT_UV1, INPUT_UV1_MATRIX, INPUT_UV_CUBE, INPUT_UV_SPHERE, NOOP, SAMPLER_1D, SAMPLER_2D, SAMPLER_3D, SAMPLER_CUBE, SAMPLER_TEXTURE_0, SAMPLER_TEXTURE_1, SAMPLER_TEXTURE_2, SAMPLER_TEXTURE_3, SAMPLER_TEXTURE_4, SAMPLER_TEXTURE_5, SAMPLER_TEXTURE_6, SAMPLER_TEXTURE_7, SAMPLER_TEXTURE_NONE, TEXTURE_BUMPMAP, TEXTURE_DIFFUSE, TEXTURE_LIGHTMAP, and X_COLOUR.
Referenced by Graphics::Aurora::ModelNode_Witcher::buildMaterial(), and Graphics::Aurora::ModelNode::buildMaterial().
|
private |
|
private |
Definition at line 185 of file shaderbuilder.h.
Referenced by build(), clear(), declareInput(), and genName().
|
private |
|
private |
Definition at line 186 of file shaderbuilder.h.
Referenced by build(), clear(), declareSampler(), and genName().
|
private |
Definition at line 187 of file shaderbuilder.h.
Referenced by build(), clear(), and declareUniform().