From 54afbb9ff88f400760dbe3ffd4deb313f52f854e Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 14 Feb 2011 13:50:14 +0000 Subject: [PATCH] From Jahannes Bauerle, "l discovered that the shader class(/src/osg/Shader.cpp) shows wrong behavior when using binary shaders . When shader objects are compared the reference pointer behind the _shaderBinary member is not included in the comparison. I included binary shaders into an osgt model file. These shaders only consists of the binary shader code, I did not supply the text version additionally. When loading the model the osg::Optimizer threw away all shaders except the first one. In the current trunk version of the file two shader objects are identical despite differing _shaderBinary members as the compare method of the Shader class does not include the comparison of that member. The fix in this submission adds the check for identity of the referenced binary shaders to the shader class. When comparing two shader objects with text source shaders the new lines of comparison are not even executed as the comparison returns false in the previous lines when the text shaders differ. With this fix I get expected behavior, the Optimizer handles the different shaders correctly." --- src/osg/Shader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/osg/Shader.cpp b/src/osg/Shader.cpp index ab936775d..9a6977ed6 100644 --- a/src/osg/Shader.cpp +++ b/src/osg/Shader.cpp @@ -271,6 +271,9 @@ int Shader::compare(const Shader& rhs) const if( getShaderSource() < rhs.getShaderSource() ) return -1; if( rhs.getShaderSource() < getShaderSource() ) return 1; + if( getShaderBinary() < rhs.getShaderBinary() ) return -1; + if( rhs.getShaderBinary() < getShaderBinary() ) return 1; + if( getFileName() < rhs.getFileName() ) return -1; if( rhs.getFileName() < getFileName() ) return 1; return 0;