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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
|
#ifndef _GL_H
#define _GL_H
extern "C" {
#include <stl/gl.h>
}
#include <vector>
#include <unordered_map>
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/glm.hpp>
#include <glm/gtx/matrix_major_storage.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/string_cast.hpp>
using namespace glm;
namespace Mauri
{
enum ObjectType
{
DEFAULT,
DEFAULT_FLIPPED,
FULLSCREEN,
MODEL,
COMBINE
};
enum UniformType
{
TYPE_INVALID,
TYPE_UINT,
TYPE_FLOAT,
TYPE_VEC4,
TYPE_VEC3,
TYPE_VEC2,
TYPE_MAT4,
TYPE_MAT3,
TYPE_SAMPLER2D
};
extern auto uniform_type_to_string(UniformType type) -> std::string;
extern auto uniform_type_from_string(const std::string_view &s) -> UniformType;
class Object;
class Texture;
class RenderObject
{
public:
RenderObject(ObjectType type, Object *object = nullptr, Texture *texture = nullptr);
~RenderObject();
auto set_data(f32 *vertices, s32 vertex_count) -> void;
auto bind() -> void;
auto draw() -> void;
private:
u32 vao;
u32 vbo;
u32 vertex_count;
};
class RenderShader
{
public:
RenderShader(const std::string &vs_source, const std::string &fs_source);
~RenderShader();
auto compile(u32 shader, const char *source, char *error) -> bool;
auto bind() -> void;
auto get_uniform_location(const std::string &name) -> s32;
auto set_uniform(const std::string &name, UniformType type, void *value) -> void;
private:
u32 program = 0;
std::unordered_map<std::string, s32> uniform_locations;
};
class RenderTexture
{
public:
RenderTexture(bool no_interp, bool clamp, bool filtering, s32 mm_count);
~RenderTexture();
u32 id = 0;
s32 width;
s32 height;
s32 format;
std::vector<u32> pixels;
auto upload(const void *ptr, s32 width, s32 height, s32 level, s32 iformat = GL_UNSIGNED_BYTE) -> void;
auto bind(s32 index) -> void;
private:
auto save_pixels(const void *ptr, s32 width, s32 height, bool dxt) -> void;
};
class RenderFramebuffer
{
public:
RenderFramebuffer(s32 width, s32 height, f32 scale);
~RenderFramebuffer();
u32 id = 0;
f32 width;
f32 height;
RenderTexture *texture = nullptr;
auto bind() -> void;
auto blit(u32 dest, s32 width, s32 height) -> void;
auto clear(vec4 color) -> void;
};
class Render
{
public:
static auto blend_func(s32 sfactor, s32 dfactor) -> void;
static auto color_mask(f32 r, f32 g, f32 b, f32 a) -> void;
static auto depth_test(bool enabled) -> void;
static auto bind_framebuffer(s32 id) -> void;
static auto set_viewport(s32 x, s32 y, s32 width, s32 height) -> void;
};
} // namespace Mauri
#endif // _GL_H
|