Skip to content

Commit ae89465

Browse files
committed
Always link OpenGL libs, also add option to build with GLES3
As libprojectM 4.2 and higher will use a dedicated GL loader and no longer pass down the GL dependency (so apps can choose their own implementation), linking GL is now required explicitly. Won't break older versions though. Also added a ENABLE_GLES CMake option to build the application with GLES 3.2 support, making it easier to build it on devices such as the Raspberry Pi. Affects both SDL GL initialization and the ImGui-internal GL loader. libprojectM needs to be built accordingly of course.
1 parent 7a07229 commit ae89465

4 files changed

Lines changed: 28 additions & 4 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
1515

1616
option(ENABLE_FLAT_PACKAGE "Creates a \"flat\" install layout with the executable, configuration file(s) and preset/texture dirs directly in the install prefix." OFF)
1717
option(ENABLE_INSTALL_BDEPS "Installs all shared libraries projectMSDL requires to run. On some platforms, CMake 3.31 or higher is required for this to work!" OFF)
18+
option(ENABLE_GLES "Build the application to use OpenGL ES instead of Core GL. May not work on all platforms and requires CMake 3.27 or higher." OFF)
1819

1920
set(PROJECTMSDL_PROPERTIES_FILENAME "projectMSDL.properties")
2021

@@ -97,6 +98,14 @@ endif()
9798

9899
find_package(projectM4 REQUIRED COMPONENTS Playlist)
99100
find_package(SDL2 REQUIRED)
101+
if (NOT ENABLE_GLES)
102+
find_package(OpenGL REQUIRED)
103+
else ()
104+
if (CMAKE_VERSION VERSION_LESS 3.27)
105+
message(FATAL_ERROR "CMake 3.27 or higher is required to build with OpenGL ES 3!")
106+
endif ()
107+
find_package(OpenGL REQUIRED COMPONENTS GLES3)
108+
endif()
100109
find_package(Poco REQUIRED COMPONENTS JSON XML Util Foundation)
101110

102111
if(Poco_VERSION VERSION_GREATER_EQUAL 1.14.0)

ImGui.cmake

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ target_include_directories(ImGui
4242
${SDL2_INCLUDE_DIRS}
4343
)
4444

45+
if (ENABLE_GLES)
46+
target_compile_definitions(ImGui
47+
PUBLIC
48+
IMGUI_IMPL_OPENGL_ES3
49+
)
50+
endif ()
51+
4552
# Build font embedding tool
4653
add_executable(ImGuiBinaryToCompressedC EXCLUDE_FROM_ALL
4754
vendor/imgui/misc/fonts/binary_to_compressed_c.cpp

src/CMakeLists.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ set_target_properties(projectMSDL PROPERTIES
3434
MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/resources/Info.plist.in"
3535
)
3636

37+
if (ENABLE_GLES)
38+
target_compile_definitions(projectMSDL
39+
PUBLIC
40+
USE_GLES
41+
)
42+
endif ()
43+
3744
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
3845
target_sources(projectMSDL
3946
PRIVATE
@@ -56,7 +63,7 @@ else ()
5663
)
5764
endif ()
5865

59-
# GLEW needs to be initialized if libprojectM depends on it.
66+
# GLEW needs to be initialized if libprojectM depends on it (<v4.2).
6067
if (TARGET GLEW::glew OR TARGET GLEW::glew_s)
6168
target_compile_definitions(projectMSDL
6269
PRIVATE
@@ -81,6 +88,7 @@ target_link_libraries(projectMSDL
8188
Poco::Util
8289
SDL2::SDL2$<$<STREQUAL:${SDL2_LINKAGE},static>:-static>
8390
SDL2::SDL2main
91+
OpenGL::$<IF:$<BOOL:${ENABLE_GLES}>,GLES3,GL>
8492
)
8593
8694
if (MSVC)

src/SDLRenderingWindow.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ void SDLRenderingWindow::CreateSDLWindow()
238238
}
239239

240240
#if USE_GLES
241-
// use GLES 2.0
242-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
243-
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
241+
// use GLES 3.2
242+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
243+
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
244244
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
245245
#else
246246
// projectM Requires at least Core Profile 3.30 for samplers etc.

0 commit comments

Comments
 (0)