Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion glsl_reflector/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 11 additions & 0 deletions logos/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
)
127 changes: 127 additions & 0 deletions logos/modules/logos.ixx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
// logos.ixx
// Created by wsqsy on 11/26/2025.
//
module;
#include <array>
#include <cmath>
#include <cstdint>
export module logos;

namespace sopho
{
export template <typename TScalar, std::uint8_t Row, std::uint8_t Col>
class Mat
{
std::array<std::array<TScalar, Col>, 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 <std::uint8_t OtherCol>
Mat<TScalar, Row, OtherCol> operator*(const Mat<TScalar, Col, OtherCol>& rhs) const
{
Mat<TScalar, Row, OtherCol> 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<float, 4, 4> MakeRotationY(float yaw)
{
float cy = std::cos(yaw);
float sy = std::sin(yaw);

Mat<float, 4, 4> 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<float, 4, 4> MakeRotationX(float pitch)
{
float cp = std::cos(pitch);
float sp = std::sin(pitch);

Mat<float, 4, 4> 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;
}

export Mat<float, 4, 4> Scale(float scale_size)
{

Mat<float, 4, 4> 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
53 changes: 4 additions & 49 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,7 @@
import data_type;
import glsl_reflector;
import sdl_wrapper;

/**
* @brief Structure to hold camera transformation matrix data.
*
* Contains a 4x4 matrix (16 elements) representing the camera's view transformation.
*/
struct CameraUniform
{
std::array<float, 16> m{}; ///< 4x4 transformation matrix as a flat array
};
import logos;

/**
* @brief Loads image data from the test texture file.
Expand Down Expand Up @@ -82,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

Expand Down Expand Up @@ -182,15 +171,6 @@ void main()
.m_render_procedural = std::make_shared<sopho::RenderProcedural>(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();
Expand Down Expand Up @@ -464,34 +444,9 @@ 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<float, 16> 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<float, 16> 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<std::uint32_t>(sizeof(cam.m)));
}
SDL_PushGPUVertexUniformData(
commandBuffer, 0, (sopho::MakeRotationY(yaw) * sopho::MakeRotationX(-pitch) * sopho::Scale(0.1F)).data(),
sizeof(sopho::Mat<float, 4, 4>));

SDL_BindGPUVertexBuffers(renderPass, 0, m_renderable->data()->get_vertex_buffer_binding().data(),
m_renderable->data()->get_vertex_buffer_binding().size());
Expand Down