From 474269f4415701c5e4c9ecb5e71175a396de67f1 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Wed, 26 Nov 2025 19:30:33 +0800 Subject: [PATCH 01/24] fix: rename function --- logos/modules/logos.ixx | 8 +++++--- main.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index a0c52f9..8286e0a 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -3,8 +3,10 @@ // module; #include +#include #include #include +#include export module logos; namespace sopho @@ -45,7 +47,7 @@ namespace sopho } }; - export Mat MakeRotationY(float yaw) + export Mat make_rotation_y(float yaw) { float cy = std::cos(yaw); float sy = std::sin(yaw); @@ -72,7 +74,7 @@ namespace sopho return R; } - export Mat MakeRotationX(float pitch) + export Mat make_rotation_x(float pitch) { float cp = std::cos(pitch); float sp = std::sin(pitch); @@ -99,7 +101,7 @@ namespace sopho return R; } - export Mat Scale(float scale_size) + export Mat scale(float scale_size) { Mat R{}; diff --git a/main.cpp b/main.cpp index 0283d20..9a783eb 100644 --- a/main.cpp +++ b/main.cpp @@ -445,7 +445,7 @@ void main() // Compute camera matrix and upload as a vertex uniform. SDL_PushGPUVertexUniformData( - commandBuffer, 0, (sopho::MakeRotationY(yaw) * sopho::MakeRotationX(-pitch) * sopho::Scale(0.1F)).data(), + commandBuffer, 0, (sopho::make_rotation_y(yaw) * sopho::make_rotation_x(-pitch) * sopho::scale(0.1F)).data(), sizeof(sopho::Mat)); SDL_BindGPUVertexBuffers(renderPass, 0, m_renderable->data()->get_vertex_buffer_binding().data(), From 3b61ac5504c2be687e41fbc2c26e3d8e12609e9e Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:23:01 +0800 Subject: [PATCH 02/24] feat: add translate and perspective function --- logos/modules/logos.ixx | 86 ++++++++++++++++++++++++++++++++++------- 1 file changed, 71 insertions(+), 15 deletions(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index 8286e0a..7b1a248 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -11,24 +11,24 @@ export module logos; namespace sopho { - export template + export template class Mat { - std::array, Row> m_data{}; + std::array, Col> m_data{}; public: - TScalar& operator()(std::uint8_t row, std::uint8_t col) { return m_data[row][col]; } - const TScalar& operator()(std::uint8_t row, std::uint8_t col) const { return m_data[row][col]; } + TScalar& operator()(std::uint8_t col, std::uint8_t row) { return m_data[col][row]; } + const TScalar& operator()(std::uint8_t col, std::uint8_t row) const { return m_data[col][row]; } TScalar& operator()(std::uint8_t row) requires(Col == 1) { - return m_data[row][0]; + return m_data[0][row]; } TScalar* data() { return m_data[0].data(); } template - Mat operator*(const Mat& rhs) const + Mat operator*(const Mat& rhs) const { - Mat result{}; + Mat result{}; for (std::uint8_t r = 0; r < Row; ++r) { @@ -37,9 +37,9 @@ namespace sopho TScalar sum{}; for (std::uint8_t k = 0; k < Col; ++k) { - sum += (*this)(r, k) * rhs(k, c); + sum += (*this)(k, r) * rhs(c, k); } - result(r, c) = sum; + result(c, r) = sum; } } @@ -47,7 +47,7 @@ namespace sopho } }; - export Mat make_rotation_y(float yaw) + export Mat rotation_y(float yaw) { float cy = std::cos(yaw); float sy = std::sin(yaw); @@ -56,13 +56,13 @@ namespace sopho R(0, 0) = cy; R(0, 1) = 0; - R(0, 2) = sy; + R(0, 2) = -sy; R(0, 3) = 0; R(1, 0) = 0; R(1, 1) = 1; R(1, 2) = 0; R(1, 3) = 0; - R(2, 0) = -sy; + R(2, 0) = sy; R(2, 1) = 0; R(2, 2) = cy; R(2, 3) = 0; @@ -74,7 +74,7 @@ namespace sopho return R; } - export Mat make_rotation_x(float pitch) + export Mat rotation_x(float pitch) { float cp = std::cos(pitch); float sp = std::sin(pitch); @@ -87,10 +87,10 @@ namespace sopho R(0, 3) = 0; R(1, 0) = 0; R(1, 1) = cp; - R(1, 2) = sp; + R(1, 2) = -sp; R(1, 3) = 0; R(2, 0) = 0; - R(2, 1) = -sp; + R(2, 1) = sp; R(2, 2) = cp; R(2, 3) = 0; R(3, 0) = 0; @@ -126,4 +126,60 @@ namespace sopho return R; } + export Mat translate(float x, float y, float z) + { + + Mat R{}; + + R(0, 0) = 1; + R(0, 1) = 0; + R(0, 2) = 0; + R(0, 3) = 0; + R(1, 0) = 0; + R(1, 1) = 1; + R(1, 2) = 0; + R(1, 3) = 0; + R(2, 0) = 0; + R(2, 1) = 0; + R(2, 2) = 1; + R(2, 3) = 0; + R(3, 0) = x; + R(3, 1) = y; + R(3, 2) = z; + R(3, 3) = 1; + + return R; + } + + export Mat perspective(float fovy, float aspect, float z_near, float z_far) + { + assert(std::abs(aspect - std::numeric_limits::epsilon()) > 0.0f); + + const float tanHalfFovy = std::tan(fovy * 0.5f); + + Mat P{}; + + P(0, 0) = 1.0F / (aspect * tanHalfFovy); + P(0, 1) = 0.0F; + P(0, 2) = 0.0F; + P(0, 3) = 0.0F; + + P(1, 0) = 0.0F; + P(1, 1) = 1.0F / tanHalfFovy; + P(1, 2) = 0.0F; + P(1, 3) = 0.0F; + + P(2, 0) = 0.0F; + P(2, 1) = 0.0F; + P(2, 2) = -(z_far + z_near) / (z_far - z_near); + P(2, 3) = -1.0F; + + P(3, 0) = 0.0F; + P(3, 1) = 0.0F; + P(3, 2) = -(2.0F * z_far * z_near) / (z_far - z_near); + P(3, 3) = 0.0F; + + return P; + } + } // namespace sopho From 3e96852cb4af5633de32e5bb7ba8182a05f3eebb Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:24:03 +0800 Subject: [PATCH 03/24] feat: implement perspective --- main.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 9a783eb..5c7783a 100644 --- a/main.cpp +++ b/main.cpp @@ -444,9 +444,11 @@ void main() SDL_BindGPUGraphicsPipeline(renderPass, m_renderable->procedural()->data()); // Compute camera matrix and upload as a vertex uniform. - SDL_PushGPUVertexUniformData( - commandBuffer, 0, (sopho::make_rotation_y(yaw) * sopho::make_rotation_x(-pitch) * sopho::scale(0.1F)).data(), - sizeof(sopho::Mat)); + SDL_PushGPUVertexUniformData(commandBuffer, 0, + (sopho::perspective(1, 1, 0.1, 2) * sopho::rotation_x(-pitch) * + sopho::rotation_y(yaw) * sopho::translate(0, 0, -1)) + .data(), + sizeof(sopho::Mat)); SDL_BindGPUVertexBuffers(renderPass, 0, m_renderable->data()->get_vertex_buffer_binding().data(), m_renderable->data()->get_vertex_buffer_binding().size()); From 6106115191cd33d9779990c6b4a6c55a24b161de Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:31:06 +0800 Subject: [PATCH 04/24] feat: change matrix direction --- main.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 5c7783a..40da93c 100644 --- a/main.cpp +++ b/main.cpp @@ -102,6 +102,7 @@ layout(set = 2, binding = 0) uniform sampler2D uTexture; void main() { FragColor = texture(uTexture, v_color.xy); + FragColor.a = 1; })WSQ"; public: @@ -445,8 +446,8 @@ void main() // Compute camera matrix and upload as a vertex uniform. SDL_PushGPUVertexUniformData(commandBuffer, 0, - (sopho::perspective(1, 1, 0.1, 2) * sopho::rotation_x(-pitch) * - sopho::rotation_y(yaw) * sopho::translate(0, 0, -1)) + (sopho::perspective(1, 1, 0.1, 2) * sopho::translate(0, 0, -1) * + sopho::rotation_x(-pitch) * sopho::rotation_y(yaw)) .data(), sizeof(sopho::Mat)); From 68869b310b6d0914d41344bb236b31c029204f0f Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Wed, 26 Nov 2025 20:56:21 +0800 Subject: [PATCH 05/24] feat: add RenderDataBuilder --- main.cpp | 12 +++++-- sdl_wrapper/CMakeLists.txt | 1 + sdl_wrapper/modules/sdl_wrapper.gpu.ixx | 1 - .../modules/sdl_wrapper.render_data.ixx | 29 +++++++++++++++ sdl_wrapper/src/sdl_wrapper.gpu.cpp | 35 ------------------- sdl_wrapper/src/sdl_wrapper.render_data.cpp | 33 +++++++++++++++++ 6 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 sdl_wrapper/src/sdl_wrapper.render_data.cpp diff --git a/main.cpp b/main.cpp index 40da93c..cf73190 100644 --- a/main.cpp +++ b/main.cpp @@ -150,7 +150,11 @@ void main() } // 3. Create vertex buffer. - auto render_data = m_gpu->create_data(pw_result.value(), 4, 6); + auto render_data = sopho::RenderData::Builder{} + .set_vertex_layout(pw_result.value().vertex_layout()) + .set_vertex_count(4) + .set_index_count(6) + .build(*m_gpu.get()); if (!render_data) { SDL_LogError(SDL_LOG_CATEGORY_ERROR, "Failed to create vertex buffer, error = %d", @@ -330,7 +334,11 @@ void main() } else { - auto new_data = m_gpu->create_data(*m_renderable->procedural(), 4, 6); + auto new_data = sopho::RenderData::Builder{} + .set_vertex_layout(m_renderable->procedural()->vertex_layout()) + .set_vertex_count(4) + .set_index_count(6) + .build(*m_gpu.get()); m_renderable->data() = std::move(new_data.value()); m_renderable->data()->upload(); } diff --git a/sdl_wrapper/CMakeLists.txt b/sdl_wrapper/CMakeLists.txt index e58f90c..719526f 100644 --- a/sdl_wrapper/CMakeLists.txt +++ b/sdl_wrapper/CMakeLists.txt @@ -26,6 +26,7 @@ target_sources(sdl_wrapper src/sdl_callback_implement.cpp src/sdl_wrapper.texture.cpp src/sdl_wrapper.transfer_buffer.cpp + src/sdl_wrapper.render_data.cpp ) target_link_libraries(sdl_wrapper PUBLIC SDL3::SDL3 shaderc glsl_reflector data_type) diff --git a/sdl_wrapper/modules/sdl_wrapper.gpu.ixx b/sdl_wrapper/modules/sdl_wrapper.gpu.ixx index ea8c19a..4c54aad 100644 --- a/sdl_wrapper/modules/sdl_wrapper.gpu.ixx +++ b/sdl_wrapper/modules/sdl_wrapper.gpu.ixx @@ -210,7 +210,6 @@ export namespace sopho [[nodiscard]] auto device() const { return m_ctx.device.raw; } [[nodiscard]] SDL_Window* window() const { return m_ctx.window.raw; } - [[nodiscard]] checkable> create_data(const RenderProcedural& render_procedural, std::uint32_t vertex_count, std::uint32_t index_count); auto release_buffer(SDL_GPUBuffer* buffer) { diff --git a/sdl_wrapper/modules/sdl_wrapper.render_data.ixx b/sdl_wrapper/modules/sdl_wrapper.render_data.ixx index 50daeaf..f0997c8 100644 --- a/sdl_wrapper/modules/sdl_wrapper.render_data.ixx +++ b/sdl_wrapper/modules/sdl_wrapper.render_data.ixx @@ -4,16 +4,45 @@ module; #include #include +#include #include +#include #include #include export module sdl_wrapper:render_data; import :vertex_layout; +import :gpu; namespace sopho { export class RenderData { public: + struct Builder + { + VertexLayout layout{}; + std::uint32_t vertex_count{}; + std::uint32_t index_count{}; + + Builder& set_vertex_layout(VertexLayout new_layout) + { + layout = new_layout; + return *this; + } + + Builder& set_vertex_count(std::uint32_t new_vertex_count) + { + vertex_count = new_vertex_count; + return *this; + } + + Builder& set_index_count(std::uint32_t new_index_count) + { + index_count = new_index_count; + return *this; + } + + checkable> build(GpuWrapper& gpu); + }; struct VertexView { VertexLayout layout{}; diff --git a/sdl_wrapper/src/sdl_wrapper.gpu.cpp b/sdl_wrapper/src/sdl_wrapper.gpu.cpp index f23f665..5d49e13 100644 --- a/sdl_wrapper/src/sdl_wrapper.gpu.cpp +++ b/sdl_wrapper/src/sdl_wrapper.gpu.cpp @@ -17,41 +17,6 @@ import :render_data_impl; namespace sopho { - /** - * @brief Create RenderData for a procedural render setup and given vertex count. - * - * Allocates a GPU vertex buffer sized to hold `vertex_count` vertices using the - * vertex layout from `render_procedural`, and returns a RenderData that owns - * the allocated buffer, the vertex layout, and the vertex count. If buffer - * creation fails, returns the corresponding GpuError. - * - * @param render_procedural Source procedural that provides the vertex layout. - * @param vertex_count Number of vertices the allocated buffer must hold. - * @param index_count - * @return RenderData RenderData containing the allocated vertex buffer, the vertex layout, and `vertex_count`. - */ - checkable> GpuWrapper::create_data(const RenderProcedural& render_procedural, - std::uint32_t vertex_count, - std::uint32_t index_count) - { - auto size = render_procedural.vertex_layout().get_stride() * vertex_count; - auto vertex_buffer = BufferWrapper::Builder{}.set_flag(SDL_GPU_BUFFERUSAGE_VERTEX).set_size(size).build(*this); - if (!vertex_buffer) - { - return std::unexpected(vertex_buffer.error()); - } - auto index_buffer = BufferWrapper::Builder{} - .set_flag(SDL_GPU_BUFFERUSAGE_INDEX) - .set_size(index_count * sizeof(int)) - .build(*this); - if (!index_buffer) - { - return std::unexpected(index_buffer.error()); - } - return std::make_shared(std::move(vertex_buffer.value()), std::move(index_buffer.value()), - render_procedural.vertex_layout(), vertex_count, index_count); - } - /** * @brief Create a RenderProcedural configured for the device's texture format. * diff --git a/sdl_wrapper/src/sdl_wrapper.render_data.cpp b/sdl_wrapper/src/sdl_wrapper.render_data.cpp new file mode 100644 index 0000000..2d63779 --- /dev/null +++ b/sdl_wrapper/src/sdl_wrapper.render_data.cpp @@ -0,0 +1,33 @@ +// sdl_wrapper.render_data.cpp +// Created by sophomore on 11/26/25. +// +module; +#include +#include +#include "SDL3/SDL_gpu.h" +module sdl_wrapper; +import :buffer; +import :render_data_impl; +import :render_data; +import :vertex_layout; +namespace sopho +{ + + checkable> RenderData::Builder::build(GpuWrapper& gpu) + { + auto size = layout.get_stride() * vertex_count; + auto vertex_buffer = BufferWrapper::Builder{}.set_flag(SDL_GPU_BUFFERUSAGE_VERTEX).set_size(size).build(gpu); + if (!vertex_buffer) + { + return std::unexpected(vertex_buffer.error()); + } + auto index_buffer = + BufferWrapper::Builder{}.set_flag(SDL_GPU_BUFFERUSAGE_INDEX).set_size(index_count * sizeof(int)).build(gpu); + if (!index_buffer) + { + return std::unexpected(index_buffer.error()); + } + return std::make_shared(std::move(vertex_buffer.value()), std::move(index_buffer.value()), + layout, vertex_count, index_count); + } +} // namespace sopho From b93fe4c2b978f3690737810f638573bc6de4f903 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Wed, 26 Nov 2025 21:08:58 +0800 Subject: [PATCH 06/24] fix: show index edit based on index_count --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index cf73190..85cb580 100644 --- a/main.cpp +++ b/main.cpp @@ -299,7 +299,7 @@ void main() } auto index_view = m_renderable->data()->index_view(); auto index_ptr = index_view.raw; - for (int index_index = 0; index_index < 2; ++index_index) + for (int index_index = 0; index_index < index_view.index_count; index_index+=3) { changed |= ImGui::InputInt3(std::format("index_{}", index_index).data(), reinterpret_cast(index_ptr)); From e9b57b778b7ab79eccc40b09403fe7da6c85a793 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Wed, 26 Nov 2025 22:39:04 +0800 Subject: [PATCH 07/24] feat: add default value for drawing box --- main.cpp | 33 ++++++---- .../modules/sdl_wrapper.vertex_layout.ixx | 8 +++ sdl_wrapper/src/sdl_wrapper.render_data.cpp | 63 +++++++++++++++++++ 3 files changed, 92 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 85cb580..6d7f7c4 100644 --- a/main.cpp +++ b/main.cpp @@ -77,8 +77,8 @@ class UserApp : public sopho::App R"WSQ(#version 460 layout (location = 0) in vec3 a_position; -layout (location = 1) in vec4 a_color; -layout (location = 0) out vec4 v_color; +layout (location = 1) in vec2 a_uv; +layout (location = 0) out vec2 v_uv; layout(std140, set = 1, binding = 0) uniform Camera { @@ -88,20 +88,20 @@ layout(std140, set = 1, binding = 0) uniform Camera void main() { gl_Position = uView * vec4(a_position, 1.0f); - v_color = a_color; + v_uv = a_uv; })WSQ"; std::string fragment_source = R"WSQ(#version 460 -layout (location = 0) in vec4 v_color; +layout (location = 0) in vec2 v_uv; layout (location = 0) out vec4 FragColor; layout(set = 2, binding = 0) uniform sampler2D uTexture; void main() { - FragColor = texture(uTexture, v_color.xy); + FragColor = texture(uTexture, v_uv); FragColor.a = 1; })WSQ"; @@ -152,8 +152,8 @@ void main() // 3. Create vertex buffer. auto render_data = sopho::RenderData::Builder{} .set_vertex_layout(pw_result.value().vertex_layout()) - .set_vertex_count(4) - .set_index_count(6) + .set_vertex_count(8) + .set_index_count(36) .build(*m_gpu.get()); if (!render_data) { @@ -280,6 +280,10 @@ void main() { switch (format.vector_size) { + case 2: + changed |= ImGui::DragFloat2(std::format("{}{}", format.name, vertex_index).data(), + reinterpret_cast(raw_ptr), 0.01f, -1.f, 1.f); + break; case 3: changed |= ImGui::DragFloat3(std::format("{}{}", format.name, vertex_index).data(), reinterpret_cast(raw_ptr), 0.01f, -1.f, 1.f); @@ -287,10 +291,15 @@ void main() case 4: changed |= ImGui::DragFloat4(std::format("{}{}", format.name, vertex_index).data(), reinterpret_cast(raw_ptr), 0.01f, -1.f, 1.f); + default: + SDL_Log("Not implemented size"); + assert(false); } } break; default: + SDL_Log("Not implemented Basic type"); + assert(false); break; } auto size = sopho::get_size(sopho::to_sdl_format(format.basic_type, format.vector_size)); @@ -299,7 +308,7 @@ void main() } auto index_view = m_renderable->data()->index_view(); auto index_ptr = index_view.raw; - for (int index_index = 0; index_index < index_view.index_count; index_index+=3) + for (int index_index = 0; index_index < index_view.index_count; index_index += 3) { changed |= ImGui::InputInt3(std::format("index_{}", index_index).data(), reinterpret_cast(index_ptr)); @@ -336,8 +345,8 @@ void main() { auto new_data = sopho::RenderData::Builder{} .set_vertex_layout(m_renderable->procedural()->vertex_layout()) - .set_vertex_count(4) - .set_index_count(6) + .set_vertex_count(8) + .set_index_count(36) .build(*m_gpu.get()); m_renderable->data() = std::move(new_data.value()); m_renderable->data()->upload(); @@ -454,7 +463,7 @@ void main() // Compute camera matrix and upload as a vertex uniform. SDL_PushGPUVertexUniformData(commandBuffer, 0, - (sopho::perspective(1, 1, 0.1, 2) * sopho::translate(0, 0, -1) * + (sopho::perspective(1, 1, 0.1, 10) * sopho::translate(0, 0, -5) * sopho::rotation_x(-pitch) * sopho::rotation_y(yaw)) .data(), sizeof(sopho::Mat)); @@ -474,7 +483,7 @@ void main() } - SDL_DrawGPUIndexedPrimitives(renderPass, 6, 1, 0, 0, 0); + SDL_DrawGPUIndexedPrimitives(renderPass, 36, 1, 0, 0, 0); ImGui_ImplSDLGPU3_RenderDrawData(draw_data, commandBuffer, renderPass); diff --git a/sdl_wrapper/modules/sdl_wrapper.vertex_layout.ixx b/sdl_wrapper/modules/sdl_wrapper.vertex_layout.ixx index c3203c0..dfc582c 100644 --- a/sdl_wrapper/modules/sdl_wrapper.vertex_layout.ixx +++ b/sdl_wrapper/modules/sdl_wrapper.vertex_layout.ixx @@ -2,9 +2,11 @@ // Created by wsqsy on 11/17/2025. // module; +#include #include #include #include "SDL3/SDL_gpu.h" +#include "SDL3/SDL_log.h" export module sdl_wrapper:vertex_layout; import glsl_reflector; namespace sopho @@ -88,15 +90,21 @@ namespace sopho { switch (vector_size) { + case 2: + return SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2; case 3: return SDL_GPU_VERTEXELEMENTFORMAT_FLOAT3; case 4: return SDL_GPU_VERTEXELEMENTFORMAT_FLOAT4; default: + SDL_LogError(SDL_LOG_CATEGORY_GPU,"Not supported vector size"); + assert(false); return SDL_GPU_VERTEXELEMENTFORMAT_INVALID; } } default: + SDL_LogError(SDL_LOG_CATEGORY_GPU,"Not supported Basic type"); + assert(false); return SDL_GPU_VERTEXELEMENTFORMAT_INVALID; } } diff --git a/sdl_wrapper/src/sdl_wrapper.render_data.cpp b/sdl_wrapper/src/sdl_wrapper.render_data.cpp index 2d63779..2072587 100644 --- a/sdl_wrapper/src/sdl_wrapper.render_data.cpp +++ b/sdl_wrapper/src/sdl_wrapper.render_data.cpp @@ -27,6 +27,69 @@ namespace sopho { return std::unexpected(index_buffer.error()); } + float* vertex_ptr = reinterpret_cast(vertex_buffer.value().cpu_buffer()); + vertex_ptr[0] = 0.5; + vertex_ptr[1] = 0.5; + vertex_ptr[2] = 0.5; + vertex_ptr[5] = -0.5; + vertex_ptr[6] = 0.5; + vertex_ptr[7] = 0.5; + vertex_ptr[10] = 0.5; + vertex_ptr[11] = -0.5; + vertex_ptr[12] = 0.5; + vertex_ptr[15] = -0.5; + vertex_ptr[16] = -0.5; + vertex_ptr[17] = 0.5; + vertex_ptr[20] = 0.5; + vertex_ptr[21] = 0.5; + vertex_ptr[22] = -0.5; + vertex_ptr[25] = -0.5; + vertex_ptr[26] = 0.5; + vertex_ptr[27] = -0.5; + vertex_ptr[30] = 0.5; + vertex_ptr[31] = -0.5; + vertex_ptr[32] = -0.5; + vertex_ptr[35] = -0.5; + vertex_ptr[36] = -0.5; + vertex_ptr[37] = -0.5; + + vertex_ptr[3] = 1.0; + vertex_ptr[4] = 1.0; + vertex_ptr[8] = 1.0; + vertex_ptr[9] = 0; + vertex_ptr[13] = 0; + vertex_ptr[14] = 1.0; + vertex_ptr[18] = 0; + vertex_ptr[19] = 0; + vertex_ptr[23] = 0; + vertex_ptr[24] = 1.0; + vertex_ptr[28] = 0; + vertex_ptr[29] = 0; + vertex_ptr[33] = 1; + vertex_ptr[34] = 1.0; + vertex_ptr[38] = 1; + vertex_ptr[39] = 0; + int* index_ptr = reinterpret_cast(index_buffer.value().cpu_buffer()); + index_ptr[0] = 0; + index_ptr[1] = 1; + index_ptr[2] = 2; + index_ptr[3] = 1; + index_ptr[4] = 2; + index_ptr[5] = 3; + index_ptr[6] = 0; + index_ptr[7] = 1; + index_ptr[8] = 4; + index_ptr[9] = 1; + index_ptr[10] = 4; + index_ptr[11] = 5; + index_ptr[12] = 0; + index_ptr[13] = 2; + index_ptr[14] = 4; + index_ptr[15] = 2; + index_ptr[16] = 4; + index_ptr[17] = 6; + index_ptr[18] = 0; + index_ptr[19] = 0; return std::make_shared(std::move(vertex_buffer.value()), std::move(index_buffer.value()), layout, vertex_count, index_count); } From 07a36b0eb0cb6ddd05c3f8c3e61d59516b36615a Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 13:54:46 +0800 Subject: [PATCH 08/24] fix: not install gtest --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 26f9093..52a23c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -112,6 +112,7 @@ FetchContent_Declare( GIT_SHALLOW TRUE GIT_PROGRESS TRUE ) +set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) include(CTest) From 3786e70ad38ede262623565b555e50f8c6cd0c7c Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 14:06:04 +0800 Subject: [PATCH 09/24] fix: switch from url to zip to speed up download --- CMakeLists.txt | 40 ++++++++-------------------------------- 1 file changed, 8 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 52a23c4..06cacbc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,10 +12,7 @@ set(CMAKE_MESSAGE_LOG_LEVEL STATUS CACHE STRING "" FORCE) FetchContent_Declare( SDL3 - GIT_REPOSITORY https://github.com/libsdl-org/SDL.git - GIT_TAG release-3.2.26 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/libsdl-org/SDL/archive/refs/tags/release-3.2.26.zip ) set(SDL_SHARED OFF CACHE BOOL "" FORCE) set(SDL_STATIC ON CACHE BOOL "" FORCE) @@ -23,19 +20,13 @@ FetchContent_MakeAvailable(SDL3) FetchContent_Declare( SPIRVHeaders - GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Headers.git - GIT_TAG vulkan-sdk-1.4.328.1 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/KhronosGroup/SPIRV-Headers/archive/refs/tags/vulkan-sdk-1.4.328.1.zip ) FetchContent_MakeAvailable(SPIRVHeaders) FetchContent_Declare( SPIRVTools - GIT_REPOSITORY https://github.com/KhronosGroup/SPIRV-Tools.git - GIT_TAG vulkan-sdk-1.4.328.1 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/KhronosGroup/SPIRV-Tools/archive/refs/tags/vulkan-sdk-1.4.328.1.zip ) set(SPIRV_SKIP_TESTS ON CACHE BOOL "" FORCE) set(SPIRV_SKIP_EXECUTABLES ON CACHE BOOL "" FORCE) @@ -44,10 +35,7 @@ FetchContent_MakeAvailable(SPIRVTools) FetchContent_Declare( glslang - GIT_REPOSITORY https://github.com/KhronosGroup/glslang.git - GIT_TAG vulkan-sdk-1.4.328.1 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/KhronosGroup/glslang/archive/refs/tags/vulkan-sdk-1.4.328.1.zip ) set(ENABLE_GLSLANG_BINARIES OFF CACHE BOOL "" FORCE) set(ENABLE_GLSLANG_JS OFF CACHE BOOL "" FORCE) @@ -57,10 +45,7 @@ FetchContent_MakeAvailable(glslang) FetchContent_Declare( shaderc - GIT_REPOSITORY https://github.com/google/shaderc.git - GIT_TAG v2025.4 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/google/shaderc/archive/refs/tags/v2025.4.zip ) set(SHADERC_SKIP_TESTS ON CACHE BOOL "" FORCE) set(SHADERC_SKIP_EXAMPLES ON CACHE BOOL "" FORCE) @@ -71,10 +56,7 @@ FetchContent_MakeAvailable(shaderc) FetchContent_Declare( imgui - GIT_REPOSITORY https://github.com/ocornut/imgui.git - GIT_TAG v1.92.4 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/ocornut/imgui/archive/refs/tags/v1.92.4.zip ) FetchContent_MakeAvailable(imgui) set(IMGUI_DIR ${imgui_SOURCE_DIR}) @@ -96,10 +78,7 @@ target_link_libraries(imgui PUBLIC SDL3::SDL3) FetchContent_Declare( stb - GIT_REPOSITORY https://github.com/nothings/stb.git - GIT_TAG master - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/nothings/stb/archive/refs/heads/master.zip ) FetchContent_MakeAvailable(stb) add_library(stb INTERFACE) @@ -107,10 +86,7 @@ target_include_directories(stb SYSTEM INTERFACE ${stb_SOURCE_DIR}) FetchContent_Declare( googletest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.17.0 - GIT_SHALLOW TRUE - GIT_PROGRESS TRUE + URL https://github.com/google/googletest/archive/refs/tags/v1.17.0.zip ) set(INSTALL_GTEST OFF CACHE BOOL "" FORCE) FetchContent_MakeAvailable(googletest) From 853d595f1096dd008e1970cfe7fad2421f6bdc24 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 14:33:19 +0800 Subject: [PATCH 10/24] fix: change rotation direction --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 6d7f7c4..8a704d1 100644 --- a/main.cpp +++ b/main.cpp @@ -519,10 +519,10 @@ void main() pitch = std::clamp(pitch, -std::numbers::pi_v / 2, +std::numbers::pi_v / 2); break; case SDLK_LEFT: - yaw += 0.1F; + yaw -= 0.1F; break; case SDLK_RIGHT: - yaw -= 0.1F; + yaw += 0.1F; break; default: break; From ef2ea6bd33b3c2c1f8f90c67e4e0806a4b6fe576 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 14:34:05 +0800 Subject: [PATCH 11/24] feat: implement Rodrigues' rotation formula --- logos/modules/logos.ixx | 120 +++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 52 deletions(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index 7b1a248..ada1455 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -45,61 +45,47 @@ namespace sopho return result; } - }; - - export Mat rotation_y(float yaw) - { - float cy = std::cos(yaw); - float sy = std::sin(yaw); - - Mat R{}; - - R(0, 0) = cy; - R(0, 1) = 0; - R(0, 2) = -sy; - R(0, 3) = 0; - R(1, 0) = 0; - R(1, 1) = 1; - R(1, 2) = 0; - R(1, 3) = 0; - R(2, 0) = sy; - R(2, 1) = 0; - R(2, 2) = cy; - R(2, 3) = 0; - R(3, 0) = 0; - R(3, 1) = 0; - R(3, 2) = 0; - R(3, 3) = 1; - return R; - } - - export Mat rotation_x(float pitch) - { - float cp = std::cos(pitch); - float sp = std::sin(pitch); - - Mat R{}; + Mat operator+(const Mat& rhs) const + { + Mat result{}; - R(0, 0) = 1; - R(0, 1) = 0; - R(0, 2) = 0; - R(0, 3) = 0; - R(1, 0) = 0; - R(1, 1) = cp; - R(1, 2) = -sp; - R(1, 3) = 0; - R(2, 0) = 0; - R(2, 1) = sp; - R(2, 2) = cp; - R(2, 3) = 0; - R(3, 0) = 0; - R(3, 1) = 0; - R(3, 2) = 0; - R(3, 3) = 1; + for (std::uint8_t r = 0; r < Row; ++r) + { + for (std::uint8_t c = 0; c < Col; ++c) + { + result(c, r) = (*this)(c, r) + rhs(c, r); + } + } - return R; - } + return result; + } + Mat transpose() + { + Mat result{}; + for (std::uint8_t r = 0; r < Row; ++r) + { + for (std::uint8_t c = 0; c < Col; ++c) + { + result(r, c) = (*this)(c, r); + } + } + return result; + } + template + Mat resize() + { + Mat result{}; + for (std::uint8_t r = 0; r < std::min(Row, NewRow); ++r) + { + for (std::uint8_t c = 0; c < std::min(Col, NewCol); ++c) + { + result(c, r) = (*this)(c, r); + } + } + return result; + } + }; export Mat scale(float scale_size) { @@ -126,6 +112,36 @@ namespace sopho return R; } + // Rodrigues' rotation formula + // v_rot = cos(theta)*v+(1−cos(theta))*(v*k)*k+sin(theta)*(kxv) + // (v*k)k=(k*k^T)v + export Mat rotation(Mat k, float theta) + { + Mat k_k_t = (k * k.transpose()).resize<4, 4>(); + Mat k_m{}; + k_m(0, 1) = k(2); + k_m(0, 2) = -k(1); + k_m(1, 0) = -k(2); + k_m(1, 2) = k(0); + k_m(2, 0) = k(1); + k_m(2, 1) = -k(0); + return scale(std::cos(theta)) + scale(1.F - std::cos(theta)) * k_k_t + scale(std::sin(theta)) * k_m; + } + + export Mat rotation_y(float yaw) + { + Mat y{}; + y(1) = 1; + return rotation(y, yaw); + } + + export Mat rotation_x(float pitch) + { + Mat x{}; + x(0) = 1; + return rotation(x, pitch); + } + export Mat translate(float x, float y, float z) { From 4e92f6a57d90cbc48544dc0865d84c9d5543c037 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 16:35:20 +0800 Subject: [PATCH 12/24] feat: Pipeline enable depth --- sdl_wrapper/src/sdl_wrapper.render_procedural.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sdl_wrapper/src/sdl_wrapper.render_procedural.cpp b/sdl_wrapper/src/sdl_wrapper.render_procedural.cpp index 448163e..11caa5d 100644 --- a/sdl_wrapper/src/sdl_wrapper.render_procedural.cpp +++ b/sdl_wrapper/src/sdl_wrapper.render_procedural.cpp @@ -100,6 +100,16 @@ namespace sopho info.target_info.color_target_descriptions = m_color_target_descriptions.data(); info.target_info.num_color_targets = static_cast(m_color_target_descriptions.size()); + info.target_info.has_depth_stencil_target = true; + info.target_info.depth_stencil_format = SDL_GPU_TEXTUREFORMAT_D16_UNORM; + + info.depth_stencil_state = SDL_GPUDepthStencilState{ + .compare_op = SDL_GPU_COMPAREOP_LESS, + .write_mask = 0xFF, + .enable_depth_test = true, + .enable_depth_write = true, + .enable_stencil_test = false, + }; // Shaders will be filled in later by set_vertex_shader / set_fragment_shader. info.vertex_shader = nullptr; From c3a26541765b442950d705748c8f940ae156af46 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 16:36:23 +0800 Subject: [PATCH 13/24] feat: creat SceneDepthTexture --- main.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/main.cpp b/main.cpp index 8a704d1..9b3b5ce 100644 --- a/main.cpp +++ b/main.cpp @@ -68,6 +68,7 @@ class UserApp : public sopho::App sopho::ImageData m_image_data; std::shared_ptr m_texture_wrapper{}; + SDL_GPUTexture* SceneDepthTexture{}; // camera state float yaw = 0.0f; @@ -233,6 +234,19 @@ void main() SDL_LogWarn(SDL_LOG_CATEGORY_GPU, "Failed to create texture: error = %d", static_cast(texture.error())); } + + SDL_GPUTextureCreateInfo ci = { + .type = SDL_GPU_TEXTURETYPE_2D, + .format = SDL_GPU_TEXTUREFORMAT_D16_UNORM, + .usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET, + .width = 960, + .height = 540, + .layer_count_or_depth = 1, + .num_levels = 1, + .sample_count = SDL_GPU_SAMPLECOUNT_1, + }; + + SceneDepthTexture = SDL_CreateGPUTexture(m_gpu->device(), &ci); return SDL_APP_CONTINUE; } From cd2c9fdd7af899b015d5574513d9b0538e358948 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 16:36:44 +0800 Subject: [PATCH 14/24] feat: creat SceneDepthTexture --- main.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 9b3b5ce..22077b8 100644 --- a/main.cpp +++ b/main.cpp @@ -469,7 +469,18 @@ void main() colorTargetInfo.store_op = SDL_GPU_STOREOP_STORE; colorTargetInfo.texture = swapchainTexture; - SDL_GPURenderPass* renderPass = SDL_BeginGPURenderPass(commandBuffer, &colorTargetInfo, 1, nullptr); + SDL_GPUDepthStencilTargetInfo depthStencilTargetInfo{}; + depthStencilTargetInfo.texture = SceneDepthTexture; + depthStencilTargetInfo.cycle = true; + depthStencilTargetInfo.clear_depth = 1; + depthStencilTargetInfo.clear_stencil = 0; + depthStencilTargetInfo.load_op = SDL_GPU_LOADOP_CLEAR; + depthStencilTargetInfo.store_op = SDL_GPU_STOREOP_STORE; + depthStencilTargetInfo.stencil_load_op = SDL_GPU_LOADOP_CLEAR; + depthStencilTargetInfo.stencil_store_op = SDL_GPU_STOREOP_STORE; + + SDL_GPURenderPass* renderPass = + SDL_BeginGPURenderPass(commandBuffer, &colorTargetInfo, 1, &depthStencilTargetInfo); // Bind pipeline if available. From f437e3d1592ea7f2482afcd31d158ca929090d11 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 16:37:44 +0800 Subject: [PATCH 15/24] feat: split two render pass --- main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.cpp b/main.cpp index 22077b8..2547ca2 100644 --- a/main.cpp +++ b/main.cpp @@ -510,6 +510,11 @@ void main() SDL_DrawGPUIndexedPrimitives(renderPass, 36, 1, 0, 0, 0); + SDL_EndGPURenderPass(renderPass); + + colorTargetInfo.load_op = SDL_GPU_LOADOP_LOAD; + + renderPass = SDL_BeginGPURenderPass(commandBuffer, &colorTargetInfo, 1, nullptr); ImGui_ImplSDLGPU3_RenderDrawData(draw_data, commandBuffer, renderPass); SDL_EndGPURenderPass(renderPass); From d3c34a17286ab836b8a5ca894004c8d266252053 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 16:42:28 +0800 Subject: [PATCH 16/24] feat: release resource when exit --- main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/main.cpp b/main.cpp index 2547ca2..93801df 100644 --- a/main.cpp +++ b/main.cpp @@ -570,6 +570,7 @@ void main() void quit(SDL_AppResult result) override { (void)result; + SDL_ReleaseGPUTexture(m_gpu->device(),SceneDepthTexture); ImGui_ImplSDL3_Shutdown(); ImGui_ImplSDLGPU3_Shutdown(); ImGui::DestroyContext(); From 20673365ae7bdae8d7f529601a2c87ccf9dd73ca Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 17:17:29 +0800 Subject: [PATCH 17/24] feat: add constructor of Mat Vector --- logos/modules/logos.ixx | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index ada1455..500ac32 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -17,6 +17,7 @@ namespace sopho std::array, Col> m_data{}; public: + constexpr Mat() = default; TScalar& operator()(std::uint8_t col, std::uint8_t row) { return m_data[col][row]; } const TScalar& operator()(std::uint8_t col, std::uint8_t row) const { return m_data[col][row]; } TScalar& operator()(std::uint8_t row) @@ -85,6 +86,24 @@ namespace sopho } return result; } + constexpr Mat(std::initializer_list list) + requires(Col == 1) + { + assert(list.size() <= Row); + auto it = list.begin(); + + for (std::uint8_t r = 0; r < Row; ++r) + { + if (it != list.end()) + { + (*this)(r) = *it++; + } + else + { + break; + } + } + } }; export Mat scale(float scale_size) @@ -130,15 +149,13 @@ namespace sopho export Mat rotation_y(float yaw) { - Mat y{}; - y(1) = 1; + Mat y{0, 1, 0}; return rotation(y, yaw); } export Mat rotation_x(float pitch) { - Mat x{}; - x(0) = 1; + Mat x{1, 0, 0}; return rotation(x, pitch); } From 32f15595bb5140d79807bdad257fa4ee434ea371 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 17:23:02 +0800 Subject: [PATCH 18/24] feat: using real aspect --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 93801df..0138640 100644 --- a/main.cpp +++ b/main.cpp @@ -488,8 +488,8 @@ void main() // Compute camera matrix and upload as a vertex uniform. SDL_PushGPUVertexUniformData(commandBuffer, 0, - (sopho::perspective(1, 1, 0.1, 10) * sopho::translate(0, 0, -5) * - sopho::rotation_x(-pitch) * sopho::rotation_y(yaw)) + (sopho::perspective(1, static_cast(width) / height, 0.1, 10) * + sopho::translate(0, 0, -5) * sopho::rotation_x(-pitch) * sopho::rotation_y(yaw)) .data(), sizeof(sopho::Mat)); From 749486d00ba6415c54c57e119e89f771a0f57f29 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 17:29:32 +0800 Subject: [PATCH 19/24] feat: receate texture when window resize --- main.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/main.cpp b/main.cpp index 0138640..543799c 100644 --- a/main.cpp +++ b/main.cpp @@ -74,6 +74,8 @@ class UserApp : public sopho::App float yaw = 0.0f; float pitch = 0.0f; + int win_w = 0, win_h = 0; + std::string vertex_source = R"WSQ(#version 460 @@ -235,12 +237,13 @@ void main() static_cast(texture.error())); } + SDL_GetWindowSizeInPixels(m_gpu->window(), &win_w, &win_h); SDL_GPUTextureCreateInfo ci = { .type = SDL_GPU_TEXTURETYPE_2D, .format = SDL_GPU_TEXTUREFORMAT_D16_UNORM, .usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET, - .width = 960, - .height = 540, + .width = static_cast(win_w), + .height = static_cast(win_h), .layer_count_or_depth = 1, .num_levels = 1, .sample_count = SDL_GPU_SAMPLECOUNT_1, @@ -453,6 +456,24 @@ void main() return SDL_APP_CONTINUE; } + if (win_w != width || win_h != height) + { + SDL_GPUTextureCreateInfo ci = { + .type = SDL_GPU_TEXTURETYPE_2D, + .format = SDL_GPU_TEXTUREFORMAT_D16_UNORM, + .usage = SDL_GPU_TEXTUREUSAGE_DEPTH_STENCIL_TARGET, + .width = static_cast(width), + .height = static_cast(height), + .layer_count_or_depth = 1, + .num_levels = 1, + .sample_count = SDL_GPU_SAMPLECOUNT_1, + }; + SDL_ReleaseGPUTexture(m_gpu->device(), SceneDepthTexture); + SceneDepthTexture = SDL_CreateGPUTexture(m_gpu->device(), &ci); + win_w = width; + win_h = height; + } + if (swapchainTexture == nullptr) { // You must always submit the command buffer, even if no texture is available. @@ -570,7 +591,7 @@ void main() void quit(SDL_AppResult result) override { (void)result; - SDL_ReleaseGPUTexture(m_gpu->device(),SceneDepthTexture); + SDL_ReleaseGPUTexture(m_gpu->device(), SceneDepthTexture); ImGui_ImplSDL3_Shutdown(); ImGui_ImplSDLGPU3_Shutdown(); ImGui::DestroyContext(); From 03b9810e533a78aaf876fb3b2d739266996ca4a1 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 17:39:41 +0800 Subject: [PATCH 20/24] feat: Add length function --- logos/modules/logos.ixx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index 500ac32..a5b8c7e 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -86,6 +86,16 @@ namespace sopho } return result; } + TScalar length() + requires(Col == 1) + { + TScalar sum; + for (const auto e : m_data[0]) + { + sum += e * e; + } + return std::sqrt(sum); + } constexpr Mat(std::initializer_list list) requires(Col == 1) { @@ -136,6 +146,7 @@ namespace sopho // (v*k)k=(k*k^T)v export Mat rotation(Mat k, float theta) { + assert(k.length() > 0); Mat k_k_t = (k * k.transpose()).resize<4, 4>(); Mat k_m{}; k_m(0, 1) = k(2); From e04b157c9ee2605c61985e5454a93fbc4a4bcea5 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 17:46:09 +0800 Subject: [PATCH 21/24] feat: Add length function --- logos/modules/logos.ixx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index a5b8c7e..e045a2c 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -61,6 +61,22 @@ namespace sopho return result; } + + Mat operator*(const TScalar& rhs) const + { + Mat result{}; + + for (std::uint8_t r = 0; r < Row; ++r) + { + for (std::uint8_t c = 0; c < Col; ++c) + { + result(c, r) = (*this)(c, r) * rhs; + } + } + + return result; + } + Mat transpose() { Mat result{}; @@ -89,12 +105,12 @@ namespace sopho TScalar length() requires(Col == 1) { - TScalar sum; + TScalar sum{}; for (const auto e : m_data[0]) { sum += e * e; } - return std::sqrt(sum); + return std::sqrt(sum); } constexpr Mat(std::initializer_list list) requires(Col == 1) @@ -147,6 +163,7 @@ namespace sopho export Mat rotation(Mat k, float theta) { assert(k.length() > 0); + k = k * (1 / k.length()); Mat k_k_t = (k * k.transpose()).resize<4, 4>(); Mat k_m{}; k_m(0, 1) = k(2); From e5df3da88cb74f0734bcc649d929a8e261f2c04e Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 17:55:27 +0800 Subject: [PATCH 22/24] feat: Add Model graph --- README.md | 51 ++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b105afd..07b3834 100644 --- a/README.md +++ b/README.md @@ -2,18 +2,51 @@ This is a personal learning project following [Learn OpenGL](https://learnopengl.com/) +## Module + +```mermaid +graph TD + + subgraph ThirdParty + glslang + shaderc + SPIRVTools + SDL3 + stb + imgui + end + + glslang --> shaderc + SPIRVTools --> shaderc + + SDL3 --> imgui + + glslang --> glsl_reflector + data_type --> glsl_reflector + + shaderc --> sdl_wrapper + SDL3 --> sdl_wrapper + glsl_reflector --> sdl_wrapper + data_type --> sdl_wrapper + + imgui --> SDL_TEST + sdl_wrapper --> SDL_TEST + stb --> SDL_TEST + logos --> SDL_TEST +``` + ## Track - [ ] Getting started - - [x] OpenGL - - [x] Creating a window - - [x] Hello Window - - [x] Hello Triangle - - [x] Shaders - - [x] Textures - - [x] Transformations - - [ ] Coordinate Systems - - [ ] Camera + - [x] OpenGL + - [x] Creating a window + - [x] Hello Window + - [x] Hello Triangle + - [x] Shaders + - [x] Textures + - [x] Transformations + - [ ] Coordinate Systems + - [ ] Camera - [ ] Lighting - [ ] Model Loading - [ ] Advanced OpenGL From dc4d39b7b854fd8169e5f282ef75fc17ec4a3c8b Mon Sep 17 00:00:00 2001 From: Sophomore Date: Thu, 27 Nov 2025 17:56:56 +0800 Subject: [PATCH 23/24] feat: Add Modules Graph --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 07b3834..dbb24ff 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,13 @@ graph TD imgui end + subgraph Modules + data_type + glsl_reflector + sdl_wrapper + logos + end + glslang --> shaderc SPIRVTools --> shaderc From 7aea68581a54b672b168f9656af69748bd5b65f3 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Thu, 27 Nov 2025 20:14:15 +0800 Subject: [PATCH 24/24] feat: add missing break --- main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.cpp b/main.cpp index 543799c..d9fa0e7 100644 --- a/main.cpp +++ b/main.cpp @@ -308,9 +308,11 @@ void main() case 4: changed |= ImGui::DragFloat4(std::format("{}{}", format.name, vertex_index).data(), reinterpret_cast(raw_ptr), 0.01f, -1.f, 1.f); + break; default: SDL_Log("Not implemented size"); assert(false); + break; } } break;