summaryrefslogtreecommitdiffstats
path: root/src/Shader.hpp
blob: b5516028afc8fd87778aa32334af5c93e2d7724d (plain) (blame)
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
46
47
48
49
50
51
52
53
54
55
56
#pragma once

#include <map>
#include <vector>

#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/type_ptr.hpp>

class Shader
{
private:
    const GLchar *vertex;
    const GLchar *fragment;
public:
    GLuint Program;
    Shader(const GLchar* vertexPath, const GLchar* fragmentPath, const GLchar* geometryPath = nullptr);
    void Use();

    void Reload();
};

class NewShader {
	std::map<std::string, GLuint> uniforms;
	GLuint program = 0;

	GLuint GetUniformLocation(const std::string &name);

public:
	NewShader(const NewShader &) = delete;
	NewShader(NewShader &&other) = delete;
	NewShader &operator=(const NewShader &) = delete;
	NewShader &operator=(NewShader &&other) = delete;

	NewShader(const std::string &vertSource, const std::string &fragSource, const std::vector<std::string> &uniformsNames);
	
	~NewShader();

	void Activate();

	inline void SetUniform(const std::string &name, int val) {
		glUniform1i(GetUniformLocation(name), val);
	}

	inline void SetUniform(const std::string &name, float val) {
		glUniform1f(GetUniformLocation(name), val);
	}

	inline void SetUniform(const std::string &name, glm::vec4 val) {
		glUniform4f(GetUniformLocation(name), val.x, val.y, val.z, val.w);
	}

	inline void SetUniform(const std::string &name, glm::mat4 val) {
		glUniformMatrix4fv(GetUniformLocation(name), 1, GL_FALSE, glm::value_ptr(val));
	}
};