GCC Code Coverage Report


Directory: src/gate/
File: src/gate/graphics/platform/opengl_egl_apis.h
Date: 2025-09-22 22:57:09
Exec Total Coverage
Lines: 0 38 0.0%
Functions: 0 2 0.0%
Branches: 0 54 0.0%

Line Branch Exec Source
1 /* GATE PROJECT LICENSE:
2 +----------------------------------------------------------------------------+
3 | Copyright(c) 2018-2025, 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 #ifndef GATE_GRAPHICS_PLATFORM_OPENGL_EGL_APIS_H_INCLUDED
29 #define GATE_GRAPHICS_PLATFORM_OPENGL_EGL_APIS_H_INCLUDED
30
31 #include "gate/gatetypes_sys.h"
32
33 #if defined(GATE_SYS_WINCE)
34 typedef ptrdiff_t intptr_t;
35 #endif
36
37 #if defined(GATE_SYS_WASM)
38 # define GATE_OPENGL_EGL_DIRECT_BINDING 1
39 # define GATE_OPENGL_ADD_MISSING_EGL1_ON_EGL2_FUNCS 1
40 #endif
41
42
43 #include "EGL/egl.h"
44 #include "gate/libraries.h"
45
46 typedef struct gate_egl
47 {
48 EGLBoolean(EGLAPIENTRY* ChooseConfig) (EGLDisplay dpy, const EGLint* attrib_list, EGLConfig* configs, EGLint config_size, EGLint* num_config);
49 EGLBoolean(EGLAPIENTRY* CopyBuffers) (EGLDisplay dpy, EGLSurface surface, EGLNativePixmapType target);
50 EGLContext(EGLAPIENTRY* CreateContext) (EGLDisplay dpy, EGLConfig config, EGLContext share_context, const EGLint* attrib_list);
51 EGLSurface(EGLAPIENTRY* CreatePbufferSurface) (EGLDisplay dpy, EGLConfig config, const EGLint* attrib_list);
52 EGLSurface(EGLAPIENTRY* CreatePixmapSurface) (EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint* attrib_list);
53 EGLSurface(EGLAPIENTRY* CreateWindowSurface) (EGLDisplay dpy, EGLConfig config, EGLNativeWindowType win, const EGLint* attrib_list);
54 EGLBoolean(EGLAPIENTRY* DestroyContext) (EGLDisplay dpy, EGLContext ctx);
55 EGLBoolean(EGLAPIENTRY* DestroySurface) (EGLDisplay dpy, EGLSurface surface);
56 EGLBoolean(EGLAPIENTRY* GetConfigAttrib) (EGLDisplay dpy, EGLConfig config, EGLint attribute, EGLint* value);
57 EGLBoolean(EGLAPIENTRY* GetConfigs) (EGLDisplay dpy, EGLConfig* configs, EGLint config_size, EGLint* num_config);
58 EGLDisplay(EGLAPIENTRY* GetCurrentDisplay) (void);
59 EGLSurface(EGLAPIENTRY* GetCurrentSurface) (EGLint readdraw);
60 EGLDisplay(EGLAPIENTRY* GetDisplay) (EGLNativeDisplayType display_id);
61 EGLint(EGLAPIENTRY* GetError) (void);
62 __eglMustCastToProperFunctionPointerType(EGLAPIENTRY* GetProcAddress) (const char* procname);
63 EGLBoolean(EGLAPIENTRY* Initialize) (EGLDisplay dpy, EGLint* major, EGLint* minor);
64 EGLBoolean(EGLAPIENTRY* MakeCurrent) (EGLDisplay dpy, EGLSurface draw, EGLSurface read, EGLContext ctx);
65 EGLBoolean(EGLAPIENTRY* QueryContext) (EGLDisplay dpy, EGLContext ctx, EGLint attribute, EGLint* value);
66 const char* (EGLAPIENTRY* QueryString) (EGLDisplay dpy, EGLint name);
67 EGLBoolean(EGLAPIENTRY* QuerySurface) (EGLDisplay dpy, EGLSurface surface, EGLint attribute, EGLint* value);
68 EGLBoolean(EGLAPIENTRY* SwapBuffers) (EGLDisplay dpy, EGLSurface surface);
69 EGLBoolean(EGLAPIENTRY* Terminate) (EGLDisplay dpy);
70 EGLBoolean(EGLAPIENTRY* WaitGL) (void);
71 EGLBoolean(EGLAPIENTRY* WaitNative) (EGLint engine);
72 } gate_egl_t;
73
74 static gate_egl_t egl = GATE_INIT_EMPTY;
75 static volatile gate_bool_t egl_loaded = false;
76
77
78 #if defined(GATE_OPENGL_EGL_DIRECT_BINDING)
79
80 # define egl_load_lib() GATE_RESULT_OK
81 # define GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(func_name, func_ptr) *func_ptr = &func_name
82
83 # if defined(GATE_OPENGL_ADD_MISSING_EGL1_ON_EGL2_FUNCS)
84 void glTexEnviv(GLenum target, GLenum pname, const GLint* params)
85 {
86 glTexEnvi(target, pname, *params);
87 }
88 void glMaterialf(GLenum face, GLenum pname, GLfloat param)
89 {
90 glMaterialfv(face, pname, &param);
91 }
92 void glLightf(GLenum light, GLenum pname, GLfloat param)
93 {
94 glLightfv(light, pname, &param);
95 }
96 void glGetMaterialfv(GLenum face, GLenum pname, GLfloat* params)
97 {
98 /* TODO */
99 }
100 void glGetLightfv(GLenum light, GLenum pname, GLfloat* params)
101 {
102 /* TODO */
103 }
104 EGLBoolean eglCopyBuffers(EGLDisplay display, EGLSurface surface, NativePixmapType native_pixmap)
105 {
106 return 0;
107 }
108 EGLSurface eglCreatePbufferSurface(EGLDisplay display, EGLConfig config, EGLint const* attrib_list)
109 {
110 return EGL_NO_SURFACE;
111 }
112 EGLSurface eglCreatePixmapSurface(EGLDisplay display, EGLConfig config, NativePixmapType native_pixmap, EGLint const * attrib_list)
113 {
114 return EGL_NO_SURFACE;
115 }
116
117
118 # endif
119
120 #else
121
122 # if defined(GATE_SYS_WIN)
123 # define GATE_GL_EGL_LIBNAME "libEGL.dll"
124 # else
125 # define GATE_GL_EGL_LIBNAME "libEGL.so"
126 # endif
127
128 static gate_string_t egl_lib_name = GATE_STRING_INIT_STATIC(GATE_GL_EGL_LIBNAME);
129 static gate_library_t egl_lib = NULL;
130
131
132 ✗ static gate_result_t egl_load_lib()
133 {
134 ✗ gate_result_t ret = GATE_RESULT_OK;
135 ✗ if (egl_lib == NULL)
136 {
137 ✗ ret = gate_library_open(&egl_lib_name, &egl_lib, GATE_LIBRARY_FLAG_DEFAULT);
138 }
139 ✗ return ret;
140 }
141
142 # define GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(func_name, func_ptr) \
143 do { \
144 const gate_result_t egl_load_result = gate_library_get_function_name(egl_lib, #func_name, func_ptr); \
145 GATE_RETURN_IF_FAILED(egl_load_result); \
146 } while(0)
147
148
149 #endif
150
151
152
153
154 ✗ static gate_result_t gate_egl_load_functions()
155 {
156 ✗ gate_result_t ret = GATE_RESULT_FAILED;
157
158 ✗ if (egl_loaded)
159 {
160 ✗ return GATE_RESULT_OK;
161 }
162
163 ✗ ret = egl_load_lib();
164 ✗ if (GATE_FAILED(ret))
165 {
166 ✗ return ret;
167 }
168
169 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglChooseConfig, &egl.ChooseConfig);
170 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglCopyBuffers, &egl.CopyBuffers);
171 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglCreateContext, &egl.CreateContext);
172 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglCreatePbufferSurface, &egl.CreatePbufferSurface);
173 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglCreatePixmapSurface, &egl.CreatePixmapSurface);
174 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglCreateWindowSurface, &egl.CreateWindowSurface);
175 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglDestroyContext, &egl.DestroyContext);
176 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglDestroySurface, &egl.DestroySurface);
177 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglGetConfigAttrib, &egl.GetConfigAttrib);
178 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglGetConfigs, &egl.GetConfigs);
179 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglGetCurrentDisplay, &egl.GetCurrentDisplay);
180 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglGetCurrentSurface, &egl.GetCurrentSurface);
181 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglGetDisplay, &egl.GetDisplay);
182 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglGetError, &egl.GetError);
183 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglGetProcAddress, &egl.GetProcAddress);
184 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglInitialize, &egl.Initialize);
185 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglMakeCurrent, &egl.MakeCurrent);
186 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglQueryContext, &egl.QueryContext);
187 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglQueryString, &egl.QueryString);
188 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglQuerySurface, &egl.QuerySurface);
189 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglSwapBuffers, &egl.SwapBuffers);
190 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglTerminate, &egl.Terminate);
191 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglWaitGL, &egl.WaitGL);
192 ✗ GATE_EGL_LOAD_FUNC_OR_RETURN_ERROR(eglWaitNative, &egl.WaitNative);
193
194 ✗ egl_loaded = true;
195 ✗ return GATE_RESULT_OK;
196 }
197
198 #endif /* GATE_GRAPHICS_PLATFORM_OPENGL_EGL_APIS_H_INCLUDED */
199