From cd17687f01420952712a500107e0f93e7ab8d5f8 Mon Sep 17 00:00:00 2001 From: Jacek Antonelli Date: Fri, 15 Aug 2008 23:45:34 -0500 Subject: Second Life viewer sources 1.19.1.0 --- linden/indra/newview/llglslshader.h | 299 ++++++++++++++++++++++++++++-------- 1 file changed, 238 insertions(+), 61 deletions(-) (limited to 'linden/indra/newview/llglslshader.h') 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 @@ #include "llgl.h" +class LLShaderFeatures +{ +public: + bool calculatesLighting; + bool calculatesAtmospherics; + bool hasLighting; // implies no transport (it's possible to have neither though) + bool isShiny; + bool isFullbright; // implies no lighting + bool isSpecular; + bool hasWaterFog; // implies no gamma + bool hasTransport; // implies no lighting (it's possible to have neither though) + bool hasSkinning; + bool hasAtmospherics; + bool hasGamma; + + // char numLights; + + LLShaderFeatures(); +}; + class LLGLSLShader { public: + + enum + { + SG_DEFAULT = 0, + SG_SKY, + SG_WATER + }; + LLGLSLShader(); void unload(); + BOOL createShader(std::vector * attributes, + std::vector * uniforms); + BOOL attachObject(std::string object); void attachObject(GLhandleARB object); void attachObjects(GLhandleARB* objects = NULL, S32 count = 0); - BOOL mapAttributes(const char** attrib_names = NULL, S32 count = 0); - BOOL mapUniforms(const char** uniform_names = NULL, S32 count = 0); - void mapUniform(GLint index, const char** uniform_names = NULL, S32 count = 0); + BOOL mapAttributes(const std::vector * attributes); + BOOL mapUniforms(const std::vector * uniforms); + void mapUniform(GLint index, const std::vector * uniforms); + void uniform1f(U32 index, GLfloat v); + void uniform2f(U32 index, GLfloat x, GLfloat y); + void uniform3f(U32 index, GLfloat x, GLfloat y, GLfloat z); + void uniform4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void uniform1fv(U32 index, U32 count, const GLfloat* v); + void uniform2fv(U32 index, U32 count, const GLfloat* v); + void uniform3fv(U32 index, U32 count, const GLfloat* v); + void uniform4fv(U32 index, U32 count, const GLfloat* v); + void uniform1f(const std::string& uniform, GLfloat v); + void uniform2f(const std::string& uniform, GLfloat x, GLfloat y); + void uniform3f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z); + void uniform4f(const std::string& uniform, GLfloat x, GLfloat y, GLfloat z, GLfloat w); + void uniform1fv(const std::string& uniform, U32 count, const GLfloat* v); + void uniform2fv(const std::string& uniform, U32 count, const GLfloat* v); + void uniform3fv(const std::string& uniform, U32 count, const GLfloat* v); + void uniform4fv(const std::string& uniform, U32 count, const GLfloat* v); + void uniformMatrix2fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); + void uniformMatrix3fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); + void uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, const GLfloat *v); + void uniformMatrix2fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v); + void uniformMatrix3fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v); + void uniformMatrix4fv(const std::string& uniform, U32 count, GLboolean transpose, const GLfloat *v); + void vertexAttrib4f(U32 index, GLfloat x, GLfloat y, GLfloat z, GLfloat w); void vertexAttrib4fv(U32 index, GLfloat* v); + GLint getUniformLocation(const std::string& uniform); + GLint mapUniformTextureChannel(GLint location, GLenum type); @@ -63,39 +119,95 @@ public: void unbind(); GLhandleARB mProgramObject; - std::vector mAttribute; - std::vector mUniform; + std::vector mAttribute; //lookup table of attribute enum to attribute channel + std::vector mUniform; //lookup table of uniform enum to uniform location + std::map mUniformMap; //lookup map of uniform name to uniform location + std::map mValue; //lookup map of uniform location to last known value std::vector mTexture; S32 mActiveTextureChannels; -}; - -class LLScatterShader -{ -public: - static void init(GLhandleARB shader, int map_stage); + S32 mShaderLevel; + S32 mShaderGroup; + BOOL mUniformsDirty; + LLShaderFeatures mFeatures; + std::vector< std::pair< std::string, GLenum > > mShaderFiles; + std::string mName; }; class LLShaderMgr { + friend class LLGLSLShader; + public: + static void initAttribsAndUniforms(void); + static BOOL attachShaderFeatures(LLGLSLShader * shader); static void setShaders(); static void unloadShaders(); static void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE); static BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE); static BOOL validateProgramObject(GLhandleARB obj); - static GLhandleARB loadShader(const LLString& filename, S32 cls, GLenum type); + static GLhandleARB loadShaderFile(const LLString& filename, S32 & shader_level, GLenum type); static S32 getVertexShaderLevel(S32 type); - static S32 getMaxVertexShaderLevel(S32 type); - static BOOL loadShadersLighting(); + static BOOL loadBasicShaders(); + static BOOL loadShadersEffects(); static BOOL loadShadersObject(); static BOOL loadShadersAvatar(); static BOOL loadShadersEnvironment(); + static BOOL loadShadersWater(); static BOOL loadShadersInterface(); + static BOOL loadShadersWindLight(); + + // simple model of forward iterator + // http://www.sgi.com/tech/stl/ForwardIterator.html + class shader_iter + { + friend bool operator == (shader_iter const & a, shader_iter const & b); + friend bool operator != (shader_iter const & a, shader_iter const & b); + public: + shader_iter() : mPtr(NULL) + { + } + + shader_iter(LLGLSLShader * const * ptr) : mPtr(ptr) + { + } + + LLGLSLShader & operator * () const + { + return **mPtr; + } + + LLGLSLShader * operator -> () const + { + return *mPtr; + } + + shader_iter & operator++ () + { + ++mPtr; + return *this; + } + + shader_iter operator++ (int) + { + return mPtr++; + } + + private: + LLGLSLShader * const * mPtr; + }; + + static shader_iter beginShaders() + { + return sShaderList; + } + + static shader_iter endShaders() + { + return sShaderList + sNumShaders; + } + static S32 sVertexShaderLevel[]; - static S32 sMaxVertexShaderLevel[]; - //global (reserved slot) shader parameters - static const char* sReservedAttribs[]; - static U32 sReservedAttribCount; + static S32 sMaxAvatarShaderLevel; enum EShaderClass { @@ -104,6 +216,9 @@ public: SHADER_AVATAR, SHADER_ENVIRONMENT, SHADER_INTERFACE, + SHADER_EFFECT, + SHADER_WINDLIGHT, + SHADER_WATER, SHADER_COUNT }; @@ -114,9 +229,6 @@ public: BINORMAL, END_RESERVED_ATTRIBS } eGLSLReservedAttribs; - - static const char* sReservedUniforms[]; - static U32 sReservedUniformCount; typedef enum { @@ -124,24 +236,39 @@ public: SPECULAR_MAP, BUMP_MAP, ENVIRONMENT_MAP, + CLOUD_NOISE_MAP, + FULLBRIGHT, + LIGHTNORM, + SUNLIGHT_COLOR, + AMBIENT, + BLUE_HORIZON, + BLUE_DENSITY, + HAZE_HORIZON, + HAZE_DENSITY, + CLOUD_SHADOW, + DENSITY_MULTIPLIER, + DISTANCE_MULTIPLIER, + MAX_Y, + GLOW, + CLOUD_COLOR, + CLOUD_POS_DENSITY1, + CLOUD_POS_DENSITY2, + CLOUD_SCALE, + GAMMA, + SCENE_LIGHT_STRENGTH, END_RESERVED_UNIFORMS } eGLSLReservedUniforms; - static const char* sShinyUniforms[]; - static U32 sShinyUniformCount; - typedef enum { SHINY_ORIGIN = END_RESERVED_UNIFORMS } eShinyUniforms; - //water parameters - static const char* sWaterUniforms[]; - static U32 sWaterUniformCount; - typedef enum { WATER_SCREENTEX = END_RESERVED_UNIFORMS, + WATER_SCREENDEPTH, + WATER_REFTEX, WATER_EYEVEC, WATER_TIME, WATER_WAVE_DIR1, @@ -149,34 +276,32 @@ public: WATER_LIGHT_DIR, WATER_SPECULAR, WATER_SPECULAR_EXP, - WATER_FBSCALE, - WATER_REFSCALE + WATER_FOGCOLOR, + WATER_FOGDENSITY, + WATER_REFSCALE, + WATER_WATERHEIGHT, } eWaterUniforms; - //terrain parameters - static const char* sTerrainUniforms[]; - static U32 sTerrainUniformCount; + typedef enum + { + WL_CAMPOSLOCAL = END_RESERVED_UNIFORMS, + WL_WATERHEIGHT + } eWLUniforms; typedef enum { TERRAIN_DETAIL0 = END_RESERVED_UNIFORMS, TERRAIN_DETAIL1, + TERRAIN_DETAIL2, + TERRAIN_DETAIL3, TERRAIN_ALPHARAMP } eTerrainUniforms; - //glow parameters - static const char* sGlowUniforms[]; - static U32 sGlowUniformCount; - typedef enum { GLOW_DELTA = END_RESERVED_UNIFORMS } eGlowUniforms; - //avatar shader parameter tables - static const char* sAvatarAttribs[]; - static U32 sAvatarAttribCount; - typedef enum { AVATAR_WEIGHT = END_RESERVED_ATTRIBS, @@ -186,50 +311,102 @@ public: AVATAR_GRAVITY } eAvatarAttribs; - static const char* sAvatarUniforms[]; - static U32 sAvatarUniformCount; - typedef enum { AVATAR_MATRIX = END_RESERVED_UNIFORMS } eAvatarUniforms; -}; //LLSL +private: + + // Map of shader names to compiled + static std::map sShaderObjects; + + //global (reserved slot) shader parameters + static std::vector sReservedAttribs; + + static std::vector sReservedUniforms; + + static std::vector sShinyUniforms; + + //water parameters + static std::vector sWaterUniforms; + + static std::vector sWLUniforms; + + //terrain parameters + static std::vector sTerrainUniforms; + + //glow parameters + static std::vector sGlowUniforms; + + static std::vector sGlowExtractUniforms; + + //avatar shader parameter tables + static std::vector sAvatarAttribs; + + static std::vector sAvatarUniforms; + // static std::vector< GLhandleARB > sBaseObjects; + + // the list of shaders we need to propagate parameters to. + static LLGLSLShader * const sShaderList[]; + + // the size of our shader list for convenience. + static const size_t sNumShaders; + +}; //LLShaderMgr + +inline bool operator == (LLShaderMgr::shader_iter const & a, LLShaderMgr::shader_iter const & b) +{ + return a.mPtr == b.mPtr; +} + +inline bool operator != (LLShaderMgr::shader_iter const & a, LLShaderMgr::shader_iter const & b) +{ + return a.mPtr != b.mPtr; +} -//utility shader objects (not shader programs) -extern GLhandleARB gLightVertex; -extern GLhandleARB gLightFragment; -extern GLhandleARB gScatterVertex; -extern GLhandleARB gScatterFragment; extern LLVector4 gShinyOrigin; //object shaders extern LLGLSLShader gObjectSimpleProgram; -extern LLGLSLShader gObjectAlphaProgram; -extern LLGLSLShader gObjectBumpProgram; +extern LLGLSLShader gObjectSimpleWaterProgram; +extern LLGLSLShader gObjectFullbrightProgram; +extern LLGLSLShader gObjectFullbrightWaterProgram; + +extern LLGLSLShader gObjectSimpleLODProgram; +extern LLGLSLShader gObjectFullbrightLODProgram; + +extern LLGLSLShader gObjectFullbrightShinyProgram; extern LLGLSLShader gObjectShinyProgram; +extern LLGLSLShader gObjectShinyWaterProgram; //environment shaders extern LLGLSLShader gTerrainProgram; -extern LLGLSLShader gGlowProgram; -extern LLGLSLShader gGroundProgram; +extern LLGLSLShader gTerrainWaterProgram; extern LLGLSLShader gWaterProgram; +extern LLGLSLShader gUnderWaterProgram; +extern LLGLSLShader gGlowProgram; +extern LLGLSLShader gGlowExtractProgram; //interface shaders extern LLGLSLShader gHighlightProgram; -//avatar skinning utility shader object -extern GLhandleARB gAvatarSkinVertex; - -//avatar shader handles +// avatar shader handles extern LLGLSLShader gAvatarProgram; +extern LLGLSLShader gAvatarWaterProgram; extern LLGLSLShader gAvatarEyeballProgram; extern LLGLSLShader gAvatarPickProgram; +// WindLight shader handles +extern LLGLSLShader gWLSkyProgram; +extern LLGLSLShader gWLCloudProgram; + +// Post Process Shaders +extern LLGLSLShader gPostColorFilterProgram; +extern LLGLSLShader gPostNightVisionProgram; + //current avatar shader parameter pointer extern GLint gAvatarMatrixParam; -extern GLint gMaterialIndex; -extern GLint gSpecularIndex; - + #endif -- cgit v1.1