diff options
Diffstat (limited to 'indra/llrender')
-rw-r--r-- | indra/llrender/llglslshader.cpp | 26 | ||||
-rw-r--r-- | indra/llrender/llglslshader.h | 2 | ||||
-rw-r--r-- | indra/llrender/llrender.cpp | 49 | ||||
-rw-r--r-- | indra/llrender/llshadermgr.cpp | 174 | ||||
-rw-r--r-- | indra/llrender/llshadermgr.h | 125 |
5 files changed, 344 insertions, 32 deletions
diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp index ddadf07d73..bbb62ea3c1 100644 --- a/indra/llrender/llglslshader.cpp +++ b/indra/llrender/llglslshader.cpp @@ -320,7 +320,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms) for (S32 i = 0; i < (S32) LLShaderMgr::instance()->mReservedUniforms.size(); i++) { if ( (mUniform[i] == -1) - && (LLShaderMgr::instance()->mReservedUniforms[i].compare(0, length, name, LLShaderMgr::instance()->mReservedUniforms[i].length()) == 0)) + && (LLShaderMgr::instance()->mReservedUniforms[i] == name)) { //found it mUniform[i] = location; @@ -334,7 +334,7 @@ void LLGLSLShader::mapUniform(GLint index, const vector<string> * uniforms) for (U32 i = 0; i < uniforms->size(); i++) { if ( (mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] == -1) - && ((*uniforms)[i].compare(0, length, name, (*uniforms)[i].length()) == 0)) + && ((*uniforms)[i] == name)) { //found it mUniform[i+LLShaderMgr::instance()->mReservedUniforms.size()] = location; @@ -762,8 +762,12 @@ void LLGLSLShader::uniformMatrix4fv(U32 index, U32 count, GLboolean transpose, c } } +static LLFastTimer::DeclareTimer FTM_UNIFORM_LOCATION("Get Uniform Location"); + GLint LLGLSLShader::getUniformLocation(const string& uniform) { + LLFastTimer t(FTM_UNIFORM_LOCATION); + GLint ret = -1; if (mProgramObject > 0) { @@ -783,13 +787,19 @@ GLint LLGLSLShader::getUniformLocation(const string& uniform) } } - /*if (gDebugGL) + return ret; +} + +GLint LLGLSLShader::getUniformLocation(U32 index) +{ + LLFastTimer t(FTM_UNIFORM_LOCATION); + + GLint ret = -1; + if (mProgramObject > 0) { - if (ret == -1 && ret != glGetUniformLocationARB(mProgramObject, uniform.c_str())) - { - llerrs << "Uniform map invalid." << llendl; - } - }*/ + llassert(index < mUniform.size()); + return mUniform[index]; + } return ret; } diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h index beef57796d..eb19599eca 100644 --- a/indra/llrender/llglslshader.h +++ b/indra/llrender/llglslshader.h @@ -114,6 +114,8 @@ public: void vertexAttrib4fv(U32 index, GLfloat* v); GLint getUniformLocation(const std::string& uniform); + GLint getUniformLocation(U32 index); + GLint getAttribLocation(U32 attrib); GLint mapUniformTextureChannel(GLint location, GLenum type); diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp index c73701bbcc..afb19fce55 100644 --- a/indra/llrender/llrender.cpp +++ b/indra/llrender/llrender.cpp @@ -34,6 +34,7 @@ #include "llimagegl.h" #include "llrendertarget.h" #include "lltexture.h" +#include "llshadermgr.h" LLRender gGL; @@ -1127,13 +1128,13 @@ void LLRender::syncLightState() diffuse[i].set(light->mDiffuse.mV); } - shader->uniform4fv("light_position", 8, position[0].mV); - shader->uniform3fv("light_direction", 8, direction[0].mV); - shader->uniform3fv("light_attenuation", 8, attenuation[0].mV); - shader->uniform3fv("light_diffuse", 8, diffuse[0].mV); - shader->uniform4fv("light_ambient", 1, mAmbientLightColor.mV); + shader->uniform4fv(LLShaderMgr::LIGHT_POSITION, 8, position[0].mV); + shader->uniform3fv(LLShaderMgr::LIGHT_DIRECTION, 8, direction[0].mV); + shader->uniform3fv(LLShaderMgr::LIGHT_ATTENUATION, 8, attenuation[0].mV); + shader->uniform3fv(LLShaderMgr::LIGHT_DIFFUSE, 8, diffuse[0].mV); + shader->uniform4fv(LLShaderMgr::LIGHT_AMBIENT, 1, mAmbientLightColor.mV); //HACK -- duplicate sunlight color for compatibility with drivers that can't deal with multiple shader objects referencing the same uniform - shader->uniform4fv("sunlight_color", 1, diffuse[0].mV); + shader->uniform4fv(LLShaderMgr::SUNLIGHT_COLOR, 1, diffuse[0].mV); } } @@ -1151,14 +1152,14 @@ void LLRender::syncMatrices() GL_TEXTURE, }; - std::string name[] = + U32 name[] = { - "modelview_matrix", - "projection_matrix", - "texture_matrix0", - "texture_matrix1", - "texture_matrix2", - "texture_matrix3", + LLShaderMgr::MODELVIEW_MATRIX, + LLShaderMgr::PROJECTION_MATRIX, + LLShaderMgr::TEXTURE_MATRIX0, + LLShaderMgr::TEXTURE_MATRIX1, + LLShaderMgr::TEXTURE_MATRIX2, + LLShaderMgr::TEXTURE_MATRIX3, }; LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr; @@ -1185,7 +1186,7 @@ void LLRender::syncMatrices() shader->mMatHash[i] = mMatHash[i]; //update normal matrix - S32 loc = shader->getUniformLocation("normal_matrix"); + S32 loc = shader->getUniformLocation(LLShaderMgr::NORMAL_MATRIX); if (loc > -1) { if (cached_normal_hash != mMatHash[i]) @@ -1203,12 +1204,12 @@ void LLRender::syncMatrices() norm.m[8], norm.m[9], norm.m[10] }; - shader->uniformMatrix3fv("normal_matrix", 1, GL_FALSE, norm_mat); + shader->uniformMatrix3fv(LLShaderMgr::NORMAL_MATRIX, 1, GL_FALSE, norm_mat); } //update MVP matrix mvp_done = true; - loc = shader->getUniformLocation("modelview_projection_matrix"); + loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX); if (loc > -1) { U32 proj = MM_PROJECTION; @@ -1221,7 +1222,7 @@ void LLRender::syncMatrices() cached_mvp_proj_hash = mMatHash[MM_PROJECTION]; } - shader->uniformMatrix4fv("modelview_projection_matrix", 1, GL_FALSE, cached_mvp.m); + shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.m); } } @@ -1237,7 +1238,7 @@ void LLRender::syncMatrices() if (!mvp_done) { //update MVP matrix - S32 loc = shader->getUniformLocation("modelview_projection_matrix"); + S32 loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX); if (loc > -1) { if (cached_mvp_mdv_hash != mMatHash[i] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION]) @@ -1249,7 +1250,7 @@ void LLRender::syncMatrices() cached_mvp_proj_hash = mMatHash[MM_PROJECTION]; } - shader->uniformMatrix4fv("modelview_projection_matrix", 1, GL_FALSE, cached_mvp.m); + shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.m); } } } @@ -2176,7 +2177,7 @@ void LLRender::diffuseColor3f(F32 r, F32 g, F32 b) if (shader) { - shader->uniform4f("color", r,g,b,1.f); + shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,1.f); } else { @@ -2191,7 +2192,7 @@ void LLRender::diffuseColor3fv(const F32* c) if (shader) { - shader->uniform4f("color", c[0], c[1], c[2], 1.f); + shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0], c[1], c[2], 1.f); } else { @@ -2206,7 +2207,7 @@ void LLRender::diffuseColor4f(F32 r, F32 g, F32 b, F32 a) if (shader) { - shader->uniform4f("color", r,g,b,a); + shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,a); } else { @@ -2221,7 +2222,7 @@ void LLRender::diffuseColor4fv(const F32* c) if (shader) { - shader->uniform4fv("color", 1, c); + shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, c); } else { @@ -2236,7 +2237,7 @@ void LLRender::diffuseColor4ubv(const U8* c) if (shader) { - shader->uniform4f("color", c[0]/255.f, c[1]/255.f, c[2]/255.f, c[3]/255.f); + shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0]/255.f, c[1]/255.f, c[2]/255.f, c[3]/255.f); } else { diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 16180c6831..0a99c66d09 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -897,3 +897,177 @@ BOOL LLShaderMgr::validateProgramObject(GLhandleARB obj) return success; } +//virtual +void LLShaderMgr::initAttribsAndUniforms() +{ + //MUST match order of enum in LLVertexBuffer.h + mReservedAttribs.push_back("position"); + mReservedAttribs.push_back("normal"); + mReservedAttribs.push_back("texcoord0"); + mReservedAttribs.push_back("texcoord1"); + mReservedAttribs.push_back("texcoord2"); + mReservedAttribs.push_back("texcoord3"); + mReservedAttribs.push_back("diffuse_color"); + mReservedAttribs.push_back("emissive"); + mReservedAttribs.push_back("binormal"); + mReservedAttribs.push_back("weight"); + mReservedAttribs.push_back("weight4"); + mReservedAttribs.push_back("clothing"); + mReservedAttribs.push_back("texture_index"); + + //matrix state + mReservedUniforms.push_back("modelview_matrix"); + mReservedUniforms.push_back("projection_matrix"); + mReservedUniforms.push_back("inv_proj"); + mReservedUniforms.push_back("modelview_projection_matrix"); + mReservedUniforms.push_back("normal_matrix"); + mReservedUniforms.push_back("texture_matrix0"); + mReservedUniforms.push_back("texture_matrix1"); + mReservedUniforms.push_back("texture_matrix2"); + mReservedUniforms.push_back("texture_matrix3"); + llassert(mReservedUniforms.size() == LLShaderMgr::TEXTURE_MATRIX3+1); + + mReservedUniforms.push_back("viewport"); + + mReservedUniforms.push_back("light_position"); + mReservedUniforms.push_back("light_direction"); + mReservedUniforms.push_back("light_attenuation"); + mReservedUniforms.push_back("light_diffuse"); + mReservedUniforms.push_back("light_ambient"); + mReservedUniforms.push_back("light_count"); + mReservedUniforms.push_back("light"); + mReservedUniforms.push_back("light_col"); + mReservedUniforms.push_back("far_z"); + + llassert(mReservedUniforms.size() == LLShaderMgr::MULTI_LIGHT_FAR_Z+1); + + + mReservedUniforms.push_back("proj_mat"); + mReservedUniforms.push_back("proj_near"); + mReservedUniforms.push_back("proj_p"); + mReservedUniforms.push_back("proj_n"); + mReservedUniforms.push_back("proj_origin"); + mReservedUniforms.push_back("proj_range"); + mReservedUniforms.push_back("proj_ambiance"); + mReservedUniforms.push_back("proj_shadow_idx"); + mReservedUniforms.push_back("shadow_fade"); + mReservedUniforms.push_back("proj_focus"); + mReservedUniforms.push_back("proj_lod"); + mReservedUniforms.push_back("proj_ambient_lod"); + + llassert(mReservedUniforms.size() == LLShaderMgr::PROJECTOR_AMBIENT_LOD+1); + + mReservedUniforms.push_back("color"); + mReservedUniforms.push_back("highlight_color"); + + mReservedUniforms.push_back("diffuseMap"); + mReservedUniforms.push_back("specularMap"); + mReservedUniforms.push_back("bumpMap"); + mReservedUniforms.push_back("environmentMap"); + mReservedUniforms.push_back("cloude_noise_texture"); + mReservedUniforms.push_back("fullbright"); + mReservedUniforms.push_back("lightnorm"); + mReservedUniforms.push_back("sunlight_color"); + mReservedUniforms.push_back("ambient"); + mReservedUniforms.push_back("blue_horizon"); + mReservedUniforms.push_back("blue_density"); + mReservedUniforms.push_back("haze_horizon"); + mReservedUniforms.push_back("haze_density"); + mReservedUniforms.push_back("cloud_shadow"); + mReservedUniforms.push_back("density_multiplier"); + mReservedUniforms.push_back("distance_multiplier"); + mReservedUniforms.push_back("max_y"); + mReservedUniforms.push_back("glow"); + mReservedUniforms.push_back("cloud_color"); + mReservedUniforms.push_back("cloud_pos_density1"); + mReservedUniforms.push_back("cloud_pos_density2"); + mReservedUniforms.push_back("cloud_scale"); + mReservedUniforms.push_back("gamma"); + mReservedUniforms.push_back("scene_light_strength"); + + llassert(mReservedUniforms.size() == LLShaderMgr::SCENE_LIGHT_STRENGTH+1); + + mReservedUniforms.push_back("center"); + mReservedUniforms.push_back("size"); + mReservedUniforms.push_back("falloff"); + + + mReservedUniforms.push_back("minLuminance"); + mReservedUniforms.push_back("maxExtractAlpha"); + mReservedUniforms.push_back("lumWeights"); + mReservedUniforms.push_back("warmthWeights"); + mReservedUniforms.push_back("warmthAmount"); + mReservedUniforms.push_back("glowStrength"); + mReservedUniforms.push_back("glowDelta"); + + llassert(mReservedUniforms.size() == LLShaderMgr::GLOW_DELTA+1); + + mReservedUniforms.push_back("shadow_matrix"); + mReservedUniforms.push_back("env_mat"); + mReservedUniforms.push_back("shadow_clip"); + mReservedUniforms.push_back("sun_wash"); + mReservedUniforms.push_back("shadow_noise"); + mReservedUniforms.push_back("blur_size"); + mReservedUniforms.push_back("ssao_radius"); + mReservedUniforms.push_back("ssao_max_radius"); + mReservedUniforms.push_back("ssao_factor"); + mReservedUniforms.push_back("ssao_factor_inv"); + mReservedUniforms.push_back("ssao_effect_mat"); + mReservedUniforms.push_back("screen_res"); + mReservedUniforms.push_back("near_clip"); + mReservedUniforms.push_back("shadow_offset"); + mReservedUniforms.push_back("shadow_bias"); + mReservedUniforms.push_back("spot_shadow_bias"); + mReservedUniforms.push_back("spot_shadow_offset"); + mReservedUniforms.push_back("sun_dir"); + mReservedUniforms.push_back("shadow_res"); + mReservedUniforms.push_back("proj_shadow_res"); + mReservedUniforms.push_back("depth_cutoff"); + mReservedUniforms.push_back("norm_cutoff"); + + llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_NORM_CUTOFF+1); + + mReservedUniforms.push_back("tc_scale"); + mReservedUniforms.push_back("rcp_screen_res"); + mReservedUniforms.push_back("rcp_frame_opt"); + mReservedUniforms.push_back("rcp_frame_opt2"); + + mReservedUniforms.push_back("focal_distance"); + mReservedUniforms.push_back("blur_constant"); + mReservedUniforms.push_back("tan_pixel_angle"); + mReservedUniforms.push_back("magnification"); + + mReservedUniforms.push_back("depthMap"); + mReservedUniforms.push_back("shadowMap0"); + mReservedUniforms.push_back("shadowMap1"); + mReservedUniforms.push_back("shadowMap2"); + mReservedUniforms.push_back("shadowMap3"); + mReservedUniforms.push_back("shadowMap4"); + mReservedUniforms.push_back("shadowMap5"); + + llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW5+1); + + mReservedUniforms.push_back("normalMap"); + mReservedUniforms.push_back("positionMap"); + mReservedUniforms.push_back("diffuseRect"); + mReservedUniforms.push_back("specularRect"); + mReservedUniforms.push_back("noiseMap"); + mReservedUniforms.push_back("lightFunc"); + mReservedUniforms.push_back("lightMap"); + mReservedUniforms.push_back("bloomMap"); + mReservedUniforms.push_back("projectionMap"); + + llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS); + + std::set<std::string> dupe_check; + + for (U32 i = 0; i < mReservedUniforms.size(); ++i) + { + if (dupe_check.find(mReservedUniforms[i]) != dupe_check.end()) + { + llerrs << "Duplicate reserved uniform name found: " << mReservedUniforms[i] << llendl; + } + dupe_check.insert(mReservedUniforms[i]); + } +} + diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h index 2f30103811..9cc2f1bd7f 100644 --- a/indra/llrender/llshadermgr.h +++ b/indra/llrender/llshadermgr.h @@ -36,9 +36,134 @@ public: LLShaderMgr(); virtual ~LLShaderMgr(); + typedef enum + { + MODELVIEW_MATRIX = 0, + PROJECTION_MATRIX, + INVERSE_PROJECTION_MATRIX, + MODELVIEW_PROJECTION_MATRIX, + NORMAL_MATRIX, + TEXTURE_MATRIX0, + TEXTURE_MATRIX1, + TEXTURE_MATRIX2, + TEXTURE_MATRIX3, + VIEWPORT, + LIGHT_POSITION, + LIGHT_DIRECTION, + LIGHT_ATTENUATION, + LIGHT_DIFFUSE, + LIGHT_AMBIENT, + MULTI_LIGHT_COUNT, + MULTI_LIGHT, + MULTI_LIGHT_COL, + MULTI_LIGHT_FAR_Z, + PROJECTOR_MATRIX, + PROJECTOR_NEAR, + PROJECTOR_P, + PROJECTOR_N, + PROJECTOR_ORIGIN, + PROJECTOR_RANGE, + PROJECTOR_AMBIANCE, + PROJECTOR_SHADOW_INDEX, + PROJECTOR_SHADOW_FADE, + PROJECTOR_FOCUS, + PROJECTOR_LOD, + PROJECTOR_AMBIENT_LOD, + DIFFUSE_COLOR, + HIGHLIGHT_COLOR, + DIFFUSE_MAP, + 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, + LIGHT_CENTER, + LIGHT_SIZE, + LIGHT_FALLOFF, + + GLOW_MIN_LUMINANCE, + GLOW_MAX_EXTRACT_ALPHA, + GLOW_LUM_WEIGHTS, + GLOW_WARMTH_WEIGHTS, + GLOW_WARMTH_AMOUNT, + GLOW_STRENGTH, + GLOW_DELTA, + + DEFERRED_SHADOW_MATRIX, + DEFERRED_ENV_MAT, + DEFERRED_SHADOW_CLIP, + DEFERRED_SUN_WASH, + DEFERRED_SHADOW_NOISE, + DEFERRED_BLUR_SIZE, + DEFERRED_SSAO_RADIUS, + DEFERRED_SSAO_MAX_RADIUS, + DEFERRED_SSAO_FACTOR, + DEFERRED_SSAO_FACTOR_INV, + DEFERRED_SSAO_EFFECT_MAT, + DEFERRED_SCREEN_RES, + DEFERRED_NEAR_CLIP, + DEFERRED_SHADOW_OFFSET, + DEFERRED_SHADOW_BIAS, + DEFERRED_SPOT_SHADOW_BIAS, + DEFERRED_SPOT_SHADOW_OFFSET, + DEFERRED_SUN_DIR, + DEFERRED_SHADOW_RES, + DEFERRED_PROJ_SHADOW_RES, + DEFERRED_DEPTH_CUTOFF, + DEFERRED_NORM_CUTOFF, + + FXAA_TC_SCALE, + FXAA_RCP_SCREEN_RES, + FXAA_RCP_FRAME_OPT, + FXAA_RCP_FRAME_OPT2, + + DOF_FOCAL_DISTANCE, + DOF_BLUR_CONSTANT, + DOF_TAN_PIXEL_ANGLE, + DOF_MAGNIFICATION, + + DEFERRED_DEPTH, + DEFERRED_SHADOW0, + DEFERRED_SHADOW1, + DEFERRED_SHADOW2, + DEFERRED_SHADOW3, + DEFERRED_SHADOW4, + DEFERRED_SHADOW5, + DEFERRED_NORMAL, + DEFERRED_POSITION, + DEFERRED_DIFFUSE, + DEFERRED_SPECULAR, + DEFERRED_NOISE, + DEFERRED_LIGHTFUNC, + DEFERRED_LIGHT, + DEFERRED_BLOOM, + DEFERRED_PROJECTION, + END_RESERVED_UNIFORMS + } eGLSLReservedUniforms; + // singleton pattern implementation static LLShaderMgr * instance(); + virtual void initAttribsAndUniforms(void); + BOOL attachShaderFeatures(LLGLSLShader * shader); void dumpObjectLog(GLhandleARB ret, BOOL warns = TRUE); BOOL linkProgramObject(GLhandleARB obj, BOOL suppress_errors = FALSE); |