Skip to content

Commit 681b158

Browse files
committed
remove glad forward decl, naming fixes
1 parent f0cef93 commit 681b158

9 files changed

Lines changed: 70 additions & 60 deletions

File tree

src/libprojectM/ProjectMCWrapper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <Audio/AudioConstants.hpp>
88

99
#include <Renderer/CrossGlLoader.hpp>
10-
#include <SOIL2/soil2_gl_bridge.h>
10+
#include <SOIL2/SOIL2_gl_bridge.h>
1111
#include <SOIL2/SOIL2.h>
1212

1313
#include <projectM-4/parameters.h>
@@ -88,7 +88,7 @@ projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const c
8888

8989
// init SOIL2 gl functions
9090
SOIL_GL_SetResolver(&libprojectM::Renderer::CrossGlLoader::GladResolverThunk);
91-
SOIL_init();
91+
SOIL_GL_Init();
9292

9393
// create projectM
9494
auto* projectMInstance = new libprojectM::projectMWrapper();

src/libprojectM/Renderer/CrossGlLoader.cpp

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
// Cross-platform runtime GL/GLES loader using GLAD2 C API (non-MX).
22
//
3-
// Only forward declares the GLAD loader entrypoints (gladLoadGL / gladLoadGLES2) and provides
4-
// a universal resolver.
3+
// Provides a universal resolver to find GL function pointers.
54

65
#include "CrossGlLoader.hpp"
76

87
#include <Logging.hpp>
8+
#include "OpenGL.h"
99

1010
#include <array>
1111
#include <cstdio>
1212

13-
// forward declare glad interfaces to contain dependency to this cpp
14-
namespace {
15-
16-
using GladLoadFunc = void* (*) (const char* name);
17-
18-
extern "C" {
19-
#ifndef USE_GLES
20-
int gladLoadGL(GladLoadFunc load);
21-
#else
22-
int gladLoadGLES2(GladLoadFunc load);
23-
#endif
24-
}
25-
26-
} // namespace
27-
2813
namespace libprojectM {
2914
namespace Renderer {
3015

@@ -100,7 +85,7 @@ auto CrossGlLoader::CurrentBackend() const -> Backend
10085
return m_backend;
10186
}
10287

103-
auto CrossGlLoader::GetProcAddress(const char* name) const -> void*
88+
auto CrossGlLoader::GetProcAddress(const char* name) const -> GLapiproc
10489
{
10590
// NOTE: This method is used during GLAD loading. Avoid taking the mutex here to
10691
// prevent deadlocks if GLAD calls back into us while Initialize() is holding the lock
@@ -213,17 +198,25 @@ void CrossGlLoader::DetectBackend()
213198
m_backend = Backend::None;
214199
}
215200

216-
auto CrossGlLoader::GladResolverThunk(const char* name) -> void*
201+
auto CrossGlLoader::GladResolverThunk(const char* name) -> GLapiproc
217202
{
218203
return Instance().Resolve(name);
219204
}
220205

206+
namespace {
207+
// adapt external void* handle to GLAD type
208+
auto gladBridgeResolverThunk(const char* name) -> GLADapiproc
209+
{
210+
return reinterpret_cast<GLADapiproc>(CrossGlLoader::GladResolverThunk(name));
211+
}
212+
}
213+
221214
auto CrossGlLoader::LoadViaGlad() -> bool
222215
{
223216
int result = 0;
224217

225218
#ifndef USE_GLES
226-
result = gladLoadGL(&CrossGlLoader::GladResolverThunk);
219+
result = gladLoadGL(&gladBridgeResolverThunk);
227220
if (result != 0)
228221
{
229222
LOG_DEBUG("CrossGlLoader: gladLoadGL() succeeded");
@@ -232,7 +225,7 @@ auto CrossGlLoader::LoadViaGlad() -> bool
232225
LOG_DEBUG("CrossGlLoader: gladLoadGL() failed");
233226
return false;
234227
#else
235-
result = gladLoadGLES2(&CrossGlLoader::GladResolverThunk);
228+
result = gladLoadGLES2(&gladBridgeResolverThunk);
236229
if (result != 0)
237230
{
238231
LOG_DEBUG("CrossGlLoader: gladLoadGLES2() succeeded");
@@ -243,7 +236,7 @@ auto CrossGlLoader::LoadViaGlad() -> bool
243236
#endif
244237
}
245238

246-
auto CrossGlLoader::Resolve(const char* name) const -> void*
239+
auto CrossGlLoader::Resolve(const char* name) const -> GLapiproc
247240
{
248241
if (name == nullptr)
249242
{

src/libprojectM/Renderer/CrossGlLoader.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ using UserResolver = void* (*)(const char* name, void* userData);
4545
class CrossGlLoader
4646
{
4747
public:
48+
using GLapiproc = void*;
49+
4850
CrossGlLoader() = default;
4951
~CrossGlLoader() = default;
5052

@@ -88,23 +90,23 @@ class CrossGlLoader
8890
* @param name Function name.
8991
* @return Procedure address or nullptr.
9092
*/
91-
auto GetProcAddress(const char* name) const -> void*;
93+
auto GetProcAddress(const char* name) const -> GLapiproc;
9294

9395
/**
9496
* @brief Resolves a function pointer using the loader's universal resolver from a static context.
9597
*
9698
* @param name Function name.
9799
* @return Procedure address or nullptr.
98100
*/
99-
static auto GladResolverThunk(const char* name) -> void*;
101+
static auto GladResolverThunk(const char* name) -> GLapiproc;
100102
private:
101-
using GetProcFunc = void* (*)(const char* name);
103+
using GetProcFunc = GLapiproc (*)(const char* name);
102104

103105
void OpenNativeLibraries();
104106
void ResolveProviderFunctions();
105107
void DetectBackend();
106108
auto LoadViaGlad() -> bool;
107-
auto Resolve(const char* name) const -> void*;
109+
auto Resolve(const char* name) const -> GLapiproc;
108110

109111
mutable std::mutex m_mutex;
110112

vendor/SOIL2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ add_library(SOIL2 OBJECT
66
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/pkm_helper.h
77
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2.c
88
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/wfETC.c
9-
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/soil2_gl_bridge.c
9+
${CMAKE_CURRENT_SOURCE_DIR}/src/SOIL2/SOIL2_gl_bridge.c
1010
)
1111

1212
target_include_directories(SOIL2

vendor/SOIL2/src/SOIL2/SOIL2.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define SOIL_CHECK_FOR_GL_ERRORS 0
2020

2121
// --- projectM patched GL discovery start ---
22-
#include "soil2_gl_bridge.h"
22+
#include "SOIL2_gl_bridge.h"
2323

2424
#ifndef APIENTRY
2525
# if defined(_WIN32)
@@ -334,9 +334,9 @@ static int soil2_gl_inited = 0;
334334

335335

336336

337-
void SOIL_init()
337+
void SOIL_GL_Init()
338338
{
339-
/* Must be called after a GL context exists and AFTER soil2_set_gl_resolver(). */
339+
/* Must be called after a GL context exists and AFTER SOIL_GL_SetResolver(). */
340340
if (soil2_gl_inited)
341341
return;
342342

@@ -365,7 +365,7 @@ static void soil2_ensure_gl_inited(void)
365365
{
366366
if(!soil2_gl_inited)
367367
{
368-
SOIL_init();
368+
SOIL_GL_Init();
369369
}
370370
}
371371

vendor/SOIL2/src/SOIL2/SOIL2.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ extern "C" {
6262
#define SOIL_VERSION_ATLEAST( X, Y, Z ) ( SOIL_COMPILED_VERSION >= SOIL_VERSION_NUM( X, Y, Z ) )
6363

6464
unsigned long SOIL_version();
65-
void SOIL_init();
65+
void SOIL_GL_Init();
6666

6767
/**
6868
The format of images that may be loaded (force_channels).
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "soil2_gl_bridge.h"
1+
#include "SOIL2_gl_bridge.h"
22

3-
static pm_soil_gl_resolver_t g_resolver = 0;
3+
static soil_gl_resolver_t g_resolver = 0;
44

5-
void SOIL_GL_SetResolver(pm_soil_gl_resolver_t resolver) {
5+
void SOIL_GL_SetResolver(soil_gl_resolver_t resolver) {
66
g_resolver = resolver;
77
}
88

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#ifndef SOIL2_GL_BRIDGE_H
2+
#define SOIL2_GL_BRIDGE_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#if defined(SOIL_GLES2) || defined(__ANDROID__) || defined(__EMSCRIPTEN__)
9+
#include <glad/gles2.h>
10+
#else
11+
#include <glad/gl.h>
12+
#endif
13+
14+
/**
15+
* Function used by SOIL2 to resolve GL function pointers.
16+
*/
17+
typedef void* (*soil_gl_resolver_t)(const char* name);
18+
19+
/**
20+
* Sets the GL function resolver for SOIL2.
21+
*
22+
* @param resolver The resolver function to use.
23+
*/
24+
void SOIL_GL_SetResolver(soil_gl_resolver_t resolver);
25+
26+
/**
27+
* Resolver function to look up gl functions for SOIL2.
28+
*
29+
* @param proc GL Function name.
30+
* @return Resolved function pointer for the given function name, or 0 if the function could not be resolved.
31+
*/
32+
void* SOIL_GL_GetProcAddress(const char* proc);
33+
34+
#ifdef __cplusplus
35+
}
36+
#endif
37+
38+
#endif

vendor/SOIL2/src/SOIL2/soil2_gl_bridge.h

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)