Skip to content

Commit ec616fb

Browse files
committed
formatting
1 parent ec28325 commit ec616fb

3 files changed

Lines changed: 53 additions & 22 deletions

File tree

src/libprojectM/Renderer/PlatformGLResolver.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Cross-platform runtime GL/GLES loader using GLAD2 C API (non-MX).
2-
//
3-
// Provides a universal resolver to find GL function pointers.
41

52
#include "PlatformGLResolver.hpp"
63

@@ -303,8 +300,17 @@ auto GLResolver::Initialize(UserResolver resolver, void* userData) -> bool
303300
#elif !defined(__APPLE__) && !defined(__ANDROID__)
304301

305302
diag += std::string(" glx_get_proc=\"") + (m_state.m_glxGetProcAddress != nullptr ? "yes" : "no") + "\"";
303+
304+
#if PLATFORM_GLX_ALLOW_CORE_GETPROCADDRESS_FALLBACK
305+
306+
diag += " glx_policy=\"ext+fallback\"";
307+
308+
#else
309+
306310
diag += " glx_policy=\"ext-only\"";
307311

312+
#endif
313+
308314
#endif
309315

310316
diag += std::string(" user_resolver=\"") + (m_state.m_userResolver != nullptr ? "yes" : "no") + "\"";

src/libprojectM/Renderer/PlatformGLResolver.hpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ enum class Backend : std::uint8_t
7373
using UserResolver = void* (*)(const char* name, void* userData);
7474

7575
/**
76-
* @brief Cross-platform runtime GL/GLES procedure resolver.
76+
* @brief Universal cross-platform runtime GL/GLES procedure resolver for GLAD2 (non-MX).
7777
*
7878
* Compile-time API selection:
7979
* - If USE_GLES is defined, loads OpenGL ES entry points via gladLoadGLES2() and
@@ -84,9 +84,14 @@ using UserResolver = void* (*)(const char* name, void* userData);
8484
* Supported backends/wrappers: EGL (including ANGLE), GLX (including libGLVND), WGL,
8585
* macOS CGL, WebGL (Emscripten), plus an optional user resolver.
8686
*
87+
* Lifecycle:
88+
* - The resolver is a process-singleton.
89+
* - GL libraries that have been opened are not unloaded to avoid conflicts with the host app.
90+
* They will be released by OS during process tear-down.
91+
*
8792
* Initialization:
8893
* - Must be called after a context is created and made current on the calling thread.
89-
* - Thread-safe; intended to be called once during startup before any resolution occurs.
94+
* - Thread-safe; intended to be called during startup before any resolution occurs.
9095
* - If multiple backends appear to be current, EGL is preferred.
9196
*
9297
* Resolution order (non-Emscripten):
@@ -96,18 +101,13 @@ using UserResolver = void* (*)(const char* name, void* userData);
96101
* - Queried for all symbols only when EGL_KHR_get_all_proc_addresses or
97102
* EGL_KHR_client_get_all_proc_addresses is advertised.
98103
* - Otherwise queried only for extension-style names during the provider step.
99-
* - As a last resort (after exports/global lookups fail), a best-effort call
100-
* to eglGetProcAddress may be attempted even for non-extension names to support
101-
* stacks that expose core client API entry points only via eglGetProcAddress.
102104
* - GLX: glXGetProcAddressARB / glXGetProcAddress
103-
* - Queried only for glX* or extension-style names (default).
104-
* - Optional: as a last resort, non-extension gl* names can be queried when
105-
* PLATFORM_GLX_ALLOW_CORE_GETPROCADDRESS_FALLBACK is enabled.
105+
* - Queried only for glX* or extension-style names.
106106
* - WGL: wglGetProcAddress
107107
* - Filters sentinel values; prefers exported symbols for core OpenGL 1.1 entry points.
108108
* 3) Global symbol scope lookup (dlsym(RTLD_DEFAULT) / GetProcAddress on already-loaded modules)
109109
* 4) Direct exports from explicitly opened libraries (EGL/GL/GLX)
110-
* 5) Fallback
110+
* 5) GetProcAddress fallback
111111
* - EGL: Try to resolve function via eglGetProcAddress as fallback.
112112
* Always enabled.
113113
* - GLX: Try to resolve function via glXGetProcAddress as fallback.
@@ -270,6 +270,7 @@ class GLResolver
270270
private:
271271

272272
// Basic EGL access signatures.
273+
273274
using EglProc = void (PLATFORM_EGLAPIENTRY*)();
274275
using EglGetProcAddressFn = EglProc (PLATFORM_EGLAPIENTRY*)(const char* name);
275276
using EglGetCurrentContextFn = void* (PLATFORM_EGLAPIENTRY*)();

src/libprojectM/Renderer/PlatformLoader.hpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
#pragma once
22

3-
#include <array>
4-
#include <cstddef>
53
#include <cstdint>
64
#include <cstdio>
75
#include <cstring>
86
#include <string>
97
#include <type_traits>
108

119
#ifndef __EMSCRIPTEN__
10+
1211
#ifdef _WIN32
12+
13+
#include <array>
14+
#include <cstddef>
15+
1316
#include <windows.h>
1417

1518
// -------------------------------------------------------------------------
@@ -48,12 +51,18 @@
4851
//
4952
// Define PLATFORM_ALLOW_UNSAFE_DLL_SEARCH=1 to re-enable the legacy fallback.
5053
#ifndef PLATFORM_ALLOW_UNSAFE_DLL_SEARCH
54+
5155
#define PLATFORM_ALLOW_UNSAFE_DLL_SEARCH 0
56+
5257
#endif
53-
#else
58+
59+
#else // #ifdef _WIN32
60+
5461
#include <dlfcn.h>
55-
#endif
56-
#endif
62+
63+
#endif // #ifdef _WIN32
64+
65+
#endif // #ifndef __EMSCRIPTEN__
5766

5867
// -------------------------------------------------------------------------
5968
// Minimal EGL calling-convention support
@@ -66,9 +75,13 @@
6675
// This macro is used in our local EGL function pointer typedefs to ensure we
6776
// call into the provider (ANGLE / driver EGL) using the correct ABI.
6877
#if defined(_WIN32) && !defined(_WIN64)
78+
6979
#define PLATFORM_EGLAPIENTRY __stdcall
80+
7081
#else
82+
7183
#define PLATFORM_EGLAPIENTRY
84+
7285
#endif
7386

7487
// -------------------------------------------------------------------------
@@ -123,13 +136,15 @@ inline auto TrimTrailingWhitespace(std::string& str) -> void
123136
}
124137

125138
#if PLATFORM_LOADER_DIAGNOSTICS
139+
126140
inline auto ReportFnPtrSizeMismatch(const char* where, std::size_t fnSize, std::size_t ptrSize) -> void
127141
{
128142
std::fprintf(stderr, "[PlatformLoader] %s: sizeof(Fn)=%zu sizeof(void*)=%zu; cannot convert symbol/function pointer\n",
129143
(where != nullptr ? where : "(unknown)"),
130144
static_cast<std::size_t>(fnSize),
131145
static_cast<std::size_t>(ptrSize));
132146
}
147+
133148
#endif
134149

135150
/**
@@ -162,9 +177,13 @@ auto SymbolToFunction(void* symbol) -> Fn
162177

163178
if (sizeof(Fn) != sizeof(void*))
164179
{
180+
165181
#if PLATFORM_LOADER_DIAGNOSTICS
182+
166183
ReportFnPtrSizeMismatch("SymbolToFunction", sizeof(Fn), sizeof(void*));
184+
167185
#endif
186+
168187
return nullptr;
169188
}
170189

@@ -197,9 +216,13 @@ auto FunctionToSymbol(Fn func) -> void*
197216

198217
if (sizeof(Fn) != sizeof(void*))
199218
{
219+
200220
#if PLATFORM_LOADER_DIAGNOSTICS
221+
201222
ReportFnPtrSizeMismatch("FunctionToSymbol", sizeof(Fn), sizeof(void*));
223+
202224
#endif
225+
203226
return nullptr;
204227
}
205228

@@ -228,9 +251,13 @@ auto FunctionToInteger(Fn func) -> std::uintptr_t
228251

229252
if (sizeof(Fn) != sizeof(void*))
230253
{
254+
231255
#if PLATFORM_LOADER_DIAGNOSTICS
256+
232257
ReportFnPtrSizeMismatch("FunctionToInteger", sizeof(Fn), sizeof(void*));
258+
233259
#endif
260+
234261
return 0;
235262
}
236263

@@ -269,6 +296,7 @@ inline auto WinProcToSymbol(FARPROC proc) noexcept -> void*
269296
std::memcpy(&sym, &proc, sizeof(void*));
270297
return sym;
271298
}
299+
272300
#endif
273301

274302
#ifdef __EMSCRIPTEN__
@@ -319,12 +347,8 @@ class DynamicLibrary
319347
}
320348
};
321349

322-
inline auto IsCurrentEgl(const DynamicLibrary&) -> bool
323-
{
324-
return false;
325-
}
326-
327350
#else // #ifdef __EMSCRIPTEN__
351+
328352
// -------------------------------------------------------------------------
329353
// Native implementation (Windows / POSIX)
330354
// -------------------------------------------------------------------------

0 commit comments

Comments
 (0)