/
ShaderLayer.h
311 lines (261 loc) · 7.66 KB
/
ShaderLayer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
#pragma once
#include "Texture.h"
#include "ishaderexpression.h"
#include <memory>
#include <vector>
#include <string>
#include "math/Vector2.h"
#include "math/Vector4.h"
#include "render/Colour4.h"
class IRenderEntity;
// Texture repeat types
enum ClampType
{
CLAMP_REPEAT = 1 << 0, // default = no clamping
CLAMP_NOREPEAT = 1 << 1, // "clamp"
CLAMP_ZEROCLAMP = 1 << 2, // "zeroclamp"
CLAMP_ALPHAZEROCLAMP = 1 << 3, // "alphazeroclamp"
};
/**
* \brief
* Representation of a GL blend function.
*
* A GL blend function consists of two GLenums representing the operations that
* should be performed on the source and destination pixel colours respectively,
* before the two results are added together into a final pixel colour.
*/
class BlendFunc
{
public:
// Source pixel function
GLenum src;
// Destination pixel function
GLenum dest;
// Constructor
BlendFunc(GLenum s, GLenum d)
: src(s), dest(d)
{ }
};
/**
* \brief
* A single layer of a material shader.
*
* Each shader layer contains an image texture, a blend mode (e.g. add,
* modulate) and various other data.
*/
class ShaderLayer
{
public:
/**
* \brief
* Enumeration of layer types.
*/
enum Type
{
DIFFUSE,
BUMP,
SPECULAR,
BLEND
};
// Stage flags
enum Flags
{
FLAG_IGNORE_ALPHATEST = 1 << 0,
FLAG_FILTER_NEAREST = 1 << 1,
FLAG_FILTER_LINEAR = 1 << 2,
FLAG_HIGHQUALITY = 1 << 3, // "uncompressed"
FLAG_FORCE_HIGHQUALITY = 1 << 4,
FLAG_NO_PICMIP = 1 << 5,
FLAG_MASK_RED = 1 << 6,
FLAG_MASK_GREEN = 1 << 7,
FLAG_MASK_BLUE = 1 << 8,
FLAG_MASK_ALPHA = 1 << 9,
FLAG_MASK_DEPTH = 1 << 10,
FLAG_CENTERSCALE = 1 << 11, // whether to translate -0.5, scale and translate +0.5
FLAG_IGNORE_DEPTH = 1 << 12, // use depthfunc always
};
enum TexGenType
{
TEXGEN_NORMAL = 1 << 0,
TEXGEN_REFLECT = 1 << 1,
TEXGEN_SKYBOX = 1 << 2,
TEXGEN_WOBBLESKY = 1 << 3,
TEXGEN_SCREEN = 1 << 4, // screen aligned, for mirrorRenders and screen space temporaries
};
/**
* \brief
* Destructor
*/
virtual ~ShaderLayer() {}
/**
* \brief
* Return the layer type.
*/
virtual Type getType() const = 0;
/**
* \brief
* Return the Texture object corresponding to this layer (may be NULL).
*/
virtual TexturePtr getTexture() const = 0;
/**
* Evaluate all shader expressions used in this stage. Call this once (each frame)
* before requesting things like getAlphaTest(), getColour() or isVisible()
*/
virtual void evaluateExpressions(std::size_t time) = 0;
/**
* Like evaluateExpressions(time), but with an additional renderentity as argument
* to give this stage the ability to resolve parm0..parm11 values.
*/
virtual void evaluateExpressions(std::size_t time, const IRenderEntity& entity) = 0;
/**
* The flags set on this stage.
*/
virtual int getStageFlags() const = 0;
/**
* Each stage can have its own clamp type, overriding the per-material one.
*/
virtual ClampType getClampType() const = 0;
/**
* Returns the texgen type: normal, reflect, skybox, etc.
* Use getTexGenParam(i) to retrieve the wobblesky parameters [0..2]
*/
virtual TexGenType getTexGenType() const = 0;
/**
* TexGen type wobblesky has 3 parameters, get them here, with index in [0..2]
*/
virtual float getTexGenParam(std::size_t index) const = 0;
/**
* \brief
* Return the GL blend function for this layer.
*
* Only layers of type BLEND use a BlendFunc. Layers of type DIFFUSE, BUMP
* and SPECULAR do not use blend functions.
*/
virtual BlendFunc getBlendFunc() const = 0;
// Get the blend string as defined in the material def, e.g. "add" or "gl_one, gl_zero"
virtual const std::pair<std::string, std::string>& getBlendFuncStrings() const = 0;
/**
* \brief
* Multiplicative layer colour (set with "red 0.6", "green 0.2" etc)
*/
virtual Colour4 getColour() const = 0;
/**
* \brief
* Vertex colour blend mode enumeration.
*/
enum VertexColourMode
{
VERTEX_COLOUR_NONE, // no vertex colours
VERTEX_COLOUR_MULTIPLY, // "vertexColor"
VERTEX_COLOUR_INVERSE_MULTIPLY // "inverseVertexColor"
};
/**
* \brief
* Get the vertex colour mode for this layer.
*/
virtual VertexColourMode getVertexColourMode() const = 0;
enum class MapType
{
Map, // regular map
CubeMap, // corresponds to CUBE_MAP_OBJECT
CameraCubeMap, // corresponds to CUBE_MAP_CAMERA
VideoMap,
SoundMap,
MirrorRenderMap,
RemoteRenderMap,
};
// Get the map type used by this stage
virtual MapType getMapType() const = 0;
/**
* \brief
* Enumeration of cube map modes for this layer.
*/
enum CubeMapMode
{
CUBE_MAP_NONE,
CUBE_MAP_CAMERA, // cube map in camera space ("cameraCubeMap")
CUBE_MAP_OBJECT // cube map in object space ("cubeMap")
};
/**
* \brief
* Get the cube map mode for this layer.
*/
virtual CubeMapMode getCubeMapMode() const = 0;
/**
* Returns the dimensions specifying the map size for
* stages using the "mirrorRenderMap", "remoteRenderMap" keywords.
*/
virtual const Vector2& getRenderMapSize() = 0;
/**
* Returns the value of the scale expressions of this stage.
*/
virtual Vector2 getScale() = 0;
/**
* Returns the value of the translate expressions of this stage.
*/
virtual Vector2 getTranslation() = 0;
/**
* Returns the value of the rotate expression of this stage.
*/
virtual float getRotation() = 0;
/**
* Returns the value of the 'shear' expressions of this stage.
*/
virtual Vector2 getShear() = 0;
// Returns true if this layer has an alphatest expression defined
virtual bool hasAlphaTest() const = 0;
/**
* \brief
* Get the alpha test value for this layer.
*
* \return
* The alpha test value, within (0..1] if it is set. If no alpha test
* value is set, 0 will be returned.
*/
virtual float getAlphaTest() const = 0;
/**
* Whether this stage is active. Unconditional stages always return true,
* conditional ones return the result of the most recent condition expression evaluation.
*/
virtual bool isVisible() const = 0;
/**
* Returns the name of this stage's fragment program.
*/
virtual const std::string& getVertexProgram() = 0;
/**
* Returns the name of this stage's fragment program.
*/
virtual const std::string& getFragmentProgram() = 0;
/**
* Returns the 4 parameter values for the vertexParm index <parm>.
*/
virtual Vector4 getVertexParm(int parm) = 0;
/**
* Returns the number of fragment maps in this stage.
*/
virtual std::size_t getNumFragmentMaps() = 0;
/**
* Returns the fragment map with the given index.
*/
virtual TexturePtr getFragmentMap(int index) = 0;
/**
* Stage-specific polygon offset, overriding the "global" one defined on the material.
*/
virtual float getPrivatePolygonOffset() = 0;
// If this stage is referring to a single image file, this will return
// the VFS path to it with the file extension removed.
// If this layer doesn't refer to a single image file, an empty string is returned
virtual std::string getMapImageFilename() = 0;
// The map expression used to generate/define the texture of this stage
virtual shaders::IMapExpression::Ptr getMapExpression() = 0;
};
/**
* \brief
* Shader pointer for ShaderLayer,
*/
typedef std::shared_ptr<ShaderLayer> ShaderLayerPtr;
/**
* \brief
* Vector of ShaderLayer pointers.
*/
typedef std::vector<ShaderLayerPtr> ShaderLayerVector;