From 43394c8a8908442982e3a7e25975c31b3c952923 Mon Sep 17 00:00:00 2001 From: Nikolas Date: Sun, 27 Oct 2024 12:52:55 +0200 Subject: root --- graphics/shader.h | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 graphics/shader.h (limited to 'graphics/shader.h') diff --git a/graphics/shader.h b/graphics/shader.h new file mode 100644 index 0000000..4774d64 --- /dev/null +++ b/graphics/shader.h @@ -0,0 +1,57 @@ +#pragma once + +#include +#include +#include "glm/glm.hpp" + +#define ASSERT_GL {assert (glGetError()==GL_NO_ERROR);} + +class Uniform +{ +protected: + int id; +public: + operator int() { return id; } + Uniform(int i) : id(i) {} + Uniform() : id(-1) {} + Uniform(const Uniform & right); + Uniform & operator = (const Uniform & right); + Uniform & operator = (int); + Uniform & operator = (float); + Uniform & operator = (unsigned int); + Uniform & operator = (glm::vec3); + Uniform & operator = (glm::vec4); + Uniform & operator = (glm::vec2); + Uniform & operator = (glm::ivec3); + Uniform & operator = (glm::ivec2); + Uniform & operator = (glm::ivec4); + Uniform & operator = (glm::mat4); + Uniform & operator = (glm::mat3); +}; + + + + +class Shader +{ + std::map uniforms; + bool ready = false; + + + unsigned int vshader, fshader; + +protected: + void printLog(unsigned int obj); + +public: + unsigned int program; + explicit operator bool () const { return ready; } + Shader(const char * vertex = nullptr, const char * fragment = nullptr); + Uniform & operator [] (const char * name); + bool use(bool use = true); + std::string loadShaderText(char * file); + bool init(); + void setFragmentLocation(char * name, unsigned int location); + unsigned int getAttributeLocation(const char * attrib); + ~Shader(); +}; -- cgit v1.2.3