--- a/CLIParser.h Fri Dec 01 20:25:49 2023 +0100
+++ b/CLIParser.h Fri Dec 01 21:02:02 2023 +0100
@@ -74,9 +74,7 @@
} else if (option == OPTION_SHADER) {
const auto type = readNext(arguments, i);
const auto file = readNext(arguments, i);
- if (type == "fragment") c.fragmentShaders.push_back({file});
- else if (type == "vertex") c.vertexShaders .push_back({file});
- else throw std::invalid_argument("unsupported shader type");
+ c.shaders.push_back({file, type});
} else if (option == OPTION_BACKGROUND_COLOR) {
c.backgroundColor = parseHexColor(readNext(arguments, i));
} else if (option == OPTION_ROOT_WINDOW) {
--- a/Configuration.h Fri Dec 01 20:25:49 2023 +0100
+++ b/Configuration.h Fri Dec 01 21:02:02 2023 +0100
@@ -33,18 +33,19 @@
};
class Shader : public File {
- };
+ public:
+
+ std::string type;
- class VertexShader : public Shader {
- };
+ Shader(const std::string& fileName, const std::string& type) :
+ File(fileName), type(type) {
+ }
- class FragmentShader : public Shader {
};
// TODO: support loading whole directory and monitoring using inotify
std::vector<Texture> textures;
- std::vector<VertexShader> vertexShaders;
- std::vector<FragmentShader> fragmentShaders;
+ std::vector<Shader> shaders;
unsigned long backgroundColor = (0x33 << 16 | 0x33 << 8 | 0x33);
Window rootWindow = 0;
--- a/Shark.cpp Fri Dec 01 20:25:49 2023 +0100
+++ b/Shark.cpp Fri Dec 01 21:02:02 2023 +0100
@@ -376,20 +376,27 @@
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
- std::vector<std::string> fileNames = {
- "shaders/first.vert",
- "shaders/first.frag",
- };
+ if (cfg.shaders.empty()) {
+ // TODO: configurable absolute path or embedded defaults
+ cfg.shaders.push_back({"shaders/first.vert", "vertex"});
+ cfg.shaders.push_back({"shaders/first.frag", "fragment"});
+ }
std::shared_ptr<Program> program = std::make_shared<Program>();
// glBindFragDataLocation(program, 0, "outColor");
// glBindAttribLocation(program, LOC.input, "vertices");
- for (const std::string& fileName : fileNames) {
+ for (const Configuration::Shader definition : cfg.shaders) {
+ Shader::Type type;
+ std::string fileName = definition.fileName;
+ if (definition.type == "fragment") type = Shader::Type::FRAGMENT;
+ else if (definition.type == "vertex") type = Shader::Type::VERTEX;
+ else throw std::invalid_argument("unsupported shader type");
+
MappedFile file(fileName);
std::shared_ptr<Shader> shader = std::make_shared<Shader>(
- toShaderType(fileName), file, fileName);
+ type, file, fileName);
program->attachShader(*shader.get());
shaders.push_back(shader);
--- a/opengl.h Fri Dec 01 20:25:49 2023 +0100
+++ b/opengl.h Fri Dec 01 21:02:02 2023 +0100
@@ -49,13 +49,6 @@
}
inline
-Shader::Type toShaderType(const std::string& fileName) {
- if (fileName.ends_with(".vert")) return Shader::Type::VERTEX;
- else if (fileName.ends_with(".frag")) return Shader::Type::FRAGMENT;
- else throw std::invalid_argument("Expecting *.vert or *.frag file");
-}
-
-inline
void dump(const char* name, const glm::vec3& value) {
std::cerr << "dump: " << name << " = ["
<< value.x << ", "