diff --git a/BUILDING-cmake.md b/BUILDING-cmake.md index ee27dee7fe..d169e3815d 100644 --- a/BUILDING-cmake.md +++ b/BUILDING-cmake.md @@ -11,7 +11,6 @@ Required tools and dependencies: - CMake 3.21 or higher. - A working toolchain, e.g. Visual Studio on Windows or the `build-essentials` package on Ubuntu Linux. - Main OpenGL libraries and development files. -- The `GLEW` Library on Windows. To use the library in other projects, it is required to install it. Use `CMAKE_INSTALL_PREFIX` to specify the installation directory. diff --git a/BUILDING.md b/BUILDING.md index 9a3fe3127d..64b0415c4e 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -100,11 +100,6 @@ development files. To build projectM, both binaries and development files need t library dependencies and/or using CMake to configure the build. Mainly used on Windows, but also works for Linux and macOS. -### Only relevant for Windows: - -* [**GLEW**](http://glew.sourceforge.net/): The OpenGL Extension Wrangler Library. Only required if using CMake to - configure the build, the pre-created solutions use a bundled copy of GLEW. - ## Building on Linux and macOS ### Installing dependencies diff --git a/CMakeLists.txt b/CMakeLists.txt index 32000a1bb8..9d59c9b18a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -165,10 +165,6 @@ else() if(ENABLE_GLES) message(STATUS "Building for OpenGL Embedded Profile") - if(NOT CMAKE_SYSTEM_NAME STREQUAL Linux - AND NOT CMAKE_SYSTEM_NAME STREQUAL Android) - message(FATAL_ERROR "OpenGL ES 3 support is currently only available for Linux platforms. You're building for ${CMAKE_SYSTEM_NAME}.") - endif() # We use a local find script for OpenGL::GLES3 until the proposed changes are merged upstream. list(APPEND CMAKE_MODULE_PATH "${PROJECTM_SOURCE_DIR}/cmake/gles") @@ -183,19 +179,6 @@ else() message(STATUS "Building for OpenGL Core Profile") find_package(OpenGL REQUIRED) set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL) - # GLX is required by SOIL2 on platforms with the X Window System (e.g. most Linux distributions) - if(TARGET OpenGL::GLX) - list(APPEND PROJECTM_OPENGL_LIBRARIES OpenGL::GLX) - endif() - if(CMAKE_SYSTEM_NAME STREQUAL "Windows") - find_package(GLEW REQUIRED) - # Prefer shared, but check for static lib if shared is not available. - if(TARGET GLEW::glew) - list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew) - elseif(TARGET GLEW::glew_s) - list(APPEND PROJECTM_OPENGL_LIBRARIES GLEW::glew_s) - endif() - endif() endif() endif() diff --git a/docs/building.rst b/docs/building.rst index 9a82b2e6a4..07b8735f4c 100644 --- a/docs/building.rst +++ b/docs/building.rst @@ -138,9 +138,6 @@ Only relevant for Windows: library dependencies and/or using CMake to configure the build. - `NuGet `__: Dependency manager for .NET. Required to build the EyeTune app. -- `GLEW `__: The OpenGL Extension - Wrangler Library. Only required if using CMake to configure the - build, the pre-created solutions use a bundled copy of GLEW. Building on Linux and macOS --------------------------- diff --git a/src/api/include/projectM-4/core.h b/src/api/include/projectM-4/core.h index b54e698682..c9efc6a7c9 100644 --- a/src/api/include/projectM-4/core.h +++ b/src/api/include/projectM-4/core.h @@ -38,12 +38,31 @@ extern "C" { * If this function returns NULL, in most cases the OpenGL context is not initialized, not made * current or insufficient to render projectM visuals. * + * Note: The OpenGL resolver is initialized on the first invocation of either projectm_create() or projectm_create_with_opengl_load_proc(). + * All projectM instances created will use the same resolver. + * * @return A projectM handle for the newly created instance that must be used in subsequent API calls. * NULL if the instance could not be created successfully. * @since 4.0.0 */ PROJECTM_EXPORT projectm_handle projectm_create(); +/** + * @brief Creates a new projectM instance using the given function to resolve GL api functions. + * + * The load_proc function accepts a function name and a user data pointer. + * If this function returns NULL, in most cases the OpenGL context is not initialized, not made + * current or insufficient to render projectM visuals. + * + * Note: The OpenGL resolver is initialized on the first invocation of either projectm_create() or projectm_create_with_opengl_load_proc(). + * All projectM instances created will use the same resolver and subsequent calls will ignore the given load_proc. + * + * @return A projectM handle for the newly created instance that must be used in subsequent API calls. + * NULL if the instance could not be created successfully. + * @since 4.2.0 + */ +PROJECTM_EXPORT projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data); + /** * @brief Destroys the given instance and frees the resources. * diff --git a/src/libprojectM/CMakeLists.txt b/src/libprojectM/CMakeLists.txt index 2fc1c3160e..d32712e128 100644 --- a/src/libprojectM/CMakeLists.txt +++ b/src/libprojectM/CMakeLists.txt @@ -6,11 +6,21 @@ add_compile_definitions( $,STBI_NO_DDS,> ) +include_directories( + "${PROJECTM_SOURCE_DIR}/vendor/glad/include" + ) + add_subdirectory(Audio) add_subdirectory(MilkdropPreset) add_subdirectory(Renderer) add_subdirectory(UserSprites) +set(PROJECTM_LINK_GL_LIBS "") +if (WIN32) + # windows libs need to link to opengl32.dll + set(PROJECTM_LINK_GL_LIBS "${PROJECTM_OPENGL_LIBRARIES}") +endif() + add_library(projectM_main OBJECT "${PROJECTM_EXPORT_HEADER}" Logging.cpp @@ -70,6 +80,7 @@ add_library(projectM $ $ $ + $ ) target_include_directories(projectM @@ -79,7 +90,7 @@ target_include_directories(projectM target_link_libraries(projectM PUBLIC - ${PROJECTM_OPENGL_LIBRARIES} + ${PROJECTM_LINK_GL_LIBS} libprojectM::API ${PROJECTM_FILESYSTEM_LIBRARY} ) diff --git a/src/libprojectM/MilkdropPreset/CMakeLists.txt b/src/libprojectM/MilkdropPreset/CMakeLists.txt index 6889d8ad2f..3231a97279 100644 --- a/src/libprojectM/MilkdropPreset/CMakeLists.txt +++ b/src/libprojectM/MilkdropPreset/CMakeLists.txt @@ -140,7 +140,6 @@ target_link_libraries(MilkdropPreset PUBLIC hlslparser GLM::GLM - ${PROJECTM_OPENGL_LIBRARIES} ) if(NOT BUILD_SHARED_LIBS) diff --git a/src/libprojectM/ProjectM.cpp b/src/libprojectM/ProjectM.cpp index 552c1e071e..6fa75a7e04 100644 --- a/src/libprojectM/ProjectM.cpp +++ b/src/libprojectM/ProjectM.cpp @@ -38,8 +38,8 @@ namespace libprojectM { -ProjectM::ProjectM() - : m_presetFactoryManager(std::make_unique()) +ProjectM::ProjectM(const std::shared_ptr& glResolver) + : m_glResolver(glResolver), m_presetFactoryManager(std::make_unique()) { Initialize(); } diff --git a/src/libprojectM/ProjectM.hpp b/src/libprojectM/ProjectM.hpp index 7b293b45b7..da5138a900 100644 --- a/src/libprojectM/ProjectM.hpp +++ b/src/libprojectM/ProjectM.hpp @@ -39,6 +39,11 @@ class Renderer; class TextureManager; class ShaderCache; class TransitionShaderManager; + +namespace Platform { +class GLResolver; +} + } // namespace Renderer namespace UserSprites { @@ -52,7 +57,7 @@ class TimeKeeper; class PROJECTM_EXPORT ProjectM { public: - ProjectM(); + ProjectM(const std::shared_ptr& glResolver); virtual ~ProjectM(); @@ -291,6 +296,7 @@ class PROJECTM_EXPORT ProjectM bool m_presetLocked{false}; //!< If true, the preset change event will not be sent. bool m_presetChangeNotified{false}; //!< Stores whether the user has been notified that projectM wants to switch the preset. + std::shared_ptr m_glResolver; //!< Function resolver for accessing GL backend. std::unique_ptr m_presetFactoryManager; //!< Provides access to all available preset factories. Audio::PCM m_audioStorage; //!< Audio data buffer and analyzer instance. diff --git a/src/libprojectM/ProjectMCWrapper.cpp b/src/libprojectM/ProjectMCWrapper.cpp index 0c89ba64e2..9c046afe56 100644 --- a/src/libprojectM/ProjectMCWrapper.cpp +++ b/src/libprojectM/ProjectMCWrapper.cpp @@ -5,6 +5,7 @@ #include #include