aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llglslshader.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-09-06 18:24:57 -0500
committerJacek Antonelli2008-09-06 18:25:07 -0500
commit798d367d54a6c6379ad355bd8345fa40e31e7fe9 (patch)
tree1921f1708cd0240648c97bc02df2c2ab5f2fc41e /linden/indra/newview/llglslshader.h
parentSecond Life viewer sources 1.20.15 (diff)
downloadmeta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.zip
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.gz
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.bz2
meta-impy-798d367d54a6c6379ad355bd8345fa40e31e7fe9.tar.xz
Second Life viewer sources 1.21.0-RC
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llglslshader.h420
1 files changed, 0 insertions, 420 deletions
diff --git a/linden/indra/newview/llglslshader.h b/linden/indra/newview/llglslshader.h
deleted file mode 100644
index e517b94..0000000
--- a/linden/indra/newview/llglslshader.h
+++ /dev/null
@@ -1,420 +0,0 @@
1/**
2 * @file llglslshader.h
3 * @brief GLSL shader wrappers
4 *
5 * $LicenseInfo:firstyear=2001&license=viewergpl$
6 *
7 * Copyright (c) 2001-2008, Linden Research, Inc.
8 *
9 * Second Life Viewer Source Code
10 * The source code in this file ("Source Code") is provided by Linden Lab
11 * to you under the terms of the GNU General Public License, version 2.0
12 * ("GPL"), unless you have obtained a separate licensing agreement
13 * ("Other License"), formally executed by you and Linden Lab. Terms of
14 * the GPL can be found in doc/GPL-license.txt in this distribution, or
15 * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
16 *
17 * There are special exceptions to the terms and conditions of the GPL as
18 * it is applied to this Source Code. View the full text of the exception
19 * in the file doc/FLOSS-exception.txt in this software distribution, or
20 * online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
21 *
22 * By copying, modifying or distributing this software, you acknowledge
23 * that you have read and understood your obligations described above,
24 * and agree to abide by those obligations.
25 *
26 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
27 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
28 * COMPLETENESS OR PERFORMANCE.
29 * $/LicenseInfo$
30 */
31
32#ifndef LL_LLGLSLSHADER_H
33#define LL_LLGLSLSHADER_H
34
35#include "llgl.h"
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
57class LLGLSLShader
58{
59public:
60
61 enum
62 {
63 SG_DEFAULT = 0,
64 SG_SKY,
65 SG_WATER
66 };
67
68 LLGLSLShader();
69
70 void unload();
71 BOOL createShader(std::vector<std::string> * attributes,
72 std::vector<std::string> * uniforms);
73 BOOL attachObject(std::string object);
74 void attachObject(GLhandleARB object);
75 void attachObjects(GLhandleARB* objects = NULL, S32 count = 0);
76 BOOL mapAttributes(const std::vector<std::string> * attributes);
77 BOOL mapUniforms(const std::vector<std::string> * uniforms);
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
102 void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
103 void vertexAttrib4fv(U32 index, GLfloat* v);
104
105 GLint getUniformLocation(const std::string& uniform);
106
107 GLint mapUniformTextureChannel(GLint location, GLenum type);
108
109
110 //enable/disable texture channel for specified uniform
111 //if given texture uniform is active in the shader,
112 //the corresponding channel will be active upon return
113 //returns channel texture is enabled in from [0-MAX)
114 S32 enableTexture(S32 uniform, S32 mode = GL_TEXTURE_2D);
115 S32 disableTexture(S32 uniform, S32 mode = GL_TEXTURE_2D);
116
117 BOOL link(BOOL suppress_errors = FALSE);
118 void bind();
119 void unbind();
120
121 // Unbinds any previously bound shader by explicitly binding no shader.
122 static void bindNoShader(void);
123
124 GLhandleARB mProgramObject;
125 std::vector<GLint> mAttribute; //lookup table of attribute enum to attribute channel
126 std::vector<GLint> mUniform; //lookup table of uniform enum to uniform location
127 std::map<std::string, GLint> mUniformMap; //lookup map of uniform name to uniform location
128 std::map<GLint, LLVector4> mValue; //lookup map of uniform location to last known value
129 std::vector<GLint> mTexture;
130 S32 mActiveTextureChannels;
131 S32 mShaderLevel;
132 S32 mShaderGroup;
133 BOOL mUniformsDirty;
134 LLShaderFeatures mFeatures;
135 std::vector< std::pair< std::string, GLenum > > mShaderFiles;
136 std::string mName;
137};
138
139class LLShaderMgr
140{
141 friend class LLGLSLShader;
142
143public:
144 static void initAttribsAndUniforms(void);
145 static BOOL attachShaderFeatures(LLGLSLShader * shader);
146 static void setShaders();
147 static void unloadShaders();
148 static void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE);
149 static BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE);
150 static BOOL validateProgramObject(GLhandleARB obj);
151 static GLhandleARB loadShaderFile(const LLString& filename, S32 & shader_level, GLenum type);
152 static S32 getVertexShaderLevel(S32 type);
153 static BOOL loadBasicShaders();
154 static BOOL loadShadersEffects();
155 static BOOL loadShadersDeferred();
156 static BOOL loadShadersObject();
157 static BOOL loadShadersAvatar();
158 static BOOL loadShadersEnvironment();
159 static BOOL loadShadersWater();
160 static BOOL loadShadersInterface();
161 static BOOL loadShadersWindLight();
162
163 // simple model of forward iterator
164 // http://www.sgi.com/tech/stl/ForwardIterator.html
165 class shader_iter
166 {
167 friend bool operator == (shader_iter const & a, shader_iter const & b);
168 friend bool operator != (shader_iter const & a, shader_iter const & b);
169 public:
170 shader_iter() : mPtr(NULL)
171 {
172 }
173
174 shader_iter(LLGLSLShader * const * ptr) : mPtr(ptr)
175 {
176 }
177
178 LLGLSLShader & operator * () const
179 {
180 return **mPtr;
181 }
182
183 LLGLSLShader * operator -> () const
184 {
185 return *mPtr;
186 }
187
188 shader_iter & operator++ ()
189 {
190 ++mPtr;
191 return *this;
192 }
193
194 shader_iter operator++ (int)
195 {
196 return mPtr++;
197 }
198
199 private:
200 LLGLSLShader * const * mPtr;
201 };
202
203 static shader_iter beginShaders()
204 {
205 return sShaderList;
206 }
207
208 static shader_iter endShaders()
209 {
210 return sShaderList + sNumShaders;
211 }
212
213 static S32 sVertexShaderLevel[];
214 static S32 sMaxAvatarShaderLevel;
215
216 enum EShaderClass
217 {
218 SHADER_LIGHTING,
219 SHADER_OBJECT,
220 SHADER_AVATAR,
221 SHADER_ENVIRONMENT,
222 SHADER_INTERFACE,
223 SHADER_EFFECT,
224 SHADER_WINDLIGHT,
225 SHADER_WATER,
226 SHADER_DEFERRED,
227 SHADER_COUNT
228 };
229
230 typedef enum
231 {
232 MATERIAL_COLOR = 0,
233 SPECULAR_COLOR,
234 BINORMAL,
235 END_RESERVED_ATTRIBS
236 } eGLSLReservedAttribs;
237
238 typedef enum
239 {
240 DIFFUSE_MAP = 0,
241 SPECULAR_MAP,
242 BUMP_MAP,
243 ENVIRONMENT_MAP,
244 CLOUD_NOISE_MAP,
245 FULLBRIGHT,
246 LIGHTNORM,
247 SUNLIGHT_COLOR,
248 AMBIENT,
249 BLUE_HORIZON,
250 BLUE_DENSITY,
251 HAZE_HORIZON,
252 HAZE_DENSITY,
253 CLOUD_SHADOW,
254 DENSITY_MULTIPLIER,
255 DISTANCE_MULTIPLIER,
256 MAX_Y,
257 GLOW,
258 CLOUD_COLOR,
259 CLOUD_POS_DENSITY1,
260 CLOUD_POS_DENSITY2,
261 CLOUD_SCALE,
262 GAMMA,
263 SCENE_LIGHT_STRENGTH,
264 END_RESERVED_UNIFORMS
265 } eGLSLReservedUniforms;
266
267 typedef enum
268 {
269 SHINY_ORIGIN = END_RESERVED_UNIFORMS
270 } eShinyUniforms;
271
272 typedef enum
273 {
274 WATER_SCREENTEX = END_RESERVED_UNIFORMS,
275 WATER_SCREENDEPTH,
276 WATER_REFTEX,
277 WATER_EYEVEC,
278 WATER_TIME,
279 WATER_WAVE_DIR1,
280 WATER_WAVE_DIR2,
281 WATER_LIGHT_DIR,
282 WATER_SPECULAR,
283 WATER_SPECULAR_EXP,
284 WATER_FOGCOLOR,
285 WATER_FOGDENSITY,
286 WATER_REFSCALE,
287 WATER_WATERHEIGHT,
288 } eWaterUniforms;
289
290 typedef enum
291 {
292 WL_CAMPOSLOCAL = END_RESERVED_UNIFORMS,
293 WL_WATERHEIGHT
294 } eWLUniforms;
295
296 typedef enum
297 {
298 TERRAIN_DETAIL0 = END_RESERVED_UNIFORMS,
299 TERRAIN_DETAIL1,
300 TERRAIN_DETAIL2,
301 TERRAIN_DETAIL3,
302 TERRAIN_ALPHARAMP
303 } eTerrainUniforms;
304
305 typedef enum
306 {
307 GLOW_DELTA = END_RESERVED_UNIFORMS
308 } eGlowUniforms;
309
310 typedef enum
311 {
312 AVATAR_WEIGHT = END_RESERVED_ATTRIBS,
313 AVATAR_CLOTHING,
314 AVATAR_WIND,
315 AVATAR_SINWAVE,
316 AVATAR_GRAVITY
317 } eAvatarAttribs;
318
319 typedef enum
320 {
321 AVATAR_MATRIX = END_RESERVED_UNIFORMS
322 } eAvatarUniforms;
323
324private:
325
326 // Map of shader names to compiled
327 static std::map<std::string, GLhandleARB> sShaderObjects;
328
329 //global (reserved slot) shader parameters
330 static std::vector<std::string> sReservedAttribs;
331
332 static std::vector<std::string> sReservedUniforms;
333
334 static std::vector<std::string> sShinyUniforms;
335
336 //water parameters
337 static std::vector<std::string> sWaterUniforms;
338
339 static std::vector<std::string> sWLUniforms;
340
341 //terrain parameters
342 static std::vector<std::string> sTerrainUniforms;
343
344 //glow parameters
345 static std::vector<std::string> sGlowUniforms;
346
347 static std::vector<std::string> sGlowExtractUniforms;
348
349 //avatar shader parameter tables
350 static std::vector<std::string> sAvatarAttribs;
351
352 static std::vector<std::string> sAvatarUniforms;
353 // static std::vector< GLhandleARB > sBaseObjects;
354
355 // the list of shaders we need to propagate parameters to.
356 static LLGLSLShader * const sShaderList[];
357
358 // the size of our shader list for convenience.
359 static const size_t sNumShaders;
360
361}; //LLShaderMgr
362
363inline bool operator == (LLShaderMgr::shader_iter const & a, LLShaderMgr::shader_iter const & b)
364{
365 return a.mPtr == b.mPtr;
366}
367
368inline bool operator != (LLShaderMgr::shader_iter const & a, LLShaderMgr::shader_iter const & b)
369{
370 return a.mPtr != b.mPtr;
371}
372
373
374extern LLVector4 gShinyOrigin;
375
376//object shaders
377extern LLGLSLShader gObjectSimpleProgram;
378extern LLGLSLShader gObjectSimpleWaterProgram;
379extern LLGLSLShader gObjectFullbrightProgram;
380extern LLGLSLShader gObjectFullbrightWaterProgram;
381
382extern LLGLSLShader gObjectSimpleLODProgram;
383extern LLGLSLShader gObjectFullbrightLODProgram;
384
385extern LLGLSLShader gObjectFullbrightShinyProgram;
386extern LLGLSLShader gObjectShinyProgram;
387extern LLGLSLShader gObjectShinyWaterProgram;
388
389//environment shaders
390extern LLGLSLShader gTerrainProgram;
391extern LLGLSLShader gTerrainWaterProgram;
392extern LLGLSLShader gWaterProgram;
393extern LLGLSLShader gUnderWaterProgram;
394extern LLGLSLShader gGlowProgram;
395extern LLGLSLShader gGlowExtractProgram;
396
397//interface shaders
398extern LLGLSLShader gHighlightProgram;
399
400// avatar shader handles
401extern LLGLSLShader gAvatarProgram;
402extern LLGLSLShader gAvatarWaterProgram;
403extern LLGLSLShader gAvatarEyeballProgram;
404extern LLGLSLShader gAvatarPickProgram;
405
406// WindLight shader handles
407extern LLGLSLShader gWLSkyProgram;
408extern LLGLSLShader gWLCloudProgram;
409
410// Post Process Shaders
411extern LLGLSLShader gPostColorFilterProgram;
412extern LLGLSLShader gPostNightVisionProgram;
413
414// Deferred rendering shaders
415extern LLGLSLShader gDeferredDiffuseProgram;
416
417//current avatar shader parameter pointer
418extern GLint gAvatarMatrixParam;
419
420#endif