30 #include <boost/regex.hpp>
32 #include "../../common/WLogger.h"
33 #include "../../common/WStringUtils.h"
35 #include "WGEShaderVersionPreprocessor.h"
59 static const boost::regex versionRegexp(
"^[ ]*#[ ]*version[ ]+([123456789][0123456789][0123456789]).*$" );
63 boost::smatch matches;
64 bool foundVersion =
false;
65 unsigned int version = 120;
66 std::stringstream completeCode( code );
67 std::ostringstream cleanedCode;
68 while( std::getline( completeCode, line ) )
70 if( boost::regex_match( line, matches, versionRegexp ) )
72 unsigned int versionNum = string_utils::fromString< unsigned int >( matches[1] );
73 version = std::max( versionNum, version );
75 cleanedCode <<
"// " << line << std::endl;
79 cleanedCode << line << std::endl;
85 wlog::warn(
"WGEShader (" + file +
")" ) <<
"No version statements in unrolled shader file \"" << file <<
"\" found. Using default: "
91 vs <<
"#version " << version << std::endl
92 <<
"#line 1 " << std::endl << cleanedCode.str();
bool getActive() const
If the preprocessor is active, this returns true.
virtual ~WGEShaderVersionPreprocessor()
Destructor.
WGEShaderVersionPreprocessor()
Default constructor.
virtual std::string process(const std::string &file, const std::string &code) const
Process the whole code.
WStreamedLogger warn(const std::string &source)
Logging a warning message.