From 7e6e2ec813f4443cf69831ee57f1abb1e8b78b77 Mon Sep 17 00:00:00 2001 From: Meoweg Date: Fri, 13 Nov 2015 13:10:49 +0000 Subject: [PATCH] Redesign program --- src/main.cpp | 4 +--- src/program.cpp | 6 +++++- src/program.hpp | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 352e18a..abba5c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,9 +72,7 @@ int main() glfwSetKeyCallback(on_key); emscripten_set_mousemove_callback(nullptr, nullptr, false, on_em_mousemove); - Program *program = new Program("textured"); - program->bind_attribs(__count, attribs); - program->link(); + const Program *program = Program("textured").build(__count, attribs); program->use(); diff --git a/src/program.cpp b/src/program.cpp index 240fadb..a742d59 100644 --- a/src/program.cpp +++ b/src/program.cpp @@ -27,10 +27,14 @@ void Program::bind_attrib_location(GLuint index, const GLchar *name) glBindAttribLocation(_id, index, name); } -void Program::bind_attribs(GLuint count, const GLchar *const names[]) +const Program *Program::build(GLuint count, const GLchar *const names[]) { for (GLuint index = 0; index < count; ++index) bind_attrib_location(index, names[index]); + + link(); + + return this; } void Program::link() diff --git a/src/program.hpp b/src/program.hpp index 1a18577..95487b9 100644 --- a/src/program.hpp +++ b/src/program.hpp @@ -9,10 +9,7 @@ struct Program { Program(const std::string &name); - void bind_attrib_location(GLuint index, const GLchar *name); - void bind_attribs(GLuint count, const GLchar *const names[]); - - void link(); + const Program *build(GLuint count, const GLchar *const names[]); void use() const; GLuint get_uniform_location(const GLchar *name) const; @@ -20,6 +17,9 @@ struct Program private: static const std::string filename(const std::string &name); + void bind_attrib_location(GLuint index, const GLchar *name); + void link(); + GLuint _id; };