GCC Code Coverage Report


Directory: src/gate/
File: src/gate/graphics/cxx_gl_apis.cpp
Date: 2026-06-15 21:53:51
Exec Total Coverage
Lines: 0 201 0.0%
Functions: 0 60 0.0%
Branches: 0 72 0.0%

Line Branch Exec Source
1 #include "gate/graphics/gl_apis.hpp"
2 #include "gate/exceptions.hpp"
3
4 namespace gate
5 {
6 namespace graph
7 {
8
9 ✗ GlApi::GlApi()
10 {
11 ✗ result_t result = gate_gl_api_init();
12 ✗ GATEXX_CHECK_EXCEPTION(result);
13 ✗ }
14
15 ✗ GlApi::~GlApi() noexcept
16 {
17 ✗ }
18
19 #if !defined(GATE_GRAPHICS_NO_LEGACY_OPENGL)
20 ✗ void GlApi::enableClientState(ClientStateEnum state)
21 {
22 ✗ gate_gl_api_enableclientstate((gate_gl_api_clientstate_t)(int)state);
23 ✗ }
24 ✗ void GlApi::disableClientState(ClientStateEnum state)
25 {
26 ✗ gate_gl_api_disableclientstate((gate_gl_api_clientstate_t)(int)state);
27 ✗ }
28 ✗ void GlApi::setShadeModel(ShadeModelEnum model)
29 {
30 ✗ gate_gl_api_shademodel((gate_gl_api_shademodel_t)(int)model);
31 ✗ }
32
33 ✗ void GlApi::mulMatrix(real32_t const matrix[16])
34 {
35 ✗ gate_gl_api_multmatrix(matrix);
36 ✗ }
37 ✗ void GlApi::translate(real32_t x, real32_t y, real32_t z)
38 {
39 ✗ gate_gl_api_translate(x, y, z);
40 ✗ }
41 ✗ void GlApi::rotate(real32_t angle, real32_t x, real32_t y, real32_t z)
42 {
43 ✗ gate_gl_api_rotate(angle, x, y, z);
44 ✗ }
45
46 ✗ void GlApi::setPerspective(real32_t fovy, real32_t aspect, real32_t znear, real32_t zfar)
47 {
48 ✗ gate_gl_api_perspective(fovy, aspect, znear, zfar);
49 ✗ }
50 ✗ void GlApi::lookAt(real32_t eyeX, real32_t eyeY, real32_t eyeZ, real32_t lookX, real32_t lookY, real32_t lookZ, real32_t upX, real32_t upY, real32_t upZ)
51 {
52 ✗ gate_gl_api_lookat(eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
53 ✗ }
54
55 ✗ void GlApi::setTexCoordPointer(size_t coord_count, real32_t const* ptr_coords)
56 {
57 ✗ gate_gl_api_texcoordpointer(coord_count, ptr_coords);
58 ✗ }
59
60 ✗ void GlApi::setColor(real32_t r, real32_t g, real32_t b, real32_t a)
61 {
62 ✗ gate_gl_api_color4(r, g, b, a);
63 ✗ }
64 ✗ void GlApi::setColorByte(uint8_t r, uint8_t g, uint8_t b, uint8_t a)
65 {
66 ✗ gate_gl_api_color4b(r, g, b, a);
67 ✗ }
68 ✗ void GlApi::setColor(real32_t r, real32_t g, real32_t b)
69 {
70 ✗ gate_gl_api_color3(r, g, b);
71 ✗ }
72 ✗ void GlApi::setColorByte(uint8_t r, uint8_t g, uint8_t b)
73 {
74 ✗ gate_gl_api_color3b(r, g, b);
75 ✗ }
76
77 #endif /* !defined(GATE_GRAPHICS_NO_LEGACY_OPENGL) */
78
79 ✗ void GlApi::setVertexPointer(size_t coord_count, real32_t const* ptr_coords)
80 {
81 ✗ gate_gl_api_vertexpointer(coord_count, ptr_coords);
82 ✗ }
83 ✗ void GlApi::setBlendFunc(BlendEnum srcFunc, BlendEnum dstFunc)
84 {
85 ✗ gate_gl_api_blendfunc((gate_gl_api_blend_t)(int)srcFunc, (gate_gl_api_blend_t)(int)dstFunc);
86 ✗ }
87 ✗ void GlApi::setClearColor(real32_t r, real32_t g, real32_t b, real32_t a)
88 {
89 ✗ gate_gl_api_clearcolor(r, g, b, a);
90 ✗ }
91 ✗ void GlApi::setClearDepth(real32_t depth)
92 {
93 ✗ gate_gl_api_cleardepth(depth);
94 ✗ }
95 ✗ void GlApi::enableCapability(CapabilityEnum capability)
96 {
97 ✗ gate_gl_api_enable((gate_gl_api_capability_t)(int)capability);
98 ✗ }
99 ✗ void GlApi::disableCapability(CapabilityEnum capability)
100 {
101 ✗ gate_gl_api_disable((gate_gl_api_capability_t)(int)capability);
102 ✗ }
103 ✗ void GlApi::setDepthFunc(DepthEnum depthFunction)
104 {
105 ✗ gate_gl_api_depthfunc((gate_gl_api_depth_t)(int)depthFunction);
106 ✗ }
107 ✗ void GlApi::setDepthMask(bool_t enabled)
108 {
109 ✗ gate_gl_api_depthmask(enabled);
110 ✗ }
111
112 ✗ void GlApi::setHint(HintEnum hintType, HintModeEnum hintMode)
113 {
114 ✗ gate_gl_api_hint((gate_gl_api_hint_t)(int)hintType, (gate_gl_api_hintmode_t)(int)hintMode);
115 ✗ }
116 ✗ void GlApi::setViewport(int32_t x, int32_t y, int32_t width, int32_t height)
117 {
118 ✗ gate_gl_api_viewport(x, y, width, height);
119 ✗ }
120 ✗ void GlApi::setMatrixMode(MatrixModeEnum matrixMode)
121 {
122 ✗ gate_gl_api_matrixmode((gate_gl_api_matrixmode_t)(int)matrixMode);
123 ✗ }
124 ✗ void GlApi::loadIdentity()
125 {
126 ✗ gate_gl_api_loadidentity();
127 ✗ }
128
129 ✗ void GlApi::flush()
130 {
131 ✗ gate_gl_api_flush();
132 ✗ }
133 ✗ void GlApi::finish()
134 {
135 ✗ gate_gl_api_finish();
136 ✗ }
137 ✗ void GlApi::clear(unsigned clearBits)
138 {
139 ✗ gate_gl_api_clear(clearBits);
140 ✗ }
141 ✗ void GlApi::drawArrays(DrawModeEnum drawMode, int index, size_t vertex_count)
142 {
143 ✗ gate_gl_api_drawarrays((gate_gl_api_drawmode_t)(int)drawMode, index, vertex_count);
144 ✗ }
145 ✗ void* GlApi::createTexture(PixelFormatEnum pixelFormat, uint32_t width, uint32_t height, void const* data)
146 {
147 ✗ return gate_gl_api_createtexture((gate_gl_api_pixelformat_t)(int)pixelFormat, width, height, data);
148 }
149 ✗ void GlApi::deleteTexture(void* textureId)
150 {
151 ✗ gate_gl_api_deletetexture(textureId);
152 ✗ }
153 ✗ void GlApi::bindTexture(void* textureId)
154 {
155 ✗ gate_gl_api_bindtexture(textureId);
156 ✗ }
157 ✗ void GlApi::setCullFace(CullFaceEnum cullface)
158 {
159 ✗ gate_gl_api_cullface((gate_gl_api_cullface_t)cullface);
160 ✗ }
161
162
163 #if defined(GATE_GRAPHICS_OPENGL2_SUPPORT)
164 uintptr_t GlApi::createShader(gate_gl2_api_shader_type_t type)
165 {
166 return gate_gl2_api_create_shader(type);
167 }
168 void GlApi::shaderSource(uintptr_t shader, size_t count, char const* const* code, size_t const* length)
169 {
170 gate_gl2_api_shader_source(shader, count, code, length);
171 }
172 void GlApi::compileShader(uintptr_t shader)
173 {
174 gate_gl2_api_compile_shader(shader);
175 }
176 void GlApi::getShaderIv(uintptr_t shader, gate_gl2_api_shader_param_t param_name, intptr_t* params)
177 {
178 gate_gl2_api_get_shader_iv(shader, param_name, params);
179 }
180 void GlApi::getShaderInfoLog(uintptr_t shader, size_t max_length, size_t& len_used, char* info_buffer)
181 {
182 gate_gl2_api_get_shader_info_log(shader, max_length, &len_used, info_buffer);
183 }
184
185 void GlApi::deleteShader(uintptr_t shader)
186 {
187 gate_gl2_api_delete_shader(shader);
188 }
189
190 uintptr_t GlApi::createProgram(void)
191 {
192 return gate_gl2_api_create_program();
193 }
194 void GlApi::linkProgram(uintptr_t program)
195 {
196 gate_gl2_api_link_program(program);
197 }
198 void GlApi::getProgramIv(uintptr_t program, gate_gl2_api_program_param_t param_name, intptr_t* params)
199 {
200 gate_gl2_api_get_program_iv(program, param_name, params);
201 }
202 void GlApi::getProgramInfoLog(uintptr_t program, size_t bufSize, size_t* length, char* infoLog)
203 {
204 gate_gl2_api_get_program_info_log(program, bufSize, length, infoLog);
205 }
206 void GlApi::useProgram(uintptr_t program)
207 {
208 gate_gl2_api_use_program(program);
209 }
210 void GlApi::attachShader(uintptr_t program, uintptr_t shader)
211 {
212 gate_gl2_api_attach_shader(program, shader);
213 }
214 void GlApi::deleteProgram(uintptr_t program)
215 {
216 gate_gl2_api_delete_program(program);
217 }
218 void GlApi::bindAttribLocation(uintptr_t program, size_t index, char const* name)
219 {
220 gate_gl2_api_bind_attrib_location(program, index, name);
221 }
222 intptr_t GlApi::getAttribLocation(uintptr_t program, char const* name)
223 {
224 return gate_gl2_api_get_attrib_location(program, name);
225 }
226 intptr_t GlApi::getUniformLocation(uintptr_t program, char const* name)
227 {
228 return gate_gl2_api_get_uniform_location(program, name);
229 }
230
231
232 void GlApi::genBuffers(size_t n, unsigned int* buffers)
233 {
234 gate_gl2_api_gen_buffers(n, buffers);
235 }
236 void GlApi::deleteBuffers(size_t n, unsigned int* buffers)
237 {
238 gate_gl2_api_delete_buffers(n, buffers);
239 }
240 void GlApi::bindBuffer(gate_gl2_api_buffer_type_t target_type, unsigned int buffer)
241 {
242 gate_gl2_api_bind_buffer(target_type, buffer);
243 }
244 void GlApi::bufferData(gate_gl2_api_buffer_type_t target_type, size_t size, void const* data, gate_gl2_api_usage_type_t usage)
245 {
246 gate_gl2_api_buffer_data(target_type, size, data, usage);
247 }
248 /*
249 void GlApi::namedBufferData(unsigned int buffer, size_t size, void const* data, gate_gl2_api_usage_type_t usage)
250 {
251 gate_gl2_api_named_buffer_data(buffer, size, data, usage);
252 }
253 */
254 void GlApi::vertexAttribPointer(uintptr_t index, size_t size, gate_gl2_api_vertex_attrib_type_t type, bool_t normalized, size_t stride, void const* pointer)
255 {
256 gate_gl2_api_vertex_attrib_pointer(index, size, type, normalized, stride, pointer);
257 }
258 void GlApi::enableVertexAttribArray(uintptr_t index)
259 {
260 gate_gl2_api_enable_vertex_attrib_array(index);
261 }
262 void GlApi::disableVertexAttribArray(uintptr_t index)
263 {
264 gate_gl2_api_disable_vertex_attrib_array(index);
265 }
266 void GlApi::activeTexture(uintptr_t texture_index)
267 {
268 gate_gl2_api_active_texture(texture_index);
269 }
270
271
272 void GlApi::uniform1f(intptr_t location, real32_t v0)
273 {
274 gate_gl2_api_uniform1f(location, v0);
275 }
276 void GlApi::uniform2f(intptr_t location, real32_t v0, real32_t v1)
277 {
278 gate_gl2_api_uniform2f(location, v0, v1);
279 }
280 void GlApi::uniform3f(intptr_t location, real32_t v0, real32_t v1, real32_t v2)
281 {
282 gate_gl2_api_uniform3f(location, v0, v1, v2);
283 }
284 void GlApi::uniform4f(intptr_t location, real32_t v0, real32_t v1, real32_t v2, real32_t v3)
285 {
286 gate_gl2_api_uniform4f(location, v0, v1, v2, v3);
287 }
288 void GlApi::uniform1fv(intptr_t location, size_t count, const real32_t *value)
289 {
290 gate_gl2_api_uniform1fv(location, count, value);
291 }
292 void GlApi::uniform2fv(intptr_t location, size_t count, const real32_t *value)
293 {
294 gate_gl2_api_uniform2fv(location, count, value);
295 }
296 void GlApi::uniform3fv(intptr_t location, size_t count, const real32_t *value)
297 {
298 gate_gl2_api_uniform3fv(location, count, value);
299 }
300 void GlApi::uniform4fv(intptr_t location, size_t count, const real32_t *value)
301 {
302 gate_gl2_api_uniform4fv(location, count, value);
303 }
304 void GlApi::uniform1i(intptr_t location, int v0)
305 {
306 gate_gl2_api_uniform1i(location, v0);
307 }
308 void GlApi::uniform2i(intptr_t location, int v0, int v1)
309 {
310 gate_gl2_api_uniform2i(location, v0, v1);
311 }
312 void GlApi::uniform3i(intptr_t location, int v0, int v1, int v2)
313 {
314 gate_gl2_api_uniform3i(location, v0, v1, v2);
315 }
316 void GlApi::uniform4i(intptr_t location, int v0, int v1, int v2, int v3)
317 {
318 gate_gl2_api_uniform4i(location, v0, v1, v2, v3);
319 }
320 void GlApi::uniform1iv(intptr_t location, size_t count, const int *value)
321 {
322 gate_gl2_api_uniform1iv(location, count, value);
323 }
324 void GlApi::uniform2iv(intptr_t location, size_t count, const int *value)
325 {
326 gate_gl2_api_uniform2iv(location, count, value);
327 }
328 void GlApi::uniform3iv(intptr_t location, size_t count, const int *value)
329 {
330 gate_gl2_api_uniform3iv(location, count, value);
331 }
332 void GlApi::uniform4iv(intptr_t location, size_t count, const int *value)
333 {
334 gate_gl2_api_uniform4iv(location, count, value);
335 }
336
337 void GlApi::uniform_matrix2fv(intptr_t location, size_t count, bool_t transpose, const real32_t *value)
338 {
339 gate_gl2_api_uniform_matrix2fv(location, count, transpose, value);
340 }
341 void GlApi::uniform_matrix3fv(intptr_t location, size_t count, bool_t transpose, const real32_t *value)
342 {
343 gate_gl2_api_uniform_matrix3fv(location, count, transpose, value);
344 }
345 void GlApi::uniform_matrix4fv(intptr_t location, size_t count, bool_t transpose, const real32_t *value)
346 {
347 gate_gl2_api_uniform_matrix4fv(location, count, transpose, value);
348 }
349
350 #endif
351
352
353
354 ✗ GlSurfaceEventSink::GlSurfaceEventSink()
355 ✗ : surface_ptr(NULL)
356 {
357 ✗ }
358
359 ✗ GlSurfaceEventSink::~GlSurfaceEventSink() noexcept
360 {
361 ✗ }
362
363 ✗ GlSurface& GlSurfaceEventSink::getSurface()
364 {
365 ✗ if (!this->surface_ptr)
366 {
367 ✗ GATEXX_RAISE_ERROR(results::NullPointer);
368 }
369 ✗ return *this->surface_ptr;
370 }
371 ✗ void GlSurfaceEventSink::connectSurface(GlSurface& surface)
372 {
373 ✗ this->surface_ptr = &surface;
374 ✗ }
375
376
377
378 enumint_t const GlSurface::Flag_SoftwareRendering = GATE_GL_SURFACE_FLAG_SOFTWARE_RENDERING;
379
380
381 ✗ GlSurface::GlSurface()
382 {
383 ✗ result_t result = gate_gl_surface_init(&this->impl);
384 ✗ GATEXX_CHECK_ERROR(result);
385 ✗ }
386 ✗ GlSurface::~GlSurface() noexcept
387 {
388 ✗ gate_gl_surface_uninit(&this->impl);
389 ✗ }
390
391 ✗ void GlSurface::openScreen(uint32_t width, uint32_t height, enumint_t flags)
392 {
393 ✗ result_t result = gate_gl_surface_open(&this->impl, gate_gl_surface_type_screen, width, height, flags);
394 ✗ GATEXX_CHECK_ERROR(result);
395 ✗ }
396 ✗ void GlSurface::openImage(uint32_t width, uint32_t height, enumint_t flags)
397 {
398 ✗ result_t result = gate_gl_surface_open(&this->impl, gate_gl_surface_type_image, width, height, flags);
399 ✗ GATEXX_CHECK_ERROR(result);
400 ✗ }
401
402 ✗ void GlSurface::close()
403 {
404 ✗ result_t result = gate_gl_surface_close(&this->impl);
405 ✗ GATEXX_CHECK_ERROR(result);
406 ✗ }
407
408 ✗ void GlSurface::getSize(uint32_t& width, uint32_t& height)
409 {
410 ✗ result_t result = gate_gl_surface_get_size(&this->impl, &width, &height);
411 ✗ GATEXX_CHECK_ERROR(result);
412 ✗ }
413 ✗ void GlSurface::resize(uint32_t width, uint32_t height)
414 {
415 ✗ result_t result = gate_gl_surface_resize(&this->impl, width, height);
416 ✗ GATEXX_CHECK_EXCEPTION(result);
417 ✗ }
418
419 ✗ RasterImage GlSurface::printImage()
420 {
421 ✗ gate_rasterimage_t rasterimage = GATE_INIT_EMPTY;
422 ✗ result_t result = gate_gl_surface_print_image(&this->impl, &rasterimage);
423 ✗ GATEXX_CHECK_ERROR(result);
424 ✗ RasterImage image(&rasterimage);
425 ✗ gate_rasterimage_release(&rasterimage);
426 ✗ return image;
427 }
428
429
430 ✗ static void GATE_CALL surface_events_on_render(gate_gl_surface_t* surface, void* user_param)
431 {
432 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
433 ✗ GATEXX_TRY_IGNORE({
434 sink->onRender(sink->getSurface());
435 })
436 ✗ }
437 ✗ static void GATE_CALL surface_events_on_exit(gate_gl_surface_t* surface, void* user_param)
438 {
439 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
440 ✗ GATEXX_TRY_IGNORE({
441 sink->onExit(sink->getSurface());
442 });
443 ✗ }
444 ✗ static void GATE_CALL surface_events_on_resize(gate_gl_surface_t* surface, gate_uint32_t width, gate_uint32_t height, void* user_param)
445 {
446 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
447 ✗ GATEXX_TRY_IGNORE({
448 sink->onResize(sink->getSurface(), width, height);
449 });
450 ✗ }
451 ✗ static void GATE_CALL surface_events_on_key_down(gate_gl_surface_t* surface, gate_input_keycode_t keyboard_key,
452 gate_input_keystates_t keyboard_states, void* user_param)
453 {
454 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
455 ✗ GATEXX_TRY_IGNORE({
456 sink->onKeyDown(sink->getSurface(), Keyboard::KeyEnum(keyboard_key), keyboard_states);
457 });
458 ✗ }
459 ✗ static void GATE_CALL surface_events_on_key_up(gate_gl_surface_t* surface, gate_input_keycode_t keyboard_key,
460 gate_input_keystates_t keyboard_states, void* user_param)
461 {
462 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
463 ✗ GATEXX_TRY_IGNORE({
464 sink->onKeyUp(sink->getSurface(), Keyboard::KeyEnum(keyboard_key), keyboard_states);
465 });
466 ✗ }
467 ✗ static void GATE_CALL surface_events_on_pointer_down(gate_gl_surface_t* surface, gate_uint32_t pointer_type, gate_real32_t x, gate_real32_t y, void* user_param)
468 {
469 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
470 ✗ GATEXX_TRY_IGNORE({
471 sink->onPointerDown(sink->getSurface(), pointer_type, x, y);
472 });
473 ✗ }
474 ✗ static void GATE_CALL surface_events_on_pointer_move(gate_gl_surface_t* surface, gate_uint32_t pointer_type, gate_real32_t x, gate_real32_t y, void* user_param)
475 {
476 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
477 ✗ GATEXX_TRY_IGNORE({
478 sink->onPointerMove(sink->getSurface(), pointer_type, x, y);
479 });
480 ✗ }
481 ✗ static void GATE_CALL surface_events_on_pointer_up(gate_gl_surface_t* surface, gate_uint32_t pointer_type, gate_real32_t x, gate_real32_t y, void* user_param)
482 {
483 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
484 ✗ GATEXX_TRY_IGNORE({
485 sink->onPointerUp(sink->getSurface(), pointer_type, x, y);
486 });
487 ✗ }
488 ✗ static void GATE_CALL surface_events_on_scroll(gate_gl_surface_t* surface, gate_int32_t x_direction, gate_int32_t y_direction, void* user_param)
489 {
490 ✗ GlSurfaceEventSink* sink = static_cast<GlSurfaceEventSink*>(user_param);
491 ✗ GATEXX_TRY_IGNORE({
492 sink->onScroll(sink->getSurface(), x_direction, y_direction);
493 });
494 ✗ }
495
496 static gate_gl_surface_events_t cpp_dispatcher =
497 {
498 &surface_events_on_resize,
499 &surface_events_on_render,
500 &surface_events_on_exit,
501
502 &surface_events_on_key_down,
503 &surface_events_on_key_up,
504 &surface_events_on_pointer_down,
505 &surface_events_on_pointer_move,
506 &surface_events_on_pointer_up,
507 &surface_events_on_scroll
508 };
509
510 ✗ void GlSurface::runEventLoop(GlSurfaceEventSink& eventHandler)
511 {
512 ✗ eventHandler.connectSurface(*this);
513 ✗ result_t result = gate_gl_surface_run_event_loop(&this->impl, &cpp_dispatcher, static_cast<void*>(&eventHandler));
514 ✗ GATEXX_CHECK_ERROR(result);
515 ✗ }
516 ✗ void GlSurface::exitEventLoop()
517 {
518 ✗ result_t result = gate_gl_surface_exit_event_loop(&this->impl);
519 ✗ GATEXX_CHECK_ERROR(result);
520 ✗ }
521 ✗ void GlSurface::swapBuffers()
522 {
523 ✗ result_t result = gate_gl_surface_swap_buffers(&this->impl);
524 ✗ GATEXX_CHECK_ERROR(result);
525 ✗ }
526
527 ✗ GlApi& GlSurface::getGlApi()
528 {
529 ✗ return this->api;
530 }
531
532 } // end of namespace graph
533 } // end of namespace gate
534