--- 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);