|
From: Lasse Kärkkäi. <tr...@us...> - 2011-03-13 00:50:15
|
Author: Lasse Karkkainen <tro...@tr...> Date: Sun Mar 6 23:15:10 2011 +0100 Re-enable bogus (the old problem remains) and improve the shader defines system. --- data/shaders/core.frag | 8 ++++++++ data/shaders/stereo3d.geom | 2 ++ game/glshader.hh | 2 +- game/video_driver.cc | 19 ++++++++++++++----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/data/shaders/core.frag b/data/shaders/core.frag index 78a3c87..f7c7e28 100644 --- a/data/shaders/core.frag +++ b/data/shaders/core.frag @@ -5,6 +5,10 @@ uniform mat4 colorMatrix; +#ifdef ENABLE_BOGUS +in float bogus; // Workaround for http://www.nvnews.net/vbulletin/showthread.php?p=2401097 +#endif + in vec3 normal; in vec4 color; @@ -28,6 +32,10 @@ uniform sampler2D tex; void main() { vec4 frag = TEXFUNC; +#ifdef ENABLE_BOGUS + frag.a += 1e-14 * bogus; // Convince the compiler not to optimize away the bogus variable +#endif + #ifdef ENABLE_VERTEX_COLOR frag *= color; #endif diff --git a/data/shaders/stereo3d.geom b/data/shaders/stereo3d.geom index 4fa2f7a..c6522c1 100644 --- a/data/shaders/stereo3d.geom +++ b/data/shaders/stereo3d.geom @@ -11,6 +11,7 @@ in vec4 vTexCoord[]; in vec3 vNormal[]; in vec4 vColor[]; +out float bogus; // Workaround for http://www.nvnews.net/vbulletin/showthread.php?p=2401097 out vec4 texCoord; out vec3 normal; out vec4 color; @@ -28,6 +29,7 @@ void passthru() { #define PROCESS(code) i = 0; do { passthru(); code; EmitVertex(); } while (++i < gl_in.length()); EndPrimitive(); void main() { + bogus = 0.0; if (sepFactor == 0.0) { gl_ViewportIndex = 0; PROCESS(); // No stereo } else { diff --git a/game/glshader.hh b/game/glshader.hh index 4a08121..22f12ff 100644 --- a/game/glshader.hh +++ b/game/glshader.hh @@ -16,7 +16,7 @@ struct Shader: public boost::noncopyable { Shader(std::string const& name); ~Shader(); /// Set a string that will replace "//DEFINES" in anything loaded by compileFile - Shader& setDefines(std::string const& defines) { defs = defines; return *this; } + Shader& addDefines(std::string const& defines) { defs += defines; return *this; } /// Load shader from file Shader& compileFile(std::string const& filename); /** Compiles a shader of a given type. */ diff --git a/game/video_driver.cc b/game/video_driver.cc index 01c712d..47b9116 100644 --- a/game/video_driver.cc +++ b/game/video_driver.cc @@ -81,38 +81,47 @@ Window::Window(unsigned int width, unsigned int height, bool fs): m_windowW(widt shader("texture").compileFile(getThemePath("shaders/stereo3d.geom")); shader("3dobject").compileFile(getThemePath("shaders/stereo3d.geom")); shader("dancenote").compileFile(getThemePath("shaders/stereo3d.geom")); + if (!GLEW_VERSION_4_1) { + // Enable bugfix for some older Nvidia cards + for (ShaderMap::iterator it = m_shaders.begin(); it != m_shaders.end(); ++it) { + Shader& sh = *it->second; + sh.addDefines("#define ENABLE_BOGUS\n"); + } + } } shader("color") - .setDefines("#define ENABLE_VERTEX_COLOR\n") + .addDefines("#define ENABLE_VERTEX_COLOR\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("surface") - .setDefines("#define ENABLE_TEXTURING 1\n") + .addDefines("#define ENABLE_TEXTURING 1\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("texture") - .setDefines("#define ENABLE_TEXTURING 2\n#define ENABLE_VERTEX_COLOR\n") + .addDefines("#define ENABLE_TEXTURING 2\n") + .addDefines("#define ENABLE_VERTEX_COLOR\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("3dobject") - .setDefines("#define ENABLE_LIGHTING\n") + .addDefines("#define ENABLE_LIGHTING\n") .compileFile(getThemePath("shaders/core.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() .bind() .setUniformMat4("colorMatrix", glmath::mat4::identity()); shader("dancenote") - .setDefines("#define ENABLE_TEXTURING 2\n#define ENABLE_VERTEX_COLOR\n") + .addDefines("#define ENABLE_TEXTURING 2\n") + .addDefines("#define ENABLE_VERTEX_COLOR\n") .compileFile(getThemePath("shaders/dancenote.vert")) .compileFile(getThemePath("shaders/core.frag")) .link() |