Skip to content

Commit 49cd77f

Browse files
committed
move constants
1 parent a63310c commit 49cd77f

3 files changed

Lines changed: 134 additions & 128 deletions

File tree

src/libprojectM/Renderer/Platform/DynamicLibrary.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -596,20 +596,10 @@ DynamicLibrary::~DynamicLibrary()
596596
}
597597

598598
// If the host has already loaded EGL/GLES provider DLLs (e.g., ANGLE), probe those modules as well.
599-
// This is a enhancement for applications embedding this library where we may not have
599+
// This is an enhancement for applications embedding this library where we may not have
600600
// opened the provider libraries ourselves.
601601
{
602-
static constexpr std::array<const char*, 6> moduleNames =
603-
{
604-
"libEGL.dll",
605-
"EGL.dll",
606-
"libGLESv2.dll",
607-
"GLESv2.dll",
608-
"libGLESv3.dll",
609-
"GLESv3.dll"
610-
};
611-
612-
for (const auto& m : moduleNames)
602+
for (const auto& m : kAllEglModuleNames)
613603
{
614604
if (HMODULE mod = ::GetModuleHandleA(m))
615605
{

src/libprojectM/Renderer/Platform/DynamicLibrary.hpp

Lines changed: 118 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <array>
34
#include <cstdint>
45
#include <cstring>
56
#include <string>
@@ -50,15 +51,128 @@ namespace Platform {
5051
* @brief Platform library handle type.
5152
*/
5253
#ifdef _WIN32
53-
5454
using LibHandle = HMODULE;
55-
5655
#else
57-
5856
using LibHandle = void*;
59-
6057
#endif
6158

59+
#ifdef _WIN32
60+
61+
// Windows GL/EGL library name candidates
62+
63+
constexpr std::array<const char*, 3> kNativeEglNames = {
64+
"libEGL.dll",
65+
"EGL.dll",
66+
nullptr};
67+
68+
constexpr std::array<const char*, 2> kNativeGlNames = {
69+
"opengl32.dll",
70+
nullptr};
71+
72+
constexpr std::array<const char*, 5> kNativeGlesNames = {
73+
"libGLESv3.dll",
74+
"GLESv3.dll",
75+
"libGLESv2.dll",
76+
"GLESv2.dll",
77+
nullptr};
78+
79+
/**
80+
* EGL names for global module lookup.
81+
*/
82+
static constexpr std::array<const char*, 6> kAllEglModuleNames = {
83+
"libEGL.dll",
84+
"EGL.dll",
85+
"libGLESv2.dll",
86+
"GLESv2.dll",
87+
"libGLESv3.dll",
88+
"GLESv3.dll"};
89+
90+
#elif defined(__APPLE__)
91+
92+
// macOS GL/EGL library name candidates
93+
// macOS native OpenGL uses CGL (OpenGL.framework). ANGLE (and other portability layers).
94+
// commonly provide EGL/GLES dylibs in the application bundle / @rpath.
95+
96+
constexpr std::array<const char*, 6> kNativeEglNames = {
97+
"@rpath/libEGL.dylib",
98+
"@rpath/libEGL.1.dylib",
99+
"libEGL.dylib",
100+
"libEGL.1.dylib",
101+
"EGL",
102+
nullptr};
103+
104+
constexpr std::array<const char*, 2> kNativeGlNames = {
105+
"/System/Library/Frameworks/OpenGL.framework/OpenGL",
106+
nullptr};
107+
108+
constexpr std::array<const char*, 7> kNativeGlesNames = {
109+
"@rpath/libGLESv3.dylib",
110+
"@rpath/libGLESv2.dylib",
111+
"@rpath/libGLESv2_with_capture.dylib",
112+
"libGLESv3.dylib",
113+
"libGLESv2.dylib",
114+
"libGLESv2_with_capture.dylib",
115+
nullptr};
116+
117+
#elif defined(__ANDROID__)
118+
119+
// Android EGL + GLES (no desktop libGL / GLX) library name candidates
120+
121+
constexpr std::array<const char*, 2> kNativeEglNames = {
122+
"libEGL.so",
123+
nullptr};
124+
125+
constexpr std::array<const char*, 3> kNativeGlesNames = {
126+
"libGLESv3.so",
127+
"libGLESv2.so",
128+
nullptr};
129+
130+
#else // #ifdef _WIN32
131+
132+
// Unix GL/EGL library name candidates
133+
134+
constexpr std::array<const char*, 3> kNativeEglNames = {
135+
"libEGL.so.1",
136+
"libEGL.so",
137+
nullptr
138+
};
139+
140+
/**
141+
* Linux / GLES:
142+
* Prefer libGLESv3/libGLESv2 sonames. Core GLES entry points are expected
143+
* to be available as library exports. eglGetProcAddress is not guaranteed
144+
* to return core symbols unless EGL_KHR_get_all_proc_addresses (or its
145+
* client variant) is advertised.
146+
*/
147+
constexpr std::array<const char*, 6> kNativeGlesNames = {
148+
"libGLESv3.so.3",
149+
"libGLESv3.so",
150+
"libGLESv2.so.2",
151+
"libGLESv2.so.1",
152+
"libGLESv2.so",
153+
nullptr};
154+
155+
/**
156+
* Linux / GLVND note:
157+
* Many modern distributions use GLVND, which splits OpenGL entry points (libOpenGL) from
158+
* window-system glue such as GLX (libGLX). Prefer GLVND-facing libs first, but keep legacy
159+
* libGL names in the candidate list for compatibility with older or non-GLVND stacks.
160+
*/
161+
constexpr std::array<const char*, 6> kNativeGlNames = {
162+
"libOpenGL.so.1", // GLVND OpenGL dispatcher (core gl* entry points)
163+
"libOpenGL.so.0", // older GLVND soname
164+
"libGL.so.1", // legacy/compat umbrella (often provided by GLVND)
165+
"libGL.so.0", // sometimes shipped as .so.0
166+
"libGL.so",
167+
nullptr};
168+
169+
constexpr std::array<const char*, 3> kNativeGlxNames = {
170+
"libGLX.so.1", // GLVND GLX dispatcher (glXGetProcAddress*)
171+
"libGLX.so.0", // older GLVND soname
172+
nullptr};
173+
174+
#endif // #ifdef _WIN32
175+
62176
#if GLRESOLVER_LOADER_DIAGNOSTICS
63177

64178
inline auto ReportFnPtrSizeMismatch(const char* where, std::size_t fnSize, std::size_t ptrSize) -> void

src/libprojectM/Renderer/Platform/GLResolver.cpp

Lines changed: 14 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -53,104 +53,7 @@ auto AllowEglCoreGetProcAddressFallback() -> bool
5353
return enabled;
5454
}
5555

56-
#ifdef _WIN32
57-
58-
// Windows GL/EGL library name candidates
59-
60-
constexpr std::array<const char*, 3> kNativeEglNames = {
61-
"libEGL.dll",
62-
"EGL.dll",
63-
nullptr};
64-
65-
constexpr std::array<const char*, 2> kNativeGlNames = {
66-
"opengl32.dll",
67-
nullptr};
68-
69-
constexpr std::array<const char*, 5> kNativeGlesNames = {
70-
"libGLESv3.dll",
71-
"GLESv3.dll",
72-
"libGLESv2.dll",
73-
"GLESv2.dll",
74-
nullptr};
75-
76-
#elif defined(__APPLE__)
77-
78-
// macOS GL/EGL library name candidates
79-
// macOS native OpenGL uses CGL (OpenGL.framework). ANGLE (and other portability layers).
80-
// commonly provide EGL/GLES dylibs in the application bundle / @rpath.
81-
82-
constexpr std::array<const char*, 6> kNativeEglNames = {
83-
"@rpath/libEGL.dylib",
84-
"@rpath/libEGL.1.dylib",
85-
"libEGL.dylib",
86-
"libEGL.1.dylib",
87-
"EGL",
88-
nullptr};
89-
90-
constexpr std::array<const char*, 2> kNativeGlNames = {
91-
"/System/Library/Frameworks/OpenGL.framework/OpenGL",
92-
nullptr};
93-
94-
constexpr std::array<const char*, 7> kNativeGlesNames = {
95-
"@rpath/libGLESv3.dylib",
96-
"@rpath/libGLESv2.dylib",
97-
"@rpath/libGLESv2_with_capture.dylib",
98-
"libGLESv3.dylib",
99-
"libGLESv2.dylib",
100-
"libGLESv2_with_capture.dylib",
101-
nullptr};
102-
#elif defined(__ANDROID__)
103-
104-
// Android EGL + GLES (no desktop libGL / GLX) library name candidates
105-
106-
constexpr std::array<const char*, 2> kNativeEglNames = {
107-
"libEGL.so",
108-
nullptr};
109-
110-
constexpr std::array<const char*, 3> kNativeGlesNames = {
111-
"libGLESv3.so",
112-
"libGLESv2.so",
113-
nullptr};
114-
115-
#else // #ifdef _WIN32
116-
117-
// Unix GL/EGL library name candidates
118-
119-
constexpr std::array<const char*, 3> kNativeEglNames = {"libEGL.so.1", "libEGL.so", nullptr};
120-
121-
/**
122-
* Linux / GLES:
123-
* Prefer libGLESv3/libGLESv2 sonames. Core GLES entry points are expected
124-
* to be available as library exports. eglGetProcAddress is not guaranteed
125-
* to return core symbols unless EGL_KHR_get_all_proc_addresses (or its
126-
* client variant) is advertised.
127-
*/
128-
constexpr std::array<const char*, 6> kNativeGlesNames = {
129-
"libGLESv3.so.3",
130-
"libGLESv3.so",
131-
"libGLESv2.so.2",
132-
"libGLESv2.so.1",
133-
"libGLESv2.so",
134-
nullptr};
135-
136-
/**
137-
* Linux / GLVND note:
138-
* Many modern distributions use GLVND, which splits OpenGL entry points (libOpenGL) from
139-
* window-system glue such as GLX (libGLX). Prefer GLVND-facing libs first, but keep legacy
140-
* libGL names in the candidate list for compatibility with older or non-GLVND stacks.
141-
*/
142-
constexpr std::array<const char*, 6> kNativeGlNames = {
143-
"libOpenGL.so.1", // GLVND OpenGL dispatcher (core gl* entry points)
144-
"libOpenGL.so.0", // older GLVND soname
145-
"libGL.so.1", // legacy/compat umbrella (often provided by GLVND)
146-
"libGL.so.0", // sometimes shipped as .so.0
147-
"libGL.so",
148-
nullptr};
149-
150-
constexpr std::array<const char*, 3> kNativeGlxNames = {
151-
"libGLX.so.1", // GLVND GLX dispatcher (glXGetProcAddress*)
152-
"libGLX.so.0", // older GLVND soname
153-
nullptr};
56+
#if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
15457

15558
/**
15659
* GLX fallback for resolving non-extension gl* names via glXGetProcAddress*.
@@ -169,7 +72,7 @@ auto AllowGlxCoreGetProcAddressFallback() -> bool
16972
return enabled;
17073
}
17174

172-
#endif // #ifdef _WIN32
75+
#endif // #if !defined(_WIN32) && !defined(__APPLE__) && !defined(__ANDROID__)
17376

17477
#ifdef __APPLE__
17578

@@ -484,8 +387,7 @@ auto GLResolver::Initialize(UserResolver resolver, void* userData) -> bool
484387
" egl=\"" + state.m_eglLib.LoadedName() + "\"" +
485388
" gl=\"" + state.m_glLib.LoadedName() + "\"" +
486389
" glx=\"" + state.m_glxLib.LoadedName() + "\"" +
487-
" egl_get_proc=\"" + (state.m_eglGetProcAddress != nullptr ? "yes" : "no") + "\"" +
488-
" egl_all_proc=\"" + (state.m_eglGetAllProcAddresses ? "yes" : "no") + "\""
390+
" egl_get_proc=\"" + (state.m_eglGetProcAddress != nullptr ? "yes" : "no") + "\""
489391

490392
#endif
491393
;
@@ -496,21 +398,22 @@ auto GLResolver::Initialize(UserResolver resolver, void* userData) -> bool
496398

497399
diag += std::string(" glx_get_proc=\"") + (state.m_glxGetProcAddress != nullptr ? "yes" : "no") + "\"";
498400

499-
if (AllowGlxCoreGetProcAddressFallback())
500-
{
501-
diag += " glx_policy=\"ext+fallback\"";
502-
}
503-
else
504-
{
505-
diag += " glx_policy=\"ext-only\"";
506-
}
401+
diag += " glx_policy=\"";
402+
diag += AllowGlxCoreGetProcAddressFallback() ? "ext+fallback" : "ext-only";
403+
diag += "\"";
507404

508405
#endif // #ifdef _WIN32
509406

510407
#ifndef __EMSCRIPTEN__
511408

512-
diag += " egl_fallback=\"";
513-
diag += AllowEglCoreGetProcAddressFallback() ? "yes" : "no";
409+
diag += " egl_policy=\"";
410+
if (state.m_eglGetAllProcAddresses)
411+
{
412+
diag += "all";
413+
} else
414+
{
415+
diag += AllowEglCoreGetProcAddressFallback() ? "ext+fallback" : "ext-only";
416+
}
514417
diag += "\"";
515418

516419
#endif // #ifndef __EMSCRIPTEN__
@@ -1341,7 +1244,6 @@ auto GLResolver::ResolveProcAddress(const ResolverState& state, const char* name
13411244
#endif // #ifndef _WIN32 #else
13421245

13431246
// 4) Global symbol table (works if the process already linked/loaded GL libs).
1344-
// NOTE: After initialization completes, native libraries are not mutated; m_mutex not needed here.
13451247
void* global = DynamicLibrary::FindGlobalSymbol(name);
13461248
if (global != nullptr)
13471249
{

0 commit comments

Comments
 (0)