-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathglutil.h
101 lines (77 loc) · 1.9 KB
/
glutil.h
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#pragma once
#include <string>
#include <GL/gl.h>
#include "panic.h"
#define GL_CHECK(expr) \
[&] { \
expr; \
auto e = glGetError(); \
if (e != GL_NO_ERROR) \
panic("%s:%d: GL error: %x", __FILE__, __LINE__, e); \
}()
#define GL_CHECK_R(expr) \
[&] { \
auto r = expr; \
auto e = glGetError(); \
if (e != GL_NO_ERROR) \
panic("%s:%d: GL error: %x", __FILE__, __LINE__, e); \
return r; \
}()
namespace gl {
class noncopyable
{
protected:
noncopyable() = default;
~noncopyable() = default;
noncopyable(const noncopyable&) = delete;
noncopyable& operator=(const noncopyable&) = delete;
};
class shader : private noncopyable
{
public:
shader(GLenum type);
void set_source(const std::string& source);
void load_source(const std::string& filename);
private:
friend class program;
GLuint id_;
};
class program : private noncopyable
{
public:
program();
void attach(const shader& s);
void link();
void use();
class uniform
{
public:
uniform(GLint location);
void set_f(GLfloat v0);
void set_f(GLfloat v0, GLfloat v1);
void set_f(GLfloat v0, GLfloat v1, GLfloat v2);
void set_f(GLfloat v0, GLfloat v1, GLfloat v2, GLfloat v3);
void set_i(GLint v0);
void set_i(GLint v0, GLint v1);
void set_i(GLint v0, GLint v1, GLint v2);
void set_i(GLint v0, GLint v1, GLint v2, GLint v3);
private:
GLint location_;
};
uniform get_uniform(const std::string& name);
private:
GLuint id_;
};
class buffer : private noncopyable
{
public:
buffer(GLenum target);
void bind();
void bind_base(int index);
void set_data(GLsizeiptr size, const GLvoid *data);
void get_sub_data(GLintptr offset, GLsizeiptr size, GLvoid *data);
private:
GLuint id_;
GLenum target_;
};
} // gl