xoreos  0.0.5
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
Graphics::Shader::ShaderDescriptor Class Reference

#include <shaderbuilder.h>

Collaboration diagram for Graphics::Shader::ShaderDescriptor:
Collaboration graph
[legend]

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
 

Detailed Description

Definition at line 46 of file shaderbuilder.h.

Member Enumeration Documentation

◆ Action

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.

◆ Blend

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.

◆ Input

< Vertex shader input data. Each should have a corresponding output.

Enumerator
INPUT_POSITION0 
INPUT_POSITION1 
INPUT_POSITION2 
INPUT_POSITION3 
INPUT_NORMAL0 
INPUT_NORMAL1 
INPUT_NORMAL2 
INPUT_NORMAL3 
INPUT_UV0 
INPUT_UV1 
INPUT_UV0_MATRIX 

Same as INPUT_UV0, but specifies input matrix too.

INPUT_UV1_MATRIX 

Same as INPUT_UV1, but specifies input matrix too.

INPUT_UV_CUBE 

Not strictly speaking an input, but generated for an output.

INPUT_UV_SPHERE 

Not strictly speaking an input, but generated for an output.

INPUT_COLOUR 

Definition at line 50 of file shaderbuilder.h.

◆ Sampler

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.

◆ SamplerType

Enumerator
SAMPLER_1D 
SAMPLER_2D 
SAMPLER_3D 
SAMPLER_CUBE 

Definition at line 82 of file shaderbuilder.h.

◆ Uniform

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.

Constructor & Destructor Documentation

◆ ShaderDescriptor()

Graphics::Shader::ShaderDescriptor::ShaderDescriptor ( )

Definition at line 36 of file shaderbuilder.cpp.

◆ ~ShaderDescriptor()

Graphics::Shader::ShaderDescriptor::~ShaderDescriptor ( )

Definition at line 39 of file shaderbuilder.cpp.

Member Function Documentation

◆ addPass()

void Graphics::Shader::ShaderDescriptor::addPass ( ShaderDescriptor::Action  action,
ShaderDescriptor::Blend  blend 
)

Definition at line 67 of file shaderbuilder.cpp.

References _passes, and pass.

Referenced by Graphics::Aurora::ModelNode_Witcher::buildMaterial(), Graphics::Aurora::ModelNode::buildMaterial(), and Graphics::Shader::ShaderManager::init().

Here is the caller graph for this function:

◆ build()

void Graphics::Shader::ShaderDescriptor::build ( bool  isGL3,
Common::UString v_string,
Common::UString f_string 
)
Todo:
Declare required inputs here. For vertex shaders this means the camera view and transform matrices, and the appropriate object transform matrix. Fragment shaders have an alpha value and fraggle/froggle for building the final colour output.

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().

Here is the caller graph for this function:

◆ clear()

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().

Here is the caller graph for this function:

◆ connect()

void Graphics::Shader::ShaderDescriptor::connect ( ShaderDescriptor::Sampler  sampler,
ShaderDescriptor::Input  input,
ShaderDescriptor::Action  action 
)

Connect an input to a sampler and an action.

Parameters
samplerSampler to associate with the input and the action. Use SAMPLER_TEXTURE_NONE if this is to be ignored.
inputAssociate a sampler with an input to be used for UVW coordinates.
actionAssociate 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().

Here is the caller graph for this function:

◆ declareInput()

void Graphics::Shader::ShaderDescriptor::declareInput ( ShaderDescriptor::Input  input)

◆ declareSampler()

void Graphics::Shader::ShaderDescriptor::declareSampler ( ShaderDescriptor::Sampler  sampler,
ShaderDescriptor::SamplerType  type 
)

◆ declareUniform()

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().

Here is the caller graph for this function:

◆ genName()

void Graphics::Shader::ShaderDescriptor::genName ( Common::UString n_string)

Member Data Documentation

◆ _connectors

std::vector<Connector> Graphics::Shader::ShaderDescriptor::_connectors
private

Definition at line 188 of file shaderbuilder.h.

Referenced by build(), clear(), connect(), and genName().

◆ _inputDescriptors

std::vector<Input> Graphics::Shader::ShaderDescriptor::_inputDescriptors
private

Definition at line 185 of file shaderbuilder.h.

Referenced by build(), clear(), declareInput(), and genName().

◆ _passes

std::vector<Pass> Graphics::Shader::ShaderDescriptor::_passes
private

Definition at line 189 of file shaderbuilder.h.

Referenced by addPass(), build(), clear(), and genName().

◆ _samplerDescriptors

std::vector<SamplerDescriptor> Graphics::Shader::ShaderDescriptor::_samplerDescriptors
private

Definition at line 186 of file shaderbuilder.h.

Referenced by build(), clear(), declareSampler(), and genName().

◆ _uniformDescriptors

std::vector<UniformDescriptor> Graphics::Shader::ShaderDescriptor::_uniformDescriptors
private

Definition at line 187 of file shaderbuilder.h.

Referenced by build(), clear(), and declareUniform().


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