summaryrefslogtreecommitdiff
path: root/gfx/gl/shader.h
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-01-24 13:16:05 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2021-01-24 13:16:05 +0000
commit12d38a0114657cc468e93f7eb0f97b2b1ac8f924 (patch)
tree7aec12c6469db3a46811ef6c49800b33a029292e /gfx/gl/shader.h
parentAllow physical objects to share meshes and textures (diff)
downloadilt-12d38a0114657cc468e93f7eb0f97b2b1ac8f924.tar.bz2
ilt-12d38a0114657cc468e93f7eb0f97b2b1ac8f924.tar.xz
ilt-12d38a0114657cc468e93f7eb0f97b2b1ac8f924.zip
Big tidy up of shader wrapper
Diffstat (limited to 'gfx/gl/shader.h')
-rw-r--r--gfx/gl/shader.h32
1 files changed, 17 insertions, 15 deletions
diff --git a/gfx/gl/shader.h b/gfx/gl/shader.h
index 2072199..e253f50 100644
--- a/gfx/gl/shader.h
+++ b/gfx/gl/shader.h
@@ -2,34 +2,36 @@
#define SHADER_INCLUDED_H
#include <GL/glew.h>
-#include <array>
-#include <special_members.hpp>
-#include <string>
+#include <glRef.hpp>
+#include <string_view>
class Camera;
class Transform;
class Shader {
public:
- explicit Shader(const std::string & fileName);
- virtual ~Shader();
-
- NO_COPY(Shader);
- NO_MOVE(Shader);
+ Shader();
void Bind() const;
void Update(const Transform & transform, const Camera & camera) const;
private:
- static constexpr unsigned int NUM_SHADERS = 2;
- static constexpr unsigned int NUM_UNIFORMS = 3;
+ class Source {
+ public:
+ using ShaderRef = glRef<GLuint, __glewCreateShader, __glewDeleteShader>;
+
+ Source(const std::basic_string_view<unsigned char> text, GLuint type);
+ Source(const GLchar * text, GLint len, GLuint type);
+
+ ShaderRef id;
+ };
+
+ static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);
- static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string & errorMessage);
- static GLuint CreateShader(const GLchar * text, GLint len, unsigned int type);
+ using ProgramRef = glRef<GLuint, __glewCreateProgram, __glewDeleteProgram>;
- GLuint m_program;
- std::array<GLuint, NUM_SHADERS> m_shaders;
- std::array<GLint, NUM_UNIFORMS> m_uniforms;
+ ProgramRef m_program;
+ GLint mvp_uniform, normal_uniform, lightDir_uniform;
};
#endif