From 9fa3defb0ef4b1c32908cfce1d2b14bd221fc5e8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 11 Feb 2015 16:41:31 +0000 Subject: [PATCH] Added reassignment of the #version line to the first entry in the source list. git-svn-id: http://svn.openscenegraph.org/osg/OpenSceneGraph/trunk@14688 16af8721-9629-0410-8352-f15c8da7e697 --- src/osg/Shader.cpp | 49 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index b9896ab28..d271f3596 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -634,10 +634,51 @@ void Shader::PerContextShader::compileShader(osg::State& state) } else { - const GLchar* sourceText[2]; - sourceText[0] = reinterpret_cast(_defineStr.c_str()); - sourceText[1] = reinterpret_cast(source.c_str()); - _extensions->glShaderSource( _glShaderHandle, 2, sourceText, NULL ); + + std::string versionLine; + unsigned int lineNum = 0; + std::string::size_type previous_pos = 0; + do + { + std::string::size_type start_of_line = source.find_first_not_of(" \t", previous_pos); + std::string::size_type end_of_line = (start_of_line != std::string::npos) ? source.find_first_of("\n\r", start_of_line) : std::string::npos; + if (end_of_line != std::string::npos) + { + // OSG_NOTICE<<"A Checking line "<=8 && source.compare(start_of_line, 8, "#version")==0) + { + versionLine = source.substr(start_of_line, end_of_line-start_of_line+1); + source.insert(start_of_line, "// following version spec has been automatically reassigned to start of source list: "); + //source.erase(start_of_line, end_of_line-start_of_line); + break; + } + previous_pos = end_of_line+1(versionLine.c_str()); + sourceText[1] = reinterpret_cast(_defineStr.c_str()); + sourceText[2] = reinterpret_cast(source.c_str()); + _extensions->glShaderSource( _glShaderHandle, 3, sourceText, NULL ); + } + else + { + const GLchar* sourceText[2]; + sourceText[0] = reinterpret_cast(_defineStr.c_str()); + sourceText[1] = reinterpret_cast(source.c_str()); + _extensions->glShaderSource( _glShaderHandle, 2, sourceText, NULL ); + } } _extensions->glCompileShader( _glShaderHandle ); _extensions->glGetShaderiv( _glShaderHandle, GL_COMPILE_STATUS, &compiled );