From 38e0b7de96de02243453eeaf5710b924f68abc7a Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 6 Feb 2012 18:56:19 -0600 Subject: SH-2729 Fix for horizontal line of glitching graphics when DoF enabled --- indra/llrender/llshadermgr.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 908443e8cf..d03d349f0f 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -1070,6 +1070,8 @@ void LLShaderMgr::initAttribsAndUniforms() mReservedUniforms.push_back("magnification"); mReservedUniforms.push_back("max_cof"); mReservedUniforms.push_back("res_scale"); + mReservedUniforms.push_back("dof_width"); + mReservedUniforms.push_back("dof_height"); mReservedUniforms.push_back("depthMap"); mReservedUniforms.push_back("shadowMap0"); -- cgit v1.2.3 From 3710c6110d65d3a604f7b419cd764cf5b9b98600 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 10 Feb 2012 20:04:19 -0600 Subject: SH-2908 Rework indexed texture rendering to use a uvec4 instead of a float for texture indices in the data stream. Also rework gl_FragColor overrides to not collide with some odd driver implementations. --- indra/llrender/llshadermgr.cpp | 92 ++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 49 deletions(-) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index d03d349f0f..321b139181 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -575,31 +575,39 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade 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.3f) + S32 major_version = gGLManager.mGLSLVersionMajor; + S32 minor_version = gGLManager.mGLSLVersionMinor; + + if (major_version == 1 && minor_version < 30) { - //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"); + if (minor_version < 10) + { + //should NEVER get here -- if major version is 1 and minor version is less than 10, + // viewer should never attempt to use shaders, continuing will result in undefined behavior + llerrs << "Unsupported GLSL Version." << llendl; + } + + if (minor_version <= 19) + { + text[count++] = strdup("#version 110\n"); + text[count++] = strdup("#define ATTRIBUTE attribute\n"); + text[count++] = strdup("#define VARYING varying\n"); + text[count++] = strdup("#define VARYING_FLAT varying\n"); + } + else if (minor_version <= 29) + { + //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"); + text[count++] = strdup("#define VARYING_FLAT varying\n"); + } } else { - if (version < 4.f) + if (major_version < 4) { //set version to 1.30 text[count++] = strdup("#version 130\n"); @@ -618,13 +626,17 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade { //"varying" state is "out" in a vertex program, "in" in a fragment program // ("varying" is deprecated after version 1.20) text[count++] = strdup("#define VARYING out\n"); + text[count++] = strdup("#define VARYING_FLAT flat out\n"); } else { text[count++] = strdup("#define VARYING in\n"); + text[count++] = strdup("#define VARYING_FLAT flat in\n"); } //backwards compatibility with legacy texture lookup syntax + text[count++] = strdup("#define texture2D texture\n"); + text[count++] = strdup("#define texture2DRect texture\n"); text[count++] = strdup("#define textureCube texture\n"); text[count++] = strdup("#define texture2DLod textureLod\n"); text[count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); @@ -651,11 +663,11 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade . uniform sampler2D texN; - VARYING float vary_texture_index; + VARYING uvec4 vary_texture_index; vec4 diffuseLookup(vec2 texcoord) { - switch (int(vary_texture_index+0.25)) + switch (vary_texture_index.r)) { case 0: return texture2D(tex0, texcoord); case 1: return texture2D(tex1, texcoord); @@ -679,7 +691,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (texture_index_channels > 1) { - text[count++] = strdup("VARYING float vary_texture_index;\n"); + text[count++] = strdup("VARYING_FLAT uvec4 vary_texture_index;\n"); } text[count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n"); @@ -691,9 +703,9 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade text[count++] = strdup("return texture2D(tex0, texcoord);\n"); text[count++] = strdup("}\n"); } - else if (gGLManager.mGLVersion >= 3.f) - { - text[count++] = strdup("\tswitch (int(vary_texture_index+0.25))\n"); + else if (major_version > 1 || minor_version >= 30) + { //switches are supported in GLSL 1.30 and later + text[count++] = strdup("\tswitch (vary_texture_index.r)\n"); text[count++] = strdup("\t{\n"); //switch body @@ -708,28 +720,10 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade text[count++] = strdup("}\n"); } else - { - //switches aren't supported, make block that looks like: - /* - int ti = int(vary_texture_index+0.25); - if (ti == 0) return texture2D(tex0, texcoord); - if (ti == 1) return texture2D(tex1, texcoord); - . - . - . - if (ti == N) return texture2D(texN, texcoord); - */ - - text[count++] = strdup("int ti = int(vary_texture_index+0.25);\n"); - for (S32 i = 0; i < texture_index_channels; ++i) - { - std::string if_str = llformat("if (ti == %d) return texture2D(tex%d, texcoord);\n", i, i); - text[count++] = strdup(if_str.c_str()); - } - - text[count++] = strdup("\treturn vec4(1,0,1,1);\n"); - text[count++] = strdup("}\n"); - } + { //should never get here. Indexed texture rendering requires GLSL 1.30 or later + // (for passing integers between vertex and fragment shaders) + llerrs << "Indexed texture rendering requires GLSL 1.30 or later." << llendl; + } } //copy file into memory -- cgit v1.2.3 From 76a27f5100666739aae53c0988318a6dae647666 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Mon, 13 Feb 2012 13:55:51 -0600 Subject: SH-2964 Fix for shader compilation error on some older NVIDIA cards. --- indra/llrender/llshadermgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 321b139181..269f78c8cd 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -663,7 +663,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade . uniform sampler2D texN; - VARYING uvec4 vary_texture_index; + VARYING ivec4 vary_texture_index; vec4 diffuseLookup(vec2 texcoord) { @@ -691,7 +691,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (texture_index_channels > 1) { - text[count++] = strdup("VARYING_FLAT uvec4 vary_texture_index;\n"); + text[count++] = strdup("VARYING_FLAT ivec4 vary_texture_index;\n"); } text[count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n"); -- cgit v1.2.3 From 8d12038ef674dca701f313431b1089458816f638 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Fri, 17 Feb 2012 15:06:48 -0600 Subject: SH-2908 Potential fix for precision complaints from some AMD OpenGL 3.1 implementations. --- indra/llrender/llshadermgr.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 269f78c8cd..9aeb1a99f8 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -611,6 +611,9 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade { //set version to 1.30 text[count++] = strdup("#version 130\n"); + + //some implementations of GLSL 1.30 require integer precision be explicitly declared + text[count++] = strdup("precision mediump int;\n"); } else { //set version to 400 @@ -663,7 +666,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade . uniform sampler2D texN; - VARYING ivec4 vary_texture_index; + VARYING_FLAT ivec4 vary_texture_index; vec4 diffuseLookup(vec2 texcoord) { -- cgit v1.2.3 From e1a71a97cd00d70fedeb6191b6ebb10361019ee1 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 21 Feb 2012 14:02:09 -0600 Subject: SH-2908 Potential fix for pink textures on some OpenGL 3.1 implementations. --- indra/llrender/llshadermgr.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index 9aeb1a99f8..e1cd8fa62d 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -614,6 +614,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade //some implementations of GLSL 1.30 require integer precision be explicitly declared text[count++] = strdup("precision mediump int;\n"); + text[count++] = strdup("precision highp float;\n"); } else { //set version to 400 @@ -668,20 +669,22 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade VARYING_FLAT ivec4 vary_texture_index; + vec4 ret = vec4(1,0,1,1); + vec4 diffuseLookup(vec2 texcoord) { switch (vary_texture_index.r)) { - case 0: return texture2D(tex0, texcoord); - case 1: return texture2D(tex1, texcoord); - case 2: return texture2D(tex2, texcoord); + case 0: ret = texture2D(tex0, texcoord); break; + case 1: ret = texture2D(tex1, texcoord); break; + case 2: ret = texture2D(tex2, texcoord); break; . . . - case N: return texture2D(texN, texcoord); + case N: return texture2D(texN, texcoord); break; } - return vec4(0,0,0,0); + return ret; } */ @@ -708,18 +711,19 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade } else if (major_version > 1 || minor_version >= 30) { //switches are supported in GLSL 1.30 and later + text[count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n"); text[count++] = strdup("\tswitch (vary_texture_index.r)\n"); text[count++] = strdup("\t{\n"); //switch body for (S32 i = 0; i < texture_index_channels; ++i) { - std::string case_str = llformat("\t\tcase %d: return texture2D(tex%d, texcoord);\n", i, i); + std::string case_str = llformat("\t\tcase %d: ret = texture2D(tex%d, texcoord); break;\n", i, i); text[count++] = strdup(case_str.c_str()); } text[count++] = strdup("\t}\n"); - text[count++] = strdup("\treturn vec4(1,0,1,1);\n"); + text[count++] = strdup("\treturn ret;\n"); text[count++] = strdup("}\n"); } else -- cgit v1.2.3 From 8f261582b80d7d4a61cf8bb42c0429fa58f0c186 Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Wed, 22 Feb 2012 14:30:24 -0600 Subject: SH-2908 Fix for crash when enabling Lighting and Shadows on some AMD GPUs --- indra/llrender/llshadermgr.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index e1cd8fa62d..b28a97adaa 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -644,6 +644,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade text[count++] = strdup("#define textureCube texture\n"); text[count++] = strdup("#define texture2DLod textureLod\n"); text[count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); + text[count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n"); } //copy preprocessor definitions into buffer -- cgit v1.2.3 From 353907bac61e6db0aca16e7e43f13f627b414dca Mon Sep 17 00:00:00 2001 From: Dave Parks Date: Tue, 28 Feb 2012 16:10:04 -0600 Subject: SH-2908 Fix for incompatibility issue with GLSL 1.30 --- indra/llrender/llshadermgr.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index b28a97adaa..7d384450e6 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -640,11 +640,15 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade //backwards compatibility with legacy texture lookup syntax text[count++] = strdup("#define texture2D texture\n"); - text[count++] = strdup("#define texture2DRect texture\n"); text[count++] = strdup("#define textureCube texture\n"); text[count++] = strdup("#define texture2DLod textureLod\n"); text[count++] = strdup("#define shadow2D(a,b) vec2(texture(a,b))\n"); - text[count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n"); + + if (major_version > 1 || minor_version >= 40) + { //GLSL 1.40 replaces texture2DRect et al with texture + text[count++] = strdup("#define texture2DRect texture\n"); + text[count++] = strdup("#define shadow2DRect(a,b) vec2(texture(a,b))\n"); + } } //copy preprocessor definitions into buffer -- cgit v1.2.3