Conflicts:
	indra/newview/app_settings/shaders/class2/effects/gaussBlurF.glsl
	indra/newview/llmanipscale.cpp
	indra/newview/llmeshrepository.cpp
	indra/newview/llviewerregion.cpp
	indra/newview/llvovolume.cpp
This commit is contained in:
Siana Gearz
2011-12-24 20:12:12 +01:00
528 changed files with 24927 additions and 13128 deletions

View File

@@ -2,31 +2,25 @@
* @file llshadermgr.cpp
* @brief Shader manager implementation.
*
* $LicenseInfo:firstyear=2005&license=viewergpl$
*
* Copyright (c) 2005-2009, Linden Research, Inc.
*
* $LicenseInfo:firstyear=2005&license=viewerlgpl$
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
* Copyright (C) 2010, Linden Research, Inc.
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at
* http://secondlifegrid.net/programs/open_source/licensing/flossexception
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
* $/LicenseInfo$
*/
@@ -89,7 +83,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
// NOTE order of shader object attaching is VERY IMPORTANT!!!
if (features->calculatesAtmospherics)
{
if (!shader->attachObject("windlight/atmosphericsVarsV.glsl"))
if (features->hasWaterFog)
{
if (!shader->attachObject("windlight/atmosphericsVarsWaterV.glsl"))
{
return FALSE;
}
}
else if (!shader->attachObject("windlight/atmosphericsVarsV.glsl"))
{
return FALSE;
}
@@ -109,9 +110,13 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
return FALSE;
}
if (!shader->attachObject("lighting/sumLightsSpecularV.glsl"))
if (!features->isAlphaLighting)
{
return FALSE;
if (!shader->attachObject("lighting/sumLightsSpecularV.glsl"))
{
return FALSE;
}
}
if (!shader->attachObject("lighting/lightSpecularV.glsl"))
@@ -126,9 +131,12 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
return FALSE;
}
if (!shader->attachObject("lighting/sumLightsV.glsl"))
if (!features->isAlphaLighting)
{
return FALSE;
if (!shader->attachObject("lighting/sumLightsV.glsl"))
{
return FALSE;
}
}
if (!shader->attachObject("lighting/lightV.glsl"))
@@ -155,7 +163,6 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
}
}
#if MESH_ENABLED
if (features->hasObjectSkinning)
{
if (!shader->attachObject("avatar/objectSkinV.glsl"))
@@ -163,7 +170,6 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
return FALSE;
}
}
#endif //MESH_ENABLED
///////////////////////////////////////
// Attach Fragment Shader Features Next
@@ -171,7 +177,14 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
if(features->calculatesAtmospherics)
{
if (!shader->attachObject("windlight/atmosphericsVarsF.glsl"))
if (features->hasWaterFog)
{
if (!shader->attachObject("windlight/atmosphericsVarsWaterF.glsl"))
{
return FALSE;
}
}
else if (!shader->attachObject("windlight/atmosphericsVarsF.glsl"))
{
return FALSE;
}
@@ -453,6 +466,22 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
}
}
}
if (features->mIndexedTextureChannels <= 1)
{
if (!shader->attachObject("objects/nonindexedTextureV.glsl"))
{
return FALSE;
}
}
else
{
if (!shader->attachObject("objects/indexedTextureV.glsl"))
{
return FALSE;
}
}
return TRUE;
}
@@ -542,28 +571,48 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
}
//we can't have any lines longer than 1024 characters
//or any shaders longer than 1024 lines... deal - DaveP
//or any shaders longer than 4096 lines... deal - DaveP
GLcharARB buff[1024];
GLcharARB* text[4096];
GLuint count = 0;
F32 version = gGLManager.mGLVersion;
//hack to never use GLSL > 1.20 on OSX
#if LL_DARWIN
version = llmin(version, 2.9f);
#endif
if (version < 2.1f)
{
text[count++] = strdup("#version 110\n");
text[count++] = strdup("#define ATTRIBUTE attribute\n");
text[count++] = strdup("#define VARYING varying\n");
}
else if (version < 3.f)
else if (version < 3.3f)
{
//set version to 1.20
text[count++] = strdup("#version 120\n");
text[count++] = strdup("#define FXAA_GLSL_120 1\n");
text[count++] = strdup("#define FXAA_FAST_PIXEL_OFFSET 0\n");
text[count++] = strdup("#define ATTRIBUTE attribute\n");
text[count++] = strdup("#define VARYING varying\n");
}
else
{ //set version to 1.30
text[count++] = strdup("#version 130\n");
{
if (version < 4.f)
{
//set version to 1.30
text[count++] = strdup("#version 130\n");
}
else
{ //set version to 400
text[count++] = strdup("#version 400\n");
}
text[count++] = strdup("#define DEFINE_GL_FRAGCOLOR 1\n");
text[count++] = strdup("#define FXAA_GLSL_130 1\n");
text[count++] = strdup("#define ATTRIBUTE in\n");
if (type == GL_VERTEX_SHADER_ARB)
@@ -585,10 +634,6 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade
text[count++] = strdup("#define texture2D texture\n");
text[count++] = strdup("#define texture2DRect texture\n");
text[count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n");
//Will go away soon:
text[count++] = strdup("#define ftransform() gl_ModelViewProjectionMatrix * gl_Vertex\n");
}
//copy preprocessor definitions into buffer
@@ -856,28 +901,42 @@ BOOL LLShaderMgr::linkProgramObject(GLhandleARB obj, BOOL suppress_errors)
LL_WARNS("ShaderLoading") << "GLSL Linker Error:" << LL_ENDL;
}
// NOTE: Removing LL_DARWIN block as it doesn't seem to actually give the correct answer,
// but want it for reference once I move it.
#if 0
// Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software
// per Apple's suggestion
glBegin(gGL.mMode);
glEnd();
#if LL_DARWIN
// Query whether the shader can or cannot run in hardware
// http://developer.apple.com/qa/qa2007/qa1502.html
long vertexGPUProcessing;
CGLContextObj ctx = CGLGetCurrentContext();
CGLGetParameter (ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing);
long fragmentGPUProcessing;
CGLGetParameter (ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing);
if (!fragmentGPUProcessing || !vertexGPUProcessing)
// For some reason this absolutely kills the frame rate when VBO's are enabled
if (0)
{
LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL;
success = GL_FALSE;
suppress_errors = FALSE;
// Force an evaluation of the gl state so the driver can tell if the shader will run in hardware or software
// per Apple's suggestion
LLGLSLShader::sNoFixedFunction = false;
glUseProgramObjectARB(obj);
gGL.begin(LLRender::TRIANGLES);
gGL.vertex3f(0.0f, 0.0f, 0.0f);
gGL.vertex3f(0.0f, 0.0f, 0.0f);
gGL.vertex3f(0.0f, 0.0f, 0.0f);
gGL.end();
gGL.flush();
glUseProgramObjectARB(0);
LLGLSLShader::sNoFixedFunction = true;
// Query whether the shader can or cannot run in hardware
// http://developer.apple.com/qa/qa2007/qa1502.html
GLint vertexGPUProcessing, fragmentGPUProcessing;
CGLContextObj ctx = CGLGetCurrentContext();
CGLGetParameter(ctx, kCGLCPGPUVertexProcessing, &vertexGPUProcessing);
CGLGetParameter(ctx, kCGLCPGPUFragmentProcessing, &fragmentGPUProcessing);
if (!fragmentGPUProcessing || !vertexGPUProcessing)
{
LL_WARNS("ShaderLoading") << "GLSL Linker: Running in Software:" << LL_ENDL;
success = GL_FALSE;
suppress_errors = FALSE;
}
}
#else
std::string log = get_object_log(obj);
LLStringUtil::toLower(log);
@@ -915,3 +974,181 @@ 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("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_copy");
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("minimum_alpha");
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("max_cof");
mReservedUniforms.push_back("res_scale");
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]);
}
}