cli arg for base program

This commit is contained in:
Christoph J. Scherr 2023-10-20 15:10:14 +02:00
parent fe00f536bd
commit 743e7d14ca
3 changed files with 43 additions and 10 deletions

View File

@ -1,4 +1,6 @@
#include <boost/algorithm/string/case_conv.hpp>
#include <boost/log/trivial.hpp>
#include <boost/algorithm/string.hpp>
#include <exception>
#include <glad/glad.c>
// glad must be loaded before GLFW
@ -9,6 +11,22 @@
using namespace std;
ShaderProgram::Base ShaderProgram::baseFromName(string name) {
string lname = name;
boost::algorithm::to_lower(lname); // yes, cpp needs a library to do this.
// can't do a switch over strings in cpp.
if (lname == "empty") {
return Empty;
}
if (lname == "triangle") {
return Triangle;
}
else {
BOOST_LOG_TRIVIAL(fatal) << "unknown base program \"" << name << "\"";
exit(EXIT_USAGE);
}
}
/* class ShaderProgram Implementations */
string ShaderProgram::baseName() {
/*
@ -64,6 +82,8 @@ int ShaderProgram::run() {
return 0;
}
/* functions that run out graphics stuff */
void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
glViewport(0, 0, width, height);
}

View File

@ -9,6 +9,7 @@ class ShaderProgram {
public:
enum Base { Empty, Triangle };
std::string baseName();
static Base baseFromName(std::string name);
ShaderProgram(Base base, char** vertexSource, char** fragSource);
int run();

View File

@ -15,14 +15,15 @@ int main(int argc, char **argv) {
po::options_description desc("Available options");
desc.add_options()("help,h", "show help")("verbose,v", "more verbose output")(
"vert", po::value<string>()->required(), "vertex shader file")(
"frag", po::value<string>()->required(), "fragment shader file");
"frag", po::value<string>()->required(), "fragment shader file")(
"base,b", po::value<string>()->required(), "base program");
/* unused for now */
po::positional_options_description pdesc;
// NOTE: if you want to add a positional argument,
// you need to create and option for it as it seems.
pdesc.add("vert", 1);
pdesc.add("frag", 1);
/* pdesc.add("vert", 1); */
/* pdesc.add("frag", 1); */
po::variables_map vm;
try {
@ -59,6 +60,9 @@ int main(int argc, char **argv) {
return EXIT_GL;
}
/* find the requested */
ShaderProgram::Base base = ShaderProgram::baseFromName(vm["base"].as<string>());
/* setup the shader program */
BOOST_LOG_TRIVIAL(trace) << "Reading shader files";
auto fvert = fopen(vm["vert"].as<string>().c_str(), "r");
@ -79,9 +83,11 @@ int main(int argc, char **argv) {
char *frag = (char *)malloc(sfrag + 1);
fread(vert, sizeof(char), svert, fvert);
fread(frag, sizeof(char), sfrag, ffrag);
BOOST_LOG_TRIVIAL(debug) << "vert file:\n```glsl\n" << vert << "```\n"
BOOST_LOG_TRIVIAL(debug) << "vert file:\n```glsl\n"
<< vert << "```\n"
<< svert << "B";
BOOST_LOG_TRIVIAL(debug) << "frag file:\n```glsl\n" << frag << "```\n"
BOOST_LOG_TRIVIAL(debug) << "frag file:\n```glsl\n"
<< frag << "```\n"
<< sfrag << "B";
fclose(fvert);
fclose(ffrag);
@ -89,7 +95,7 @@ int main(int argc, char **argv) {
BOOST_LOG_TRIVIAL(trace) << "Creating ShaderProgram";
// TODO: determinde ShaderProgram::Base with a CLI arg
ShaderProgram shaderProgram(ShaderProgram::Base::Empty, &vert, &frag);
ShaderProgram shaderProgram(base, &vert, &frag);
/* Run our main program */
BOOST_LOG_TRIVIAL(trace) << "Starting mainWindow";
@ -106,12 +112,18 @@ void help(char *prog, po::options_description desc) {
<< endl
<< endl
<< "return values:" << endl
<< "0\tSuccess"
<< "1\tGeneric Failure"
<< "2\tBad arguments"
<< "0\tSuccess" << endl
<< "1\tGeneric Failure" << endl
<< "2\tBad arguments" << endl
<< "3\tI/O Error" << endl
<< "3\tOpenGL Error" << endl
<< endl
<< endl
<< "base programs:" << endl
<< "Empty\t\t-\tEmpty window with colored background" << endl
<< "Triangle\t-\tA static Triangle" << endl
<< endl
<< endl
<< desc << endl;
// NOTE: constants for the error codes are defined in main.hpp
}