Skip to content

Commit a455942

Browse files
committed
replace OpenGL depencencies with GLAD
add GL resolver, load GLAD remove GLEW, adjust sdl-test-ui
1 parent 4965d5e commit a455942

22 files changed

Lines changed: 3487 additions & 110 deletions

CMakeLists.txt

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

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

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,31 @@ extern "C" {
3838
* If this function returns NULL, in most cases the OpenGL context is not initialized, not made
3939
* current or insufficient to render projectM visuals.
4040
*
41+
* Note: The OpenGL resolver is initialized on the first call to either projectm_create() or projectm_create_with_opengl_load_proc().
42+
* All projectM instances share the same resolver.
43+
*
4144
* @return A projectM handle for the newly created instance that must be used in subsequent API calls.
4245
* NULL if the instance could not be created successfully.
4346
* @since 4.0.0
4447
*/
4548
PROJECTM_EXPORT projectm_handle projectm_create();
4649

50+
/**
51+
* @brief Creates a new projectM instance using the given function to resolve GL api functions.
52+
*
53+
* The load_proc function accepts a function name and a user data pointer.
54+
* If this function returns NULL, in most cases the OpenGL context is not initialized, not made
55+
* current or insufficient to render projectM visuals.
56+
*
57+
* Note: The OpenGL resolver is initialized on the first call to either projectm_create() or projectm_create_with_opengl_load_proc().
58+
* All projectM instances share the same resolver, and subsequent calls ignore the provided load_proc.
59+
*
60+
* @return A projectM handle for the newly created instance that must be used in subsequent API calls.
61+
* NULL if the instance could not be created successfully.
62+
* @since 4.2.0
63+
*/
64+
PROJECTM_EXPORT projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data);
65+
4766
/**
4867
* @brief Destroys the given instance and frees the resources.
4968
*

src/libprojectM/CMakeLists.txt

Lines changed: 6 additions & 8 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}
@@ -220,14 +226,6 @@ if(ENABLE_INSTALL)
220226
COMPONENT Devel
221227
)
222228

223-
if(NOT ENABLE_EMSCRIPTEN AND ENABLE_GLES)
224-
install(FILES
225-
"${PROJECTM_SOURCE_DIR}/cmake/gles/FindOpenGL.cmake"
226-
DESTINATION "${PROJECTM_LIB_DIR}/cmake/projectM4"
227-
COMPONENT Devel
228-
)
229-
endif()
230-
231229
install(EXPORT libprojectMTargets
232230
FILE projectM4Targets.cmake
233231
NAMESPACE libprojectM::

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: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <Logging.hpp>
66

77
#include <Audio/AudioConstants.hpp>
8+
#include <Renderer/PlatformGLResolver.hpp>
89

910
#include <projectM-4/parameters.h>
1011
#include <projectM-4/render_opengl.h>
@@ -67,10 +68,27 @@ void projectm_free_string(const char* str)
6768
}
6869

6970
projectm_handle projectm_create()
71+
{
72+
return projectm_create_with_opengl_load_proc(nullptr, nullptr);
73+
}
74+
75+
projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data)
7076
{
7177
try
7278
{
73-
auto projectMInstance = new libprojectM::projectMWrapper();
79+
// obtain shared resolver instance
80+
auto& glResolver = libprojectM::Renderer::Platform::GLResolver::Instance();
81+
82+
// init resolver to discover gl function pointers and init GLAD
83+
// Initialize() is guarded internally, may be called multiple times
84+
auto success = glResolver.Initialize(load_proc, user_data);
85+
if (!success)
86+
{
87+
return nullptr;
88+
}
89+
90+
// create projectM
91+
auto* projectMInstance = new libprojectM::projectMWrapper();
7492
return reinterpret_cast<projectm_handle>(projectMInstance);
7593
}
7694
catch (...)

src/libprojectM/Renderer/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ add_library(Renderer OBJECT
3232
MilkdropNoise.cpp
3333
MilkdropNoise.hpp
3434
OpenGL.h
35+
PlatformGLContextCheck.cpp
36+
PlatformGLContextCheck.hpp
37+
PlatformGLResolver.cpp
38+
PlatformGLResolver.hpp
39+
PlatformLoader.cpp
40+
PlatformLoader.hpp
3541
Point.hpp
3642
PresetTransition.cpp
3743
PresetTransition.hpp
@@ -59,7 +65,7 @@ add_library(Renderer OBJECT
5965
VertexBufferUsage.hpp
6066
VertexIndexArray.cpp
6167
VertexIndexArray.hpp
62-
)
68+
)
6369

6470
target_include_directories(Renderer
6571
PRIVATE
@@ -76,6 +82,7 @@ target_link_libraries(Renderer
7682
GLM::GLM
7783
hlslparser
7884
stb_image
85+
glad
7986
${PROJECTM_OPENGL_LIBRARIES}
8087
)
8188

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)