diff --git a/src/main.cpp b/src/main.cpp index 4ad4c60..5f4753b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -73,7 +73,7 @@ int main() glfwSetKeyCallback(on_key); emscripten_set_mousemove_callback(nullptr, nullptr, false, on_em_mousemove); - exe = Program("textured").build( + exe = Program(store, "textured").build( __attrib_count, attribs, __uniform_count, uniforms ); diff --git a/src/program.cpp b/src/program.cpp index 0ac12e6..16235b0 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -9,9 +9,9 @@ const std::string Program::filename(const std::string &name) return "/data/shaders/" + name; } -Program::Program(const std::string &name): - vertex_shader(name + ".vert"), - fragment_shader(name + ".frag") +Program::Program(Store &store, const std::string &name): + vertex_shader(store.load(name + ".vert")), + fragment_shader(store.load(name + ".frag")) {} const Executable *Program::build( @@ -20,8 +20,8 @@ const Executable *Program::build( { Executable *exe = new Executable(); - exe->attach_shader(vertex_shader); - exe->attach_shader(fragment_shader); + exe->attach_shader(*vertex_shader); + exe->attach_shader(*fragment_shader); for (GLuint attrib = 0; attrib < attrib_count; ++attrib) exe->bind_attrib_location(attrib, attribs[attrib]); diff --git a/src/program.hpp b/src/program.hpp index d1f6d77..7d248e5 100644 --- a/src/program.hpp +++ b/src/program.hpp @@ -1,13 +1,14 @@ #ifndef _PROGRAM_HPP_ #define _PROGRAM_HPP_ +#include "shader.hpp" #include "executable.hpp" #include struct Program { - Program(const std::string &name); + Program(Store &store, const std::string &name); const Executable *build( GLuint attrib_count, const GLchar *const attribs[], @@ -16,8 +17,8 @@ struct Program private: static const std::string filename(const std::string &name); - const Shader vertex_shader; - const Shader fragment_shader; + const Shader *vertex_shader; + const Shader *fragment_shader; }; #endif // _PROGRAM_HPP_ diff --git a/src/shader.cpp b/src/shader.cpp index 69243c4..a46da58 100644 --- a/src/shader.cpp +++ b/src/shader.cpp @@ -8,7 +8,7 @@ const std::string Shader::filename(const std::string &name) return "/data/shaders/" + name; } -Shader::Shader(const std::string &name) +Shader::Shader(__attribute__((unused)) Store &store, const std::string &name) { const GLuint type = name.substr(name.size() - 5) == ".vert" ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER; diff --git a/src/shader.hpp b/src/shader.hpp index e6fee19..e7ebafd 100644 --- a/src/shader.hpp +++ b/src/shader.hpp @@ -2,17 +2,18 @@ #define _SHADER_HPP_ #include "gl.hpp" +#include "resource.hpp" #include -struct Shader +struct Shader: + Resource { - Shader(const std::string &filename); + RESOURCE(Shader) + inline GLuint id() const { return _id; }; private: - static const std::string filename(const std::string &name); - GLuint _id; };