Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
71851a7
feat: Update readme
WSQS Nov 27, 2025
827323b
feat: ignore keyboard if imgui is handle keyboard
WSQS Nov 27, 2025
33b957a
feat: change uv for squire
WSQS Nov 27, 2025
69d16f9
feat: discard if alpha is near zero
WSQS Nov 27, 2025
8a57edd
fix: add check when width and height is zero
Sophomore42 Nov 28, 2025
e888f1f
feat: split app into lifecycle module
Sophomore42 Nov 28, 2025
3728c08
feat: change sampler from linear to nearest
Sophomore42 Nov 28, 2025
621dcec
doc: add lifecycle module in readme
Sophomore42 Nov 28, 2025
7fdd231
fix: remove forward declaration
Sophomore42 Nov 28, 2025
ee65de4
feat: add module sdl_raii and move GpuHandle into it.
Sophomore42 Nov 28, 2025
11674bb
fix:change header file format
Sophomore42 Nov 28, 2025
33dbd50
fix:change header file
Sophomore42 Nov 28, 2025
542414e
fix: move class window handle to sdl_raii module
Sophomore42 Nov 28, 2025
9c46edf
fix: move class claim window handle to sdl_raii module
Sophomore42 Nov 28, 2025
7d656ca
fix: remove type alias
Sophomore42 Nov 28, 2025
d7efbcf
feat: add class TransferBufferRaii
Sophomore42 Nov 28, 2025
57d5fea
fix:rename member variable
Sophomore42 Nov 28, 2025
a2f3c93
feat: add class GpuBufferRaii
Sophomore42 Nov 28, 2025
11d219e
fix: remove function release_buffer
Sophomore42 Nov 28, 2025
694cdce
feat:add template GpuResourceRaii
Sophomore42 Nov 28, 2025
507edda
fix: export partition module gpu resource
WSQS Nov 28, 2025
79a83bd
fix: using Gpu Shader Raii
WSQS Nov 28, 2025
ded13ad
fix: Add pipeline raii
WSQS Nov 28, 2025
e072adb
fix: Remove unused function
WSQS Nov 28, 2025
2993eee
feat: add class texture raii
WSQS Nov 28, 2025
9965ea3
feat: add class sampler raii
WSQS Nov 28, 2025
d69db40
fix:change structure of sdl_raii
WSQS Nov 28, 2025
5dde83f
fix:rename file
WSQS Nov 28, 2025
25f5175
Revert "fix:change structure of sdl_raii"
WSQS Nov 28, 2025
6ac17a4
fix:Add default GpuResourceTraits
WSQS Nov 28, 2025
57dce19
fix:Move template
WSQS Nov 28, 2025
ddff90e
doc: add node in graph
WSQS Nov 28, 2025
3f08a52
feat: rename template and class
WSQS Nov 28, 2025
7b60ea0
feat: Add template pure raii and command buffer raii
WSQS Nov 28, 2025
24d5d17
fix: using GpuCommandBufferRaii
WSQS Nov 28, 2025
c4d0291
fix: clean code
WSQS Nov 28, 2025
6ac0afc
fix: Using command line raii
WSQS Nov 29, 2025
84bd9ab
fix: remove class gpu device
WSQS Nov 29, 2025
39e467d
fix: remove file sdl_raii.window.ixx
WSQS Nov 29, 2025
6a01627
fix: remove file sdl_raii.claim_window.ixx
WSQS Nov 29, 2025
0e64b73
fix: Upload vertex data from main.cpp
WSQS Nov 29, 2025
5d3738a
fix: Upload index data from main.cpp
WSQS Nov 29, 2025
ac378d1
feat: add assert to check
WSQS Nov 30, 2025
81be120
feat:add header file
Sophomore42 Dec 1, 2025
2245875
feat:add function Renderable::draw
Sophomore42 Dec 1, 2025
8d20d3f
feat:change type of m_renderables
Sophomore42 Dec 1, 2025
88c7a46
feat:Draw multi box
Sophomore42 Dec 1, 2025
e3a51b7
feat:add location movement of camera
Sophomore42 Dec 1, 2025
906355d
feat:move direction decide by camera direction
Sophomore42 Dec 1, 2025
81cc4e3
fix: add missing Header
Sophomore42 Dec 1, 2025
88e7126
fix: add missing Header
Sophomore42 Dec 1, 2025
60580a9
fix: add missing header
WSQS Dec 1, 2025
5c6c7e8
feat: add function update add log for fps
WSQS Dec 1, 2025
270c739
log: add for duration time
WSQS Dec 1, 2025
3e88255
feat: make rotation smooth
WSQS Dec 1, 2025
c52c53b
feat: make movement smooth
WSQS Dec 1, 2025
07b074f
feat: Add check for texture wrapper
WSQS Dec 1, 2025
b11719b
feat: draw different box
WSQS Dec 1, 2025
d6f6629
feat: add q e for moving up and down
WSQS Dec 1, 2025
5063a53
feat: Add camera control logic
WSQS Dec 1, 2025
b858f6e
feat: change clear color
WSQS Dec 1, 2025
2bb49e3
doc: mark camera and colors finished
WSQS Dec 1, 2025
bc41959
fix: rename struct name
WSQS Dec 1, 2025
7e970c5
style: format code with ClangFormat
deepsource-autofix[bot] Dec 1, 2025
cfa2346
feat: remove chinese comment
Sophomore42 Dec 2, 2025
7a00f10
feat: change walking speed
Sophomore42 Dec 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ graph TD
sdl_wrapper
logos
end

subgraph sdl_wrapper
lifecycle
sdl_raii
end

glslang --> shaderc
SPIRVTools --> shaderc
Expand All @@ -44,17 +49,23 @@ graph TD

## Track

- [ ] Getting started
- [x] Getting started
- [x] OpenGL
- [x] Creating a window
- [x] Hello Window
- [x] Hello Triangle
- [x] Shaders
- [x] Textures
- [x] Transformations
- [ ] Coordinate Systems
- [ ] Camera
- [x] Coordinate Systems
- [x] Camera
- [ ] Lighting
- [x] Colors
- [ ] Basic Lighting
- [ ] Materials
- [ ] Lighting maps
- [ ] Light casters
- [ ] Multiple lights
- [ ] Model Loading
- [ ] Advanced OpenGL
- [ ] Advanced Lighting
Expand Down
545 changes: 359 additions & 186 deletions main.cpp

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions sdl_wrapper/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ add_library(sdl_wrapper STATIC)
target_sources(sdl_wrapper
PUBLIC
FILE_SET cxx_modules TYPE CXX_MODULES FILES
modules/lifecycle.ixx
modules/sdl_raii/sdl_raii.ixx
modules/sdl_raii/sdl_raii.bound_raii.ixx
modules/sdl_raii/sdl_raii.bound_traits.ixx
modules/sdl_raii/sdl_raii.pure_raii.ixx
modules/sdl_raii/sdl_raii.pure_traits.ixx
modules/sdl_wrapper.ixx
modules/sdl_wrapper.buffer.ixx
modules/sdl_wrapper.app.ixx
modules/sdl_wrapper.render_procedural.ixx
modules/sdl_wrapper.render_data.ixx
modules/sdl_wrapper.render_data_impl.ixx
Expand All @@ -20,13 +25,14 @@ target_sources(sdl_wrapper
modules/sdl_wrapper.transfer_buffer.ixx
modules/sdl_wrapper.texture.ixx
PRIVATE
src/lifecycle.cpp
src/sdl_wrapper.buffer.cpp
src/sdl_wrapper.render_procedural.cpp
src/sdl_wrapper.gpu.cpp
src/sdl_callback_implement.cpp
src/sdl_wrapper.texture.cpp
src/sdl_wrapper.transfer_buffer.cpp
src/sdl_wrapper.render_data.cpp
src/sdl_wrapper.renderable.cpp
)

target_link_libraries(sdl_wrapper PUBLIC SDL3::SDL3 shaderc glsl_reflector data_type)
target_link_libraries(sdl_wrapper PUBLIC SDL3::SDL3 shaderc glsl_reflector data_type logos)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//
module;
#include "SDL3/SDL_init.h"
export module sdl_wrapper:app;
export module lifecycle;
export namespace sopho
{
class App
Expand Down
65 changes: 65 additions & 0 deletions sdl_wrapper/modules/sdl_raii/sdl_raii.bound_raii.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// sdl_raii.bound_raii.ixx
// Created by sophomore on 11/28/25.
//

export module sdl_raii:bound_raii;
import :bound_traits;
namespace sopho
{
export template <typename T>
struct BoundRaii
{
using Traits = BoundTraits<T>;
using Device = typename Traits::Device;

private:
Device* m_gpu_device{};
T* m_raw{};

public:
BoundRaii() noexcept = default;

explicit BoundRaii(Device* device, T* resource) noexcept : m_gpu_device(device), m_raw(resource) {}

BoundRaii(const BoundRaii&) = delete;
BoundRaii& operator=(const BoundRaii&) = delete;

BoundRaii(BoundRaii&& other) noexcept : m_gpu_device(other.m_gpu_device), m_raw(other.m_raw)
{
other.m_gpu_device = nullptr;
other.m_raw = nullptr;
}

BoundRaii& operator=(BoundRaii&& other) noexcept
{
if (this != &other)
{
reset();

m_gpu_device = other.m_gpu_device;
m_raw = other.m_raw;

other.m_gpu_device = nullptr;
other.m_raw = nullptr;
}
return *this;
}

~BoundRaii() noexcept { reset(); }

void reset(Device* device = nullptr ,T* resource = nullptr) noexcept
{
if (m_raw && m_gpu_device)
{
Traits::release(m_gpu_device, m_raw);
}

m_gpu_device = device;
m_raw = resource;
}

[[nodiscard]] T* raw() const noexcept { return m_raw; }
[[nodiscard]] bool valid() const noexcept { return m_gpu_device != nullptr && m_raw != nullptr; }
[[nodiscard]] explicit operator bool() const noexcept { return valid(); }
};
} // namespace sopho
71 changes: 71 additions & 0 deletions sdl_wrapper/modules/sdl_raii/sdl_raii.bound_traits.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
// sdl_raii.bound_traits.ixx
// Created by wsqsy on 11/28/2025.
//
module;
#include <SDL3/SDL_gpu.h>
export module sdl_raii:bound_traits;
namespace sopho
{
template <typename T>
struct BoundTraits;

// Due to Windows msvc problem, we need to put all template in one module partition.

template <>
struct BoundTraits<SDL_GPUBuffer>
{
using Device = SDL_GPUDevice;

static void release(Device* device, SDL_GPUBuffer* buffer) noexcept { SDL_ReleaseGPUBuffer(device, buffer); }
};
template <>
struct BoundTraits<SDL_GPUGraphicsPipeline>
{
using Device = SDL_GPUDevice;

static void release(Device* device, SDL_GPUGraphicsPipeline* raw) noexcept
{
SDL_ReleaseGPUGraphicsPipeline(device, raw);
}
};
template <>
struct BoundTraits<SDL_GPUSampler>
{
using Device = SDL_GPUDevice;

static void release(Device* device, SDL_GPUSampler* raw) noexcept { SDL_ReleaseGPUSampler(device, raw); }
};
template <>
struct BoundTraits<SDL_GPUShader>
{
using Device = SDL_GPUDevice;

static void release(Device* device, SDL_GPUShader* raw) noexcept { SDL_ReleaseGPUShader(device, raw); }
};
template <>
struct BoundTraits<SDL_GPUTexture>
{
using Device = SDL_GPUDevice;

static void release(Device* device, SDL_GPUTexture* raw) noexcept { SDL_ReleaseGPUTexture(device, raw); }
};
template <>
struct BoundTraits<SDL_GPUTransferBuffer>
{
using Device = SDL_GPUDevice;

static void release(Device* device, SDL_GPUTransferBuffer* buffer) noexcept
{
SDL_ReleaseGPUTransferBuffer(device, buffer);
}
};
template <>
struct BoundTraits<SDL_Window>
{
using Device = SDL_GPUDevice;

static void release(Device* device, SDL_Window* raw) noexcept { SDL_ReleaseWindowFromGPUDevice(device, raw); }
};


} // namespace sopho
25 changes: 25 additions & 0 deletions sdl_wrapper/modules/sdl_raii/sdl_raii.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// sdl_raii.ixx
// Created by wsqsy on 11/28/2025.
//
module;
#include <SDL3/SDL_gpu.h>
export module sdl_raii;

export import :bound_traits;
export import :bound_raii;
export import :pure_traits;
export import :pure_raii;

export namespace sopho
{
using GpuBufferRaii = BoundRaii<SDL_GPUBuffer>;
using GPUGraphicsPipelineRaii = BoundRaii<SDL_GPUGraphicsPipeline>;
using GPUSamplerRaii = BoundRaii<SDL_GPUSampler>;
using GpuShaderRaii = BoundRaii<SDL_GPUShader>;
using GpuTextureRaii = BoundRaii<SDL_GPUTexture>;
using GpuTransferBufferRaii = BoundRaii<SDL_GPUTransferBuffer>;
using ClaimWindowRaii = BoundRaii<SDL_Window>;
using GpuCommandBufferRaii = PureRaii<SDL_GPUCommandBuffer>;
using GpuDeviceRaii = PureRaii<SDL_GPUDevice>;
using WindowRaii = PureRaii<SDL_Window>;
} // namespace sopho
53 changes: 53 additions & 0 deletions sdl_wrapper/modules/sdl_raii/sdl_raii.pure_raii.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// sdl_raii.pure_raii.ixx
// Created by sophomore on 11/29/25.
//

export module sdl_raii:pure_raii;
import :pure_traits;
namespace sopho
{
export template <typename T>
struct PureRaii
{
using Traits = PureTraits<T>;

private:
T* m_raw{};

public:
PureRaii() noexcept = default;

explicit PureRaii(T* raw) noexcept : m_raw(raw) {}

PureRaii(const PureRaii&) = delete;
PureRaii& operator=(const PureRaii&) = delete;

PureRaii(PureRaii&& other) noexcept : m_raw(other.m_raw) { other.m_raw = nullptr; }
PureRaii& operator=(PureRaii&& other) noexcept
{
if (this != &other)
{
reset();
m_raw = other.m_raw;
other.m_raw = nullptr;
}
return *this;
}

~PureRaii() noexcept { reset(); }

void reset(T* raw = nullptr) noexcept
{
if (m_raw)
{
Traits::release(m_raw);
}

m_raw = raw;
}

[[nodiscard]] T* raw() const noexcept { return m_raw; }
[[nodiscard]] bool valid() const noexcept { return m_raw != nullptr; }
[[nodiscard]] explicit operator bool() const noexcept { return valid(); }
};
} // namespace sopho
29 changes: 29 additions & 0 deletions sdl_wrapper/modules/sdl_raii/sdl_raii.pure_traits.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// sdl_raii.pure_traits.ixx
// Created by sophomore on 11/29/25.
//
module;
#include <SDL3/SDL_gpu.h>
export module sdl_raii:pure_traits;
namespace sopho
{
template <typename T>
struct PureTraits;

// Due to Windows msvc problem, we need to put all template in one module partition.

template <>
struct PureTraits<SDL_GPUCommandBuffer>
{
static void release(SDL_GPUCommandBuffer* raw) noexcept { SDL_SubmitGPUCommandBuffer(raw); }
};
template <>
struct PureTraits<SDL_GPUDevice>
{
static void release(SDL_GPUDevice* raw) noexcept { SDL_DestroyGPUDevice(raw); }
};
template <>
struct PureTraits<SDL_Window>
{
static void release(SDL_Window* raw) noexcept { SDL_DestroyWindow(raw); }
};
} // namespace sopho
11 changes: 6 additions & 5 deletions sdl_wrapper/modules/sdl_wrapper.buffer.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module;

export module sdl_wrapper:buffer;
import data_type;
import sdl_raii;
import :decl;
import :transfer_buffer;

Expand All @@ -19,15 +20,15 @@ namespace sopho
class BufferWrapper
{
std::shared_ptr<GpuWrapper> m_gpu{}; // Owns the device lifetime
SDL_GPUBuffer* m_gpu_buffer{}; // Target GPU buffer
GpuBufferRaii m_gpu_buffer{}; // Target GPU buffer
TransferBufferWrapper m_transfer_buffer; // Staging/transfer buffer
std::uint32_t m_buffer_size{}; // Total size of the GPU buffer
std::vector<std::byte> m_cpu_buffer{};

// Only GpuWrapper is allowed to construct this type.
BufferWrapper(std::shared_ptr<GpuWrapper> gpu, SDL_GPUBuffer* gpu_buffer, TransferBufferWrapper transfer_buffer,
BufferWrapper(std::shared_ptr<GpuWrapper> gpu, GpuBufferRaii gpu_buffer, TransferBufferWrapper transfer_buffer,
std::uint32_t size) noexcept :
m_gpu(std::move(gpu)), m_gpu_buffer(gpu_buffer), m_transfer_buffer(std::move(transfer_buffer)),
m_gpu(std::move(gpu)), m_gpu_buffer(std::move(gpu_buffer)), m_transfer_buffer(std::move(transfer_buffer)),
m_buffer_size(size)
{
m_cpu_buffer.resize(m_buffer_size);
Expand Down Expand Up @@ -64,10 +65,10 @@ namespace sopho
[[nodiscard]] std::expected<std::monostate, GpuError> upload();

/// Returns the underlying SDL_GPUBuffer pointer.
[[nodiscard]] SDL_GPUBuffer* gpu_buffer() const noexcept { return m_gpu_buffer; }
[[nodiscard]] SDL_GPUBuffer* gpu_buffer() const noexcept { return m_gpu_buffer.raw(); }
[[nodiscard]] std::byte* cpu_buffer() noexcept { return m_cpu_buffer.data(); }

~BufferWrapper() noexcept;
~BufferWrapper() noexcept = default;

friend class GpuWrapper;
};
Expand Down
2 changes: 1 addition & 1 deletion sdl_wrapper/modules/sdl_wrapper.decl.ixx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export module sdl_wrapper:decl;

export namespace sopho
{
class App;
class GpuWrapper;
class RenderProcedural;
class RenderData;
class TextureWrapper;
}
Loading
Loading