Skip to content

Commit

Permalink
Fix regex when ofShader int define is set to 0. (openframeworks#6608)
Browse files Browse the repository at this point in the history
Co-authored-by: Elie Zananiri <[email protected]>
  • Loading branch information
prisonerjohn and Elie Zananiri authored Aug 9, 2020
1 parent 29f5ede commit a52280c
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions libs/openFrameworks/gl/ofShader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,19 +353,19 @@ bool ofShader::setupShaderFromSource(ofShader::Source && source){
// parse for includes
source.expandedSource = parseForIncludes( source.source, source.directoryPath );

// parse and set defines
for(auto & define: source.intDefines){
const auto & name = define.first;
const auto & value = define.second;
std::regex re_define("#define[ \t]+" + name + "[ \t]+(([1-9][0-9]*)|(0[xX][0-9a-fA-F]+))");
source.expandedSource = std::regex_replace(source.expandedSource, re_define, "#define " + name + " " + std::to_string(value));
}

for(auto & define: source.floatDefines){
const auto & name = define.first;
const auto & value = define.second;
// parse and set defines
for (auto& define : source.intDefines) {
const auto& name = define.first;
const auto& value = define.second;
std::regex re_define("#define[ \t]+" + name + "[ \t]+(([1-9][0-9]*)|(0([xX][0-9a-fA-F]+)?))");
source.expandedSource = std::regex_replace(source.expandedSource, re_define, "#define " + name + " " + std::to_string(value));
}

for (auto& define : source.floatDefines) {
const auto& name = define.first;
const auto& value = define.second;
std::regex re_define("#define[ \t]+" + name + "[ \t]+[0-9]*(\\.[0-9]*f?)?");
source.expandedSource = std::regex_replace(source.expandedSource, re_define, "#define " + name + " " + std::to_string(value));
source.expandedSource = std::regex_replace(source.expandedSource, re_define, "#define " + name + " " + std::to_string(value));
}

// store source code (that's the expanded source with all includes copied in)
Expand Down

0 comments on commit a52280c

Please sign in to comment.