Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion BUILDING-cmake.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 0 additions & 17 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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()

Expand Down
3 changes: 0 additions & 3 deletions docs/building.rst
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ Only relevant for Windows:
library dependencies and/or using CMake to configure the build.
- `NuGet <https://www.nuget.org/>`__: Dependency manager for .NET.
Required to build the EyeTune app.
- `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
---------------------------
Expand Down
19 changes: 19 additions & 0 deletions src/api/include/projectM-4/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
13 changes: 12 additions & 1 deletion src/libprojectM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,21 @@ add_compile_definitions(
$<IF:$<PLATFORM_ID:Windows>,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
Expand Down Expand Up @@ -70,6 +80,7 @@ add_library(projectM
$<TARGET_OBJECTS:SOIL2>
$<TARGET_OBJECTS:projectM_main>
$<TARGET_OBJECTS:projectM::Eval>
$<TARGET_OBJECTS:glad_obj>
)

target_include_directories(projectM
Expand All @@ -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}
)
Expand Down
1 change: 0 additions & 1 deletion src/libprojectM/MilkdropPreset/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ target_link_libraries(MilkdropPreset
PUBLIC
hlslparser
GLM::GLM
${PROJECTM_OPENGL_LIBRARIES}
)

if(NOT BUILD_SHARED_LIBS)
Expand Down
4 changes: 2 additions & 2 deletions src/libprojectM/ProjectM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

namespace libprojectM {

ProjectM::ProjectM()
: m_presetFactoryManager(std::make_unique<PresetFactoryManager>())
ProjectM::ProjectM(const std::shared_ptr<Renderer::Platform::GLResolver>& glResolver)
: m_glResolver(glResolver), m_presetFactoryManager(std::make_unique<PresetFactoryManager>())
{
Initialize();
}
Expand Down
8 changes: 7 additions & 1 deletion src/libprojectM/ProjectM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ class Renderer;
class TextureManager;
class ShaderCache;
class TransitionShaderManager;

namespace Platform {
class GLResolver;
}

} // namespace Renderer

namespace UserSprites {
Expand All @@ -52,7 +57,7 @@ class TimeKeeper;
class PROJECTM_EXPORT ProjectM
{
public:
ProjectM();
ProjectM(const std::shared_ptr<Renderer::Platform::GLResolver>& glResolver);

virtual ~ProjectM();

Expand Down Expand Up @@ -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<Renderer::Platform::GLResolver> m_glResolver; //!< Function resolver for accessing GL backend.
std::unique_ptr<PresetFactoryManager> m_presetFactoryManager; //!< Provides access to all available preset factories.

Audio::PCM m_audioStorage; //!< Audio data buffer and analyzer instance.
Expand Down
25 changes: 24 additions & 1 deletion src/libprojectM/ProjectMCWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <Logging.hpp>

#include <Audio/AudioConstants.hpp>
#include <Renderer/PlatformGLResolver.hpp>

#include <projectM-4/parameters.h>
#include <projectM-4/render_opengl.h>
Expand All @@ -14,6 +15,11 @@

namespace libprojectM {

projectMWrapper::projectMWrapper(const std::shared_ptr<Renderer::Platform::GLResolver>& glResolver)
: ProjectM(glResolver)
{
}

void projectMWrapper::PresetSwitchRequestedEvent(bool isHardCut) const
{
if (m_presetSwitchRequestedEventCallback)
Expand Down Expand Up @@ -67,10 +73,27 @@ void projectm_free_string(const char* str)
}

projectm_handle projectm_create()
{
return projectm_create_with_opengl_load_proc(nullptr, nullptr);
}

projectm_handle projectm_create_with_opengl_load_proc(void* (*load_proc)(const char*, void*), void* user_data)
{
try
{
auto projectMInstance = new libprojectM::projectMWrapper();
// obtain shared resolver instance
auto glResolver = libprojectM::Renderer::Platform::GLResolver::Instance();

// init resolver to discover gl function pointers and init glad
// Initialize() is guarded internally, may be executed multiple times
auto success = glResolver->Initialize(load_proc, user_data);
if (!success)
{
return nullptr;
}

// create projectM
auto* projectMInstance = new libprojectM::projectMWrapper(glResolver);
return reinterpret_cast<projectm_handle>(projectMInstance);
}
catch (...)
Expand Down
2 changes: 2 additions & 0 deletions src/libprojectM/ProjectMCWrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ namespace libprojectM {
class projectMWrapper : public ProjectM
{
public:
projectMWrapper(const std::shared_ptr<Renderer::Platform::GLResolver>& glResolver);

void PresetSwitchFailedEvent(const std::string& presetFilename,
const std::string& failureMessage) const override;
void PresetSwitchRequestedEvent(bool isHardCut) const override;
Expand Down
5 changes: 5 additions & 0 deletions src/libprojectM/Renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ add_library(Renderer OBJECT
MilkdropNoise.cpp
MilkdropNoise.hpp
OpenGL.h
PlatformGLResolver.cpp
PlatformGLResolver.hpp
PlatformLoader.h
Point.hpp
PresetTransition.cpp
PresetTransition.hpp
Expand Down Expand Up @@ -76,6 +79,8 @@ target_link_libraries(Renderer
GLM::GLM
hlslparser
SOIL2
glad
${PROJECTM_FILESYSTEM_LIBRARY}
)

set_target_properties(Renderer PROPERTIES
Expand Down
27 changes: 2 additions & 25 deletions src/libprojectM/Renderer/OpenGL.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,8 @@
*/
#pragma once

#ifdef __APPLE__ /* macOS */
#include <OpenGL/gl3.h>
#include <OpenGL/gl3ext.h>
#elif defined(EYETUNE_WINRT) /* Universal Windows Platform */
#define GL_GLEXT_PROTOTYPES
#define GLM_FORCE_CXX03
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include <GLES3/gl3.h>
#include <GLES3/gl31.h>
#elif defined(_WIN32) /* Windows Desktop */
#define GLM_FORCE_CXX03
#include <GL/glew.h>
#include <GL/wglew.h>
#include <windows.h>
#else /* Linux, BSD, Android, emscripten etc. */
#ifdef USE_GLES
#include <GLES3/gl3.h>
#include <glad/gles2.h>
#else
#if !defined(GL_GLEXT_PROTOTYPES)
#define GL_GLEXT_PROTOTYPES
#endif
#include <GL/gl.h>
#include <GL/glext.h>
#endif
#include <glad/gl.h>
#endif
Loading
Loading