Template project to play around with SDL3 GPU API with C++23 using modules.
- In root
CMakeLists.txt
changeproject name
,url
, anddescription
. - In
src/CMakeLists.txt
changePRJ_APP_NAME
- Ensure
dxc
shader compiler is findable by CMake,target_hlsl_sources
cmake function accepts shader format as option. It will choose DXC location based on shader format insrc/CMakeLists.txt
Supports either SPIR-V or DXIL (DXIL is windows only)
VSCode will run these automatically.
- On Windows
# Configure Project
cmake --preset windows-default
# Build Project, parameter order matters
cmake --build --preset windows-debug
- On Linux
# Configure Project
cmake --preset linux-default
# Build Project, parameter order matters
cmake --build --preset linux-debug
- CPM.CMake for package management
- Ninja-Build for build engine
- CMake 3.31+ with cmakepresets for configuration and build
- There is an issue, on my machine, with CMake 4.0. It fails to configure properly.
- CMake 4.0.1 fixed the issue with configure, seems like it was regression in CMake.
- C++ modules enabled
- Uses C++ Standard Library modules
- MSVC (Windows only)
- Clang (Linux with libc++ only)
- Focuses on SDL3 GPU
- HLSL for all shaders
Uses following libraries retrieved from their project repos by CPM.CMake
- SDL3, obviously
- GLM, for math
- DXC, from Vulkan SDK (for Vulkan backend)
- As much as is possible, functions will not take ownership of pointers to objects.
- Where able, all SDL GPU types are wrapped into std::unique_ptr with custom deleters, so they self clean on scope exit.
- SDL init and quit is wrapped in C++ class and created/destructed by Application class.
Application
class does following- Create SDL Window and GPU, in Application
C'Tor
- Create Basic Pipeline, in
Prepare Scene
- Simple vertex shader that uses uniform buffer to fix rendering perspective
- Simple pixel/fragment shader
- Vertex and Index buffers for Square mesh, in
Prepare Scene
- Create Perpective projection, in
Prepare Scene
Draw
s square using Indexed Primitives- Quit on any-key pressed, in
Handle SDL Input
- Create SDL Window and GPU, in Application
- Intellisense and clangd both cannot handle modules so don't work correctly
- Hacky solution for intellisense to show STD library types.
- CMake 3.30 magic encantations, https://www.kitware.com/import-std-in-cmake-3-30/
- CMake module compilations, https://www.kitware.com/import-cmake-the-experiment-is-over/