Skip to content

Commit 03470f5

Browse files
committed
cleanup
1 parent 6c2426f commit 03470f5

File tree

6 files changed

+63
-45
lines changed

6 files changed

+63
-45
lines changed

src/libprojectM/ProjectMCWrapper.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
#include <Logging.hpp>
66

77
#include <Audio/AudioConstants.hpp>
8-
98
#include <Renderer/PlatformGLResolver.hpp>
10-
#include <SOIL2/SOIL2.h>
11-
#include <SOIL2/SOIL2_gl_bridge.h>
129

1310
#include <projectM-4/parameters.h>
1411
#include <projectM-4/render_opengl.h>
@@ -88,7 +85,7 @@ projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const c
8885
auto glResolver = libprojectM::Renderer::Platform::GLResolver::Instance();
8986

9087
// init resolver to discover gl function pointers and init glad
91-
// init is guarded internally, so it actually only happens once
88+
// Initialize() is guarded internally, may be executed multiple times
9289
auto success = glResolver->Initialize(load_proc, user_data);
9390
if (!success)
9491
{

src/libprojectM/Renderer/PlatformGLResolver.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ namespace Platform {
2121

2222
GLResolver::~GLResolver()
2323
{
24-
Shutdown();
24+
// make sure handles are released
25+
m_eglLib.Close();
26+
m_glLib.Close();
2527
}
2628

2729
auto GLResolver::Instance() -> std::shared_ptr<GLResolver>
@@ -62,18 +64,23 @@ auto GLResolver::Initialize(UserResolver resolver, void* userData) -> bool
6264

6365
if (m_userResolver == nullptr)
6466
{
67+
// need to find source for gl functions
68+
// open libs and detect backend
6569
OpenNativeLibraries();
6670
ResolveProviderFunctions();
6771
DetectBackend();
6872
}
6973
else
7074
{
75+
// user resolver was provided
76+
// we *should* be able to get all gl functions from the resolver
77+
// using user resolver + global symbol fallback
7178
m_backend = Backend::UserResolver;
7279
}
7380

7481
if (LoadGlad())
7582
{
76-
// set default if detection failed, but loading succeeded
83+
// set default in case detection failed, but loading succeeded
7784
SetBackendDefault();
7885

7986
// init SOIL2 gl functions
@@ -181,7 +188,7 @@ void GLResolver::ResolveProviderFunctions()
181188

182189
{
183190
char buf[256];
184-
std::snprintf(buf, sizeof(buf), "[PlatformGLResolver] Library handles: egl=%p gl=%p",
191+
std::snprintf(buf, sizeof(buf), "[GLResolver] Library handles: egl=%p gl=%p",
185192
reinterpret_cast<void*>(m_eglLib.Handle()),
186193
reinterpret_cast<void*>(m_glLib.Handle()));
187194
LOG_DEBUG(buf);
@@ -204,28 +211,28 @@ void GLResolver::DetectBackend()
204211

205212
if (usingEgl)
206213
{
207-
LOG_DEBUG("[PlatformGLResolver] current context: EGL");
214+
LOG_DEBUG("[GLResolver] current context: EGL");
208215
m_backend = Backend::EglGles;
209216
return;
210217
}
211218

212219
#ifndef _WIN32
213220
if (usingGlx)
214221
{
215-
LOG_DEBUG("[PlatformGLResolver] current context: GLX");
222+
LOG_DEBUG("[GLResolver] current context: GLX");
216223
m_backend = Backend::GlxGl;
217224
return;
218225
}
219226
#else
220227
if (usingWgl)
221228
{
222-
LOG_DEBUG("[PlatformGLResolver] current context: WGL");
229+
LOG_DEBUG("[GLResolver] current context: WGL");
223230
m_backend = Backend::WglGl;
224231
return;
225232
}
226233
#endif
227234

228-
LOG_DEBUG("[PlatformGLResolver] current context: (unknown, will try generic loader)");
235+
LOG_DEBUG("[GLResolver] current context: (unknown, will try generic loader)");
229236
m_backend = Backend::None;
230237
}
231238

@@ -235,11 +242,20 @@ auto GLResolver::GladResolverThunk(const char* name) -> GLapiproc
235242
}
236243

237244
namespace {
238-
// adapt external void* handle to GLAD type
245+
246+
/**
247+
* Resolves a GL function by name using GladResolverThunk.
248+
* Adapt external void* handle to GLAD type
249+
*
250+
* @param name GL function name.
251+
*
252+
* @return Function pointer as GLADapiproc.
253+
*/
239254
auto gladBridgeResolverThunk(const char* name) -> GLADapiproc
240255
{
241256
return reinterpret_cast<GLADapiproc>(GLResolver::GladResolverThunk(name));
242257
}
258+
243259
}
244260

245261
auto GLResolver::LoadGlad() -> bool
@@ -250,19 +266,19 @@ auto GLResolver::LoadGlad() -> bool
250266
result = gladLoadGL(&gladBridgeResolverThunk);
251267
if (result != 0)
252268
{
253-
LOG_DEBUG("[PlatformGLResolver] gladLoadGL() succeeded");
269+
LOG_DEBUG("[GLResolver] gladLoadGL() succeeded");
254270
return true;
255271
}
256-
LOG_FATAL("[PlatformGLResolver] gladLoadGL() failed");
272+
LOG_FATAL("[GLResolver] gladLoadGL() failed");
257273
return false;
258274
#else
259275
result = gladLoadGLES2(&gladBridgeResolverThunk);
260276
if (result != 0)
261277
{
262-
LOG_DEBUG("[PlatformGLResolver] gladLoadGLES2() succeeded");
278+
LOG_DEBUG("[GLResolver] gladLoadGLES2() succeeded");
263279
return true;
264280
}
265-
LOG_FATAL("[PlatformGLResolver] gladLoadGLES2() failed");
281+
LOG_FATAL("[GLResolver] gladLoadGLES2() failed");
266282
return false;
267283
#endif
268284
}

src/libprojectM/Renderer/PlatformGLResolver.hpp

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,20 +138,19 @@ class GLResolver
138138
auto LoadGlad() -> bool;
139139
auto Resolve(const char* name) const -> GLapiproc;
140140

141-
mutable std::mutex m_mutex;
141+
mutable std::mutex m_mutex; //!< Mutex to synchronize initialization and access.
142+
bool m_loaded{false}; //!< True if the resolver is initialized.
143+
Backend m_backend{ Backend::None }; //!< Detected GL backend.
142144

143-
bool m_loaded{};
144-
Backend m_backend{ Backend::None };
145+
UserResolver m_userResolver{nullptr}; //!< User provided function resolver.
146+
void* m_userData{nullptr}; //!< User data to pass to user provided function resolver.
145147

146-
UserResolver m_userResolver{};
147-
void* m_userData{};
148+
DynamicLibrary m_eglLib; //!< EGL library handle. Optional, may not be assigned.
149+
DynamicLibrary m_glLib; //!< Detected GL backend. Optional, may not be assigned.
148150

149-
Platform::DynamicLibrary m_eglLib;
150-
Platform::DynamicLibrary m_glLib;
151-
152-
GetProcFunc m_eglGetProcAddress{};
153-
GetProcFunc m_glxGetProcAddress{};
154-
GetProcFunc m_wglGetProcAddress{};
151+
GetProcFunc m_eglGetProcAddress{nullptr}; //!< Function pointer to EGL proc resolver function.
152+
GetProcFunc m_glxGetProcAddress{nullptr}; //!< Function pointer to GLX proc resolver function.
153+
GetProcFunc m_wglGetProcAddress{nullptr}; //!< Function pointer to WGL proc resolver function.
155154
};
156155

157156
} // namespace Platform

src/libprojectM/Renderer/PlatformLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class DynamicLibrary
197197
}
198198

199199
private:
200-
LibHandle m_handle{};
200+
LibHandle m_handle{}; //!< Library handle used to access the system library.
201201
};
202202

203203
/**

vendor/SOIL2/CMakeLists.txt

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,30 @@ add_library(SOIL2 OBJECT
22
${CMAKE_CURRENT_SOURCE_DIR}/src/common/common.cpp
33
${CMAKE_CURRENT_SOURCE_DIR}/src/common/common.hpp
44
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_DXT.c
5+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_DXT.h
56
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_helper.c
7+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/image_helper.h
68
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/pkm_helper.h
9+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/pvr_helper.h
710
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2.c
11+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2.h
12+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stb_image.h
13+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stb_image_write.h
14+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_DDS.h
15+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_DDS_c.h
16+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_ext.h
17+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_ext_c.h
18+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pkm.h
19+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pkm_c.h
20+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pvr.h
21+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_pvr_c.h
22+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_qoi.h
23+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_qoi_c.h
24+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/stbi_qoi_write.h
825
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/wfETC.c
26+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/wfETC.h
927
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2_gl_bridge.c
28+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2_gl_bridge.h
1029
)
1130

1231
target_include_directories(SOIL2
@@ -37,31 +56,18 @@ else()
3756
)
3857
endif()
3958

40-
# GLES / EGL settings
4159
if (USE_GLES)
4260
target_compile_definitions(SOIL2
43-
PRIVATE
61+
PUBLIC
4462
SOIL_GLES2
4563
)
46-
4764
target_link_libraries(SOIL2
4865
PUBLIC
4966
${CMAKE_DL_LIBS}
5067
)
51-
else()
52-
target_compile_definitions(SOIL2
53-
PRIVATE
54-
SOIL_NO_EGL
55-
)
5668
endif()
5769

58-
if (EMSCRIPTEN)
59-
target_compile_definitions(SOIL2
60-
PRIVATE
61-
SOIL_GLES2
62-
SOIL_NO_EGL
63-
)
64-
elseif (NOT TARGET OpenGL::EGL)
70+
if(NOT TARGET OpenGL::EGL)
6571
target_compile_definitions(SOIL2
6672
PRIVATE
6773
SOIL_NO_EGL

vendor/SOIL2/src/SOIL2/SOIL2_gl_bridge.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern "C" {
1616
*/
1717
typedef void* (*soil_gl_resolver_t)(const char* name);
1818

19-
/**
19+
/**
2020
* Sets the GL function resolver for SOIL2.
2121
*
2222
* @param resolver The resolver function to use.
@@ -29,7 +29,7 @@ extern "C" {
2929
* @param proc GL Function name.
3030
* @return Resolved function pointer for the given function name, or 0 if the function could not be resolved.
3131
*/
32-
void* SOIL_GL_GetProcAddress(const char* proc);
32+
void* SOIL_GL_GetProcAddress(const char* proc);
3333

3434
#ifdef __cplusplus
3535
}

0 commit comments

Comments
 (0)