ShaderDataGenerator.h
Go to the documentation of this file.
1 #ifndef B_SHADER_DATA_GENERATOR_H
2 #define B_SHADER_DATA_GENERATOR_H
3 
4 #include "IShaderData.h"
5 #include "MaterialData.h"
6 #include "Texture.h"
7 
9 {
10  GLuint maxLights; // The maximum number of light sources to be used
11  bool ambientLighting; // Set true if the shader should support ambient lighting
12  bool diffuseLighting; // Set true if the shader should support diffuse lighting
13  bool specularLighting; // Set true if the shader should support specular lighting
14  bool ambientColor; // Set true if the material specifies an ambient color (usually Ka)
15  bool diffuseColor; // Set true if the material specifies a diffuse color (usually Kd)
16  bool specularColor; // Set true if the material specifies a specular color (usually Ks)
17  bool diffuseMap; // Set true if a texture should be used for diffuse coloring
18  bool normalMap; // Set true if a texture should be used to define the normal vectors
19  bool specularMap; // Set true if a texture should be used to define specularity
20  bool transparencyValue; // Set true if a transparency value should be passed
21  bool variableNumberOfLights; // Set true if the number of lights may vary, otherwise the number of lights has to be the same as specified as maximum number of lights
22  bool isText; // Set true if the shader should be used for displaying text
23 };
24 
29 {
30 public:
31 
32  /* Typedefs */
33  typedef std::unordered_map<std::string, std::string> TextureMap;
34  typedef std::unordered_map<std::string, std::string> CubeRelflectionMap;
35  typedef std::unordered_map<std::string, vmml::Vector3f> Vector3Map;
36  typedef std::unordered_map<std::string, GLfloat> ScalarMap;
37 
38  /* Functions */
39 
43 
51  ShaderDataGenerator(GLuint maxLights, bool ambientLighting, const MaterialData &materialData, bool variableNumberOfLights, bool isText);
52 
56  ShaderDataGenerator(const ShaderGeneratorSettings &shaderGeneratorSettings);
57 
60  virtual ~ShaderDataGenerator() {}
61 
65  ShaderDataGenerator &create(const ShaderGeneratorSettings &shaderGeneratorSettings);
66 
69  std::string getVertShaderSrc() const { return _vertShaderSrc; }
70 
73  std::string getFragShaderSrc() const { return _fragShaderSrc; }
74 
77  GLuint getMaxLights() const { return _maxLights; }
78 
81  bool supportsVariableNumberOfLights() const { return _variableNumberOfLights; }
82 
85  bool supportsAmbientLighting() const { return _ambientLighting; }
86 
89  bool supportsDiffuseLighting() const { return _diffuseLighting; }
90 
93  bool supportsSpecularLighting() const { return _specularLighting; }
94 
97  bool supportsCubicReflectionMap() const { return _cubicReflectionMap; }
98 
101  bool isValid() const { return _valid; }
102 
103 private:
104 
105  /* Functions */
106 
107  void buildShader();
108  void initializeSourceCommonVariables();
109  void createVertShader();
110  void createFragShader();
111  void readMaterialAttributes(GLuint maxLights, bool variableNumberOfLights, bool ambientLighting, bool isText, const TextureMap &t, const Vector3Map &v, const ScalarMap &s);
112 
113  /* Variables */
114 
115  std::string _vertShaderSrc;
116  std::string _fragShaderSrc;
117  bool _valid;
118 
119  GLuint _maxLights;
120  bool _variableNumberOfLights;
121  bool _ambientLighting;
122  bool _diffuseLighting;
123  bool _specularLighting;
124  bool _ambientColor;
125  bool _diffuseColor;
126  bool _specularColor;
127  bool _diffuseMap;
128  bool _normalMap;
129  bool _specularMap;
130  bool _cubicReflectionMap;
131  bool _transparencyValue;
132  bool _isText;
133 
134 };
135 
136 #endif /* defined(B_SHADER_DATA_GENERATOR_H) */
std::unordered_map< std::string, vmml::Vector3f > Vector3Map
Definition: ShaderDataGenerator.h:35
virtual ~ShaderDataGenerator()
Virtual destructor.
Definition: ShaderDataGenerator.h:60
bool ambientLighting
Definition: ShaderDataGenerator.h:11
bool supportsVariableNumberOfLights() const
Returns true if the number of lights is variable in the shader.
Definition: ShaderDataGenerator.h:81
std::unordered_map< std::string, std::string > CubeRelflectionMap
Definition: ShaderDataGenerator.h:34
bool isValid() const
Returns true if the shader is valid.
Definition: ShaderDataGenerator.h:101
bool normalMap
Definition: ShaderDataGenerator.h:18
bool isText
Definition: ShaderDataGenerator.h:22
bool transparencyValue
Definition: ShaderDataGenerator.h:20
std::unordered_map< std::string, std::string > TextureMap
Definition: ShaderDataGenerator.h:33
bool ambientColor
Definition: ShaderDataGenerator.h:14
std::string getVertShaderSrc() const
Gets the source code of the vertex shader as a string.
Definition: ShaderDataGenerator.h:69
bool diffuseMap
Definition: ShaderDataGenerator.h:17
An interface for the underlying data of a shader.
Definition: IShaderData.h:10
bool supportsAmbientLighting() const
Returns true if the shader supports ambient lighting.
Definition: ShaderDataGenerator.h:85
bool specularMap
Definition: ShaderDataGenerator.h:19
The underlying data of a shader is generated.
Definition: ShaderDataGenerator.h:28
bool diffuseLighting
Definition: ShaderDataGenerator.h:12
bool supportsDiffuseLighting() const
Returns true if the shader supports diffuse lighting.
Definition: ShaderDataGenerator.h:89
bool supportsSpecularLighting() const
Returns true if the shader supports specular lighting.
Definition: ShaderDataGenerator.h:93
ShaderDataGenerator()
Constructor.
Definition: ShaderDataGenerator.cpp:9
std::unordered_map< std::string, GLfloat > ScalarMap
Definition: ShaderDataGenerator.h:36
ShaderDataGenerator & create(const ShaderGeneratorSettings &shaderGeneratorSettings)
Constructor.
Definition: ShaderDataGenerator.cpp:27
bool variableNumberOfLights
Definition: ShaderDataGenerator.h:21
bool specularColor
Definition: ShaderDataGenerator.h:16
The underlying data of a material.
Definition: MaterialData.h:10
GLuint maxLights
Definition: ShaderDataGenerator.h:10
bool diffuseColor
Definition: ShaderDataGenerator.h:15
GLuint getMaxLights() const
Get the maximum number of lights.
Definition: ShaderDataGenerator.h:77
bool supportsCubicReflectionMap() const
Returns true if the shader supports a cubic reflection map.
Definition: ShaderDataGenerator.h:97
bool specularLighting
Definition: ShaderDataGenerator.h:13
std::string getFragShaderSrc() const
Gets the source code of the fragment shader as a string.
Definition: ShaderDataGenerator.h:73
Definition: ShaderDataGenerator.h:8