Skip to content

Commit f1c4761

Browse files
committed
add projectm_create_with_opengl_load_proc() api
replace OpenGL depencencies with GLAD add GL resolver, GL probe, GLAD loader remove GLEW, adjust sdl-test-ui
1 parent 949f249 commit f1c4761

27 files changed

Lines changed: 4452 additions & 122 deletions

CMakeLists.txt

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -166,36 +166,12 @@ else()
166166

167167
if(ENABLE_GLES)
168168
message(STATUS "Building for OpenGL Embedded Profile")
169-
if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux
170-
AND NOT CMAKE_SYSTEM_NAME STREQUAL Android)
171-
message(FATAL_ERROR "OpenGL ES 3 support is currently only available for Linux platforms. You're building for ${CMAKE_SYSTEM_NAME}.")
172-
endif()
173-
174-
# We use a local find script for OpenGL::GLES3 until the proposed changes are merged upstream.
175-
list(APPEND CMAKE_MODULE_PATH "${PROJECTM_SOURCE_DIR}/cmake/gles")
176-
find_package(OpenGL REQUIRED COMPONENTS GLES3)
177-
if(NOT TARGET OpenGL::GLES3)
178-
message(FATAL_ERROR "No suitable GLES3 library was found.")
179-
endif()
180-
181-
set(PROJECTM_OPENGL_LIBRARIES OpenGL::GLES3)
182169
set(USE_GLES ON)
183170
else()
184171
message(STATUS "Building for OpenGL Core Profile")
185-
find_package(OpenGL REQUIRED)
186-
set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL)
187-
# GLX is required by SOIL2 on platforms with the X Window System (e.g. most Linux distributions)
188-
if(TARGET OpenGL::GLX)
189-
list(APPEND PROJECTM_OPENGL_LIBRARIES OpenGL::GLX)
190-
endif()
191-
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
192-
find_package(GLEW REQUIRED)
193-
# Prefer shared, but check for static lib if shared is not available.
194-
if(TARGET GLEW::glew)
195-
list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew)
196-
elseif(TARGET GLEW::glew_s)
197-
list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew_s)
198-
endif()
172+
if(WIN32)
173+
find_package(OpenGL REQUIRED)
174+
set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL)
199175
endif()
200176
endif()
201177
endif()

src/api/include/projectM-4/core.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,51 @@
3232
extern "C" {
3333
#endif
3434

35+
/**
36+
* @brief Callback function for resolving function pointers.
37+
*
38+
* This callback functions is used to resolve platform-dependent GL function pointers.
39+
*
40+
* @param name The name of the function to resolve.
41+
* @param user_data A user-defined data pointer that is passed along with the load proc call,
42+
* e.g. context information.
43+
* @since 4.2.0
44+
*/
45+
typedef void* (*projectm_load_proc)(const char* name, void* user_data);
46+
3547
/**
3648
* @brief Creates a new projectM instance.
3749
*
3850
* If this function returns NULL, in most cases the OpenGL context is not initialized, not made
3951
* current or insufficient to render projectM visuals.
4052
*
53+
* The OpenGL resolver is initialized on the first call to either projectm_create() or projectm_create_with_opengl_load_proc().
54+
* All projectM instances share the same resolver.
55+
*
4156
* @return A projectM handle for the newly created instance that must be used in subsequent API calls.
4257
* NULL if the instance could not be created successfully.
4358
* @since 4.0.0
4459
*/
4560
PROJECTM_EXPORT projectm_handle projectm_create();
4661

62+
/**
63+
* @brief Creates a new projectM instance using the given function to resolve GL api functions.
64+
*
65+
* The load_proc function accepts a function name and a user data pointer.
66+
* If this function returns NULL, in most cases the OpenGL context is not initialized, not made
67+
* current or insufficient to render projectM visuals.
68+
*
69+
* The OpenGL resolver is initialized on the first call to either projectm_create() or projectm_create_with_opengl_load_proc().
70+
* All projectM instances share the same resolver, and subsequent calls ignore the provided load_proc.
71+
*
72+
* @param load_proc Callback function used to resolve OpenGL function pointers. Optional, may be NULL.
73+
* @param user_data Custom user data pointer to pass along to the load_proc call, e.g. context information. Optional, may be NULL.
74+
* @return A projectM handle for the newly created instance that must be used in subsequent API calls.
75+
* NULL if the instance could not be created successfully.
76+
* @since 4.2.0
77+
*/
78+
PROJECTM_EXPORT projectm_handle projectm_create_with_opengl_load_proc(projectm_load_proc load_proc, void* user_data);
79+
4780
/**
4881
* @brief Destroys the given instance and frees the resources.
4982
*

src/libprojectM/CMakeLists.txt

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ add_compile_definitions(
66
$<IF:$<PLATFORM_ID:Windows>,STBI_NO_DDS,>
77
)
88

9+
include_directories(
10+
"${PROJECTM_SOURCE_DIR}/vendor/glad/include"
11+
)
12+
913
add_subdirectory(Audio)
1014
add_subdirectory(MilkdropPreset)
1115
add_subdirectory(Renderer)
@@ -70,6 +74,7 @@ add_library(projectM
7074
$<TARGET_OBJECTS:stb_image>
7175
$<TARGET_OBJECTS:projectM_main>
7276
$<TARGET_OBJECTS:projectM::Eval>
77+
$<TARGET_OBJECTS:glad_obj>
7378
)
7479

7580
target_include_directories(projectM
@@ -84,6 +89,7 @@ if(ENABLE_CXX_INTERFACE)
8489
)
8590
endif()
8691

92+
# PROJECTM_OPENGL_LIBRARIES is present for WIN32/Desktop GL only
8793
target_link_libraries(projectM
8894
PUBLIC
8995
${PROJECTM_OPENGL_LIBRARIES}
@@ -261,20 +267,12 @@ if(ENABLE_INSTALL)
261267
PATH_VARS PROJECTM_BIN_DIR PROJECTM_INCLUDE_DIR
262268
)
263269

264-
install(FILES
265-
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4ConfigVersion.cmake"
266-
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4Config.cmake"
267-
DESTINATION "${PROJECTM_LIB_DIR}/cmake/projectM4"
268-
COMPONENT Devel
269-
)
270-
271-
if(NOT ENABLE_EMSCRIPTEN AND ENABLE_GLES)
272-
install(FILES
273-
"${PROJECTM_SOURCE_DIR}/cmake/gles/FindOpenGL.cmake"
274-
DESTINATION "${PROJECTM_LIB_DIR}/cmake/projectM4"
275-
COMPONENT Devel
276-
)
277-
endif()
270+
install(FILES
271+
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4ConfigVersion.cmake"
272+
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4Config.cmake"
273+
DESTINATION "${PROJECTM_LIB_DIR}/cmake/projectM4"
274+
COMPONENT Devel
275+
)
278276

279277
install(EXPORT libprojectMTargets
280278
FILE projectM4Targets.cmake

src/libprojectM/MilkdropPreset/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ target_link_libraries(MilkdropPreset
140140
PUBLIC
141141
hlslparser
142142
GLM::GLM
143-
${PROJECTM_OPENGL_LIBRARIES}
144143
)
145144

146145
if(BUILD_SHARED_LIBS)

src/libprojectM/ProjectMCWrapper.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
#include "ProjectMCWrapper.hpp"
22

3+
#include "Renderer/Platform/GladLoader.hpp"
4+
35
#include <projectM-4/projectM.h>
46

57
#include <Logging.hpp>
68

79
#include <Audio/AudioConstants.hpp>
10+
#include <Renderer/Platform/GLResolver.hpp>
811

912
#include <projectM-4/parameters.h>
1013
#include <projectM-4/render_opengl.h>
@@ -67,10 +70,29 @@ void projectm_free_string(const char* str)
6770
}
6871

6972
projectm_handle projectm_create()
73+
{
74+
return projectm_create_with_opengl_load_proc(nullptr, nullptr);
75+
}
76+
77+
projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data)
7078
{
7179
try
7280
{
73-
auto projectMInstance = new libprojectM::projectMWrapper();
81+
// Init resolver to discover gl function pointers (guarded internally, valid to call multiple times)
82+
// Note: only the initial load_proc will be used, parameters on subsequent calls are ignored
83+
if (!libprojectM::Renderer::Platform::GLResolver::Instance().Initialize(load_proc, user_data))
84+
{
85+
return nullptr;
86+
}
87+
88+
// Check GL requirements and init GLAD (guarded internally, valid to call multiple times)
89+
if (!libprojectM::Renderer::Platform::GladLoader::Instance().Initialize())
90+
{
91+
return nullptr;
92+
}
93+
94+
// create projectM
95+
auto* projectMInstance = new libprojectM::projectMWrapper();
7496
return reinterpret_cast<projectm_handle>(projectMInstance);
7597
}
7698
catch (...)

src/libprojectM/Renderer/CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ add_library(Renderer OBJECT
3232
MilkdropNoise.cpp
3333
MilkdropNoise.hpp
3434
OpenGL.h
35+
Platform/DynamicLibrary.cpp
36+
Platform/DynamicLibrary.hpp
37+
Platform/GladLoader.cpp
38+
Platform/GladLoader.hpp
39+
Platform/GLProbe.cpp
40+
Platform/GLProbe.hpp
41+
Platform/GLResolver.cpp
42+
Platform/GLResolver.hpp
3543
Point.hpp
3644
PresetTransition.cpp
3745
PresetTransition.hpp
@@ -76,9 +84,17 @@ target_link_libraries(Renderer
7684
GLM::GLM
7785
hlslparser
7886
stb_image
87+
glad
7988
${PROJECTM_OPENGL_LIBRARIES}
8089
)
8190

91+
if(PROJECTM_FILESYSTEM_USE_BOOST)
92+
target_link_libraries(Renderer
93+
PRIVATE
94+
${PROJECTM_FILESYSTEM_LIBRARY}
95+
)
96+
endif()
97+
8298
set_target_properties(Renderer PROPERTIES
8399
FOLDER libprojectM
84100
)

src/libprojectM/Renderer/OpenGL.h

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,8 @@
44
*/
55
#pragma once
66

7-
#ifdef __APPLE__ /* macOS */
8-
#include <OpenGL/gl3.h>
9-
#include <OpenGL/gl3ext.h>
10-
#elif defined(EYETUNE_WINRT) /* Universal Windows Platform */
11-
#define GL_GLEXT_PROTOTYPES
12-
#define GLM_FORCE_CXX03
13-
#include <EGL/egl.h>
14-
#include <EGL/eglext.h>
15-
#include <GLES2/gl2.h>
16-
#include <GLES2/gl2ext.h>
17-
#include <GLES3/gl3.h>
18-
#include <GLES3/gl31.h>
19-
#elif defined(_WIN32) /* Windows Desktop */
20-
#define GLM_FORCE_CXX03
21-
#include <GL/glew.h>
22-
#include <GL/wglew.h>
23-
#include <windows.h>
24-
#else /* Linux, BSD, Android, emscripten etc. */
257
#ifdef USE_GLES
26-
#include <GLES3/gl3.h>
8+
#include <glad/gles2.h>
279
#else
28-
#if !defined(GL_GLEXT_PROTOTYPES)
29-
#define GL_GLEXT_PROTOTYPES
30-
#endif
31-
#include <GL/gl.h>
32-
#include <GL/glext.h>
33-
#endif
10+
#include <glad/gl.h>
3411
#endif

0 commit comments

Comments
 (0)