aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llglslshader.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llglslshader.h299
1 files changed, 238 insertions, 61 deletions
diff --git a/linden/indra/newview/llglslshader.h b/linden/indra/newview/llglslshader.h
index 0bd90c3..41b0c59 100644
--- a/linden/indra/newview/llglslshader.h
+++ b/linden/indra/newview/llglslshader.h
@@ -34,20 +34,76 @@
34 34
35#include "llgl.h" 35#include "llgl.h"
36 36
37class LLShaderFeatures
38{
39public:
40 bool calculatesLighting;
41 bool calculatesAtmospherics;
42 bool hasLighting; // implies no transport (it's possible to have neither though)
43 bool isShiny;
44 bool isFullbright; // implies no lighting
45 bool isSpecular;
46 bool hasWaterFog; // implies no gamma
47 bool hasTransport; // implies no lighting (it's possible to have neither though)
48 bool hasSkinning;
49 bool hasAtmospherics;
50 bool hasGamma;
51
52 // char numLights;
53
54 LLShaderFeatures();
55};
56
37class LLGLSLShader 57class LLGLSLShader
38{ 58{
39public: 59public:
60
61 enum
62 {
63 SG_DEFAULT = 0,
64 SG_SKY,
65 SG_WATER
66 };
67
40 LLGLSLShader(); 68 LLGLSLShader();
41 69
42 void unload(); 70 void unload();
71 BOOL createShader(std::vector<std::string> * attributes,
72 std::vector<std::string> * uniforms);
73 BOOL attachObject(std::string object);
43 void attachObject(GLhandleARB object); 74 void attachObject(GLhandleARB object);
44 void attachObjects(GLhandleARB* objects = NULL, S32 count = 0); 75 void attachObjects(GLhandleARB* objects = NULL, S32 count = 0);
45 BOOL mapAttributes(const char** attrib_names = NULL, S32 count = 0); 76 BOOL mapAttributes(const std::vector<std::string> * attributes);
46 BOOL mapUniforms(const char** uniform_names = NULL, S32 count = 0); 77 BOOL mapUniforms(const std::vector<std::string> * uniforms);
47 void mapUniform(GLint index, const char** uniform_names = NULL, S32 count = 0); 78 void mapUniform(GLint index, const std::vector<std::string> * uniforms);
79 void uniform1f(U32 index, GLfloat v);
80 void uniform2f(U32 index, GLfloat x, GLfloat y);
81 void uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z);
82 void uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
83 void uniform1fv(U32 index, U32 count, const GLfloat* v);
84 void uniform2fv(U32 index, U32 count, const GLfloat* v);
85 void uniform3fv(U32 index, U32 count, const GLfloat* v);
86 void uniform4fv(U32 index, U32 count, const GLfloat* v);
87 void uniform1f(const std::string& uniform, GLfloat v);
88 void uniform2f(const std::string& uniform, GLfloat x, GLfloat y);
89 void uniform3f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z);
90 void uniform4f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
91 void uniform1fv(const std::string& uniform, U32 count, const GLfloat* v);
92 void uniform2fv(const std::string& uniform, U32 count, const GLfloat* v);
93 void uniform3fv(const std::string& uniform, U32 count, const GLfloat* v);
94 void uniform4fv(const std::string& uniform, U32 count, const GLfloat* v);
95 void uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
96 void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
97 void uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v);
98 void uniformMatrix2fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
99 void uniformMatrix3fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
100 void uniformMatrix4fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v);
101
48 void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); 102 void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
49 void vertexAttrib4fv(U32 index, GLfloat* v); 103 void vertexAttrib4fv(U32 index, GLfloat* v);
50 104
105 GLint getUniformLocation(const std::string& uniform);
106
51 GLint mapUniformTextureChannel(GLint location, GLenum type); 107 GLint mapUniformTextureChannel(GLint location, GLenum type);
52 108
53 109
@@ -63,39 +119,95 @@ public:
63 void unbind(); 119 void unbind();
64 120
65 GLhandleARB mProgramObject; 121 GLhandleARB mProgramObject;
66 std::vector<GLint> mAttribute; 122 std::vector<GLint> mAttribute; //lookup table of attribute enum to attribute channel
67 std::vector<GLint> mUniform; 123 std::vector<GLint> mUniform; //lookup table of uniform enum to uniform location
124 std::map<std::string, GLint> mUniformMap; //lookup map of uniform name to uniform location
125 std::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value
68 std::vector<GLint> mTexture; 126 std::vector<GLint> mTexture;
69 S32 mActiveTextureChannels; 127 S32 mActiveTextureChannels;
70}; 128 S32 mShaderLevel;
71 129 S32 mShaderGroup;
72class LLScatterShader 130 BOOL mUniformsDirty;
73{ 131 LLShaderFeatures mFeatures;
74public: 132 std::vector< std::pair< std::string, GLenum > > mShaderFiles;
75 static void init(GLhandleARB shader, int map_stage); 133 std::string mName;
76}; 134};
77 135
78class LLShaderMgr 136class LLShaderMgr
79{ 137{
138 friend class LLGLSLShader;
139
80public: 140public:
141 static void initAttribsAndUniforms(void);
142 static BOOL attachShaderFeatures(LLGLSLShader * shader);
81 static void setShaders(); 143 static void setShaders();
82 static void unloadShaders(); 144 static void unloadShaders();
83 static void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE); 145 static void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE);
84 static BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE); 146 static BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE);
85 static BOOL validateProgramObject(GLhandleARB obj); 147 static BOOL validateProgramObject(GLhandleARB obj);
86 static GLhandleARB loadShader(const LLString& filename, S32 cls, GLenum type); 148 static GLhandleARB loadShaderFile(const LLString& filename, S32 & shader_level, GLenum type);
87 static S32 getVertexShaderLevel(S32 type); 149 static S32 getVertexShaderLevel(S32 type);
88 static S32 getMaxVertexShaderLevel(S32 type); 150 static BOOL loadBasicShaders();
89 static BOOL loadShadersLighting(); 151 static BOOL loadShadersEffects();
90 static BOOL loadShadersObject(); 152 static BOOL loadShadersObject();
91 static BOOL loadShadersAvatar(); 153 static BOOL loadShadersAvatar();
92 static BOOL loadShadersEnvironment(); 154 static BOOL loadShadersEnvironment();
155 static BOOL loadShadersWater();
93 static BOOL loadShadersInterface(); 156 static BOOL loadShadersInterface();
157 static BOOL loadShadersWindLight();
158
159 // simple model of forward iterator
160 // http://www.sgi.com/tech/stl/ForwardIterator.html
161 class shader_iter
162 {
163 friend bool operator == (shader_iter const & a, shader_iter const & b);
164 friend bool operator != (shader_iter const & a, shader_iter const & b);
165 public:
166 shader_iter() : mPtr(NULL)
167 {
168 }
169
170 shader_iter(LLGLSLShader * const * ptr) : mPtr(ptr)
171 {
172 }
173
174 LLGLSLShader & operator * () const
175 {
176 return **mPtr;
177 }
178
179 LLGLSLShader * operator -> () const
180 {
181 return *mPtr;
182 }
183
184 shader_iter & operator++ ()
185 {
186 ++mPtr;
187 return *this;
188 }
189
190 shader_iter operator++ (int)
191 {
192 return mPtr++;
193 }
194
195 private:
196 LLGLSLShader * const * mPtr;
197 };
198
199 static shader_iter beginShaders()
200 {
201 return sShaderList;
202 }
203
204 static shader_iter endShaders()
205 {
206 return sShaderList + sNumShaders;
207 }
208
94 static S32 sVertexShaderLevel[]; 209 static S32 sVertexShaderLevel[];
95 static S32 sMaxVertexShaderLevel[]; 210 static S32 sMaxAvatarShaderLevel;
96 //global (reserved slot) shader parameters
97 static const char* sReservedAttribs[];
98 static U32 sReservedAttribCount;
99 211
100 enum EShaderClass 212 enum EShaderClass
101 { 213 {
@@ -104,6 +216,9 @@ public:
104 SHADER_AVATAR, 216 SHADER_AVATAR,
105 SHADER_ENVIRONMENT, 217 SHADER_ENVIRONMENT,
106 SHADER_INTERFACE, 218 SHADER_INTERFACE,
219 SHADER_EFFECT,
220 SHADER_WINDLIGHT,
221 SHADER_WATER,
107 SHADER_COUNT 222 SHADER_COUNT
108 }; 223 };
109 224
@@ -114,9 +229,6 @@ public:
114 BINORMAL, 229 BINORMAL,
115 END_RESERVED_ATTRIBS 230 END_RESERVED_ATTRIBS
116 } eGLSLReservedAttribs; 231 } eGLSLReservedAttribs;
117
118 static const char* sReservedUniforms[];
119 static U32 sReservedUniformCount;
120 232
121 typedef enum 233 typedef enum
122 { 234 {
@@ -124,24 +236,39 @@ public:
124 SPECULAR_MAP, 236 SPECULAR_MAP,
125 BUMP_MAP, 237 BUMP_MAP,
126 ENVIRONMENT_MAP, 238 ENVIRONMENT_MAP,
239 CLOUD_NOISE_MAP,
240 FULLBRIGHT,
241 LIGHTNORM,
242 SUNLIGHT_COLOR,
243 AMBIENT,
244 BLUE_HORIZON,
245 BLUE_DENSITY,
246 HAZE_HORIZON,
247 HAZE_DENSITY,
248 CLOUD_SHADOW,
249 DENSITY_MULTIPLIER,
250 DISTANCE_MULTIPLIER,
251 MAX_Y,
252 GLOW,
253 CLOUD_COLOR,
254 CLOUD_POS_DENSITY1,
255 CLOUD_POS_DENSITY2,
256 CLOUD_SCALE,
257 GAMMA,
258 SCENE_LIGHT_STRENGTH,
127 END_RESERVED_UNIFORMS 259 END_RESERVED_UNIFORMS
128 } eGLSLReservedUniforms; 260 } eGLSLReservedUniforms;
129 261
130 static const char* sShinyUniforms[];
131 static U32 sShinyUniformCount;
132
133 typedef enum 262 typedef enum
134 { 263 {
135 SHINY_ORIGIN = END_RESERVED_UNIFORMS 264 SHINY_ORIGIN = END_RESERVED_UNIFORMS
136 } eShinyUniforms; 265 } eShinyUniforms;
137 266
138 //water parameters
139 static const char* sWaterUniforms[];
140 static U32 sWaterUniformCount;
141
142 typedef enum 267 typedef enum
143 { 268 {
144 WATER_SCREENTEX = END_RESERVED_UNIFORMS, 269 WATER_SCREENTEX = END_RESERVED_UNIFORMS,
270 WATER_SCREENDEPTH,
271 WATER_REFTEX,
145 WATER_EYEVEC, 272 WATER_EYEVEC,
146 WATER_TIME, 273 WATER_TIME,
147 WATER_WAVE_DIR1, 274 WATER_WAVE_DIR1,
@@ -149,34 +276,32 @@ public:
149 WATER_LIGHT_DIR, 276 WATER_LIGHT_DIR,
150 WATER_SPECULAR, 277 WATER_SPECULAR,
151 WATER_SPECULAR_EXP, 278 WATER_SPECULAR_EXP,
152 WATER_FBSCALE, 279 WATER_FOGCOLOR,
153 WATER_REFSCALE 280 WATER_FOGDENSITY,
281 WATER_REFSCALE,
282 WATER_WATERHEIGHT,
154 } eWaterUniforms; 283 } eWaterUniforms;
155 284
156 //terrain parameters 285 typedef enum
157 static const char* sTerrainUniforms[]; 286 {
158 static U32 sTerrainUniformCount; 287 WL_CAMPOSLOCAL = END_RESERVED_UNIFORMS,
288 WL_WATERHEIGHT
289 } eWLUniforms;
159 290
160 typedef enum 291 typedef enum
161 { 292 {
162 TERRAIN_DETAIL0 = END_RESERVED_UNIFORMS, 293 TERRAIN_DETAIL0 = END_RESERVED_UNIFORMS,
163 TERRAIN_DETAIL1, 294 TERRAIN_DETAIL1,
295 TERRAIN_DETAIL2,
296 TERRAIN_DETAIL3,
164 TERRAIN_ALPHARAMP 297 TERRAIN_ALPHARAMP
165 } eTerrainUniforms; 298 } eTerrainUniforms;
166 299
167 //glow parameters
168 static const char* sGlowUniforms[];
169 static U32 sGlowUniformCount;
170
171 typedef enum 300 typedef enum
172 { 301 {
173 GLOW_DELTA = END_RESERVED_UNIFORMS 302 GLOW_DELTA = END_RESERVED_UNIFORMS
174 } eGlowUniforms; 303 } eGlowUniforms;
175 304
176 //avatar shader parameter tables
177 static const char* sAvatarAttribs[];
178 static U32 sAvatarAttribCount;
179
180 typedef enum 305 typedef enum
181 { 306 {
182 AVATAR_WEIGHT = END_RESERVED_ATTRIBS, 307 AVATAR_WEIGHT = END_RESERVED_ATTRIBS,
@@ -186,50 +311,102 @@ public:
186 AVATAR_GRAVITY 311 AVATAR_GRAVITY
187 } eAvatarAttribs; 312 } eAvatarAttribs;
188 313
189 static const char* sAvatarUniforms[];
190 static U32 sAvatarUniformCount;
191
192 typedef enum 314 typedef enum
193 { 315 {
194 AVATAR_MATRIX = END_RESERVED_UNIFORMS 316 AVATAR_MATRIX = END_RESERVED_UNIFORMS
195 } eAvatarUniforms; 317 } eAvatarUniforms;
196 318
197}; //LLSL 319private:
320
321 // Map of shader names to compiled
322 static std::map<std::string, GLhandleARB> sShaderObjects;
323
324 //global (reserved slot) shader parameters
325 static std::vector<std::string> sReservedAttribs;
326
327 static std::vector<std::string> sReservedUniforms;
328
329 static std::vector<std::string> sShinyUniforms;
330
331 //water parameters
332 static std::vector<std::string> sWaterUniforms;
333
334 static std::vector<std::string> sWLUniforms;
335
336 //terrain parameters
337 static std::vector<std::string> sTerrainUniforms;
338
339 //glow parameters
340 static std::vector<std::string> sGlowUniforms;
341
342 static std::vector<std::string> sGlowExtractUniforms;
343
344 //avatar shader parameter tables
345 static std::vector<std::string> sAvatarAttribs;
346
347 static std::vector<std::string> sAvatarUniforms;
348 // static std::vector< GLhandleARB > sBaseObjects;
349
350 // the list of shaders we need to propagate parameters to.
351 static LLGLSLShader * const sShaderList[];
352
353 // the size of our shader list for convenience.
354 static const size_t sNumShaders;
355
356}; //LLShaderMgr
357
358inline bool operator == (LLShaderMgr::shader_iter const & a, LLShaderMgr::shader_iter const & b)
359{
360 return a.mPtr == b.mPtr;
361}
362
363inline bool operator != (LLShaderMgr::shader_iter const & a, LLShaderMgr::shader_iter const & b)
364{
365 return a.mPtr != b.mPtr;
366}
198 367
199//utility shader objects (not shader programs)
200extern GLhandleARB gLightVertex;
201extern GLhandleARB gLightFragment;
202extern GLhandleARB gScatterVertex;
203extern GLhandleARB gScatterFragment;
204 368
205extern LLVector4 gShinyOrigin; 369extern LLVector4 gShinyOrigin;
206 370
207//object shaders 371//object shaders
208extern LLGLSLShader gObjectSimpleProgram; 372extern LLGLSLShader gObjectSimpleProgram;
209extern LLGLSLShader gObjectAlphaProgram; 373extern LLGLSLShader gObjectSimpleWaterProgram;
210extern LLGLSLShader gObjectBumpProgram; 374extern LLGLSLShader gObjectFullbrightProgram;
375extern LLGLSLShader gObjectFullbrightWaterProgram;
376
377extern LLGLSLShader gObjectSimpleLODProgram;
378extern LLGLSLShader gObjectFullbrightLODProgram;
379
380extern LLGLSLShader gObjectFullbrightShinyProgram;
211extern LLGLSLShader gObjectShinyProgram; 381extern LLGLSLShader gObjectShinyProgram;
382extern LLGLSLShader gObjectShinyWaterProgram;
212 383
213//environment shaders 384//environment shaders
214extern LLGLSLShader gTerrainProgram; 385extern LLGLSLShader gTerrainProgram;
215extern LLGLSLShader gGlowProgram; 386extern LLGLSLShader gTerrainWaterProgram;
216extern LLGLSLShader gGroundProgram;
217extern LLGLSLShader gWaterProgram; 387extern LLGLSLShader gWaterProgram;
388extern LLGLSLShader gUnderWaterProgram;
389extern LLGLSLShader gGlowProgram;
390extern LLGLSLShader gGlowExtractProgram;
218 391
219//interface shaders 392//interface shaders
220extern LLGLSLShader gHighlightProgram; 393extern LLGLSLShader gHighlightProgram;
221 394
222//avatar skinning utility shader object 395// avatar shader handles
223extern GLhandleARB gAvatarSkinVertex;
224
225//avatar shader handles
226extern LLGLSLShader gAvatarProgram; 396extern LLGLSLShader gAvatarProgram;
397extern LLGLSLShader gAvatarWaterProgram;
227extern LLGLSLShader gAvatarEyeballProgram; 398extern LLGLSLShader gAvatarEyeballProgram;
228extern LLGLSLShader gAvatarPickProgram; 399extern LLGLSLShader gAvatarPickProgram;
229 400
401// WindLight shader handles
402extern LLGLSLShader gWLSkyProgram;
403extern LLGLSLShader gWLCloudProgram;
404
405// Post Process Shaders
406extern LLGLSLShader gPostColorFilterProgram;
407extern LLGLSLShader gPostNightVisionProgram;
408
230//current avatar shader parameter pointer 409//current avatar shader parameter pointer
231extern GLint gAvatarMatrixParam; 410extern GLint gAvatarMatrixParam;
232extern GLint gMaterialIndex; 411
233extern GLint gSpecularIndex;
234
235#endif 412#endif