Skip to content

Commit

Permalink
Pioneer on RaspberryPi
Browse files Browse the repository at this point in the history
Use OpenGL 3.1 on Pi
Add PIONEER_TARGET_RASPBERRY_PI define in CmakeLists
  • Loading branch information
fluffyfreak committed Oct 14, 2024
1 parent 2884328 commit eaadad3
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 5 deletions.
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ if (USE_AVX2)
endif()
endif(USE_AVX2)

# Default to enabling PIONEER_TARGET_RASPBERRY_PI if we're compiling on ARM64
option(PIONEER_TARGET_RASPBERRY_PI "Compile for Raspberry Pi specifically (degrades to OpenGL 3.1)" ${PIONEER_TARGET_ARM64})

if (PIONEER_TARGET_RASPBERRY_PI)
# add_compile_options("-mcpu=cortex-a76" "-ffast-math")
add_compile_options("-ffast-math")
endif(PIONEER_TARGET_RASPBERRY_PI)

option(USE_LLD_LINKER "Use the LLVM lld linker instead of gcc's linker" OFF)
if (CMAKE_COMPILER_IS_GNUCXX)
add_compile_options(
Expand Down
6 changes: 2 additions & 4 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_BUILD_TYPE": "Debug",
"PROFILER_ENABLED": "1"
"CMAKE_BUILD_TYPE": "Debug"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
Expand Down Expand Up @@ -138,8 +137,7 @@
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_C_COMPILER": "/usr/bin/clang",
"CMAKE_CXX_COMPILER": "/usr/bin/clang++",
"PROFILER_ENABLED": "1"
"CMAKE_CXX_COMPILER": "/usr/bin/clang++"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
Expand Down
68 changes: 68 additions & 0 deletions scripts/CMakeExperimentalPresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"version": 2,
"configurePresets": [
{
"name": "RPi-Linux-Debug",
"displayName": "Linux RPi Debug",
"description": "Use system compiler; Profiler=no",
"binaryDir": "${sourceDir}/build/",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_BUILD_TYPE": "Debug",
"USE_SSE42": false,
"USE_AVX2": false,
"PIONEER_TARGET_RASPBERRY_PI": true
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Linux"
]
}
}
},
{
"name": "RPi-Linux-Profiler",
"displayName": "Linux RPi Profiling",
"description": "Use system compiler; Profiler=yes",
"binaryDir": "${sourceDir}/build/",
"cacheVariables": {
"CMAKE_EXPORT_COMPILE_COMMANDS": true,
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"PROFILER_ENABLED": "1",
"USE_SSE42": false,
"USE_AVX2": false,
"PIONEER_TARGET_RASPBERRY_PI": true
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Linux"
]
}
}
},
{
"name": "RPi-linux-release",
"displayName": "Linux RPi Release",
"description": "Use system compiler; Opt=yes; Profiler=no",
"binaryDir": "${sourceDir}/build/",
"cacheVariables": {
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"CMAKE_BUILD_TYPE": "Release",
"USE_SSE42": false,
"USE_AVX2": false,
"PIONEER_TARGET_RASPBERRY_PI": true
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Linux"
]
}
}
}
]
}
17 changes: 16 additions & 1 deletion src/graphics/opengl/RendererGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,16 @@ namespace Graphics {
Uint32 winFlags = 0;

winFlags |= SDL_WINDOW_OPENGL;
// We'd like a context that implements OpenGL 3.2 to allow creation of multisampled textures
// We'd like a context that implements OpenGL 3.1 to allow creation of multisampled textures
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
#if defined(PIONEER_TARGET_RASPBERRY_PI)
// on Arm and other platforms we attempt to create an OpenGL 3.1 context as this is what Raspberry Pi 4 & 5 currently support
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
#else
// x86/x64 we use newer OpenGL
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
#endif

// Request core profile as we're uninterested in old fixed-function API
// also cannot initialise 3.x context on OSX with anything but CORE profile
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
Expand Down Expand Up @@ -194,11 +201,19 @@ namespace Graphics {
if (vs.enableDebugMessages)
GLDebug::Enable();

#if defined(PIONEER_TARGET_RASPBERRY_PI)
// on Arm and other platforms we attempt to create an OpenGL 3.1 context as this is what Raspberry Pi 4 & 5 currently support
if (!glewIsSupported("GL_VERSION_3_1")) {
Error("Pioneer can not run on your device (Raspberry Pi?) as it does not appear to support OpenGL 3.1");
}
#else
// x86/x64 we use newer OpenGL
if (!glewIsSupported("GL_VERSION_3_2")) {
Error(
"Pioneer can not run on your graphics card as it does not appear to support OpenGL 3.2\n"
"Please check to see if your GPU driver vendor has an updated driver - or that drivers are installed correctly.");
}
#endif

if (!glewIsSupported("GL_EXT_texture_compression_s3tc")) {
if (glewIsSupported("GL_ARB_texture_compression")) {
Expand Down

0 comments on commit eaadad3

Please sign in to comment.