diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json index af8b807..cef71c1 100644 --- a/.vscode/c_cpp_properties.json +++ b/.vscode/c_cpp_properties.json @@ -12,8 +12,10 @@ "${workspaceFolder}/TSE/TSE_Math/src", "${workspaceFolder}/TSE/TSE_GlfwImpl/include", "${workspaceFolder}/TSE/TSE_GlfwImpl/src", - "${workspaceFolder}/TSE/TSE_GlfwOpenGlImpl/include", - "${workspaceFolder}/TSE/TSE_GlfwOpenGlImpl/src", + "${workspaceFolder}/TSE/TSE_OpenGlImpl/include", + "${workspaceFolder}/TSE/TSE_OpenGlImpl/src", + "${workspaceFolder}/TSE/TSE_Sdl3Impl/include", + "${workspaceFolder}/TSE/TSE_Sdl3Impl/src", "${workspaceFolder}/TSE/TSE_Editor/src" ], "defines": [], diff --git a/.vscode/tasks.json b/.vscode/tasks.json index eb7dd36..0fa5a63 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -33,7 +33,8 @@ "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++", "-DCMAKE_LINKER=lld-link", - "-DCMAKE_BUILD_TYPE=Debug" + "-DCMAKE_BUILD_TYPE=Debug", + "-DUSE_SDL3=ON" ], "group": { "kind": "build", @@ -55,7 +56,8 @@ "-DCMAKE_C_COMPILER=clang", "-DCMAKE_CXX_COMPILER=clang++", "-DCMAKE_LINKER=lld-link", - "-DCMAKE_BUILD_TYPE=Release" + "-DCMAKE_BUILD_TYPE=Release", + "-DUSE_SDL3=ON" ], "group": { "kind": "build", diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c26e1..b6536cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,28 @@ cmake_minimum_required(VERSION 3.31) #project name project(TSE-RTS) +# backend selection +option(USE_GLFW "Build with GLFW backend" OFF) +option(USE_SDL3 "Build with SDL3 backend" OFF) + +# default backend: GLFW +if(NOT USE_GLFW AND NOT USE_SDL3) + set(USE_GLFW ON) +endif() + +# forbid enabling both at once +if(USE_GLFW AND USE_SDL3) + message(FATAL_ERROR "USE_GLFW and USE_SDL3 cannot both be ON. Select exactly one backend.") +endif() + +if(USE_GLFW) + message(STATUS "Window backend: GLFW") +endif() + +if(USE_SDL3) + message(STATUS "Window backend: SDL3") +endif() + #cpp settings find_program(CLANG_C NAMES clang) find_program(CLANG_CXX NAMES clang++) @@ -28,8 +50,15 @@ add_subdirectory(TSE/TSE_Base) add_subdirectory(TSE/TSE_Math) add_subdirectory(TSE/TSE_Core) add_subdirectory(TSE/TSE_Editor) -add_subdirectory(TSE/TSE_GlfwImpl) -add_subdirectory(TSE/TSE_GlfwOpenGlImpl) +add_subdirectory(TSE/TSE_OpenGlImpl) + +if(USE_GLFW) + add_subdirectory(TSE/TSE_GlfwImpl) +endif() + +if(USE_SDL3) + add_subdirectory(TSE/TSE_Sdl3Impl) +endif() #source files file(GLOB CPP_SOURCE @@ -43,73 +72,127 @@ file(GLOB CPP_SOURCE "${PROJECT_SOURCE_DIR}/TSE-RTS/src/*/*/*/*.c" ) -#includes -include_directories(${PROJECT_SOURCE_DIR}/TSE-RTS/src) -include_directories(${PROJECT_SOURCE_DIR}/TSE-RTS/include) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_Math/src) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_Core/src) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_Base/src) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_Base/include) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_Editor/src) - -#includes Glfw -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/src) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/include) - -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwOpenGlImpl/src) -include_directories(${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwOpenGlImpl/include) - #project def add_executable(TSE-RTS ${CPP_SOURCE}) -if (WIN32) - if(DEBUG) - set(DEBUGSPEC - "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/FreeImageLib.d.lib" - "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/box2dd.lib" +# includes +target_include_directories(TSE-RTS PRIVATE + ${PROJECT_SOURCE_DIR}/TSE-RTS/src + ${PROJECT_SOURCE_DIR}/TSE-RTS/include + ${PROJECT_SOURCE_DIR}/TSE/TSE_Math/src + ${PROJECT_SOURCE_DIR}/TSE/TSE_Core/src + ${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include + ${PROJECT_SOURCE_DIR}/TSE/TSE_Base/src + ${PROJECT_SOURCE_DIR}/TSE/TSE_Base/include + ${PROJECT_SOURCE_DIR}/TSE/TSE_Editor/src + ${PROJECT_SOURCE_DIR}/TSE/TSE_OpenGlImpl/src + ${PROJECT_SOURCE_DIR}/TSE/TSE_OpenGlImpl/include +) + +if(USE_GLFW) + target_include_directories(TSE-RTS PRIVATE + ${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/src + ${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/include + ) +endif() + +if(USE_SDL3) + target_include_directories(TSE-RTS PRIVATE + ${PROJECT_SOURCE_DIR}/TSE/TSE_Sdl3Impl/src + ${PROJECT_SOURCE_DIR}/TSE/TSE_Sdl3Impl/include + ) +endif() + +# compile definitions for active backend +if(USE_GLFW) + target_compile_definitions(TSE-RTS PRIVATE TSE_WINDOW_BACKEND_GLFW) +endif() + +if(USE_SDL3) + target_compile_definitions(TSE-RTS PRIVATE TSE_WINDOW_BACKEND_SDL3) +endif() + +# external libs +set(LIB_SOURCE "") +set(BACKEND_LIBS "") +set(BACKEND_TARGETS "") + +if(WIN32) + if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(DEBUGSPEC + "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/FreeImageLib.d.lib" + "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/box2dd.lib" ) else() - set(DEBUGSPEC - "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/FreeImageLib.r.lib" - "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/box2d.lib" + set(DEBUGSPEC + "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/FreeImageLib.r.lib" + "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/box2d.lib" ) endif() + set(LIB_SOURCE - "${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/include/glfw3.lib" - # "${PROJECT_SOURCE_DIR}/../TSE.Core/lib/freetype.lib" - "${DEBUGSPEC}" + ${DEBUGSPEC} ) + + if(USE_GLFW) + list(APPEND LIB_SOURCE + "${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/include/glfw3.lib" + ) + list(APPEND BACKEND_TARGETS TSE_GlfwImpl) + endif() + + if(USE_SDL3) + list(APPEND LIB_SOURCE + "${PROJECT_SOURCE_DIR}/TSE/TSE_Sdl3Impl/include/SDL3.lib" + ) + list(APPEND BACKEND_TARGETS TSE_Sdl3Impl) + endif() + else() set(LIB_SOURCE - # "${PROJECT_SOURCE_DIR}/../TSE.Core/lib/libfreetype.a" - "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/libfreeimage.a" - "${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/include/libglfw3.a" - "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/libbox2d.a" + "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/libfreeimage.a" + "${PROJECT_SOURCE_DIR}/TSE/TSE_Core/include/libbox2d.a" + ) + + if(USE_GLFW) + list(APPEND LIB_SOURCE + "${PROJECT_SOURCE_DIR}/TSE/TSE_GlfwImpl/include/libglfw3.a" + ) + list(APPEND BACKEND_TARGETS TSE_GlfwImpl) + endif() + + if(USE_SDL3) + list(APPEND LIB_SOURCE + "${PROJECT_SOURCE_DIR}/TSE/TSE_Sdl3Impl/include/libSDL3.a" + ) + list(APPEND BACKEND_TARGETS TSE_Sdl3Impl) + endif() +endif() + +# link +if(WIN32) + target_link_libraries(TSE-RTS PUBLIC + TSE_Base + TSE_Math + TSE_Core + ${BACKEND_TARGETS} + TSE_OpenGlImpl + TSE_Editor + ${LIB_SOURCE} + ) +else() + target_link_libraries(TSE-RTS PUBLIC + TSE_Editor + TSE_OpenGlImpl + ${BACKEND_TARGETS} + TSE_Core + TSE_Math + TSE_Base + ${LIB_SOURCE} ) endif() -if (WIN32) - target_link_libraries(TSE-RTS PUBLIC - TSE_Base - TSE_Math - TSE_Core - TSE_GlfwImpl - TSE_GlfwOpenGlImpl - TSE_Editor - ${LIB_SOURCE}) -else() - target_link_libraries(TSE-RTS PUBLIC - TSE_Editor - TSE_GlfwOpenGlImpl - TSE_GlfwImpl - TSE_Core - TSE_Math - TSE_Base - ${LIB_SOURCE}) -endif() - -#flags +# flags target_compile_options(TSE-RTS PRIVATE -march=native) set(TARGET_DIR "${PROJECT_SOURCE_DIR}/bin") diff --git a/TSE b/TSE index f859288..a596028 160000 --- a/TSE +++ b/TSE @@ -1 +1 @@ -Subproject commit f8592886899fe936be29b1d0268ec86ea46e5ad6cae0dc4d1d4ba31299662c27 +Subproject commit a596028ed99dfe9cd67674a86ab693862f8faa2314651ff2eadd90a6a3abd291 diff --git a/TSE-RTS/src/main.cpp b/TSE-RTS/src/main.cpp index 2e3af2b..c01c293 100644 --- a/TSE-RTS/src/main.cpp +++ b/TSE-RTS/src/main.cpp @@ -1,7 +1,12 @@ #include #include "GL/gl3w.h" #include "globalVars.hpp" +#include "WindowManager.hpp" +#if defined(TSE_GLFW) #include "WindowGlfw.hpp" +#elif defined(TSE_SDL3) +#include "WindowSdl3.hpp" +#endif #include "OpenGLRenderingBackend.hpp" #include "imgui/imgui.h" #include "shader/defaultShaderHandler.cpp" @@ -21,7 +26,12 @@ #define USE_EDITOR using namespace TSE; +#if defined(TSE_GLFW) using namespace TSE::GLFW; +#elif defined(TSE_SDL3) +using namespace TSE::SDL3; +#endif +using namespace TSE::OpenGL; using namespace TSE::EDITOR; IWindow* wnd = nullptr; @@ -33,12 +43,22 @@ EditorSubsystem* editor; void SetupWindow() { Color backColor(0.0f, 0.0f, 0.0f, 0.0f); +#if defined(TSE_GLFW) #ifdef USE_EDITOR wnd = new WindowGlfw(PROJECT_NAME, 800, 600, new OpenGLRenderingBackend(backColor, false, 8, true), WindowType::Maximized); editor = new EditorSubsystem(); #else wnd = new WindowGlfw(PROJECT_NAME, 1920, 1080, new OpenGLRenderingBackend(backColor, false, 8, false), WindowType::Fullscreen); #endif +#elif defined(TSE_SDL3) +#ifdef USE_EDITOR + wnd = new WindowSdl3(PROJECT_NAME, 800, 600, new OpenGLRenderingBackend(backColor, false, 8, true), WindowType::Maximized); + editor = new EditorSubsystem(); +#else + wnd = new WindowSdl3(PROJECT_NAME, 1920, 1080, new OpenGLRenderingBackend(backColor, false, 8, false), WindowType::Fullscreen); +#endif +#endif + LoadBasicShaders(wnd->GetSize().x, wnd->GetSize().y); TileMapShader::Init(wnd->GetSize().x, wnd->GetSize().y); LastPassShader::Init(wnd->GetSize().x, wnd->GetSize().y); diff --git a/TSE-RTS/src/shaders/LastPassShader.cpp b/TSE-RTS/src/shaders/LastPassShader.cpp index b476c0e..1636624 100644 --- a/TSE-RTS/src/shaders/LastPassShader.cpp +++ b/TSE-RTS/src/shaders/LastPassShader.cpp @@ -5,7 +5,7 @@ #include "LastPassShaderGLSL.hpp" using namespace TSE; -using namespace TSE::GLFW; +using namespace TSE::OpenGL; #define SHADER_VERTEX_INDEX 0 #define SHADER_UV_INDEX 1 @@ -43,7 +43,7 @@ void LastPassShader::Init(float width, float height) instance->Disable(); } -LastPassShader::LastPassShader(std::vector> &&parts) : Shader(parts) +LastPassShader::LastPassShader(std::vector> &&parts) : Shader(parts) { PackageSize = SHADER_PACKAGE_SIZE; } diff --git a/TSE-RTS/src/shaders/LastPassShader.hpp b/TSE-RTS/src/shaders/LastPassShader.hpp index 7c47795..3af8937 100644 --- a/TSE-RTS/src/shaders/LastPassShader.hpp +++ b/TSE-RTS/src/shaders/LastPassShader.hpp @@ -5,7 +5,7 @@ #include "shader/Shader.hpp" #include "Types.hpp" -class LastPassShader : public TSE::GLFW::Shader +class LastPassShader : public TSE::OpenGL::Shader { private: static LastPassShader* instance; @@ -22,7 +22,7 @@ public: static LastPassShader* Instance(); static void Destroy(); static void Init(float width, float height); - LastPassShader(std::vector>&& parts); + LastPassShader(std::vector>&& parts); protected: void OnEnable() const override; diff --git a/TSE-RTS/src/shaders/TileMapShader.cpp b/TSE-RTS/src/shaders/TileMapShader.cpp index 067c6e8..7d95c09 100644 --- a/TSE-RTS/src/shaders/TileMapShader.cpp +++ b/TSE-RTS/src/shaders/TileMapShader.cpp @@ -5,7 +5,7 @@ #include "TileMapShaderGLSL.hpp" using namespace TSE; -using namespace TSE::GLFW; +using namespace TSE::OpenGL; #define SHADER_MESH_INDEX 0 #define SHADER_POS_INDEX 1 diff --git a/TSE-RTS/src/shaders/TileMapShader.hpp b/TSE-RTS/src/shaders/TileMapShader.hpp index ddb2b7e..cd3586a 100644 --- a/TSE-RTS/src/shaders/TileMapShader.hpp +++ b/TSE-RTS/src/shaders/TileMapShader.hpp @@ -5,7 +5,7 @@ #include "shader/Shader.hpp" #include "Types.hpp" -class TileMapShader : public TSE::GLFW::Shader +class TileMapShader : public TSE::OpenGL::Shader { private: static TileMapShader* instance; @@ -31,7 +31,7 @@ public: static TileMapShader* Instance(); static void Destroy(); static void Init(float width, float height); - TileMapShader(std::vector>&& parts); + TileMapShader(std::vector>&& parts); ~TileMapShader(); void SetMesh(const void* verts, int vertCount, int stride, int floatCountPerVertex, int posOffsetBytes, GLenum primitive, const void* indices = nullptr, int indexCount = 0, GLenum indexType = GL_UNSIGNED_SHORT);