GCC Code Coverage Report


Directory: src/gate/
File: src/gate/graphics/gl_apis.c
Date: 2026-08-06 22:46:24
Exec Total Coverage
Lines: 97 300 32.3%
Functions: 24 42 57.1%
Branches: 12 123 9.8%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2026, Stefan Meislinger |
4 | All rights reserved. |
5 | |
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met:|
8 | |
9 | 1. Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"|
16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
18 | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
19 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
25 | THE POSSIBILITY OF SUCH DAMAGE. |
26 +----------------------------------------------------------------------------+
27 */
28 #include "gate/graphics/gl_apis.h"
29
30 #include "gate/debugging.h"
31 #include "gate/mathematics.h"
32
33 #if (defined(GATE_SYS_WIN) && !defined(GATE_SYS_WINCE) && !defined(GATE_SYS_WINSTORE) && !defined(GATE_SYS_WIN16)) || (defined(GATE_SYS_POSIX) && !defined(GATE_SYS_OPENBSD) && !defined(GATE_SYS_BEOS)) || defined(GATE_SYS_WASM)
34 # define GATE_GRAPHICS_GL_OPENGL
35 #else
36 # define GATE_GARPHICS_GL_NOIMPL
37 #endif
38
39 #if defined(GATE_GRAPHICS_GL_OPENGL)
40
41 #include "gate/graphics/platform/opengl_apis.h"
42
43 #if defined(GATE_GRAPHICS_OPENGL_GLUT)
44 # define GATE_GL_API_GLUT 1
45 #elif defined(GATE_SYS_WIN) && !defined(GATE_SYS_WINCE)
46 # define GATE_GL_API_WINAPI 1
47 #elif defined(GATE_SYS_DARWIN)
48 # define GATE_GL_API_GLUT 1
49 #else
50 # define GATE_GL_API_EGL 1
51 #endif
52
53
54
55 1 gate_result_t gate_gl_api_init()
56 {
57 1 return gate_gl_api_load_functions();
58 }
59
60 #if !defined(GATE_GRAPHICS_NO_LEGACY_OPENGL)
61
62 void gate_gl_api_color3(gate_real32_t r, gate_real32_t g, gate_real32_t b)
63 {
64 gate_gl_api_color4(r, g, b, 1.0f);
65 }
66 void gate_gl_api_color3b(gate_uint8_t r, gate_uint8_t g, gate_uint8_t b)
67 {
68 gate_gl_api_color4b(r, g, b, 255);
69 }
70
71 void gate_gl_api_color4(gate_real32_t r, gate_real32_t g, gate_real32_t b, gate_real32_t a)
72 {
73 gate_gl_api.glColor4f(r, g, b, a);
74 }
75
76 void gate_gl_api_color4b(gate_uint8_t r, gate_uint8_t g, gate_uint8_t b, gate_uint8_t a)
77 {
78 gate_gl_api.glColor4f((gate_real32_t)r / 255.0f,
79 (gate_real32_t)g / 255.0f,
80 (gate_real32_t)b / 255.0f,
81 (gate_real32_t)a / 255.0f);
82 }
83
84 42 static GLenum translate_clientstate(gate_gl_api_clientstate_t client_state)
85 {
86
2/7
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 21 times.
✗ Branch 6 not taken.
42 switch (client_state)
87 {
88 21 case gate_gl_api_clientstate_color_array: return GL_COLOR_ARRAY;
89 #if defined(GL_EDGE_FLAG_ARRAY)
90 case gate_gl_api_clientstate_edge_flag_array: return GL_EDGE_FLAG_ARRAY;
91 #endif
92 #if defined(GL_INDEX_ARRAY)
93 case gate_gl_api_clientstate_index_array: return GL_INDEX_ARRAY;
94 #endif
95 case gate_gl_api_clientstate_normal_array: return GL_NORMAL_ARRAY;
96 case gate_gl_api_clientstate_texture_coord_array: return GL_TEXTURE_COORD_ARRAY;
97 21 case gate_gl_api_clientstate_vertex_array: return GL_VERTEX_ARRAY;
98 default: return 0;
99 }
100 }
101
102 40 void gate_gl_api_enableclientstate(gate_gl_api_clientstate_t state)
103 {
104 40 gate_gl_api.glEnableClientState(translate_clientstate(state));
105 40 }
106
107 2 void gate_gl_api_disableclientstate(gate_gl_api_clientstate_t state)
108 {
109 2 gate_gl_api.glDisableClientState(translate_clientstate(state));
110 2 }
111
112 void gate_gl_api_texcoordpointer(gate_size_t coord_count, gate_real32_t const* ptr_coords)
113 {
114 gate_gl_api.glTexCoordPointer((GLint)coord_count, GL_FLOAT, 0, ptr_coords);
115 }
116
117 1 void gate_gl_api_shademodel(gate_gl_api_shademodel_t model)
118 {
119 1 GLenum value = 0;
120
1/3
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
1 switch (model)
121 {
122 1 case gate_gl_api_shademodel_flat: value = GL_FLAT; break;
123 case gate_gl_api_shademodel_smooth: value = GL_SMOOTH; break;
124 }
125 1 gate_gl_api.glShadeModel(value);
126 1 }
127
128 void gate_gl_api_multmatrix(gate_real32_t const matrix[16])
129 {
130 gate_gl_api.glMultMatrixf(matrix);
131 }
132
133 20 void gate_gl_api_translate(gate_real32_t x, gate_real32_t y, gate_real32_t z)
134 {
135 20 gate_gl_api.glTranslatef(x, y, z);
136 20 }
137
138 20 void gate_gl_api_rotate(gate_real32_t angle, gate_real32_t x, gate_real32_t y, gate_real32_t z)
139 {
140 20 gate_gl_api.glRotatef(angle, x, y, z);
141 20 }
142
143 1 void gate_gl_api_perspective(gate_real32_t fovy, gate_real32_t aspect, gate_real32_t znear, gate_real32_t zfar)
144 {
145 1 gate_real32_t f = (gate_real32_t)(1.0 / gate_math_tan(gate_math_deg2rad(fovy) / 2.0));
146 1 GLfloat a = f / aspect;
147 GLfloat m[16];
148 1 m[0] = a; m[1] = 0; m[2] = 0; m[3] = 0;
149 1 m[4] = 0; m[5] = f; m[6] = 0; m[7] = 0;
150 1 m[8] = 0; m[9] = 0; m[10] = (zfar + znear) / (znear - zfar); m[11] = -1.0f;
151 1 m[12] = 0; m[13] = 0; m[14] = (2.0f * zfar * znear) / (znear - zfar); m[15] = 0;
152 1 gate_gl_api.glMultMatrixf(m);
153 1 }
154
155 static double square(double const arg)
156 {
157 return arg * arg;
158 }
159
160 static void math_cross_prod(float x1, float y1, float z1, float x2, float y2, float z2, float res[3])
161 {
162 res[0] = y1 * z2 - y2 * z1;
163 res[1] = x2 * z1 - x1 * z2;
164 res[2] = x1 * y2 - x2 * y1;
165 }
166
167 void gate_gl_api_lookat(gate_real32_t eyeX, gate_real32_t eyeY, gate_real32_t eyeZ,
168 gate_real32_t lookX, gate_real32_t lookY, gate_real32_t lookZ,
169 gate_real32_t upX, gate_real32_t upY, gate_real32_t upZ)
170 {
171 float f[3];
172 float fMag;
173 float upMag;
174 float s[3], u[3];
175 float M[16];
176
177
178 f[0] = lookX - eyeX;
179 f[1] = lookY - eyeY;
180 f[2] = lookZ - eyeZ;
181
182 fMag = (float)gate_math_sqrt(square(f[0]) + square(f[1]) + square(f[2]));
183 upMag = (float)gate_math_sqrt(square(upX) + square(upY) + square(upZ));
184
185 if (fMag != 0)
186 {
187 f[0] = f[0] / fMag;
188 f[1] = f[1] / fMag;
189 f[2] = f[2] / fMag;
190 }
191
192 if (upMag != 0)
193 {
194 upX = upX / upMag;
195 upY = upY / upMag;
196 upZ = upZ / upMag;
197 }
198
199 math_cross_prod(f[0], f[1], f[2], upX, upY, upZ, s);
200 math_cross_prod(s[0], s[1], s[2], f[0], f[1], f[2], u);
201
202 M[0] = s[0]; M[1] = u[0]; M[2] = -f[0]; M[3] = 0;
203 M[4] = s[1]; M[5] = u[1]; M[6] = -f[1]; M[7] = 0;
204 M[8] = s[2]; M[9] = u[2]; M[10] = -f[2]; M[11] = 0;
205 M[12] = 0; M[13] = 0; M[14] = 0; M[15] = 1;
206
207 gate_gl_api.glMultMatrixf(M);
208 gate_gl_api.glTranslatef(-eyeX, -eyeY, -eyeZ);
209 }
210
211 void gate_gl_api_ortho(gate_real32_t left, gate_real32_t right, gate_real32_t bottom, gate_real32_t top, gate_real32_t near_val, gate_real32_t far_val)
212 {
213 gate_gl_api.glOrtho(left, right, bottom, top, near_val, far_val);
214 }
215
216
217 #endif /* !defined(GATE_GRAPHICS_NO_LEGACY_OPENGL) */
218
219
220 20 void gate_gl_api_vertexpointer(gate_size_t coord_count, gate_size_t stride, gate_real32_t const* ptr_coords)
221 {
222 20 gate_gl_api.glVertexPointer((GLint)coord_count, GL_FLOAT, (GLsizei)stride, ptr_coords);
223 20 }
224
225 20 void gate_gl_api_colorpointer(gate_size_t color_count, gate_size_t stride, gate_real32_t const* ptr_colors)
226 {
227 20 gate_gl_api.glColorPointer((GLint)color_count, GL_FLOAT, (GLsizei)stride, ptr_colors);
228 20 }
229
230 static GLenum resolve_blend_function(gate_gl_api_blend_t blend_function)
231 {
232 switch (blend_function)
233 {
234 case gate_gl_api_blend_zero: return GL_ZERO;
235 case gate_gl_api_blend_one: return GL_ONE;
236 case gate_gl_api_blend_src_color: return GL_SRC_COLOR;
237 case gate_gl_api_blend_one_minus_src_color: return GL_ONE_MINUS_SRC_COLOR;
238 case gate_gl_api_blend_src_alpha: return GL_SRC_ALPHA;
239 case gate_gl_api_blend_one_minus_src_alpha: return GL_ONE_MINUS_SRC_ALPHA;
240 case gate_gl_api_blend_dst_alpha: return GL_DST_ALPHA;
241 case gate_gl_api_blend_one_minus_dst_alpha: return GL_ONE_MINUS_DST_ALPHA;
242 case gate_gl_api_blend_dst_color: return GL_DST_COLOR;
243 case gate_gl_api_blend_one_minus_dst_color: return GL_ONE_MINUS_DST_COLOR;
244 case gate_gl_api_blend_src_alpha_saturate: return GL_SRC_ALPHA_SATURATE;
245 }
246 return 0;
247 }
248
249 void gate_gl_api_blendfunc(gate_gl_api_blend_t blend_func_src, gate_gl_api_blend_t blend_func_dst)
250 {
251 gate_gl_api.glBlendFunc(resolve_blend_function(blend_func_src), resolve_blend_function(blend_func_dst));
252 }
253
254 20 void gate_gl_api_clearcolor(gate_real32_t r, gate_real32_t g, gate_real32_t b, gate_real32_t a)
255 {
256 20 gate_gl_api.glClearColor(r, g, b, a);
257 20 }
258
259 20 void gate_gl_api_cleardepth(gate_real32_t depth)
260 {
261 20 gate_gl_api.glClearDepth(depth);
262 20 }
263
264 2 static GLenum translate_capability(gate_gl_api_capability_t capability)
265 {
266
1/48
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
✗ Branch 16 not taken.
✗ Branch 17 not taken.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✗ Branch 20 not taken.
✗ Branch 21 not taken.
✗ Branch 22 not taken.
✗ Branch 23 not taken.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✗ Branch 27 not taken.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✗ Branch 31 not taken.
✗ Branch 32 not taken.
✗ Branch 33 not taken.
✗ Branch 34 not taken.
✗ Branch 35 not taken.
✗ Branch 36 not taken.
✗ Branch 37 not taken.
✗ Branch 38 not taken.
✗ Branch 39 not taken.
✗ Branch 40 not taken.
✗ Branch 41 not taken.
✗ Branch 42 not taken.
✗ Branch 43 not taken.
✗ Branch 44 not taken.
✗ Branch 45 not taken.
✗ Branch 46 not taken.
✗ Branch 47 not taken.
2 switch (capability)
267 {
268 case gate_gl_api_capability_alpha_test: return GL_ALPHA_TEST;
269 #if defined(GL_AUTO_NORMAL)
270 case gate_gl_api_capability_auto_normal: return GL_AUTO_NORMAL;
271 #endif
272 case gate_gl_api_capability_blend: return GL_BLEND;
273 //case gate_gl_api_capability_clip_plane: return GL_CLIP_PLANEi;
274 case gate_gl_api_capability_color_logic_op: return GL_COLOR_LOGIC_OP;
275 case gate_gl_api_capability_color_material: return GL_COLOR_MATERIAL;
276 case gate_gl_api_capability_cull_face: return GL_CULL_FACE;
277 2 case gate_gl_api_capability_depth_test: return GL_DEPTH_TEST;
278 case gate_gl_api_capability_dither: return GL_DITHER;
279 case gate_gl_api_capability_fog: return GL_FOG;
280 #if defined(GL_INDEX_LOGIC_OP)
281 case gate_gl_api_capability_index_logic_op: return GL_INDEX_LOGIC_OP;
282 #endif
283 //case gate_gl_api_capability_light: return GL_LIGHTi;
284 case gate_gl_api_capability_lighting: return GL_LIGHTING;
285 case gate_gl_api_capability_line_smooth: return GL_LINE_SMOOTH;
286 #if defined(GL_LINE_STIPPLE)
287 case gate_gl_api_capability_line_stipple: return GL_LINE_STIPPLE;
288 #endif
289 #if defined(GL_LOGIC_OP)
290 case gate_gl_api_capability_logic_op: return GL_LOGIC_OP;
291 #endif
292 #if defined(GL_MAP1_COLOR_4)
293 case gate_gl_api_capability_map1_color_4: return GL_MAP1_COLOR_4;
294 #endif
295 #if defined(GL_MAP1_INDEX)
296 case gate_gl_api_capability_map1_index: return GL_MAP1_INDEX;
297 #endif
298 #if defined(GL_MAP1_NORMAL)
299 case gate_gl_api_capability_map1_normal: return GL_MAP1_NORMAL;
300 #endif
301 #if defined(GL_MAP1_TEXTURE_COORD_1)
302 case gate_gl_api_capability_map1_texture_coord_1: return GL_MAP1_TEXTURE_COORD_1;
303 #endif
304 #if defined(GL_MAP1_TEXTURE_COORD_2)
305 case gate_gl_api_capability_map1_texture_coord_2: return GL_MAP1_TEXTURE_COORD_2;
306 #endif
307 #if defined(GL_MAP1_TEXTURE_COORD_3)
308 case gate_gl_api_capability_map1_texture_coord_3: return GL_MAP1_TEXTURE_COORD_3;
309 #endif
310 #if defined(GL_MAP1_TEXTURE_COORD_4)
311 case gate_gl_api_capability_map1_texture_coord_4: return GL_MAP1_TEXTURE_COORD_4;
312 #endif
313 #if defined(GL_MAP1_VERTEX_3)
314 case gate_gl_api_capability_map1_vertex_3: return GL_MAP1_VERTEX_3;
315 #endif
316 #if defined(GL_MAP1_VERTEX_4)
317 case gate_gl_api_capability_map1_vertex_4: return GL_MAP1_VERTEX_4;
318 #endif
319 #if defined(GL_MAP2_COLOR_4)
320 case gate_gl_api_capability_map2_color_4: return GL_MAP2_COLOR_4;
321 #endif
322 #if defined(GL_MAP2_INDEX)
323 case gate_gl_api_capability_map2_index: return GL_MAP2_INDEX;
324 #endif
325 #if defined(GL_MAP2_NORMAL)
326 case gate_gl_api_capability_map2_normal: return GL_MAP2_NORMAL;
327 #endif
328 #if defined(GL_MAP2_TEXTURE_COORD_1)
329 case gate_gl_api_capability_map2_texture_coord_1: return GL_MAP2_TEXTURE_COORD_1;
330 #endif
331 #if defined(GL_MAP2_TEXTURE_COORD_2)
332 case gate_gl_api_capability_map2_texture_coord_2: return GL_MAP2_TEXTURE_COORD_2;
333 #endif
334 #if defined(GL_MAP2_TEXTURE_COORD_3)
335 case gate_gl_api_capability_map2_texture_coord_3: return GL_MAP2_TEXTURE_COORD_3;
336 #endif
337 #if defined(GL_MAP2_TEXTURE_COORD_4)
338 case gate_gl_api_capability_map2_texture_coord_4: return GL_MAP2_TEXTURE_COORD_4;
339 #endif
340 #if defined(GL_MAP2_VERTEX_3)
341 case gate_gl_api_capability_map2_vertex_3: return GL_MAP2_VERTEX_3;
342 #endif
343 #if defined(GL_MAP2_VERTEX_4)
344 case gate_gl_api_capability_map2_vertex_4: return GL_MAP2_VERTEX_4;
345 #endif
346 case gate_gl_api_capability_normalize: return GL_NORMALIZE;
347 case gate_gl_api_capability_point_smooth: return GL_POINT_SMOOTH;
348 case gate_gl_api_capability_polygon_offset_fill: return GL_POLYGON_OFFSET_FILL;
349 #if defined(GL_POLYGON_OFFSET_LINE)
350 case gate_gl_api_capability_polygon_offset_line: return GL_POLYGON_OFFSET_LINE;
351 #endif
352 #if defined(GL_POLYGON_OFFSET_POINT)
353 case gate_gl_api_capability_polygon_offset_point: return GL_POLYGON_OFFSET_POINT;
354 #endif
355 #if defined(GL_POLYGON_SMOOTH)
356 case gate_gl_api_capability_polygon_smooth: return GL_POLYGON_SMOOTH;
357 #endif
358 #if defined(GL_POLYGON_STIPPLE)
359 case gate_gl_api_capability_polygon_stipple: return GL_POLYGON_STIPPLE;
360 #endif
361 case gate_gl_api_capability_scissor_test: return GL_SCISSOR_TEST;
362 case gate_gl_api_capability_stencil_test: return GL_STENCIL_TEST;
363 #if defined(GL_TEXTURE_1D)
364 case gate_gl_api_capability_texture_1d: return GL_TEXTURE_1D;
365 #endif
366 case gate_gl_api_capability_texture_2d: return GL_TEXTURE_2D;
367 #if defined(GL_TEXTURE_GEN_Q)
368 case gate_gl_api_capability_texture_gen_q: return GL_TEXTURE_GEN_Q;
369 #endif
370 #if defined(GL_TEXTURE_GEN_R)
371 case gate_gl_api_capability_texture_gen_r: return GL_TEXTURE_GEN_R;
372 #endif
373 #if defined(GL_TEXTURE_GEN_S)
374 case gate_gl_api_capability_texture_gen_s: return GL_TEXTURE_GEN_S;
375 #endif
376 #if defined(GL_TEXTURE_GEN_T)
377 case gate_gl_api_capability_texture_gen_t: return GL_TEXTURE_GEN_T;
378 #endif
379 default: return 0;
380 }
381 }
382
383
384 1 void gate_gl_api_enable(gate_gl_api_capability_t capability)
385 {
386 1 gate_gl_api.glEnable(translate_capability(capability));
387 1 }
388
389 1 void gate_gl_api_disable(gate_gl_api_capability_t capability)
390 {
391 1 gate_gl_api.glDisable(translate_capability(capability));
392 1 }
393
394 void gate_gl_api_depthfunc(gate_gl_api_depth_t depth_function)
395 {
396 GLenum value = 0;
397 switch (depth_function)
398 {
399 case gate_gl_api_depth_never: value = GL_NEVER; break;
400 case gate_gl_api_depth_less: value = GL_LESS; break;
401 case gate_gl_api_depth_lequal: value = GL_LEQUAL; break;
402 case gate_gl_api_depth_equal: value = GL_EQUAL; break;
403 case gate_gl_api_depth_greater: value = GL_GREATER; break;
404 case gate_gl_api_depth_notequal:value = GL_NOTEQUAL;break;
405 case gate_gl_api_depth_gequal: value = GL_GEQUAL; break;
406 case gate_gl_api_depth_always: value = GL_ALWAYS; break;
407 }
408 gate_gl_api.glDepthFunc(value);
409 }
410
411 void gate_gl_api_depthmask(gate_bool_t enabled)
412 {
413 gate_gl_api.glDepthMask(enabled ? GL_TRUE : GL_FALSE);
414 }
415
416 void gate_gl_api_hint(gate_gl_api_hint_t hint_type, gate_gl_api_hintmode_t hint_mode)
417 {
418 GLenum ht = 0, hm = 0;
419 switch (hint_type)
420 {
421 case gate_gl_api_hint_fog_hint: ht = GL_FOG_HINT; break;
422 case gate_gl_api_hint_line_smooth_hint: ht = GL_LINE_SMOOTH_HINT; break;
423 case gate_gl_api_hint_perspective_correction_hint: ht = GL_PERSPECTIVE_CORRECTION_HINT;break;
424 case gate_gl_api_hint_point_smooth_hint: ht = GL_POINT_SMOOTH_HINT; break;
425 #if defined(GL_POLYGON_SMOOTH_HINT)
426 case gate_gl_api_hint_polygon_smooth_hint: ht = GL_POLYGON_SMOOTH_HINT; break;
427 #endif
428 default: ht = 0; break;
429 }
430
431 switch (hint_mode)
432 {
433 case gate_gl_api_hintmode_fastest: hm = GL_FASTEST; break;
434 case gate_gl_api_hintmode_nicest: hm = GL_NICEST; break;
435 case gate_gl_api_hintmode_dont_care: hm = GL_DONT_CARE; break;
436 }
437
438 gate_gl_api.glHint(ht, hm);
439 }
440
441 1 void gate_gl_api_viewport(gate_int32_t x, gate_int32_t y, gate_int32_t width, gate_int32_t height)
442 {
443 1 gate_gl_api.glViewport(x, y, width, height);
444 1 }
445
446 2 void gate_gl_api_matrixmode(gate_gl_api_matrixmode_t matrix_mode)
447 {
448 2 GLenum mm = 0;
449
2/4
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2 switch (matrix_mode)
450 {
451 1 case gate_gl_api_matrixmode_modelview: mm = GL_MODELVIEW; break;
452 1 case gate_gl_api_matrixmode_projection: mm = GL_PROJECTION; break;
453 case gate_gl_api_matrixmode_texture: mm = GL_TEXTURE; break;
454 }
455 2 gate_gl_api.glMatrixMode(mm);
456 2 }
457
458 22 void gate_gl_api_loadidentity()
459 {
460 22 gate_gl_api.glLoadIdentity();
461 22 }
462
463 20 void gate_gl_api_flush()
464 {
465 20 gate_gl_api.glFlush();
466 20 }
467
468 20 void gate_gl_api_finish()
469 {
470 20 gate_gl_api.glFinish();
471 20 }
472
473 20 void gate_gl_api_clear(unsigned clear_bits)
474 {
475 20 GLbitfield bf = 0;
476
477
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (clear_bits & gate_gl_api_clearbit_color_buffer_bit)
478 {
479 20 bf |= GL_COLOR_BUFFER_BIT;
480 }
481
1/2
✓ Branch 0 taken 20 times.
✗ Branch 1 not taken.
20 if (clear_bits & gate_gl_api_clearbit_depth_buffer_bit)
482 {
483 20 bf |= GL_DEPTH_BUFFER_BIT;
484 }
485
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (clear_bits & gate_gl_api_clearbit_accum_buffer_bit)
486 {
487 #if defined(GL_ACCUM_BUFFER_BIT)
488 bf |= GL_ACCUM_BUFFER_BIT;
489 #endif
490 }
491
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if (clear_bits & gate_gl_api_clearbit_stencil_buffer_bit)
492 {
493 bf |= GL_STENCIL_BUFFER_BIT;
494 }
495 20 gate_gl_api.glClear(bf);
496 20 }
497
498 /* https://www.khronos.org/message_boards/showthread.php/4991-The-Solution-for-gluLookAt%28%29-Function!!!! */
499 /* https://community.khronos.org/t/the-solution-for-glulookat-function/521 */
500
501
502 20 static GLenum translate_draw_mode(gate_gl_api_drawmode_t draw_mode)
503 {
504 20 GLenum ret = 0;
505
1/11
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 20 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
20 switch (draw_mode)
506 {
507 case gate_gl_api_drawmode_points: ret = GL_POINTS; break;
508 case gate_gl_api_drawmode_lines: ret = GL_LINES; break;
509 case gate_gl_api_drawmode_line_loop: ret = GL_LINE_LOOP; break;
510 case gate_gl_api_drawmode_line_strip: ret = GL_LINE_STRIP; break;
511 case gate_gl_api_drawmode_triangles: ret = GL_TRIANGLES; break;
512 case gate_gl_api_drawmode_triangle_strip: ret = GL_TRIANGLE_STRIP; break;
513 case gate_gl_api_drawmode_triangle_fan: ret = GL_TRIANGLE_FAN; break;
514 #if defined(GL_QUADS)
515 20 case gate_gl_api_drawmode_quads: ret = GL_QUADS; break;
516 #endif
517 #if defined(GL_QUAD_STRIP)
518 case gate_gl_api_drawmode_quad_strip: ret = GL_QUAD_STRIP; break;
519 #endif
520 #if defined(GL_POLYGON)
521 case gate_gl_api_drawmode_polygon: ret = GL_POLYGON; break;
522 #endif
523 default: ret = 0; break;
524 }
525 20 return ret;
526 }
527
528 20 void gate_gl_api_drawarrays(gate_gl_api_drawmode_t draw_mode, int index, size_t count)
529 {
530 20 gate_gl_api.glDrawArrays(translate_draw_mode(draw_mode), (GLint)index, (GLsizei)count);
531 20 }
532
533 void* gate_gl_api_createtexture(gate_gl_api_pixelformat_t pixel_format,
534 gate_uint32_t width, gate_uint32_t height, void const* data)
535 {
536 GLenum format;
537 GLenum datatype;
538 GLuint tex;
539 GLenum paramFilter = GL_LINEAR;
540 GLint internalFormat =
541 #if defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
542 GL_RGBA;
543 #elif defined(GL_RGBA8)
544 GL_RGBA8;
545 #elif defined(GL_RGB8)
546 GL_RGB8;
547 #else
548 GL_RGBA;
549 #endif
550
551 switch (pixel_format)
552 {
553 case gate_gl_api_pixelformat_rgb:
554 {
555 format = GL_RGB;
556 datatype = GL_UNSIGNED_BYTE;
557 break;
558 }
559 case gate_gl_api_pixelformat_rgba:
560 {
561 format = GL_RGBA;
562 datatype = GL_UNSIGNED_BYTE;
563 break;
564 }
565 default:
566 {
567 /* not supported */
568 return 0;
569 }
570 }
571
572 #if !defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
573 gate_gl_api.glEnable(GL_TEXTURE_2D);
574 #endif
575 gate_gl_api.glGenTextures(1, &tex);
576 gate_gl_api.glBindTexture(GL_TEXTURE_2D, tex);
577
578 gate_gl_api.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, paramFilter);
579 gate_gl_api.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, paramFilter);
580
581 gate_gl_api.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
582 gate_gl_api.glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
583
584 gate_gl_api.glTexImage2D(GL_TEXTURE_2D, 0, internalFormat, width, height, 0, format, datatype, data);
585
586 #if !defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
587 gate_gl_api.glDisable(GL_TEXTURE_2D);
588 #endif
589
590 return (void*)(gate_uintptr_t)(tex);
591 }
592
593 void gate_gl_api_deletetexture(void* texture_id)
594 {
595 GLuint tex = (GLuint)(gate_uintptr_t)(texture_id);
596 gate_gl_api.glDeleteTextures(1, &tex);
597 }
598
599 void gate_gl_api_bindtexture(void* texture_id)
600 {
601 GLuint tex = (GLuint)(gate_uintptr_t)texture_id;
602 #if !defined(GATE_GRAPHICS_NO_LEGACY_OPENGL)
603 gate_gl_api.glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
604 #endif
605 gate_gl_api.glBindTexture(GL_TEXTURE_2D, tex);
606 }
607
608 1 void gate_gl_api_cullface(gate_gl_api_cullface_t mode)
609 {
610 1 GLenum value = GL_FRONT_AND_BACK;
611
1/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
1 switch (mode)
612 {
613 1 case gate_gl_api_cullface_front: value = GL_FRONT; break;
614 case gate_gl_api_cullface_back: value = GL_BACK; break;
615 case gate_gl_api_cullface_front_and_back: value = GL_FRONT_AND_BACK; break;
616 }
617 1 gate_gl_api.glCullFace(value);
618 1 }
619
620
621
622 #if defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
623
624 #if defined(GATE_SYS_WASM)
625 # define GATE_GL2_DIRECT_CALL
626 #endif
627
628 #if defined(GATE_GL2_DIRECT_CALL)
629 # define GL2CALL(func) func
630 #else
631 # define GL2CALL(func) gate_gl2_api. func
632 #endif
633
634
635 gate_uintptr_t gate_gl2_api_create_shader(gate_gl2_api_shader_type_t type)
636 {
637 GLenum itype = GL_VERTEX_SHADER;
638 switch(type)
639 {
640 case gate_gl2_api_shader_type_compute: itype = GL_COMPUTE_SHADER; break;
641 case gate_gl2_api_shader_type_vertex: itype = GL_VERTEX_SHADER; break;
642 case gate_gl2_api_shader_type_tess_control: itype = GL_TESS_CONTROL_SHADER; break;
643 case gate_gl2_api_shader_type_tess_evaluation: itype = GL_TESS_EVALUATION_SHADER; break;
644 case gate_gl2_api_shader_type_geometry: itype = GL_GEOMETRY_SHADER; break;
645 case gate_gl2_api_shader_type_fragment: itype = GL_FRAGMENT_SHADER; break;
646 }
647 return (gate_uintptr_t) GL2CALL(glCreateShader)(itype);
648 }
649 void gate_gl2_api_shader_source(gate_uintptr_t shader, gate_size_t count, char const * const * code, gate_size_t const* length)
650 {
651 GLint const iLength = length ? (GLint)*length : 0;
652 GL2CALL(glShaderSource)((GLuint)shader, (GLsizei)count, code, length ? &iLength : NULL);
653 }
654 void gate_gl2_api_compile_shader(gate_uintptr_t shader)
655 {
656 GL2CALL(glCompileShader)((GLuint)shader);
657 }
658 void gate_gl2_api_get_shader_iv(gate_uintptr_t shader, gate_gl2_api_shader_param_t param_name, gate_intptr_t* params)
659 {
660 GLenum pname = GL_SHADER_TYPE;
661 GLint iparam = (GLint)*params;
662 switch(param_name)
663 {
664 case gate_gl2_api_shader_param_type: pname = GL_SHADER_TYPE; break;
665 case gate_gl2_api_shader_param_delete_status: pname = GL_DELETE_STATUS; break;
666 case gate_gl2_api_shader_param_compile_status: pname = GL_COMPILE_STATUS; break;
667 case gate_gl2_api_shader_param_info_log_length: pname = GL_INFO_LOG_LENGTH; break;
668 case gate_gl2_api_shader_param_source_length: pname = GL_SHADER_SOURCE_LENGTH; break;
669 }
670 GL2CALL(glGetShaderiv)(shader, pname, &iparam);
671 *params = (gate_intptr_t)iparam;
672 }
673 void gate_gl2_api_get_shader_info_log(gate_uintptr_t shader, gate_size_t maxLength, gate_size_t* length, char* infoLog)
674 {
675 GLsizei max_length = (GLsizei)maxLength;
676 GLsizei len = max_length;
677 GLchar* ptr_info = (GLchar*)infoLog;
678 GL2CALL(glGetShaderInfoLog)((GLuint)shader, max_length, &len, ptr_info);
679 }
680 void gate_gl2_api_delete_shader(gate_uintptr_t shader)
681 {
682 GL2CALL(glDeleteShader)((GLuint)shader);
683 }
684
685
686 gate_uintptr_t gate_gl2_api_create_program(void)
687 {
688 return GL2CALL(glCreateProgram)();
689 }
690 void gate_gl2_api_link_program(gate_uintptr_t program)
691 {
692 GL2CALL(glLinkProgram)((GLuint)program);
693 }
694 void gate_gl2_api_get_program_iv(gate_uintptr_t program, gate_gl2_api_program_param_t param_name, gate_intptr_t* params)
695 {
696 GLenum pname = GL_LINK_STATUS;
697 GLint iparams = (GLint)*params;
698 switch(param_name)
699 {
700 case gate_gl2_api_program_param_active_attributes: pname = GL_ACTIVE_ATTRIBUTES; break;
701 case gate_gl2_api_program_param_active_attribute_max_length: pname = GL_ACTIVE_ATTRIBUTE_MAX_LENGTH; break;
702 case gate_gl2_api_program_param_active_uniforms: pname = GL_ACTIVE_UNIFORMS; break;
703 case gate_gl2_api_program_param_active_uniform_blocks: pname = GL_ACTIVE_UNIFORM_BLOCKS; break;
704 case gate_gl2_api_program_param_active_uniform_block_max_name_length: pname = GL_ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH; break;
705 case gate_gl2_api_program_param_active_uniform_max_length: pname = GL_ACTIVE_UNIFORM_MAX_LENGTH; break;
706 case gate_gl2_api_program_param_attached_shaders: pname = GL_ATTACHED_SHADERS; break;
707 case gate_gl2_api_program_param_delete_status: pname = GL_DELETE_STATUS; break;
708 case gate_gl2_api_program_param_info_log_length: pname = GL_INFO_LOG_LENGTH; break;
709 case gate_gl2_api_program_param_link_status: pname = GL_LINK_STATUS; break;
710 case gate_gl2_api_program_param_program_binary_retrievable_hint: pname = GL_PROGRAM_BINARY_RETRIEVABLE_HINT; break;
711 case gate_gl2_api_program_param_transform_feedback_buffer_mode: pname = GL_TRANSFORM_FEEDBACK_BUFFER_MODE; break;
712 case gate_gl2_api_program_param_transform_feedback_varyings: pname = GL_TRANSFORM_FEEDBACK_VARYINGS; break;
713 case gate_gl2_api_program_param_transform_feedback_varying_max_length: pname = GL_TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH; break;
714 case gate_gl2_api_program_param_validate_status: pname = GL_VALIDATE_STATUS; break;
715 }
716 GL2CALL(glGetProgramiv)(program, pname, &iparams);
717 *params = (gate_intptr_t)iparams;
718 }
719 void gate_gl2_api_get_program_info_log(gate_uintptr_t program, gate_size_t bufSize, gate_size_t* length, char* infoLog)
720 {
721 GLsizei len = *length;
722 GL2CALL(glGetProgramInfoLog)((GLuint)program, (GLsizei)bufSize, &len, infoLog);
723 *length = len;
724 }
725
726 void gate_gl2_api_use_program(gate_uintptr_t program)
727 {
728 GL2CALL(glUseProgram)((GLuint)program);
729 }
730 void gate_gl2_api_attach_shader(gate_uintptr_t program, gate_uintptr_t shader)
731 {
732 GL2CALL(glAttachShader)((GLuint)program, (GLuint)shader);
733 }
734 void gate_gl2_api_delete_program(gate_uintptr_t program)
735 {
736 GL2CALL(glDeleteProgram)((GLuint)program);
737 }
738 void gate_gl2_api_bind_attrib_location(gate_uintptr_t program, gate_size_t index, char const* name)
739 {
740 GL2CALL(glBindAttribLocation)((GLuint)program, (GLuint)index, name);
741 }
742 gate_intptr_t gate_gl2_api_get_attrib_location(gate_uintptr_t program, char const* name)
743 {
744 return GL2CALL(glGetAttribLocation)((GLuint)program, name);
745 }
746 gate_intptr_t gate_gl2_api_get_uniform_location(gate_uintptr_t program, char const* name)
747 {
748 return GL2CALL(glGetUniformLocation)((GLuint)program, name);
749 }
750
751
752 void gate_gl2_api_gen_buffers(gate_size_t n, unsigned int* buffers)
753 {
754 GL2CALL(glGenBuffers)((GLsizei)n, buffers);
755 }
756 void gate_gl2_api_delete_buffers(gate_size_t n, unsigned int const * buffers)
757 {
758 GL2CALL(glDeleteBuffers)((GLsizei)n, buffers);
759 }
760
761 static GLenum convert_target(gate_gl2_api_buffer_type_t target_type)
762 {
763 switch(target_type)
764 {
765 default:
766 case gate_gl2_api_buffer_type_array: return GL_ARRAY_BUFFER;
767 case gate_gl2_api_buffer_type_atomic_counter: return GL_ATOMIC_COUNTER_BUFFER;
768 case gate_gl2_api_buffer_type_copy_read: return GL_COPY_READ_BUFFER;
769 case gate_gl2_api_buffer_type_copy_write: return GL_COPY_WRITE_BUFFER;
770 case gate_gl2_api_buffer_type_dispatch_indirect: return GL_DISPATCH_INDIRECT_BUFFER;
771 case gate_gl2_api_buffer_type_draw_indirect: return GL_DRAW_INDIRECT_BUFFER;
772 case gate_gl2_api_buffer_type_element_array: return GL_ELEMENT_ARRAY_BUFFER;
773 case gate_gl2_api_buffer_type_pixel_pack: return GL_PIXEL_PACK_BUFFER;
774 case gate_gl2_api_buffer_type_pixel_unpack: return GL_PIXEL_UNPACK_BUFFER;
775 case gate_gl2_api_buffer_type_query: return GL_QUERY_BUFFER;
776 case gate_gl2_api_buffer_type_shader_storage: return GL_SHADER_STORAGE_BUFFER;
777 case gate_gl2_api_buffer_type_texture: return GL_TEXTURE_BUFFER;
778 case gate_gl2_api_buffer_type_transform_feedback: return GL_TRANSFORM_FEEDBACK_BUFFER;
779 case gate_gl2_api_buffer_type_uniform: return GL_UNIFORM_BUFFER;
780 }
781 }
782 void gate_gl2_api_bind_buffer(gate_gl2_api_buffer_type_t target_type, unsigned int buffer)
783 {
784 GLenum target = convert_target(target_type);
785 GL2CALL(glBindBuffer)(target, buffer);
786 }
787 static GLenum convert_usage(gate_gl2_api_usage_type_t usage_value)
788 {
789 switch(usage_value)
790 {
791 default:
792 case gate_gl2_api_usage_type_stream_draw: return GL_STREAM_DRAW;
793 case gate_gl2_api_usage_type_stream_read: return GL_STREAM_READ;
794 case gate_gl2_api_usage_type_stream_copy: return GL_STREAM_COPY;
795 case gate_gl2_api_usage_type_static_draw: return GL_STATIC_DRAW;
796 case gate_gl2_api_usage_type_static_read: return GL_STATIC_READ;
797 case gate_gl2_api_usage_type_static_copy: return GL_STATIC_COPY;
798 case gate_gl2_api_usage_type_dynamic_draw: return GL_DYNAMIC_DRAW;
799 case gate_gl2_api_usage_type_dynamic_read: return GL_DYNAMIC_READ;
800 case gate_gl2_api_usage_type_dynamic_copy: return GL_DYNAMIC_COPY;
801 }
802 }
803 void gate_gl2_api_buffer_data(gate_gl2_api_buffer_type_t target_type, gate_size_t size, void const* data, gate_gl2_api_usage_type_t usage_value)
804 {
805 GLenum target = convert_target(target_type);
806 GLenum usage = convert_usage(usage_value);
807 GL2CALL(glBufferData)(target, size, data, usage);
808 }
809 /*
810 void gate_gl2_api_named_buffer_data(unsigned int buffer, gate_size_t size, void const* data, gate_gl2_api_usage_type_t usage_value)
811 {
812 GLenum usage = convert_usage(usage_value);
813 gate_gl2_api.glNamedBufferData(buffer, size, data, usage);
814 }
815 */
816 void gate_gl2_api_vertex_attrib_pointer(gate_uintptr_t index, gate_size_t size, gate_gl2_api_vertex_attrib_type_t type, gate_bool_t normalized, gate_size_t stride, void const* pointer)
817 {
818 GLenum vtype = GL_INT;
819 GLboolean bnorm = normalized ? GL_TRUE : GL_FALSE;
820 switch(type)
821 {
822 case gate_gl2_api_vertex_attrib_byte: vtype = GL_BYTE; break;
823 case gate_gl2_api_vertex_attrib_unsigned_byte: vtype = GL_UNSIGNED_BYTE; break;
824 case gate_gl2_api_vertex_attrib_short: vtype = GL_SHORT; break;
825 case gate_gl2_api_vertex_attrib_unsigned_short: vtype = GL_UNSIGNED_SHORT; break;
826 case gate_gl2_api_vertex_attrib_int: vtype = GL_INT; break;
827 case gate_gl2_api_vertex_attrib_half_float: vtype = GL_HALF_FLOAT; break;
828 case gate_gl2_api_vertex_attrib_float: vtype = GL_FLOAT; break;
829 case gate_gl2_api_vertex_attrib_double: vtype = GL_DOUBLE; break;
830 case gate_gl2_api_vertex_attrib_fixed: vtype = GL_FIXED; break;
831 case gate_gl2_api_vertex_attrib_int_2_10_10_10_rev: vtype = GL_INT_2_10_10_10_REV; break;
832 case gate_gl2_api_vertex_attrib_unsigned_int_2_10_10_10_rev: vtype = GL_UNSIGNED_INT_2_10_10_10_REV; break;
833 case gate_gl2_api_vertex_attrib_unsigned_int_10F_11F_11F_rev: vtype = GL_UNSIGNED_INT_10F_11F_11F_REV; break;
834 }
835
836 GL2CALL(glVertexAttribPointer)((GLuint)index, (GLint)size, vtype, bnorm, (GLsizei)stride, pointer);
837 }
838
839 void gate_gl2_api_enable_vertex_attrib_array(gate_uintptr_t index)
840 {
841 GL2CALL(glEnableVertexAttribArray)((GLuint)index);
842 }
843 void gate_gl2_api_disable_vertex_attrib_array(gate_uintptr_t index)
844 {
845 GL2CALL(glDisableVertexAttribArray)((GLuint)index);
846 }
847 void gate_gl2_api_active_texture(gate_uintptr_t texture_index)
848 {
849 GLenum param = GL_TEXTURE0 + texture_index;
850 GL2CALL(glActiveTexture)(param);
851 }
852
853
854 void gate_gl2_api_uniform1f(gate_intptr_t location, gate_real32_t v0)
855 {
856 GL2CALL(glUniform1f)(location, v0);
857 }
858 void gate_gl2_api_uniform2f(gate_intptr_t location, gate_real32_t v0, gate_real32_t v1)
859 {
860 GL2CALL(glUniform2f)(location, v0, v1);
861 }
862 void gate_gl2_api_uniform3f(gate_intptr_t location, gate_real32_t v0, gate_real32_t v1, gate_real32_t v2)
863 {
864 GL2CALL(glUniform3f)(location, v0, v1, v2);
865 }
866 void gate_gl2_api_uniform4f(gate_intptr_t location, gate_real32_t v0, gate_real32_t v1, gate_real32_t v2, gate_real32_t v3)
867 {
868 GL2CALL(glUniform4f)(location, v0, v1, v2, v3);
869 }
870 void gate_gl2_api_uniform1fv(gate_intptr_t location, gate_size_t count,const gate_real32_t *value)
871 {
872 GL2CALL(glUniform1fv)(location, count, value);
873 }
874 void gate_gl2_api_uniform2fv(gate_intptr_t location, gate_size_t count, const gate_real32_t *value)
875 {
876 GL2CALL(glUniform2fv)(location, count, value);
877 }
878 void gate_gl2_api_uniform3fv(gate_intptr_t location, gate_size_t count, const gate_real32_t *value)
879 {
880 GL2CALL(glUniform3fv)(location, count, value);
881 }
882 void gate_gl2_api_uniform4fv(gate_intptr_t location, gate_size_t count, const gate_real32_t *value)
883 {
884 GL2CALL(glUniform4fv)(location, count, value);
885 }
886 void gate_gl2_api_uniform1i(gate_intptr_t location, int v0)
887 {
888 GL2CALL(glUniform1i)(location, v0);
889 }
890 void gate_gl2_api_uniform2i(gate_intptr_t location, int v0, int v1)
891 {
892 GL2CALL(glUniform2i)(location, v0, v1);
893 }
894 void gate_gl2_api_uniform3i(gate_intptr_t location, int v0, int v1, int v2)
895 {
896 GL2CALL(glUniform3i)(location, v0, v1, v2);
897 }
898 void gate_gl2_api_uniform4i(gate_intptr_t location, int v0, int v1, int v2, int v3)
899 {
900 GL2CALL(glUniform4i)(location, v0, v1, v2, v3);
901 }
902 void gate_gl2_api_uniform1iv(gate_intptr_t location, gate_size_t count, const int *value)
903 {
904 GL2CALL(glUniform1iv)(location, count, value);
905 }
906 void gate_gl2_api_uniform2iv(gate_intptr_t location, gate_size_t count, const int *value)
907 {
908 GL2CALL(glUniform2iv)(location, count, value);
909 }
910 void gate_gl2_api_uniform3iv(gate_intptr_t location, gate_size_t count, const int *value)
911 {
912 GL2CALL(glUniform3iv)(location, count, value);
913 }
914 void gate_gl2_api_uniform4iv(gate_intptr_t location, gate_size_t count, const int *value)
915 {
916 GL2CALL(glUniform4iv)(location, count, value);
917 }
918
919
920 void gate_gl2_api_uniform_matrix2fv(gate_intptr_t location, gate_size_t count, gate_bool_t transpose, const gate_real32_t *value)
921 {
922 GL2CALL(glUniformMatrix2fv)(location, count, transpose, value);
923 }
924 void gate_gl2_api_uniform_matrix3fv(gate_intptr_t location, gate_size_t count, gate_bool_t transpose, const gate_real32_t *value)
925 {
926 GL2CALL(glUniformMatrix3fv)(location, count, transpose, value);
927 }
928 void gate_gl2_api_uniform_matrix4fv(gate_intptr_t location, gate_size_t count, gate_bool_t transpose, const gate_real32_t *value)
929 {
930 GL2CALL(glUniformMatrix4fv)(location, count, transpose, value);
931 }
932
933
934
935 #endif /* GATE_GRAPHICS_OPENGL2_SUPPORT */
936
937
938
939 #if defined(GATE_GL_API_WINAPI)
940
941 #include "gate/graphics/platform/opengl_winapi_impl.h"
942
943 #endif /* GATE_GL_API_WINAPI */
944
945
946
947 #if defined(GATE_GL_API_GLUT)
948
949 #include "gate/graphics/platform/opengl_glut_impl.h"
950
951 #endif /* GATE_GL_API_GLUT */
952
953
954
955 #if defined(GATE_GL_API_EGL)
956
957 # include "gate/graphics/platform/opengl_egl_apis.h"
958
959 # if defined(GATE_SYS_WINCE)
960 # elif defined(GATE_SYS_WASM)
961 # include "gate/graphics/platform/opengl_emscripten_impl.h"
962 # elif defined(GATE_SYS_ANDROID)
963 # include "gate/graphics/platform/opengl_android_impl.h"
964 # else
965 # include "gate/graphics/platform/opengl_xlib_impl.h"
966 # endif
967
968 #endif /* GATE_GL_API_EGL */
969
970
971 #endif /* GATE_GRAPHICS_GL_OPENGL */
972
973
974
975 #if defined(GATE_GARPHICS_GL_NOIMPL)
976
977
978 gate_result_t gate_gl_surface_init(gate_gl_surface_t* surface)
979 {
980 (void)surface;
981 return GATE_RESULT_NOTIMPLEMENTED;
982 }
983 gate_result_t gate_gl_surface_uninit(gate_gl_surface_t* surface)
984 {
985 (void)surface;
986 return GATE_RESULT_NOTIMPLEMENTED;
987 }
988 gate_result_t gate_gl_surface_open(gate_gl_surface_t* surface, gate_gl_surface_type_t type,
989 gate_uint32_t width, gate_uint32_t height, gate_enumint_t flags)
990 {
991 (void)surface;
992 (void)type;
993 (void)width;
994 (void)height;
995 (void)flags;
996 return GATE_RESULT_NOTIMPLEMENTED;
997 }
998 gate_result_t gate_gl_surface_close(gate_gl_surface_t* surface)
999 {
1000 (void)surface;
1001 return GATE_RESULT_NOTIMPLEMENTED;
1002 }
1003 gate_result_t gate_gl_surface_resize(gate_gl_surface_t* surface, gate_uint32_t width, gate_uint32_t height)
1004 {
1005 (void)surface;
1006 (void)width;
1007 (void)height;
1008 return GATE_RESULT_NOTIMPLEMENTED;
1009 }
1010 gate_result_t gate_gl_surface_get_size(gate_gl_surface_t* surface, gate_uint32_t* width, gate_uint32_t* height)
1011 {
1012 (void)surface;
1013 (void)width;
1014 (void)height;
1015 return GATE_RESULT_NOTIMPLEMENTED;
1016 }
1017 gate_result_t gate_gl_surface_print_image(gate_gl_surface_t* surface, gate_rasterimage_t* target_image)
1018 {
1019 (void)surface;
1020 (void)target_image;
1021 return GATE_RESULT_NOTIMPLEMENTED;
1022 }
1023 gate_result_t gate_gl_surface_run_event_loop(gate_gl_surface_t* surface,
1024 gate_gl_surface_events_t* event_callbacks, void* user_param)
1025 {
1026 (void)surface;
1027 (void)event_callbacks;
1028 (void)user_param;
1029 return GATE_RESULT_NOTIMPLEMENTED;
1030 }
1031 gate_result_t gate_gl_surface_exit_event_loop(gate_gl_surface_t* surface)
1032 {
1033 (void)surface;
1034 return GATE_RESULT_NOTIMPLEMENTED;
1035 }
1036 gate_result_t gate_gl_surface_swap_buffers(gate_gl_surface_t* surface)
1037 {
1038 (void)surface;
1039 return GATE_RESULT_NOTIMPLEMENTED;
1040 }
1041
1042
1043
1044 gate_result_t gate_gl_api_init()
1045 {
1046 return GATE_RESULT_NOTIMPLEMENTED;
1047 }
1048
1049 void gate_gl_api_color3(gate_real32_t r, gate_real32_t g, gate_real32_t b)
1050 {
1051 (void)r;
1052 (void)g;
1053 (void)b;
1054 }
1055 void gate_gl_api_color4(gate_real32_t r, gate_real32_t g, gate_real32_t b, gate_real32_t a)
1056 {
1057 (void)r;
1058 (void)g;
1059 (void)b;
1060 (void)a;
1061 }
1062 void gate_gl_api_color3b(gate_uint8_t r, gate_uint8_t g, gate_uint8_t b)
1063 {
1064 (void)r;
1065 (void)g;
1066 (void)b;
1067 }
1068 void gate_gl_api_color4b(gate_uint8_t r, gate_uint8_t g, gate_uint8_t b, gate_uint8_t a)
1069 {
1070 (void)r;
1071 (void)g;
1072 (void)b;
1073 (void)a;
1074 }
1075 void gate_gl_api_vertexpointer(gate_size_t coord_count, gate_size_t stride, gate_real32_t const* ptr_coords)
1076 {
1077 (void)coord_count;
1078 (void)stride;
1079 (void)ptr_coords;
1080 }
1081 void gate_gl_api_colorpointer(gate_size_t color_count, gate_size_t stride, gate_real32_t const* ptr_colors)
1082 {
1083 (void)color_count;
1084 (void)stride;
1085 (void)ptr_colors;
1086 }
1087
1088 void gate_gl_api_texcoordpointer(gate_size_t coord_count, gate_real32_t const* ptr_coords)
1089 {
1090 (void)coord_count;
1091 (void)ptr_coords;
1092 }
1093 void gate_gl_api_shademodel(gate_gl_api_shademodel_t model)
1094 {
1095 (void)model;
1096 }
1097 void gate_gl_api_blendfunc(gate_gl_api_blend_t blend_func_src, gate_gl_api_blend_t blend_func_dst)
1098 {
1099 (void)blend_func_src;
1100 (void)blend_func_dst;
1101 }
1102 void gate_gl_api_clearcolor(gate_real32_t r, gate_real32_t g, gate_real32_t b, gate_real32_t a)
1103 {
1104 (void)r;
1105 (void)g;
1106 (void)b;
1107 (void)a;
1108 }
1109 void gate_gl_api_cleardepth(gate_real32_t depth)
1110 {
1111 (void)depth;
1112 }
1113 void gate_gl_api_enable(gate_gl_api_capability_t capability)
1114 {
1115 (void)capability;
1116 }
1117 void gate_gl_api_disable(gate_gl_api_capability_t capability)
1118 {
1119 (void)capability;
1120 }
1121 void gate_gl_api_depthfunc(gate_gl_api_depth_t depth_function)
1122 {
1123 (void)depth_function;
1124 }
1125 void gate_gl_api_depthmask(gate_bool_t enabled)
1126 {
1127 (void)enabled;
1128 }
1129 void gate_gl_api_hint(gate_gl_api_hint_t hint_type, gate_gl_api_hintmode_t hint_mode)
1130 {
1131 (void)hint_type;
1132 (void)hint_mode;
1133 }
1134 void gate_gl_api_viewport(gate_int32_t x, gate_int32_t y, gate_int32_t width, gate_int32_t height)
1135 {
1136 (void)x;
1137 (void)y;
1138 (void)width;
1139 (void)height;
1140 }
1141 void gate_gl_api_matrixmode(gate_gl_api_matrixmode_t matrix_mode)
1142 {
1143 (void)matrix_mode;
1144 }
1145 void gate_gl_api_loadidentity()
1146 {
1147 }
1148 void gate_gl_api_multmatrix(gate_real32_t const matrix[16])
1149 {
1150 (void)matrix;
1151 }
1152 void gate_gl_api_translate(gate_real32_t x, gate_real32_t y, gate_real32_t z)
1153 {
1154 (void)x;
1155 (void)y;
1156 (void)z;
1157 }
1158 void gate_gl_api_rotate(gate_real32_t angle, gate_real32_t x, gate_real32_t y, gate_real32_t z)
1159 {
1160 (void)angle;
1161 (void)x;
1162 (void)y;
1163 (void)z;
1164 }
1165 void gate_gl_api_flush()
1166 {
1167
1168 }
1169 void gate_gl_api_finish()
1170 {
1171
1172 }
1173 void gate_gl_api_clear(unsigned clear_bits)
1174 {
1175 (void)clear_bits;
1176 }
1177 void gate_gl_api_perspective(gate_real32_t fovy, gate_real32_t aspect, gate_real32_t znear, gate_real32_t zfar)
1178 {
1179 (void)fovy;
1180 (void)aspect;
1181 (void)znear;
1182 (void)zfar;
1183 }
1184 void gate_gl_api_lookat(gate_real32_t eyeX, gate_real32_t eyeY, gate_real32_t eyeZ,
1185 gate_real32_t lookX, gate_real32_t lookY, gate_real32_t lookZ,
1186 gate_real32_t upX, gate_real32_t upY, gate_real32_t upZ)
1187 {
1188 (void)eyeX;
1189 (void)eyeY;
1190 (void)eyeZ;
1191 (void)lookX;
1192 (void)lookY;
1193 (void)lookZ;
1194 (void)upX;
1195 (void)upY;
1196 (void)upZ;
1197 }
1198 void gate_gl_api_ortho(gate_real32_t left, gate_real32_t right, gate_real32_t bottom, gate_real32_t top,
1199 gate_real32_t near_val, gate_real32_t far_val)
1200 {
1201 (void)left;
1202 (void)right;
1203 (void)bottom;
1204 (void)top;
1205 (void)near_val;
1206 (void)far_val;
1207 }
1208 void gate_gl_api_enableclientstate(gate_gl_api_clientstate_t state)
1209 {
1210 (void)state;
1211 }
1212 void gate_gl_api_disableclientstate(gate_gl_api_clientstate_t state)
1213 {
1214 (void)state;
1215 }
1216 void gate_gl_api_drawarrays(gate_gl_api_drawmode_t draw_mode, int index, size_t count)
1217 {
1218 (void)draw_mode;
1219 (void)index;
1220 (void)count;
1221 }
1222 void* gate_gl_api_createtexture(gate_gl_api_pixelformat_t pixel_format, gate_uint32_t width, gate_uint32_t height,
1223 void const* data)
1224 {
1225 (void)pixel_format;
1226 (void)width;
1227 (void)height;
1228 (void)data;
1229 return NULL;
1230 }
1231 void gate_gl_api_deletetexture(void* texture_id)
1232 {
1233 (void)texture_id;
1234 }
1235 void gate_gl_api_bindtexture(void* texture_id)
1236 {
1237 (void)texture_id;
1238 }
1239 void gate_gl_api_cullface(gate_gl_api_cullface_t mode)
1240 {
1241 (void)mode;
1242 }
1243
1244 #endif /* GATE_GRAPHICS_GL_OPENGL */
1245
1246