?
Hab jetzt eine relativ einfache Lösung gefunden:
bool NLShaderLoader::saveShader( const char* filename, const std::string& vertex, const std::string& fragment )
{
// Create standard ofstream
std::ofstream file(filename, std::ios_base::out|std::ios_base::binary);
assert(file.good());
if ( file.is_open() )
{
// Create filter
bi::filtering_ostream out;
out.push(bi::zlib_compressor());
out.push(file);
// Write source
out << vertex << "\n";
out << "//--[[]]--\n";
out << fragment << "\n";
}
return true;
}
bool NLShaderLoader::loadShader( const std::string& name, const char* filename, std::string& o_vertex, std::string& o_fragment )
{
std::ifstream file(filename, std::ios_base::in|std::ios_base::binary);
assert(file.good());
if ( file.is_open() )
{
std::stringstream vertex, fragment;
// Create filter
bi::filtering_istream in;
in.push(bi::zlib_decompressor());
in.push(file);
std::stringstream ss;
bi::copy( in, ss );
// Read Vertex Shader
{
std::string line;
do
{
std::getline(ss, line);
if ( line != "//--[[]]--")
{
vertex << line << "\n";
}
}while( line != "//--[[]]--");
}
// Read Fragment Shader
{
std::string line;
do
{
std::getline(ss, line);
fragment << line << "\n";
}while( !ss.eof() );
}
o_vertex = vertex.str();
o_fragment = fragment.str();
return true;
}
return false;
}
Die Herausforderung ist, zwischen den beiden Teilen zu unterscheiden. Das einfachste schien es mir, einen "Tag", in dem Fall "//--[[]]--" zu reservieren, der im normalen Code nicht vorkommen sollte.
Falls jemand noch bessere Lösungen hat, immer her damit :).