-
Notifications
You must be signed in to change notification settings - Fork 26
/
gl45_emu.cpp
242 lines (224 loc) · 5.84 KB
/
gl45_emu.cpp
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
#include <stdio.h>
#include "gl45_emu.h"
void gl3CopyImageSubData(GLuint srcName, GLenum srcTarget, GLint srcLevel, GLint srcX, GLint srcY, GLint srcZ,
GLuint dstName, GLenum dstTarget, GLint dstLevel, GLint dstX, GLint dstY, GLint dstZ,
GLsizei srcWidth, GLsizei srcHeight, GLsizei srcDepth)
{
#if USE_GL3
// all calls ported
static bool warn_once = true;
if (warn_once)
{
warn_once = false;
printf("WARNING: GL3 calling unimplemented glCopyImageSubData()\n");
}
#else
glCopyImageSubData(srcName, srcTarget, srcLevel, srcX, srcY, srcZ,
dstName, dstTarget, dstLevel, dstX, dstY, dstZ,
srcWidth, srcHeight, srcDepth);
#endif
}
void gl3GetTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
GLsizei width, GLsizei height, GLsizei depth,
GLenum format, GLenum type, GLsizei bufSize, void *pixels)
{
#if USE_GL3
// TODO later
// used by font editor (get pixel) & glyphs coverage calculator (not needed for end user)
static bool warn_once = true;
if (warn_once)
{
warn_once = false;
printf("WARNING: GL3 calling unimplemented glGetTextureSubImage()\n");
}
#else
glGetTextureSubImage(texture, level, xoffset, yoffset, zoffset,
width, height, depth, format, type, bufSize, pixels);
#endif
}
void gl3TextureStorage2D(GLuint tex, GLint levels, GLenum ifmt, GLsizei w, GLsizei h)
{
#if USE_GL3
int t;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &t);
glBindTexture(GL_TEXTURE_2D, tex);
for (int lev = 0; lev < levels; lev++)
{
if (ifmt == GL_RGBA8UI)
glTexImage2D(GL_TEXTURE_2D, lev, ifmt, w, h, 0, GL_RGBA_INTEGER, GL_UNSIGNED_BYTE, 0);
else
if (ifmt == GL_R16UI)
glTexImage2D(GL_TEXTURE_2D, lev, ifmt, w, h, 0, GL_RED_INTEGER, GL_UNSIGNED_SHORT, 0);
else
glTexImage2D(GL_TEXTURE_2D, lev, ifmt, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
w >>= 1;
h >>= 1;
if (!w)
w = 1;
if (!h)
h = 1;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1);
glBindTexture(GL_TEXTURE_2D, t);
#else
glTextureStorage2D(tex, levels, ifmt, w, h);
#endif
}
void gl3TextureStorage3D(GLuint tex, GLint levels, GLenum ifmt, GLsizei w, GLsizei h, GLsizei d)
{
#if USE_GL3
int t;
glGetIntegerv(GL_TEXTURE_BINDING_3D, &t);
glBindTexture(GL_TEXTURE_3D, tex);
for (int lev = 0; lev < levels; lev++)
{
glTexImage3D(GL_TEXTURE_3D, lev, ifmt, w, h, d, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
w >>= 1;
h >>= 1;
d >>= 1;
if (!w)
w = 1;
if (!h)
h = 1;
if (!d)
d = 1;
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, levels - 1);
glBindTexture(GL_TEXTURE_3D, t);
#else
glTextureStorage3D(tex, levels, ifmt, w, h, d);
#endif
}
void gl3CreateTextures(GLenum target, GLsizei num, GLuint* arr)
{
#if USE_GL3
glGenTextures(num, arr);
#else
glCreateTextures(target, num, arr);
#endif
}
void gl3TextureSubImage2D(GLuint tex, GLint level, GLint x, GLint y, GLsizei w, GLsizei h, GLenum fmt, GLenum type, const void *pix)
{
#if USE_GL3
int t;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &t);
glBindTexture(GL_TEXTURE_2D, tex);
glTexSubImage2D(GL_TEXTURE_2D, level, x, y, w, h, fmt, type, pix);
glBindTexture(GL_TEXTURE_2D, t);
#else
glTextureSubImage2D(tex, level, x, y, w, h, fmt, type, pix);
#endif
}
void gl3BindTextureUnit2D(GLuint unit, GLuint tex)
{
#if USE_GL3
int u;
glGetIntegerv(GL_ACTIVE_TEXTURE, &u);
glActiveTexture(GL_TEXTURE0 + unit);
glBindTexture(GL_TEXTURE_2D, tex);
if (!tex)
glBindTexture(GL_TEXTURE_3D, 0);
glActiveTexture(u);
#else
glBindTextureUnit(unit, tex);
#endif
}
void gl3BindTextureUnit3D(GLuint unit, GLuint tex)
{
#if USE_GL3
int u;
glGetIntegerv(GL_ACTIVE_TEXTURE, &u);
glActiveTexture(GL_TEXTURE0 + unit);
glBindTexture(GL_TEXTURE_3D, tex);
if (!tex)
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(u);
#else
glBindTextureUnit(unit, tex);
#endif
}
void gl3TextureParameteri2D(GLuint tex, GLenum param, GLint val)
{
#if USE_GL3
int t;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &t);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameteri(GL_TEXTURE_2D, param, val);
glBindTexture(GL_TEXTURE_2D, t);
#else
glTextureParameteri(tex, param, val);
#endif
}
void gl3TextureParameteri3D(GLuint tex, GLenum param, GLint val)
{
#if USE_GL3
int t;
glGetIntegerv(GL_TEXTURE_BINDING_3D, &t);
glBindTexture(GL_TEXTURE_3D, tex);
glTexParameteri(GL_TEXTURE_3D, param, val);
glBindTexture(GL_TEXTURE_3D, t);
#else
glTextureParameteri(tex, param, val);
#endif
}
void gl3TextureParameterfv2D(GLuint tex, GLenum param, GLfloat* val)
{
#if USE_GL3
int t;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &t);
glBindTexture(GL_TEXTURE_2D, tex);
glTexParameterfv(GL_TEXTURE_2D, param, val);
glBindTexture(GL_TEXTURE_2D, t);
#else
glTextureParameterfv(tex, param, val);
#endif
}
void gl3TextureParameterfv3D(GLuint tex, GLenum param, GLfloat* val)
{
#if USE_GL3
int t;
glGetIntegerv(GL_TEXTURE_BINDING_3D, &t);
glBindTexture(GL_TEXTURE_3D, tex);
glTexParameterfv(GL_TEXTURE_3D, param, val);
glBindTexture(GL_TEXTURE_3D, t);
#else
glTextureParameterfv(tex, param, val);
#endif
}
void gl3CreateBuffers(GLsizei num, GLuint* arr)
{
#if USE_GL3
glGenBuffers(num, arr);
#else
glCreateBuffers(num, arr);
#endif
}
void gl3NamedBufferStorage(GLuint buffer, GLsizeiptr size, const void *data, GLbitfield flags)
{
#if USE_GL3
glBindBuffer(GL_COPY_WRITE_BUFFER, buffer);
GLenum usage = GL_STATIC_DRAW;
if (flags & GL_DYNAMIC_STORAGE_BIT)
usage = GL_DYNAMIC_DRAW;
glBufferData(GL_COPY_WRITE_BUFFER, size, data, GL_DYNAMIC_DRAW);
#else
glNamedBufferStorage(buffer, size, data, flags);
#endif
}
void gl3NamedBufferSubData(GLuint buffer, GLintptr offset, GLsizeiptr size, const void *data)
{
#if USE_GL3
glBindBuffer(GL_COPY_WRITE_BUFFER, buffer);
glBufferSubData(GL_COPY_WRITE_BUFFER, offset, size, data);
#else
glNamedBufferSubData(buffer, offset, size, data);
#endif
}
void gl3CreateVertexArrays(GLsizei num, GLuint* arr)
{
#if USE_GL3
glGenVertexArrays(num, arr);
#else
glCreateVertexArrays(num, arr);
#endif
}