Skip to content
Open
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
30 changes: 3 additions & 27 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,36 +166,12 @@ 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")
find_package(OpenGL REQUIRED COMPONENTS GLES3)
if(NOT TARGET OpenGL::GLES3)
message(FATAL_ERROR "No suitable GLES3 library was found.")
endif()

set(PROJECTM_OPENGL_LIBRARIES OpenGL::GLES3)
set(USE_GLES ON)
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()
if(WIN32)
find_package(OpenGL REQUIRED)
set(PROJECTM_OPENGL_LIBRARIES OpenGL::GL)
Comment on lines +172 to +174
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really required on Windows? glad should load opengl32.dll from the OS, which is exactly what we'd link here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, for some reason, it appears to be a hard requirement to link opengl32.dll on Windows for desktop GL.

endif()
endif()
endif()
Expand Down
33 changes: 33 additions & 0 deletions src/api/include/projectM-4/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,51 @@
extern "C" {
#endif

/**
* @brief Callback function for resolving function pointers.
*
* This callback functions is used to resolve platform-dependent GL function pointers.
*
* @param name The name of the function to resolve.
* @param user_data A user-defined data pointer that is passed along with the load proc call,
* e.g. context information.
* @since 4.2.0
*/
typedef void* (*projectm_load_proc)(const char* name, void* user_data);

/**
* @brief Creates a new projectM instance.
*
* If this function returns NULL, in most cases the OpenGL context is not initialized, not made
* current or insufficient to render projectM visuals.
*
* The OpenGL resolver is initialized on the first call to either projectm_create() or projectm_create_with_opengl_load_proc().
* All projectM instances share 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.
*
* The OpenGL resolver is initialized on the first call to either projectm_create() or projectm_create_with_opengl_load_proc().
* All projectM instances share the same resolver, and subsequent calls ignore the provided load_proc.
*
* @param load_proc Callback function used to resolve OpenGL function pointers. Optional, may be NULL.
* @param user_data Custom user data pointer to pass along to the load_proc call, e.g. context information. Optional, may be NULL.
* @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(projectm_load_proc load_proc, void* user_data);

/**
* @brief Destroys the given instance and frees the resources.
*
Expand Down
26 changes: 12 additions & 14 deletions src/libprojectM/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ 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)
Expand Down Expand Up @@ -70,6 +74,7 @@ add_library(projectM
$<TARGET_OBJECTS:stb_image>
$<TARGET_OBJECTS:projectM_main>
$<TARGET_OBJECTS:projectM::Eval>
$<TARGET_OBJECTS:glad_obj>
)

target_include_directories(projectM
Expand All @@ -84,6 +89,7 @@ if(ENABLE_CXX_INTERFACE)
)
endif()

# PROJECTM_OPENGL_LIBRARIES is present for WIN32/Desktop GL only
target_link_libraries(projectM
PUBLIC
${PROJECTM_OPENGL_LIBRARIES}
Expand Down Expand Up @@ -261,20 +267,12 @@ if(ENABLE_INSTALL)
PATH_VARS PROJECTM_BIN_DIR PROJECTM_INCLUDE_DIR
)

install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4Config.cmake"
DESTINATION "${PROJECTM_LIB_DIR}/cmake/projectM4"
COMPONENT Devel
)

if(NOT ENABLE_EMSCRIPTEN AND ENABLE_GLES)
install(FILES
"${PROJECTM_SOURCE_DIR}/cmake/gles/FindOpenGL.cmake"
DESTINATION "${PROJECTM_LIB_DIR}/cmake/projectM4"
COMPONENT Devel
)
endif()
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4ConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/libprojectM/projectM4Config.cmake"
DESTINATION "${PROJECTM_LIB_DIR}/cmake/projectM4"
COMPONENT Devel
)

install(EXPORT libprojectMTargets
FILE projectM4Targets.cmake
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(BUILD_SHARED_LIBS)
Expand Down
24 changes: 23 additions & 1 deletion src/libprojectM/ProjectMCWrapper.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "ProjectMCWrapper.hpp"

#include "Renderer/Platform/GladLoader.hpp"

#include <projectM-4/projectM.h>

#include <Logging.hpp>

#include <Audio/AudioConstants.hpp>
#include <Renderer/Platform/GLResolver.hpp>

#include <projectM-4/parameters.h>
#include <projectM-4/render_opengl.h>
Expand Down Expand Up @@ -67,10 +70,29 @@ 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();
// Init resolver to discover gl function pointers (guarded internally, valid to call multiple times)
// Note: only the initial load_proc will be used, parameters on subsequent calls are ignored
if (!libprojectM::Renderer::Platform::GLResolver::Instance().Initialize(load_proc, user_data))
{
return nullptr;
}

// Check GL requirements and init GLAD (guarded internally, valid to call multiple times)
if (!libprojectM::Renderer::Platform::GladLoader::Instance().Initialize())
{
return nullptr;
}

// create projectM
auto* projectMInstance = new libprojectM::projectMWrapper();
return reinterpret_cast<projectm_handle>(projectMInstance);
}
catch (...)
Expand Down
16 changes: 16 additions & 0 deletions src/libprojectM/Renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ add_library(Renderer OBJECT
MilkdropNoise.cpp
MilkdropNoise.hpp
OpenGL.h
Platform/DynamicLibrary.cpp
Platform/DynamicLibrary.hpp
Platform/GladLoader.cpp
Platform/GladLoader.hpp
Platform/GLProbe.cpp
Platform/GLProbe.hpp
Platform/GLResolver.cpp
Platform/GLResolver.hpp
Point.hpp
PresetTransition.cpp
PresetTransition.hpp
Expand Down Expand Up @@ -76,9 +84,17 @@ target_link_libraries(Renderer
GLM::GLM
hlslparser
stb_image
glad
${PROJECTM_OPENGL_LIBRARIES}
)

if(PROJECTM_FILESYSTEM_USE_BOOST)
target_link_libraries(Renderer
PRIVATE
${PROJECTM_FILESYSTEM_LIBRARY}
)
endif()

set_target_properties(Renderer PROPERTIES
FOLDER libprojectM
)
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