blob: 4774d6401491c59160bc98c0a104c35e631c7b92 (
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
46
47
48
49
50
51
52
53
54
55
56
57
|
#pragma once
#include <map>
#include <string>
#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<const char *, Uniform> 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();
};
|