Platform detection and the Linux platform layer (SDL3) #10

Closed
UnflavoredMeson/Primal_Plus_Plus
opened 2026-11-24 20:15:49 +00:00 by UnflavoredMeson · 0 comments
Owner

Why

The engine needs windows, events and input on Linux before anything can be shown there. Win32 stays native on Windows; Linux gets one library for windows, input and the event loop.

Decided

  • Engine/Common/PlatformDetection.h defines PRIMAL_PLATFORM_WINDOWS / PRIMAL_PLATFORM_LINUX; code uses those, never _WIN64.
  • Linux: SDL3 (system package, find_package(SDL3 3.2 ... SDL3-shared)) for windows, events and input (Input/InputSDL.cpp). Windows: the existing Win32 code.
  • PRIMAL_GRAPHICS=vulkan|d3d12 picks the backend at run time; the default is D3D12 on Windows and Vulkan on Linux.
  • Content paths are relative to the executable on both OSes.

Read first

  • LinuxVulkanPort, "Phase 3 – Platform layer" and "Phase 4 – Content and paths".
  • Engine/Platform/PlatformWin32.cpp, Engine/Platform/Window.h, Engine/Input/InputWin32.cpp on master.

Steps

  • 1. Add PlatformDetection.h and replace the _WIN64 checks.
  • 2. Write PlatformLinux.cpp with SDL3: create, resize, close and fullscreen a window.
  • 3. Map SDL keys and mouse events onto the engine's input codes (InputSDL.cpp); unknown keys map to the invalid code.
  • 4. Make content loading use paths relative to the executable on Linux.
  • 5. Run the window EngineTest on both OSes.

Done when

  • The window and entity-components EngineTests run on Linux and Windows.
  • Builds with 0 warnings on both OSes; clang-tidy 0; UnitTests pass (add input-mapping tests).

Claude can help with

  • Looking up SDL3 API details and its key-code tables.
  • Testing on Wayland and X11 if you only run one.

Learn

  • How SDL3's event loop differs from a Win32 message pump.
## Why The engine needs windows, events and input on Linux before anything can be shown there. Win32 stays native on Windows; Linux gets one library for windows, input and the event loop. ## Decided - `Engine/Common/PlatformDetection.h` defines `PRIMAL_PLATFORM_WINDOWS` / `PRIMAL_PLATFORM_LINUX`; code uses those, never `_WIN64`. - Linux: SDL3 (system package, `find_package(SDL3 3.2 ... SDL3-shared)`) for windows, events and input (`Input/InputSDL.cpp`). Windows: the existing Win32 code. - `PRIMAL_GRAPHICS=vulkan|d3d12` picks the backend at run time; the default is D3D12 on Windows and Vulkan on Linux. - Content paths are relative to the executable on both OSes. ## Read first - [LinuxVulkanPort](https://forgejo.unflavoredmeson.com/UnflavoredMeson/Primal_Plus_Plus/wiki/LinuxVulkanPort), "Phase 3 – Platform layer" and "Phase 4 – Content and paths". - `Engine/Platform/PlatformWin32.cpp`, `Engine/Platform/Window.h`, `Engine/Input/InputWin32.cpp` on `master`. ## Steps - [x] 1. Add `PlatformDetection.h` and replace the `_WIN64` checks. - [x] 2. Write `PlatformLinux.cpp` with SDL3: create, resize, close and fullscreen a window. - [x] 3. Map SDL keys and mouse events onto the engine's input codes (`InputSDL.cpp`); unknown keys map to the invalid code. - [x] 4. Make content loading use paths relative to the executable on Linux. - [x] 5. Run the window EngineTest on both OSes. ## Done when - [x] The window and entity-components EngineTests run on Linux and Windows. - [x] Builds with 0 warnings on both OSes; clang-tidy 0; UnitTests pass (add input-mapping tests). ## Claude can help with - Looking up SDL3 API details and its key-code tables. - Testing on Wayland and X11 if you only run one. ## Learn - How SDL3's event loop differs from a Win32 message pump.
Sign in to join this conversation.
No assignees
No project
Blocks
#15 Display scale and HiDPI on both platforms
UnflavoredMeson/Primal_Plus_Plus
#31 Vulkan device, loader, memory and swapchain
UnflavoredMeson/Primal_Plus_Plus
Depends on
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
UnflavoredMeson/Primal_Plus_Plus#10
No description provided.