Added osg::ShaderBinary::readShaderBinaryFile(..) static method

This commit is contained in:
Robert Osfield
2009-11-18 11:25:28 +00:00
parent f8ab593c4b
commit 4262d10217
2 changed files with 30 additions and 7 deletions

View File

@@ -63,7 +63,26 @@ void ShaderBinary::assign(unsigned int size, const unsigned char* data)
}
}
///////////////////////////////////////////////////////////////////////////
ShaderBinary* ShaderBinary::readShaderBinaryFile(const std::string& fileName)
{
std::ifstream fin;
fin.open(fileName.c_str(), std::ios::binary);
if (!fin) return 0;
fin.seekg(0, std::ios::end);
int length = fin.tellg();
if (length==0) return 0;
osg::ref_ptr<ShaderBinary> shaderBinary = new osg::ShaderBinary;
shaderBinary->allocate(length);
fin.seekg(0, std::ios::beg);
fin.read(reinterpret_cast<char*>(shaderBinary->getData()), length);
fin.close();
return shaderBinary.release();
}
///////////////////////////////////////////////////////////////////////////
// static cache of glShaders flagged for deletion, which will actually
// be deleted in the correct GL context.