From 3cac9e9603b17e7a284661dde4d070f9283f6947 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 11 Jan 2011 17:04:37 +0000 Subject: [PATCH] From Glenn Waldron, "Attached is a fix to State::convertVertexShaderSourceToOsgBuiltIns. The method was incorrectly inserting new declarations before a GLSL "#version" directive, which must always be the first line in a shader. This patch detects the #version directive and ensures that new declarations are inserted after it. Attached is the modified State.cpp file. I have also attached a sample transcript, showing the new code working properly. I ran it against osgEarth's shaders and it works as expected. " --- src/osg/State.cpp | 56 +++++++++++++++++++++++++++++------------------ 1 file changed, 35 insertions(+), 21 deletions(-) diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 87f7b3579..0ee645007 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -1265,11 +1265,11 @@ namespace State_Utils return replacedStr; } - void replaceAndInsertDeclaration(std::string& source, const std::string& originalStr, const std::string& newStr, const std::string& declarationPrefix) + void replaceAndInsertDeclaration(std::string& source, std::string::size_type declPos, const std::string& originalStr, const std::string& newStr, const std::string& declarationPrefix) { if (replace(source, originalStr, newStr)) { - source.insert(0, declarationPrefix + newStr + std::string(";\n")); + source.insert(declPos, declarationPrefix + newStr + std::string(";\n")); } } } @@ -1279,32 +1279,46 @@ bool State::convertVertexShaderSourceToOsgBuiltIns(std::string& source) const OSG_NOTICE<<"State::convertShaderSourceToOsgBuiltIns()"<