forked from emilk/emilib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gl_lib_fwd.hpp
187 lines (143 loc) · 4.5 KB
/
gl_lib_fwd.hpp
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma once
#include <memory>
#include <utility>
#if __APPLE__
#include "TargetConditionals.h"
#endif
// ----------------------------------------------------------------------------
#ifndef TARGET_OS_IPHONE
# error TARGET_OS_IPHONE not defined
#endif
#ifndef TARGET_OS_MAC
# error TARGET_OS_MAC not defined
#endif
#if TARGET_OS_IPHONE
#define GLLIB_GLES 1
#define GLLIB_OPENGL_VERSION 200
#define GLLIB_TRILLINEAR_FILTERING 1
#else // !TARGET_OS_IPHONE
#define GLLIB_GLES 0
#define GLLIB_OPENGL_VERSION 320 // 210, 320, 330, 410, ...
#define GLLIB_TRILLINEAR_FILTERING 1
#endif // !TARGET_OS_IPHONE
// ----------------------------------------------------------------------------
namespace gl {
class Program;
typedef std::unique_ptr<Program> Program_UP;
typedef std::shared_ptr<Program> Program_SP;
class Texture;
typedef std::unique_ptr<Texture> Texture_UP;
typedef std::shared_ptr<Texture> Texture_SP;
struct VertComp;
class VertexFormat;
class VBO;
typedef std::unique_ptr<VBO> VBO_UP;
typedef std::shared_ptr<VBO> VBO_SP;
class VAO;
typedef std::unique_ptr<VAO> VAO_UP;
typedef std::shared_ptr<VAO> VAO_SP;
class MeshPainter;
typedef std::unique_ptr<MeshPainter> MeshPainter_UP;
typedef std::shared_ptr<MeshPainter> MeshPainter_SP;
template<typename Vertex>
class TriangleStrip;
class FBO;
typedef std::unique_ptr<FBO> FBO_UP;
typedef std::shared_ptr<FBO> FBO_SP;
// FOr VBO:s and the like
enum class Usage
{
WRITE_ONCE_READ_MANY,
WRITE_MANY_READ_MANY,
WRITE_ONCE_READ_ONCE,
};
struct Size
{
unsigned x, y;
};
struct Rectangle
{
int x, y;
int width, height;
};
// ------------------------------------------------
// ImageFormat
enum class ImageFormat
{
INVALID,
Alpha8, // One byte
Red8, // One byte
RGB24, // Three bytes
RGBA32, // Four bytes
BGRA32, // GL_BGRA - Four bytes
AlphaHF, // 16-bit half-float, alpha channel only.
RGBAHF, // RGBA Half-float
RGBAf, // 32bit float RGBA
// Avilable as render-target:
//RGBA16F_EXT 0x881A
//RGB16F_EXT 0x881B
//RG16F_EXT 0x822F
//R16F_EXT
};
// byte size per pixel
constexpr int format_size(ImageFormat format) {
return (format == ImageFormat::Alpha8 ? 1 : 4);
}
constexpr bool is_half(ImageFormat f)
{
return f==ImageFormat::AlphaHF || f==ImageFormat::RGBAHF;
}
// ------------------------------------------------
enum class TexFilter {
Nearest,
Linear,
Mipmapped,
DontCare, // Best based on size
};
enum class WrapMode {
Repeat,
Mirror,
Clamp,
DontCare,
};
struct TexParams {
TexFilter filter = TexFilter::Mipmapped;
std::pair<WrapMode, WrapMode> wrap = std::make_pair(WrapMode::Clamp, WrapMode::Clamp);
TexParams() {}
TexParams(TexFilter f, WrapMode w) : filter(f), wrap(w,w) {}
TexParams(TexFilter f, WrapMode u, WrapMode v) : filter(f), wrap(u,v) {}
static TexParams clamped(TexFilter f=TexFilter::DontCare) { return TexParams(f, WrapMode::Clamp); }
static TexParams repeated(TexFilter f=TexFilter::DontCare) { return TexParams(f, WrapMode::Repeat); }
static TexParams clamped_nearest() { return clamped(TexFilter::Nearest); }
static TexParams clamped_linear() { return clamped(TexFilter::Linear); }
static TexParams clamped_mipmapped() { return clamped(TexFilter::Mipmapped); }
static TexParams repeated_linear() { return repeated(TexFilter::Linear); }
static TexParams repeated_mipmapped() { return repeated(TexFilter::Mipmapped); }
static TexParams mipmapped(WrapMode u, WrapMode v) { return TexParams(TexFilter::Mipmapped, u, v); }
friend bool operator<(const TexParams& a, const TexParams& b) {
if (a.filter != b.filter) { return a.filter < b.filter; }
if (a.wrap != b.wrap) { return a.wrap < b.wrap; }
return false; // Same
}
};
// ------------------------------------------------
void check_for_gl_error(const char* file, int line);
#ifndef NDEBUG
#define CHECK_FOR_GL_ERROR gl::check_for_gl_error(__FILE__, __LINE__)
#else
#define CHECK_FOR_GL_ERROR
#endif
// ----------------------------------------------------------------------------
class PaintGrouper
{
public:
PaintGrouper(const char* name);
PaintGrouper(const std::string& name);
~PaintGrouper();
PaintGrouper(PaintGrouper&) = delete;
PaintGrouper& operator=(PaintGrouper&) = delete;
};
#define NAME_PAINT_GROUP(name) gl::PaintGrouper LOGURU_ANONYMOUS_VARIABLE(paint_scope_)(name)
#define NAME_PAINT_FUNCTION() NAME_PAINT_GROUP(__PRETTY_FUNCTION__)
// ------------------------------------------------
} // gl