From 0669f5d9e25f6cfbe8b95610d06c99b74d7e3a6e Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 14:18:32 +0800 Subject: [PATCH 01/10] fix:cleanup cmake --- glsl_reflector/CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/glsl_reflector/CMakeLists.txt b/glsl_reflector/CMakeLists.txt index 5e0ec26..8631e09 100644 --- a/glsl_reflector/CMakeLists.txt +++ b/glsl_reflector/CMakeLists.txt @@ -16,6 +16,5 @@ add_executable(glslr test/test.cpp) target_link_libraries(glslr PUBLIC glsl_reflector gtest gtest_main) -add_test(NAME unit_tests COMMAND glslr) gtest_discover_tests(glslr DISCOVERY_TIMEOUT 60) From 73c4ad414f6f1230c7f9049caebb190740b90a1d Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 14:19:35 +0800 Subject: [PATCH 02/10] feat: add module logos --- logos/CMakeLists.txt | 11 +++++++++++ logos/modules/logos.ixx | 5 +++++ 2 files changed, 16 insertions(+) create mode 100644 logos/CMakeLists.txt create mode 100644 logos/modules/logos.ixx diff --git a/logos/CMakeLists.txt b/logos/CMakeLists.txt new file mode 100644 index 0000000..1e24b8e --- /dev/null +++ b/logos/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.30) +project(logos LANGUAGES CXX) + +set(CMAKE_CXX_STANDARD 23) +add_library(logos STATIC) + +target_sources(logos + PUBLIC + FILE_SET cxx_modules TYPE CXX_MODULES FILES + modules/logos.ixx +) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx new file mode 100644 index 0000000..8348ab1 --- /dev/null +++ b/logos/modules/logos.ixx @@ -0,0 +1,5 @@ +// logos.ixx +// Created by wsqsy on 11/26/2025. +// + +export module logos; From 4affdee2f1955ab559c5505a5b6f6ac7107170ba Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 15:31:59 +0800 Subject: [PATCH 03/10] feat:link logos to SDL_TEST --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 21cf4db..26f9093 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -120,9 +120,10 @@ include(GoogleTest) add_subdirectory(data_type) add_subdirectory(sdl_wrapper) add_subdirectory(glsl_reflector) +add_subdirectory(logos) add_executable(SDL_TEST main.cpp) -target_link_libraries(SDL_TEST PRIVATE imgui sdl_wrapper stb) +target_link_libraries(SDL_TEST PRIVATE imgui sdl_wrapper stb logos) include(GNUInstallDirs) install(TARGETS SDL_TEST From b087841337cbe7a3deffb447ff9b4293daf1969d Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 15:32:16 +0800 Subject: [PATCH 04/10] feat:add class Mat --- logos/modules/logos.ixx | 99 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 98 insertions(+), 1 deletion(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index 8348ab1..680e375 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -1,5 +1,102 @@ // logos.ixx // Created by wsqsy on 11/26/2025. // - +module; +#include +#include +#include export module logos; + +namespace sopho +{ + template + class Mat + { + std::array, Row> 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 row) + requires(Col == 1) + { + return m_data[row][0]; + } + TScalar* data() { return m_data[0].data(); } + template + Mat operator*(const Mat& rhs) const + { + Mat result{}; + + for (std::uint8_t r = 0; r < Row; ++r) + { + for (std::uint8_t c = 0; c < OtherCol; ++c) + { + TScalar sum{}; + for (std::uint8_t k = 0; k < Col; ++k) + { + sum += (*this)(r, k) * rhs(k, c); + } + result(r, c) = sum; + } + } + + return result; + } + }; + + export Mat MakeRotationY(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 MakeRotationX(float pitch) + { + float cp = std::cos(pitch); + float sp = std::sin(pitch); + + 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) = 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; + + return R; + } + +} // namespace sopho From ac5beb584e3861b1198cb3625a0a51e13a91c190 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 15:33:33 +0800 Subject: [PATCH 05/10] feat: using logos to calculate camera transformation --- main.cpp | 31 +++---------------------------- 1 file changed, 3 insertions(+), 28 deletions(-) diff --git a/main.cpp b/main.cpp index 81eef1a..00e5ffd 100644 --- a/main.cpp +++ b/main.cpp @@ -26,6 +26,7 @@ import data_type; import glsl_reflector; import sdl_wrapper; +import logos; /** * @brief Structure to hold camera transformation matrix data. @@ -464,34 +465,8 @@ void main() SDL_BindGPUGraphicsPipeline(renderPass, m_renderable->procedural()->data()); // Compute camera matrix and upload as a vertex uniform. - { - float cy = std::cos(yaw); - float sy = std::sin(yaw); - float cp = std::cos(pitch); - float sp = std::sin(pitch); - - std::array Ry = {cy, 0.0F, sy, 0.0F, 0.0F, 1.0F, 0.0F, 0.0F, - -sy, 0.0F, cy, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F}; - - std::array Rx = {1.0F, 0.0F, 0.0F, 0.0F, 0.0F, cp, sp, 0.0F, - 0.0F, -sp, cp, 0.0F, 0.0F, 0.0F, 0.0F, 1.0F}; - - auto mulMat4 = [](const float* A, const float* B, float* C) - { - for (int col = 0; col < 4; ++col) - { - for (int row = 0; row < 4; ++row) - { - C[col * 4 + row] = A[0 * 4 + row] * B[col * 4 + 0] + A[1 * 4 + row] * B[col * 4 + 1] + - A[2 * 4 + row] * B[col * 4 + 2] + A[3 * 4 + row] * B[col * 4 + 3]; - } - } - }; - - // uView = Rx * Ry - mulMat4(Rx.data(), Ry.data(), cam.m.data()); - SDL_PushGPUVertexUniformData(commandBuffer, 0, cam.m.data(), static_cast(sizeof(cam.m))); - } + SDL_PushGPUVertexUniformData(commandBuffer, 0, (sopho::MakeRotationX(pitch) * sopho::MakeRotationY(yaw)).data(), + sizeof(cam.m)); SDL_BindGPUVertexBuffers(renderPass, 0, m_renderable->data()->get_vertex_buffer_binding().data(), m_renderable->data()->get_vertex_buffer_binding().size()); From 59ecd29e2c3d1e413e9f2f6e605a5258cc3a3520 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 15:36:45 +0800 Subject: [PATCH 06/10] feat: Add function Scale --- logos/modules/logos.ixx | 25 +++++++++++++++++++++++++ main.cpp | 5 +++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index 680e375..cc6020a 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -99,4 +99,29 @@ namespace sopho return R; } + export Mat Scale(float scale_size) + { + + Mat R{}; + + R(0, 0) = scale_size; + R(0, 1) = 0; + R(0, 2) = 0; + R(0, 3) = 0; + R(1, 0) = 0; + R(1, 1) = scale_size; + R(1, 2) = 0; + R(1, 3) = 0; + R(2, 0) = 0; + R(2, 1) = 0; + R(2, 2) = scale_size; + R(2, 3) = 0; + R(3, 0) = 0; + R(3, 1) = 0; + R(3, 2) = 0; + R(3, 3) = 1; + + return R; + } + } // namespace sopho diff --git a/main.cpp b/main.cpp index 00e5ffd..69d47b6 100644 --- a/main.cpp +++ b/main.cpp @@ -465,8 +465,9 @@ void main() SDL_BindGPUGraphicsPipeline(renderPass, m_renderable->procedural()->data()); // Compute camera matrix and upload as a vertex uniform. - SDL_PushGPUVertexUniformData(commandBuffer, 0, (sopho::MakeRotationX(pitch) * sopho::MakeRotationY(yaw)).data(), - sizeof(cam.m)); + SDL_PushGPUVertexUniformData( + commandBuffer, 0, (sopho::MakeRotationX(pitch) * sopho::MakeRotationY(yaw) * sopho::Scale(0.1F)).data(), + sizeof(cam.m)); SDL_BindGPUVertexBuffers(renderPass, 0, m_renderable->data()->get_vertex_buffer_binding().data(), m_renderable->data()->get_vertex_buffer_binding().size()); From edea6c4d5fa3958cf9820a3f81a8b0c77df09eda Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 15:41:26 +0800 Subject: [PATCH 07/10] fix:using butter rotation --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 69d47b6..d505c55 100644 --- a/main.cpp +++ b/main.cpp @@ -466,7 +466,7 @@ void main() // Compute camera matrix and upload as a vertex uniform. SDL_PushGPUVertexUniformData( - commandBuffer, 0, (sopho::MakeRotationX(pitch) * sopho::MakeRotationY(yaw) * sopho::Scale(0.1F)).data(), + commandBuffer, 0, (sopho::MakeRotationY(yaw) * sopho::MakeRotationX(-pitch) * sopho::Scale(0.1F)).data(), sizeof(cam.m)); SDL_BindGPUVertexBuffers(renderPass, 0, m_renderable->data()->get_vertex_buffer_binding().data(), From 404fbc6396f79c8705eec76018ab69882fab5a33 Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 15:43:15 +0800 Subject: [PATCH 08/10] fix: mark transformation finished --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2dde53b..b105afd 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ This is a personal learning project following [Learn OpenGL](https://learnopengl - [x] Hello Triangle - [x] Shaders - [x] Textures - - [ ] Transformations + - [x] Transformations - [ ] Coordinate Systems - [ ] Camera - [ ] Lighting From a4feca041ede96948cfd0e5d8fe35f22dfa9a86d Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 16:58:41 +0800 Subject: [PATCH 09/10] fix: remove unused camera uniform --- main.cpp | 23 +---------------------- 1 file changed, 1 insertion(+), 22 deletions(-) diff --git a/main.cpp b/main.cpp index d505c55..0283d20 100644 --- a/main.cpp +++ b/main.cpp @@ -28,16 +28,6 @@ import glsl_reflector; import sdl_wrapper; import logos; -/** - * @brief Structure to hold camera transformation matrix data. - * - * Contains a 4x4 matrix (16 elements) representing the camera's view transformation. - */ -struct CameraUniform -{ - std::array m{}; ///< 4x4 transformation matrix as a flat array -}; - /** * @brief Loads image data from the test texture file. * @@ -83,8 +73,6 @@ class UserApp : public sopho::App float yaw = 0.0f; float pitch = 0.0f; - CameraUniform cam{}; - std::string vertex_source = R"WSQ(#version 460 @@ -183,15 +171,6 @@ void main() .m_render_procedural = std::make_shared(std::move(pw_result.value())), .m_render_data = std::move(render_data.value())}); - // 6. Initialize camera matrix to identity. - { - cam.m.fill(0.0F); - cam.m[0] = 1.0F; - cam.m[5] = 1.0F; - cam.m[10] = 1.0F; - cam.m[15] = 1.0F; - } - // 7. Setup Dear ImGui context. IMGUI_CHECKVERSION(); ImGui::CreateContext(); @@ -467,7 +446,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(), - sizeof(cam.m)); + sizeof(sopho::Mat)); SDL_BindGPUVertexBuffers(renderPass, 0, m_renderable->data()->get_vertex_buffer_binding().data(), m_renderable->data()->get_vertex_buffer_binding().size()); From fc0a774f1010763cd47ebb5c3055bab73827373a Mon Sep 17 00:00:00 2001 From: Sophomore Date: Wed, 26 Nov 2025 16:58:55 +0800 Subject: [PATCH 10/10] fix: export template --- logos/modules/logos.ixx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logos/modules/logos.ixx b/logos/modules/logos.ixx index cc6020a..a0c52f9 100644 --- a/logos/modules/logos.ixx +++ b/logos/modules/logos.ixx @@ -9,7 +9,7 @@ export module logos; namespace sopho { - template + export template class Mat { std::array, Row> m_data{};