From Bryan Thrall, "The attached ReaderWriterGLSL.cpp conveniently sets the shader type when

the filename extension is "vert" or "frag" but still lets this be
overridden by the Options (for those crazy people who store their
fragment shaders in .vert files :) )."
This commit is contained in:
Robert Osfield 2009-03-13 10:40:00 +00:00
parent f2fb93aeec
commit 9a4e17b766

View File

@ -62,7 +62,17 @@ class ReaderWriterGLSL : public osgDB::ReaderWriter
osgDB::ifstream istream(fileName.c_str(), std::ios::in | std::ios::binary);
if(!istream) return ReadResult::FILE_NOT_HANDLED;
ReadResult rr = readShader(istream, options);
if(rr.validShader()) rr.getShader()->setFileName(file);
if(rr.validShader())
{
osg::Shader* shader = rr.getShader();
shader->setFileName(file);
if (shader->getType() == osg::Shader::UNDEFINED)
{
// set type based on filename extension, where possible
if (ext == "frag") shader->setType(osg::Shader::FRAGMENT);
if (ext == "vert") shader->setType(osg::Shader::VERTEX);
}
}
return rr;
}