From 5a8efa16493cdc94bf42a5dcfc155cbe81f9edb7 Mon Sep 17 00:00:00 2001 From: Martin-Kevin Neumann Date: Sun, 15 Jan 2017 14:17:22 +0100 Subject: [PATCH] added refactoring of shader handling from visvalda's fog shader --- apps/openmw/mwrender/water.cpp | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) diff --git a/apps/openmw/mwrender/water.cpp b/apps/openmw/mwrender/water.cpp index 18ef8b560a..b99c128a34 100644 --- a/apps/openmw/mwrender/water.cpp +++ b/apps/openmw/mwrender/water.cpp @@ -30,6 +30,8 @@ #include #include +#include + #include #include @@ -189,29 +191,6 @@ public: } }; -osg::ref_ptr readShader (osg::Shader::Type type, const std::string& file, const std::map& defineMap = std::map()) -{ - osg::ref_ptr shader (new osg::Shader(type)); - - // use boost in favor of osg::Shader::readShaderFile, to handle utf-8 path issues on Windows - boost::filesystem::ifstream inStream; - inStream.open(boost::filesystem::path(file)); - std::stringstream strstream; - strstream << inStream.rdbuf(); - - std::string shaderSource = strstream.str(); - - for (std::map::const_iterator it = defineMap.begin(); it != defineMap.end(); ++it) - { - size_t pos = shaderSource.find(it->first); - if (pos != std::string::npos) - shaderSource.replace(pos, it->first.length(), it->second); - } - - shader->setShaderSource(shaderSource); - return shader; -} - osg::ref_ptr readPngImage (const std::string& file) { // use boost in favor of osgDB::readImage, to handle utf-8 path issues on Windows @@ -524,10 +503,11 @@ void Water::createShaderWaterStateSet(osg::Node* node, Reflection* reflection, R { // use a define map to conditionally compile the shader std::map defineMap; - defineMap.insert(std::make_pair(std::string("@refraction_enabled"), std::string(refraction ? "1" : "0"))); + defineMap.insert(std::make_pair(std::string("refraction_enabled"), std::string(refraction ? "1" : "0"))); - osg::ref_ptr vertexShader (readShader(osg::Shader::VERTEX, mResourcePath + "/shaders/water_vertex.glsl", defineMap)); - osg::ref_ptr fragmentShader (readShader(osg::Shader::FRAGMENT, mResourcePath + "/shaders/water_fragment.glsl", defineMap)); + Shader::ShaderManager& shaderMgr = mResourceSystem->getSceneManager()->getShaderManager(); + osg::ref_ptr vertexShader (shaderMgr.getShader("water_vertex.glsl", defineMap, osg::Shader::VERTEX)); + osg::ref_ptr fragmentShader (shaderMgr.getShader("water_fragment.glsl", defineMap, osg::Shader::FRAGMENT)); osg::ref_ptr normalMap (new osg::Texture2D(readPngImage(mResourcePath + "/shaders/water_nm.png"))); if (normalMap->getImage())