Skip to content

Commit

Permalink
Factorise code
Browse files Browse the repository at this point in the history
  • Loading branch information
Hugues Evrard committed May 3, 2017
1 parent 26cb8c1 commit 8856bec
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions get_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,33 +158,28 @@ int setUniformsFromJSON(const std::string& jsonFilename, const GLuint& program)

// Dispatch to matching init function
std::string uniformFunc = uniformInfo["func"];

// FIXME: can we use a template to factor the following? Hugues
// thinks not since it would required the code to be expanded at
// runtime (not compilation time) from the string obtained when
// reading the JSON file. Proper meta-programming like in LISP could
// do it though.
json args = uniformInfo["args"];

// TODO: check that args has the good number of fields and type

if (uniformFunc == "glUniform1f") {
glUniform1f(uniformLocation, uniformInfo["args"][0]);
glUniform1f(uniformLocation, args[0]);
} else if (uniformFunc == "glUniform2f") {
glUniform2f(uniformLocation, uniformInfo["args"][0], uniformInfo["args"][1]);
glUniform2f(uniformLocation, args[0], args[1]);
} else if (uniformFunc == "glUniform3f") {
glUniform3f(uniformLocation, uniformInfo["args"][0], uniformInfo["args"][1], uniformInfo["args"][2]);
glUniform3f(uniformLocation, args[0], args[1], args[2]);
} else if (uniformFunc == "glUniform4f") {
glUniform4f(uniformLocation, uniformInfo["args"][0], uniformInfo["args"][1], uniformInfo["args"][2], uniformInfo["args"][3]);
glUniform4f(uniformLocation, args[0], args[1], args[2], args[3]);
}

else if (uniformFunc == "glUniform1i") {
glUniform1i(uniformLocation, uniformInfo["args"][0]);
glUniform1i(uniformLocation, args[0]);
} else if (uniformFunc == "glUniform2i") {
glUniform2i(uniformLocation, uniformInfo["args"][0], uniformInfo["args"][1]);
glUniform2i(uniformLocation, args[0], args[1]);
} else if (uniformFunc == "glUniform3i") {
glUniform3i(uniformLocation, uniformInfo["args"][0], uniformInfo["args"][1], uniformInfo["args"][2]);
glUniform3i(uniformLocation, args[0], args[1], args[2]);
} else if (uniformFunc == "glUniform4i") {
glUniform4i(uniformLocation, uniformInfo["args"][0], uniformInfo["args"][1], uniformInfo["args"][2], uniformInfo["args"][3]);
glUniform4i(uniformLocation, args[0], args[1], args[2], args[3]);
}

else {
Expand Down

0 comments on commit 8856bec

Please sign in to comment.