From ed1b78e32235680c3978b9830e5ba81115a0ab7d Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Tue, 28 Aug 2012 10:33:32 -0400 Subject: Added support for adding custom preprocessor definitions (for shader permutations) --- indra/llrender/llshadermgr.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index b6a9a6b653..d15584d2e1 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -521,7 +521,7 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns) } } -GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, S32 texture_index_channels) +GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map defines, S32 texture_index_channels) { GLenum error = GL_NO_ERROR; if (gDebugGL) @@ -657,6 +657,15 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade std::string define = "#define " + iter->first + " " + iter->second + "\n"; text[count++] = (GLcharARB *) strdup(define.c_str()); } + + for (std::map::iterator iter = defines.begin(); iter != defines.end(); ++iter) + { + if (iter->first != "NULL") + { + std::string define = "#define " + iter->first + " " + iter->second + "\n"; + text[count++] = (GLcharARB *) strdup(define.c_str()); + } + } if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER_ARB) { @@ -854,7 +863,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade if (shader_level > 1) { shader_level--; - return loadShaderFile(filename,shader_level,type,texture_index_channels); + return loadShaderFile(filename,shader_level,type, defines, texture_index_channels); } LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL; } -- cgit v1.2.3 From c911efb953a600092a6213c088d5b94fcf7779d3 Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Wed, 29 Aug 2012 03:41:26 -0400 Subject: Just pass in an empty preprocessor definition map from now on. The shader compiler won't add new #defines if it's empty. --- indra/llrender/llshadermgr.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'indra/llrender/llshadermgr.cpp') diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp index d15584d2e1..4f7f845c70 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -660,11 +660,8 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade for (std::map::iterator iter = defines.begin(); iter != defines.end(); ++iter) { - if (iter->first != "NULL") - { - std::string define = "#define " + iter->first + " " + iter->second + "\n"; - text[count++] = (GLcharARB *) strdup(define.c_str()); - } + std::string define = "#define " + iter->first + " " + iter->second + "\n"; + text[count++] = (GLcharARB *) strdup(define.c_str()); } if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER_ARB) -- cgit v1.2.3 From d5b45b0b636557333c3408e7a60d5ef587ea99ad Mon Sep 17 00:00:00 2001 From: Jonathan Goodman Date: Wed, 29 Aug 2012 08:02:46 -0400 Subject: Use an unordered map for custom #defines instead of a map. Lookups are faster, and we don't really care about any particular order anyways for these. --- 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 4f7f845c70..3b1ec281c9 100644 --- a/indra/llrender/llshadermgr.cpp +++ b/indra/llrender/llshadermgr.cpp @@ -521,7 +521,7 @@ void LLShaderMgr::dumpObjectLog(GLhandleARB ret, BOOL warns) } } -GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map defines, S32 texture_index_channels) +GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, boost::unordered_map defines, S32 texture_index_channels) { GLenum error = GL_NO_ERROR; if (gDebugGL) @@ -658,7 +658,7 @@ GLhandleARB LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shade text[count++] = (GLcharARB *) strdup(define.c_str()); } - for (std::map::iterator iter = defines.begin(); iter != defines.end(); ++iter) + for (boost::unordered_map::iterator iter = defines.begin(); iter != defines.end(); ++iter) { std::string define = "#define " + iter->first + " " + iter->second + "\n"; text[count++] = (GLcharARB *) strdup(define.c_str()); -- cgit v1.2.3