From 34052b51e00c939a35294d7085cadb5111484dd3 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 26 May 2018 13:20:47 +0200 Subject: Separate headers into compilation units --- src/shader/wrap/graphic_shader.h | 51 ++++++++++++---------------------------- 1 file changed, 15 insertions(+), 36 deletions(-) (limited to 'src/shader/wrap/graphic_shader.h') diff --git a/src/shader/wrap/graphic_shader.h b/src/shader/wrap/graphic_shader.h index 03249d5..82f7e7a 100644 --- a/src/shader/wrap/graphic_shader.h +++ b/src/shader/wrap/graphic_shader.h @@ -1,5 +1,11 @@ #pragma once +#include +#include + +#include +#include + #include "shader/util.h" class GraphicShader { @@ -10,43 +16,16 @@ public: struct Guard { const GLuint _id; - Guard(GLuint id): _id(id) { - glUseProgram(_id); - } - ~Guard() { - glUseProgram(0); - } + Guard(GLuint id); + ~Guard(); }; - Guard use() const { - return Guard(_id); - } + Guard use() const; - GraphicShader(const std::string& vertex, const std::string fragment): - _id(glCreateProgram()) { - glAttachShader(_id, util::compileShader(vertex, GL_VERTEX_SHADER)); - glAttachShader(_id, util::compileShader(fragment, GL_FRAGMENT_SHADER)); - glLinkProgram(_id); - }; - ~GraphicShader() { - glDeleteProgram(_id); - } - - GLuint setUniform(const std::string& name, int value) const { - GLuint id = util::getUniform(_id, name); - glUniform1i(id, value); - return id; - } - - GLuint setUniform(const std::string& name, const std::vector& v) const { - GLuint id = util::getUniform(_id, name); - glUniform1iv(id, v.size(), reinterpret_cast(v.data())); - return id; - } - - GLuint setUniform(const std::string& name, glm::mat4& M) const { - GLuint id = util::getUniform(_id, name); - glUniformMatrix4fv(id, 1, GL_FALSE, &M[0][0]); - return id; - } + GraphicShader(const std::string& vertex, const std::string fragment); + ~GraphicShader(); + + GLuint setUniform(const std::string& name, int value) const; + GLuint setUniform(const std::string& name, const std::vector& v) const; + GLuint setUniform(const std::string& name, glm::mat4& M) const; }; -- cgit v1.2.3