llglslshader.h

Go to the documentation of this file.
00001 
00032 #ifndef LL_LLGLSLSHADER_H
00033 #define LL_LLGLSLSHADER_H
00034 
00035 #include "llgl.h"
00036 
00037 class LLGLSLShader
00038 {
00039 public:
00040         LLGLSLShader();
00041 
00042         void unload();
00043         void attachObject(GLhandleARB object);
00044         void attachObjects(GLhandleARB* objects = NULL, S32 count = 0);
00045         BOOL mapAttributes(const char** attrib_names = NULL, S32 count = 0);
00046         BOOL mapUniforms(const char** uniform_names = NULL,  S32 count = 0);
00047         void mapUniform(GLint index, const char** uniform_names = NULL,  S32 count = 0);
00048         void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w);
00049         void vertexAttrib4fv(U32 index, GLfloat* v);
00050         
00051         GLint mapUniformTextureChannel(GLint location, GLenum type);
00052         
00053 
00054         //enable/disable texture channel for specified uniform
00055         //if given texture uniform is active in the shader, 
00056         //the corresponding channel will be active upon return
00057         //returns channel texture is enabled in from [0-MAX)
00058         S32 enableTexture(S32 uniform, S32 mode = GL_TEXTURE_2D);
00059         S32 disableTexture(S32 uniform, S32 mode = GL_TEXTURE_2D); 
00060         
00061     BOOL link(BOOL suppress_errors = FALSE);
00062         void bind();
00063         void unbind();
00064 
00065         GLhandleARB mProgramObject;
00066         std::vector<GLint> mAttribute;
00067         std::vector<GLint> mUniform;
00068         std::vector<GLint> mTexture;
00069         S32 mActiveTextureChannels;
00070 };
00071 
00072 class LLScatterShader
00073 {
00074 public:
00075         static void init(GLhandleARB shader, int map_stage);
00076 };
00077 
00078 class LLShaderMgr
00079 {
00080 public:
00081         static void setShaders();
00082         static void unloadShaders();
00083         static void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE);
00084         static BOOL     linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE);
00085         static BOOL     validateProgramObject(GLhandleARB obj);
00086         static GLhandleARB loadShader(const LLString& filename, S32 cls, GLenum type);
00087         static S32 getVertexShaderLevel(S32 type);
00088         static S32 getMaxVertexShaderLevel(S32 type);
00089         static BOOL loadShadersLighting();
00090         static BOOL loadShadersObject();
00091         static BOOL loadShadersAvatar();
00092         static BOOL loadShadersEnvironment();
00093         static BOOL loadShadersInterface();
00094         static S32      sVertexShaderLevel[];
00095         static S32      sMaxVertexShaderLevel[];
00096         //global (reserved slot) shader parameters
00097         static const char* sReservedAttribs[];
00098         static U32 sReservedAttribCount;
00099 
00100         enum EShaderClass
00101         {
00102                 SHADER_LIGHTING,
00103                 SHADER_OBJECT,
00104                 SHADER_AVATAR,
00105                 SHADER_ENVIRONMENT,
00106                 SHADER_INTERFACE,
00107                 SHADER_COUNT
00108         };
00109 
00110         typedef enum 
00111         {
00112                 MATERIAL_COLOR = 0,
00113                 SPECULAR_COLOR,
00114                 BINORMAL,
00115                 END_RESERVED_ATTRIBS
00116         } eGLSLReservedAttribs;
00117 
00118         static const char* sReservedUniforms[];
00119         static U32 sReservedUniformCount;
00120         
00121         typedef enum
00122         {
00123                 DIFFUSE_MAP = 0,
00124                 SPECULAR_MAP,
00125                 BUMP_MAP,
00126                 ENVIRONMENT_MAP,
00127                 END_RESERVED_UNIFORMS
00128         } eGLSLReservedUniforms;
00129 
00130         static const char* sShinyUniforms[];
00131         static U32 sShinyUniformCount;
00132 
00133         typedef enum
00134         {
00135                 SHINY_ORIGIN = END_RESERVED_UNIFORMS
00136         } eShinyUniforms;
00137 
00138         //water parameters
00139         static const char* sWaterUniforms[];
00140         static U32 sWaterUniformCount;
00141 
00142         typedef enum
00143         {
00144                 WATER_SCREENTEX = END_RESERVED_UNIFORMS,
00145                 WATER_EYEVEC,
00146                 WATER_TIME,
00147                 WATER_WAVE_DIR1,
00148                 WATER_WAVE_DIR2,
00149                 WATER_LIGHT_DIR,
00150                 WATER_SPECULAR,
00151                 WATER_SPECULAR_EXP,
00152                 WATER_FBSCALE,
00153                 WATER_REFSCALE
00154         } eWaterUniforms;
00155 
00156         //terrain parameters
00157         static const char* sTerrainUniforms[];
00158         static U32 sTerrainUniformCount;
00159 
00160         typedef enum
00161         {
00162                 TERRAIN_DETAIL0 = END_RESERVED_UNIFORMS,
00163                 TERRAIN_DETAIL1,
00164                 TERRAIN_ALPHARAMP
00165         } eTerrainUniforms;
00166 
00167         //glow parameters
00168         static const char* sGlowUniforms[];
00169         static U32 sGlowUniformCount;
00170 
00171         typedef enum
00172         {
00173                 GLOW_DELTA = END_RESERVED_UNIFORMS
00174         } eGlowUniforms;
00175 
00176         //avatar shader parameter tables
00177         static const char* sAvatarAttribs[];
00178         static U32 sAvatarAttribCount;
00179 
00180         typedef enum
00181         {
00182                 AVATAR_WEIGHT = END_RESERVED_ATTRIBS,
00183                 AVATAR_CLOTHING,
00184                 AVATAR_WIND,
00185                 AVATAR_SINWAVE,
00186                 AVATAR_GRAVITY
00187         } eAvatarAttribs;
00188 
00189         static const char* sAvatarUniforms[];
00190         static U32 sAvatarUniformCount;
00191 
00192         typedef enum
00193         {
00194                 AVATAR_MATRIX = END_RESERVED_UNIFORMS
00195         } eAvatarUniforms;
00196 
00197 }; //LLSL
00198 
00199 //utility shader objects (not shader programs)
00200 extern GLhandleARB                      gLightVertex;
00201 extern GLhandleARB                      gLightFragment;
00202 extern GLhandleARB                      gScatterVertex;
00203 extern GLhandleARB                      gScatterFragment;
00204 
00205 extern LLVector4                        gShinyOrigin;
00206 
00207 //object shaders
00208 extern LLGLSLShader                     gObjectSimpleProgram;
00209 extern LLGLSLShader                     gObjectAlphaProgram;
00210 extern LLGLSLShader                     gObjectBumpProgram;
00211 extern LLGLSLShader                     gObjectShinyProgram;
00212 
00213 //environment shaders
00214 extern LLGLSLShader                     gTerrainProgram;
00215 extern LLGLSLShader                     gGlowProgram;
00216 extern LLGLSLShader                     gGroundProgram;
00217 extern LLGLSLShader                     gWaterProgram;
00218 
00219 //interface shaders
00220 extern LLGLSLShader                     gHighlightProgram;
00221 
00222 //avatar skinning utility shader object
00223 extern GLhandleARB                      gAvatarSkinVertex;
00224 
00225 //avatar shader handles
00226 extern LLGLSLShader                     gAvatarProgram;
00227 extern LLGLSLShader                     gAvatarEyeballProgram;
00228 extern LLGLSLShader                     gAvatarPickProgram;
00229 
00230 //current avatar shader parameter pointer
00231 extern GLint                            gAvatarMatrixParam;
00232 extern GLint                            gMaterialIndex;
00233 extern GLint                            gSpecularIndex;
00234         
00235 #endif

Generated on Thu Jul 1 06:08:40 2010 for Second Life Viewer by  doxygen 1.4.7