summaryrefslogtreecommitdiff
path: root/gfx/gl/shader.h
blob: 293ce9b1001fbebb07e2df6baa27814ea8b2b00a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#ifndef SHADER_INCLUDED_H
#define SHADER_INCLUDED_H

#include "shader-source.h"
#include <GL/glew.h>
#include <array>
#include <glRef.hpp>
#include <glm/glm.hpp>
#include <string_view>

class Shader {
public:
	enum class Program { Basic = 0, Water = 1, LandMass = 2 };

	Shader();

	void setView(glm::mat4 view) const;
	void setModel(glm::mat4 model, Program = Program::Basic) const;
	void setUniform(const GLchar *, glm::vec3 dir) const;

private:
	class Source {
	public:
		using ShaderRef = glRef<GLuint, __glewCreateShader, __glewDeleteShader>;

		explicit Source(const GLsource src);

		ShaderRef id;
	};

	static void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, std::string_view errorMessage);

	class ProgramHandle {
	public:
		ProgramHandle(GLuint, GLuint);
		using ProgramRef = glRef<GLuint, __glewCreateProgram, __glewDeleteProgram>;

		ProgramRef m_program;
		GLint viewProjection_uniform, model_uniform;
	};

	std::array<ProgramHandle, 3> programs;
};

#endif