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."
This commit is contained in:
Robert Osfield 2011-02-14 13:50:14 +00:00
parent aca9c9c848
commit 54afbb9ff8

View File

@ -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;