From d6831afa4c116892d7d0063a83fe4c8009d86925 Mon Sep 17 00:00:00 2001 From: Daniel '0xdbeef' Zalega Date: Wed, 24 Apr 2024 03:07:22 +0200 Subject: [PATCH] Moved PSP build from SDL1 to SDL2; Adjustments due to toolchain update --- cmake/DependenciesPSP.cmake | 81 +++++++++------------- scripts/config-psp.sh | 3 +- src/audio/CMakeLists.txt | 2 +- src/audio/src/Audio_SDL_mixer.cpp | 5 +- src/input/CMakeLists.txt | 2 +- src/time/CMakeLists.txt | 4 +- src/time/src/Timestep_SDL2.cpp | 4 +- src/video/CMakeLists.txt | 2 +- src/video/src/Video_PSP.cpp | 67 +++++++++--------- vendor/glad/CMakeLists.txt | 2 +- vendor/glad/glad_dummy/CMakeLists.txt | 5 ++ vendor/glad/glad_dummy/include/glad/glad.h | 1 + 12 files changed, 87 insertions(+), 91 deletions(-) create mode 100644 vendor/glad/glad_dummy/CMakeLists.txt create mode 100644 vendor/glad/glad_dummy/include/glad/glad.h diff --git a/cmake/DependenciesPSP.cmake b/cmake/DependenciesPSP.cmake index fed5daae..17dfe5fb 100644 --- a/cmake/DependenciesPSP.cmake +++ b/cmake/DependenciesPSP.cmake @@ -1,61 +1,46 @@ -# FIXME: This macro probably defines target that links to more libraries than actually needed. macro(add_psp_dependencies) - add_library(SDL_1_XX INTERFACE) - target_link_libraries(SDL_1_XX INTERFACE - -lSDL_mixer - -lSDLmain - -lSDL - ) + add_library(PSP_SDK INTERFACE) + target_link_libraries(PSP_SDK INTERFACE + -L${PSPDEV}/psp/sdk/lib + -lpspirkeyb + -lpspdebug + -lpspgu + -lpspvram + -lpspvfpu + -lpspctrl + -lpspge + -lpspdisplay + -lpsphprm + -lpspaudio + -lpsppower_driver + -lpsppower + ) + + add_library(SDL_2_XX INTERFACE) + target_link_libraries(SDL_2_XX INTERFACE + -L${PSPDEV}/psp + -lGL + -lmodplug + -lvorbisenc + -lvorbisfile + -lvorbis + -logg + -lSDL2_mixer + -lSDL2main + -lSDL2 + ) add_library(Dependencies INTERFACE) target_link_libraries(Dependencies INTERFACE - -L${PSPDEV}/psp/lib - -lg - -lstdc++ - -lc - -lGLU - -lglut - -lz - -lm - -lGL - -lvorbisidec - -lmikmod - -lpspvfpu - -L${PSPDEV}/psp/sdk/lib - -L${PSPDEV}/psp - -lpspdebug - -lpspgu - -lpspctrl - -lpspge - -lpspirkeyb - -lpsppower - -lpsppower_driver - -lpspdisplay - -lpsphprm - -lpspsdk - -lpsprtc - -lpspaudio - -lpsputility - -lpspnet_inet - -lc - -lpspuser - ) - + PSP_SDK + ) target_compile_definitions(Dependencies INTERFACE SPELUNKY_PSP_PLATFORM_PSP -Dmain=SDL_main - ) - + ) endmacro() macro(spelunky_psp_post_build_psp) - add_custom_command( - TARGET Spelunky_PSP - POST_BUILD COMMAND - "psp-strip" "$" - COMMENT "Stripping binary" - ) - create_pbp_file(TARGET Spelunky_PSP ICON_PATH ${ASSETS_PATH}/metadata/icon.png BACKGROUND_PATH ${ASSETS_PATH}/metadata/background.png diff --git a/scripts/config-psp.sh b/scripts/config-psp.sh index 3b44d5da..feffad01 100755 --- a/scripts/config-psp.sh +++ b/scripts/config-psp.sh @@ -16,4 +16,5 @@ cd $BUILD_PATH psp-cmake $ROOT_PATH \ -DCMAKE_BUILD_TYPE=Release \ --DCMAKE_INSTALL_PREFIX=$INSTALL_PATH +-DCMAKE_INSTALL_PREFIX=$INSTALL_PATH \ +-DCMAKE_VERBOSE_MAKEFILE=ON diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index c85b9337..502e62b7 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -42,7 +42,7 @@ target_link_libraries(Audio Patterns PRIVATE Logger - $,SDL_1_XX,> + $,SDL_2_XX,> $,SDL_1_XX,> $,SDL_2_XX,> $,SDL_2_XX,> diff --git a/src/audio/src/Audio_SDL_mixer.cpp b/src/audio/src/Audio_SDL_mixer.cpp index efd2696c..37d280dc 100644 --- a/src/audio/src/Audio_SDL_mixer.cpp +++ b/src/audio/src/Audio_SDL_mixer.cpp @@ -2,8 +2,9 @@ #include "AudioBank.hpp" #include "logger/log.h" -#include -#include +// FIXME: Forcing SDL2; move all platforms to SDL2 (Windows left) +#include +#include #include #include diff --git a/src/input/CMakeLists.txt b/src/input/CMakeLists.txt index f38364ad..d8d41bd8 100644 --- a/src/input/CMakeLists.txt +++ b/src/input/CMakeLists.txt @@ -30,7 +30,7 @@ target_link_libraries(Input $<$:SDL_2_XX> $<$:SDL_2_XX> $<$:SDL_1_XX> - $<$:SDL_1_XX> + $<$:SDL_2_XX> $<$:imgui> Dependencies ) diff --git a/src/time/CMakeLists.txt b/src/time/CMakeLists.txt index 6613d721..be36ce6b 100644 --- a/src/time/CMakeLists.txt +++ b/src/time/CMakeLists.txt @@ -2,7 +2,7 @@ project(Time) add_library(Time STATIC interface/time/Timestep.hpp - $,src/Timestep_SDL1.cpp,> + $,src/Timestep_SDL2.cpp,> $,src/Timestep_SDL1.cpp,> $,src/Timestep_SDL1.cpp,> $,src/Timestep_SDL2.cpp,> @@ -15,7 +15,7 @@ target_include_directories(Time ) target_link_libraries(Time PUBLIC - $,SDL_1_XX,> + $,SDL_2_XX,> $,SDL_1_XX,> $,SDL_2_XX,> $,SDL_2_XX,> diff --git a/src/time/src/Timestep_SDL2.cpp b/src/time/src/Timestep_SDL2.cpp index ed77c8db..80642512 100644 --- a/src/time/src/Timestep_SDL2.cpp +++ b/src/time/src/Timestep_SDL2.cpp @@ -1,5 +1,7 @@ #include "time/Timestep.hpp" -#include + +// FIXME: Forcing SDL2; move all platforms to SDL2 (Windows left) +#include Timestamp Timestep::delay() const { diff --git a/src/video/CMakeLists.txt b/src/video/CMakeLists.txt index 77f18441..8fde9884 100644 --- a/src/video/CMakeLists.txt +++ b/src/video/CMakeLists.txt @@ -29,7 +29,7 @@ target_link_libraries(Video glad Input GraphicsUtils - $,SDL_1_XX,> + $,SDL_2_XX,> $,SDL_1_XX,> $,SDL_2_XX,> $,SDL_2_XX,> diff --git a/src/video/src/Video_PSP.cpp b/src/video/src/Video_PSP.cpp index 79f7c136..f5793d2f 100644 --- a/src/video/src/Video_PSP.cpp +++ b/src/video/src/Video_PSP.cpp @@ -1,16 +1,16 @@ -// -// Created by dbeef on 7/7/19. -// #include "video/Video.hpp" -#include "glad/glad.h" #include "graphics_utils/DebugGlCall.hpp" +#include "time/Timestep.hpp" #include "logger/log.h" +#include "glad/glad.h" -#include +#include +#include struct PlatformSpecific { - // Nothing platform specific to be stored. + SDL_Window* window; + void* gl_context; }; Video::~Video() = default; // For pimpl idiom. @@ -18,12 +18,17 @@ Video::Video() : _timestep(60) {}; // For pimpl idiom. void Video::tear_down_gl() { + SDL_GL_DeleteContext(_platform_specific->gl_context); + SDL_DestroyWindow(_platform_specific->window); SDL_QuitSubSystem(SDL_INIT_VIDEO); + + _platform_specific->window = nullptr; + _platform_specific->gl_context = nullptr; } void Video::swap_buffers() const { - SDL_GL_SwapBuffers(); + SDL_GL_SwapWindow(_platform_specific->window); } bool Video::setup_gl() @@ -31,51 +36,47 @@ bool Video::setup_gl() log_info("Entered Video::setup_gl."); _platform_specific = std::make_unique(); - _viewport = std::make_shared(480, 272); - if (SDL_InitSubSystem(SDL_INIT_VIDEO) < 0) { + if (SDL_Init(SDL_INIT_VIDEO) < 0) { log_error("SDL_Init Error: %s", SDL_GetError()); SDL_ClearError(); return false; } - SDL_GL_SetAttribute( SDL_GL_RED_SIZE, 5 ); - SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, 5 ); - SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, 5 ); - - SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, 0); - SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 0); - SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, 0); - - SDL_GL_SetAttribute( SDL_GL_ACCUM_RED_SIZE, 0); - SDL_GL_SetAttribute( SDL_GL_ACCUM_GREEN_SIZE, 0); - SDL_GL_SetAttribute( SDL_GL_ACCUM_BLUE_SIZE, 0); - SDL_GL_SetAttribute( SDL_GL_ACCUM_ALPHA_SIZE, 0); - - SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1); - - SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); + SDL_GL_LoadLibrary(nullptr); + SDL_ClearError(); // Create a window - auto surface = SDL_SetVideoMode(_viewport->get_width_pixels(), - _viewport->get_height_pixels(), - 0, // current display's bpp - SDL_DOUBLEBUF | SDL_OPENGL | SDL_SWSURFACE); - if (!surface) { - log_error("SDL_SetVideoMode Error: %s", SDL_GetError()); + _platform_specific->window = SDL_CreateWindow("SpelunkyPSP", + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + 480, 272, + SDL_WINDOW_OPENGL); + if (!_platform_specific->window) + { + log_error("SDL_CreateWindow Error: %s", SDL_GetError()); SDL_ClearError(); return false; } - if(!gladLoadGLES1Loader((GLADloadproc) SDL_GL_GetProcAddress)) { - log_error("Error while loading ptrs to OpenGL functions"); + int w, h; + SDL_GL_GetDrawableSize(_platform_specific->window, &w, &h); + _viewport = std::make_shared(w, h); + + _platform_specific->gl_context = SDL_GL_CreateContext(_platform_specific->window); + if (!_platform_specific->gl_context) + { + log_error("SDL_GL_CreateContext Error: %s", SDL_GetError()); + SDL_ClearError(); return false; } + SDL_GL_MakeCurrent(_platform_specific->window, _platform_specific->gl_context); SDL_ClearError(); DebugGlCall(glEnable(GL_TEXTURE_2D)); + DebugGlCall(glShadeModel(GL_SMOOTH)); DebugGlCall(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE)); diff --git a/vendor/glad/CMakeLists.txt b/vendor/glad/CMakeLists.txt index 5b169742..a2d547d3 100644 --- a/vendor/glad/CMakeLists.txt +++ b/vendor/glad/CMakeLists.txt @@ -3,7 +3,7 @@ if (SPELUNKY_PSP_PLATFORM_LINUX OR SPELUNKY_PSP_PLATFORM_DARWIN) add_subdirectory(glad_opengl_1.3) elseif(SPELUNKY_PSP_PLATFORM_PSP) - add_subdirectory(glad_opengl_es_1.0) + add_subdirectory(glad_dummy) elseif(SPELUNKY_PSP_PLATFORM_ANDROID) add_subdirectory(glad_opengl_es_1.0) else() diff --git a/vendor/glad/glad_dummy/CMakeLists.txt b/vendor/glad/glad_dummy/CMakeLists.txt new file mode 100644 index 00000000..3d8aa721 --- /dev/null +++ b/vendor/glad/glad_dummy/CMakeLists.txt @@ -0,0 +1,5 @@ +add_library(glad INTERFACE) +target_include_directories(glad INTERFACE include) + +# For platform defines: +target_link_libraries(glad INTERFACE Dependencies) diff --git a/vendor/glad/glad_dummy/include/glad/glad.h b/vendor/glad/glad_dummy/include/glad/glad.h new file mode 100644 index 00000000..323ca3c3 --- /dev/null +++ b/vendor/glad/glad_dummy/include/glad/glad.h @@ -0,0 +1 @@ +#include "SDL2/SDL_opengl.h"