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