diff --git a/.gitmodules b/.gitmodules index 38b83926..ef1b1e64 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,12 @@ [submodule "Engine/cpp/thirdparty/bx"] - path = Engine/cpp/thirdparty/bx + path = Engine/cpp/ThirdParty/bx url = https://github.com/bkaradzic/bx [submodule "Engine/cpp/thirdparty/bimg"] - path = Engine/cpp/thirdparty/bimg + path = Engine/cpp/ThirdParty/bimg url = https://github.com/bkaradzic/bimg [submodule "Engine/cpp/thirdparty/bgfx"] - path = Engine/cpp/thirdparty/bgfx + path = Engine/cpp/ThirdParty/bgfx url = https://github.com/bkaradzic/bgfx [submodule "Engine/cpp/thirdparty/sdl"] - path = Engine/cpp/thirdparty/sdl + path = Engine/cpp/ThirdParty/sdl url = https://github.com/libsdl-org/SDL diff --git a/Engine/cpp/CMakeLists.txt b/Engine/cpp/CMakeLists.txt index 3e594b1a..fdd866e5 100644 --- a/Engine/cpp/CMakeLists.txt +++ b/Engine/cpp/CMakeLists.txt @@ -1,6 +1,6 @@ -add_subdirectory(thirdparty SYSTEM) +add_subdirectory(ThirdParty SYSTEM) -add_modules_library(runtime) -target_link_libraries(runtime PUBLIC platform core input scene rendering) +add_modules_library(Runtime SHARED) +target_link_libraries(Runtime PUBLIC Platform Core Input Scene Rendering) # TODO: binding library \ No newline at end of file diff --git a/Engine/cpp/Runtime/CMakeLists.txt b/Engine/cpp/Runtime/CMakeLists.txt new file mode 100644 index 00000000..e8b7737e --- /dev/null +++ b/Engine/cpp/Runtime/CMakeLists.txt @@ -0,0 +1,11 @@ +add_modules_library(Platform) +add_modules_library(Core PIC) +add_modules_library(Input) +add_modules_library(Rendering PIC) +add_modules_library(Scene) + +target_link_libraries(Platform PUBLIC Platform_impl) +target_link_libraries(Core PUBLIC Definitions Math IO Memory) +target_link_libraries(Input PRIVATE SDL3::SDL3-static Platform Core) +target_link_libraries(Rendering PUBLIC RHI RenderGraph Mesh Material QuadRenderer Renderer) +target_link_libraries(Scene PUBLIC Renderable TransformComponent Camera) diff --git a/Engine/cpp/Runtime/Core/CMakeLists.txt b/Engine/cpp/Runtime/Core/CMakeLists.txt new file mode 100644 index 00000000..4289b47c --- /dev/null +++ b/Engine/cpp/Runtime/Core/CMakeLists.txt @@ -0,0 +1,8 @@ +add_modules_library(Definitions) +add_modules_library(Math) +add_modules_library(IO) +add_modules_library(Memory) + +target_link_libraries(Math PUBLIC Definitions bx) +target_link_libraries(IO PUBLIC Definitions stb_image) +target_link_libraries(Memory PUBLIC Definitions Math) diff --git a/Engine/cpp/runtime/core/core.cppm b/Engine/cpp/Runtime/Core/Core.cppm similarity index 81% rename from Engine/cpp/runtime/core/core.cppm rename to Engine/cpp/Runtime/Core/Core.cppm index 9de09a0a..baec3625 100644 --- a/Engine/cpp/runtime/core/core.cppm +++ b/Engine/cpp/Runtime/Core/Core.cppm @@ -1,5 +1,6 @@ export module core; export import core.defs; +export import core.version; export import core.math; export import core.memory; export import core.io; diff --git a/Engine/cpp/runtime/core/definitions/definitions.cppm b/Engine/cpp/Runtime/Core/Definitions/Definitions.cppm similarity index 92% rename from Engine/cpp/runtime/core/definitions/definitions.cppm rename to Engine/cpp/Runtime/Core/Definitions/Definitions.cppm index 822c9985..cc981b48 100644 --- a/Engine/cpp/runtime/core/definitions/definitions.cppm +++ b/Engine/cpp/Runtime/Core/Definitions/Definitions.cppm @@ -3,10 +3,9 @@ module; #include export module core.defs; -export import core.version; export import core.stdtypes; -static_assert(__cplusplus >= 202207L, "Minimum of C++23 required. Consider upgrading your compiler."); +static_assert(__cplusplus >= 202207L, "Minimum of C++23 required."); export namespace draco { template diff --git a/Engine/cpp/runtime/core/definitions/stdtypes.cppm b/Engine/cpp/Runtime/Core/Definitions/StdTypes.cppm similarity index 100% rename from Engine/cpp/runtime/core/definitions/stdtypes.cppm rename to Engine/cpp/Runtime/Core/Definitions/StdTypes.cppm diff --git a/Engine/cpp/runtime/core/io/filesystem.cpp b/Engine/cpp/Runtime/Core/IO/FileSystem.cpp similarity index 94% rename from Engine/cpp/runtime/core/io/filesystem.cpp rename to Engine/cpp/Runtime/Core/IO/FileSystem.cpp index 36e98247..396101aa 100644 --- a/Engine/cpp/runtime/core/io/filesystem.cpp +++ b/Engine/cpp/Runtime/Core/IO/FileSystem.cpp @@ -11,7 +11,7 @@ import core.stdtypes; namespace draco::core::io::filesystem { - std::vector load_binary(const std::string& path) + std::vector loadBinary(const std::string& path) { // Open at the end (ate) to get size and in binary mode std::ifstream file(path, std::ios::binary | std::ios::ate); diff --git a/Engine/cpp/runtime/core/io/filesystem.cppm b/Engine/cpp/Runtime/Core/IO/FileSystem.cppm similarity index 78% rename from Engine/cpp/runtime/core/io/filesystem.cppm rename to Engine/cpp/Runtime/Core/IO/FileSystem.cppm index bdba6bdc..26c8601f 100644 --- a/Engine/cpp/runtime/core/io/filesystem.cppm +++ b/Engine/cpp/Runtime/Core/IO/FileSystem.cppm @@ -11,5 +11,5 @@ import core.stdtypes; export namespace draco::core::io::filesystem { // Returns a buffer of the file data - std::vector load_binary(const std::string& path); + std::vector loadBinary(const std::string& path); } diff --git a/Engine/cpp/runtime/core/io/io.cppm b/Engine/cpp/Runtime/Core/IO/IO.cppm similarity index 61% rename from Engine/cpp/runtime/core/io/io.cppm rename to Engine/cpp/Runtime/Core/IO/IO.cppm index 64c775d8..ae8d71ae 100644 --- a/Engine/cpp/runtime/core/io/io.cppm +++ b/Engine/cpp/Runtime/Core/IO/IO.cppm @@ -1,4 +1,4 @@ export module core.io; export import core.io.filesystem; -export import core.io.image_loader; \ No newline at end of file +export import core.io.loader.image; diff --git a/Engine/cpp/runtime/core/io/image_loader.cpp b/Engine/cpp/Runtime/Core/IO/ImageLoader.cpp similarity index 90% rename from Engine/cpp/runtime/core/io/image_loader.cpp rename to Engine/cpp/Runtime/Core/IO/ImageLoader.cpp index 98ec0b44..fd971f4f 100644 --- a/Engine/cpp/runtime/core/io/image_loader.cpp +++ b/Engine/cpp/Runtime/Core/IO/ImageLoader.cpp @@ -8,15 +8,15 @@ module; #define STB_IMAGE_IMPLEMENTATION #include -module core.io.image_loader; +module core.io.loader.image; import core.stdtypes; // TODO: I'm too lazy to write code so we need somethin' better -namespace draco::core::io::image_loader +namespace draco::core::io::loader::image { - ImageData load_image(const std::filesystem::path& path) + ImageData loadImage(const std::filesystem::path& path) { ImageData result; @@ -53,7 +53,7 @@ namespace draco::core::io::image_loader result.width = static_cast(width); result.height = static_cast(height); result.channels = 4; - result.is_valid = true; + result.isValid = true; // Free the memory allocated by stb stbi_image_free(data); diff --git a/Engine/cpp/runtime/core/io/image_loader.cppm b/Engine/cpp/Runtime/Core/IO/ImageLoader.cppm similarity index 54% rename from Engine/cpp/runtime/core/io/image_loader.cppm rename to Engine/cpp/Runtime/Core/IO/ImageLoader.cppm index a1dd61f6..0c94d4bf 100644 --- a/Engine/cpp/runtime/core/io/image_loader.cppm +++ b/Engine/cpp/Runtime/Core/IO/ImageLoader.cppm @@ -3,21 +3,21 @@ module; #include #include -export module core.io.image_loader; +export module core.io.loader.image; import core.stdtypes; -export namespace draco::core::io::image_loader +export namespace draco::core::io::loader::image { struct ImageData { - std::vector pixels; + std::vector pixels{}; u32 width = 0; u32 height = 0; u8 channels = 0; - bool is_valid = false; + bool isValid = false; }; // Load an image file (PNG, JPG, etc.) & decode it to raw RGBA8 - ImageData load_image(const std::filesystem::path& path); + ImageData loadImage(const std::filesystem::path& path); } \ No newline at end of file diff --git a/Engine/cpp/runtime/core/math/constants.cppm b/Engine/cpp/Runtime/Core/Math/Constants.cppm similarity index 100% rename from Engine/cpp/runtime/core/math/constants.cppm rename to Engine/cpp/Runtime/Core/Math/Constants.cppm diff --git a/Engine/cpp/runtime/core/math/functions.cppm b/Engine/cpp/Runtime/Core/Math/Functions.cppm similarity index 90% rename from Engine/cpp/runtime/core/math/functions.cppm rename to Engine/cpp/Runtime/Core/Math/Functions.cppm index c3260098..86aba8b3 100644 --- a/Engine/cpp/runtime/core/math/functions.cppm +++ b/Engine/cpp/Runtime/Core/Math/Functions.cppm @@ -15,18 +15,18 @@ export namespace draco::math { constexpr T sqr(T x) noexcept { return x*x; } template - [[nodiscard]] constexpr bool is_nan(T val) noexcept { + [[nodiscard]] constexpr bool isNan(T val) noexcept { // Only NaN does not equal itself. return val != val; } template - [[nodiscard]] constexpr bool is_inf(T val) noexcept { + [[nodiscard]] constexpr bool isInf(T val) noexcept { return std::isinf(val); } template - [[nodiscard]] constexpr bool is_finite(T val) noexcept { + [[nodiscard]] constexpr bool isFinite(T val) noexcept { return std::isfinite(val); } @@ -91,12 +91,12 @@ export namespace draco::math { } template - constexpr T deg_to_rad(T y) noexcept { + constexpr T degToRad(T y) noexcept { return y * (T{PI} / T{180.}); } template - constexpr T rad_to_deg(T y) noexcept { + constexpr T radToDeg(T y) noexcept { return y * (T{180.} / T{PI}); } @@ -111,7 +111,7 @@ export namespace draco::math { } template - constexpr T cubic_interpolate(T from, T to, T before, T after, T weight) noexcept { + constexpr T cubicInterpolate(T from, T to, T before, T after, T weight) noexcept { // weight squared. T w2 = weight * weight; // weight cubed. @@ -135,7 +135,7 @@ export namespace draco::math { } template - constexpr T cubic_interpolate_in_time( + constexpr T cubicInterpolateInTime( T from, T to, T before, T after, T weight, T to_t, T before_t, T after_t) noexcept { @@ -169,7 +169,7 @@ export namespace draco::math { } template - constexpr T bezier_interpolate(T start, T control_1, T control_2, T end, T t) noexcept { + constexpr T bezierInterpolate(T start, T control_1, T control_2, T end, T t) noexcept { /* Formula from Wikipedia article on Bezier curves. */ // one minus t. T omt = T{1.} - t; @@ -184,7 +184,7 @@ export namespace draco::math { } template - constexpr T bezier_derivative(T start, T control_1, T control_2, T end, T t) noexcept { + constexpr T bezierDerivative(T start, T control_1, T control_2, T end, T t) noexcept { /* Formula from Wikipedia article on Bezier curves. */ T omt = T{1.} - t; T omt2 = omt * omt; diff --git a/Engine/cpp/runtime/core/math/math.cppm b/Engine/cpp/Runtime/Core/Math/Math.cppm similarity index 100% rename from Engine/cpp/runtime/core/math/math.cppm rename to Engine/cpp/Runtime/Core/Math/Math.cppm diff --git a/Engine/cpp/runtime/core/math/math.test.cpp b/Engine/cpp/Runtime/Core/Math/Math.test.cpp similarity index 99% rename from Engine/cpp/runtime/core/math/math.test.cpp rename to Engine/cpp/Runtime/Core/Math/Math.test.cpp index 55452830..4b300766 100644 --- a/Engine/cpp/runtime/core/math/math.test.cpp +++ b/Engine/cpp/Runtime/Core/Math/Math.test.cpp @@ -455,7 +455,7 @@ TEST_SUITE("vector2") { using math::CMP_EPSILON; static constexpr Vector2 v{1.0f, 2.0f}; - static constexpr Vector2 offset = Vector2::x_axis(CMP_EPSILON); + static constexpr Vector2 offset = Vector2::xAxis(CMP_EPSILON); BASIC_R_SUBCASE("distance < epsilon", ( approx_eq(v, v + offset * 0.5f) ), @@ -910,7 +910,7 @@ TEST_SUITE("vector3") { using math::CMP_EPSILON; static constexpr Vector3 v{1.0f, 2.0f, 3.0f}; - static constexpr Vector3 offset = Vector3::x_axis(CMP_EPSILON); + static constexpr Vector3 offset = Vector3::xAxis(CMP_EPSILON); BASIC_R_SUBCASE("distance < epsilon", ( approx_eq(v, v + offset * 0.5f) ), @@ -933,8 +933,8 @@ TEST_SUITE("vector3") { using math::cross; RAC_CHECK_EQ( - ( cross(Vector3::x_axis(), Vector3::y_axis()) ), - ( Vector3::z_axis() ) + ( cross(Vector3::xAxis(), Vector3::yAxis()) ), + ( Vector3::zAxis() ) ) } } @@ -1401,7 +1401,7 @@ TEST_SUITE("vector4") { using math::CMP_EPSILON; static constexpr Vector4 v{1.0f, 2.0f, 3.0f, 4.0f}; - static constexpr Vector4 offset = Vector4::x_axis(CMP_EPSILON); + static constexpr Vector4 offset = Vector4::xAxis(CMP_EPSILON); BASIC_R_SUBCASE("distance < epsilon", ( approx_eq(v, v + offset * 0.5f) ), diff --git a/Engine/cpp/runtime/core/math/transform.cpp b/Engine/cpp/Runtime/Core/Math/Transform.cpp similarity index 93% rename from Engine/cpp/runtime/core/math/transform.cpp rename to Engine/cpp/Runtime/Core/Math/Transform.cpp index b1238927..5e1029b4 100644 --- a/Engine/cpp/runtime/core/math/transform.cpp +++ b/Engine/cpp/Runtime/Core/Math/Transform.cpp @@ -10,7 +10,7 @@ import core.stdtypes; namespace draco::math { - void Transform::to_matrix(f32 out[16]) const + void Transform::toMatrix(f32 out[16]) const { f32 translation[16]; f32 rx[16]; diff --git a/Engine/cpp/runtime/core/math/transform.cppm b/Engine/cpp/Runtime/Core/Math/Transform.cppm similarity index 65% rename from Engine/cpp/runtime/core/math/transform.cppm rename to Engine/cpp/Runtime/Core/Math/Transform.cppm index 06f85d5d..176cbe7c 100644 --- a/Engine/cpp/runtime/core/math/transform.cppm +++ b/Engine/cpp/Runtime/Core/Math/Transform.cppm @@ -12,59 +12,59 @@ export namespace draco::math f32 rotation[3] = { 0.0f, 0.0f, 0.0f }; // Euler (radians) f32 scale[3] = { 1.0f, 1.0f, 1.0f }; - constexpr void set_position(f32 x, f32 y, f32 z) noexcept { + constexpr void setPosition(f32 x, f32 y, f32 z) noexcept { position[0] = x; position[1] = y; position[2] = z; } - constexpr void set_position(const Vector3& v) noexcept { + constexpr void setPosition(const Vector3& v) noexcept { position[0] = v.x; position[1] = v.y; position[2] = v.z; } - [[nodiscard]] constexpr Vector3 get_position() const noexcept { + [[nodiscard]] constexpr Vector3 getPosition() const noexcept { return Vector3{position[0], position[1], position[2]}; } - constexpr void set_rotation(f32 x, f32 y, f32 z) noexcept + constexpr void setRotation(const f32 x, const f32 y, const f32 z) noexcept { rotation[0] = x; rotation[1] = y; rotation[2] = z; } - constexpr void set_rotation(const Vector3& v) noexcept + constexpr void setRotation(const Vector3& v) noexcept { rotation[0] = v.x; rotation[1] = v.y; rotation[2] = v.z; } - [[nodiscard]] constexpr Vector3 get_rotation() const noexcept { + [[nodiscard]] constexpr Vector3 getRotation() const noexcept { return Vector3{rotation[0], rotation[1], rotation[2]}; } - constexpr void set_scale(f32 x, f32 y, f32 z) noexcept + constexpr void setScale(const f32 x, const f32 y, const f32 z) noexcept { scale[0] = x; scale[1] = y; scale[2] = z; } - constexpr void set_scale(const Vector3& v) noexcept + constexpr void setScale(const Vector3& v) noexcept { scale[0] = v.x; scale[1] = v.y; scale[2] = v.z; } - [[nodiscard]] constexpr Vector3 get_scale() const noexcept { + [[nodiscard]] constexpr Vector3 getScale() const noexcept { return Vector3{scale[0], scale[1], scale[2]}; } // Compute column-major matrix from transform - void to_matrix(f32 out[16]) const; + void toMatrix(f32 out[16]) const; }; } diff --git a/Engine/cpp/runtime/core/math/types.cppm b/Engine/cpp/Runtime/Core/Math/Types.cppm similarity index 100% rename from Engine/cpp/runtime/core/math/types.cppm rename to Engine/cpp/Runtime/Core/Math/Types.cppm diff --git a/Engine/cpp/runtime/core/math/types_common.cppm b/Engine/cpp/Runtime/Core/Math/TypesCommon.cppm similarity index 91% rename from Engine/cpp/runtime/core/math/types_common.cppm rename to Engine/cpp/Runtime/Core/Math/TypesCommon.cppm index 4de2e55e..c9df0996 100644 --- a/Engine/cpp/runtime/core/math/types_common.cppm +++ b/Engine/cpp/Runtime/Core/Math/TypesCommon.cppm @@ -17,8 +17,8 @@ export namespace draco::math { [[nodiscard]] constexpr explicit Vector2(const Vector4& xy) noexcept; // static - [[nodiscard]] static constexpr Vector2 x_axis(f32 x = 1.0f) noexcept; - [[nodiscard]] static constexpr Vector2 y_axis(f32 y = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector2 xAxis(f32 x = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector2 yAxis(f32 y = 1.0f) noexcept; [[nodiscard]] static Vector2 polar(f32 angle, f32 radius = 1.0f) noexcept; // element access @@ -57,9 +57,9 @@ export namespace draco::math { [[nodiscard]] constexpr explicit Vector3(const Vector4& xyz) noexcept; // static - [[nodiscard]] static constexpr Vector3 x_axis(f32 x = 1.0f) noexcept; - [[nodiscard]] static constexpr Vector3 y_axis(f32 y = 1.0f) noexcept; - [[nodiscard]] static constexpr Vector3 z_axis(f32 z = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector3 xAxis(f32 x = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector3 yAxis(f32 y = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector3 zAxis(f32 z = 1.0f) noexcept; [[nodiscard]] static Vector3 spherical(f32 azimuth, f32 inclination, f32 radius = 1.0f) noexcept; [[nodiscard]] static Vector3 cylindrical(f32 angle, f32 radius = 1.0f, f32 height = 0.0f) noexcept; @@ -103,10 +103,10 @@ export namespace draco::math { [[nodiscard]] constexpr Vector4(f32 x, const Vector3& yzw) noexcept; // static - [[nodiscard]] static constexpr Vector4 x_axis(f32 x = 1.0f) noexcept; - [[nodiscard]] static constexpr Vector4 y_axis(f32 y = 1.0f) noexcept; - [[nodiscard]] static constexpr Vector4 z_axis(f32 z = 1.0f) noexcept; - [[nodiscard]] static constexpr Vector4 w_axis(f32 w = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector4 xAxis(f32 x = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector4 yAxis(f32 y = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector4 zAxis(f32 z = 1.0f) noexcept; + [[nodiscard]] static constexpr Vector4 wAxis(f32 w = 1.0f) noexcept; // element access [[nodiscard]] constexpr f32& operator[](i32 i) noexcept; diff --git a/Engine/cpp/runtime/core/math/vector2.cppm b/Engine/cpp/Runtime/Core/Math/Vector2.cppm similarity index 98% rename from Engine/cpp/runtime/core/math/vector2.cppm rename to Engine/cpp/Runtime/Core/Math/Vector2.cppm index fd0e1e31..cc1ccaa3 100644 --- a/Engine/cpp/runtime/core/math/vector2.cppm +++ b/Engine/cpp/Runtime/Core/Math/Vector2.cppm @@ -32,11 +32,11 @@ export namespace draco::math { : x{xy.x}, y{xy.y} { } // static - [[nodiscard]] constexpr Vector2 Vector2::x_axis(const f32 x) noexcept { + [[nodiscard]] constexpr Vector2 Vector2::xAxis(const f32 x) noexcept { return { x, 0.0f }; } - [[nodiscard]] constexpr Vector2 Vector2::y_axis(const f32 y) noexcept { + [[nodiscard]] constexpr Vector2 Vector2::yAxis(const f32 y) noexcept { return { 0.0f, y }; } diff --git a/Engine/cpp/runtime/core/math/vector3.cppm b/Engine/cpp/Runtime/Core/Math/Vector3.cppm similarity index 98% rename from Engine/cpp/runtime/core/math/vector3.cppm rename to Engine/cpp/Runtime/Core/Math/Vector3.cppm index fe8e8a2f..b7bc2cef 100644 --- a/Engine/cpp/runtime/core/math/vector3.cppm +++ b/Engine/cpp/Runtime/Core/Math/Vector3.cppm @@ -35,15 +35,15 @@ export namespace draco::math { : x{xyz.x}, y{xyz.y}, z{xyz.z} { } // static - [[nodiscard]] constexpr Vector3 Vector3::x_axis(const f32 x) noexcept { + [[nodiscard]] constexpr Vector3 Vector3::xAxis(const f32 x) noexcept { return { x, 0.0f, 0.0f }; } - [[nodiscard]] constexpr Vector3 Vector3::y_axis(const f32 y) noexcept { + [[nodiscard]] constexpr Vector3 Vector3::yAxis(const f32 y) noexcept { return { 0.0f, y, 0.0f }; } - [[nodiscard]] constexpr Vector3 Vector3::z_axis(const f32 z) noexcept { + [[nodiscard]] constexpr Vector3 Vector3::zAxis(const f32 z) noexcept { return { 0.0f, 0.0f, z }; } diff --git a/Engine/cpp/runtime/core/math/vector4.cppm b/Engine/cpp/Runtime/Core/Math/Vector4.cppm similarity index 98% rename from Engine/cpp/runtime/core/math/vector4.cppm rename to Engine/cpp/Runtime/Core/Math/Vector4.cppm index 850daef1..3733a407 100644 --- a/Engine/cpp/runtime/core/math/vector4.cppm +++ b/Engine/cpp/Runtime/Core/Math/Vector4.cppm @@ -47,19 +47,19 @@ export namespace draco::math { : x{x}, y{yzw.x}, z{yzw.y}, w{yzw.z} { } // static - [[nodiscard]] constexpr Vector4 Vector4::x_axis(const f32 x) noexcept { + [[nodiscard]] constexpr Vector4 Vector4::xAxis(const f32 x) noexcept { return { x, 0.0f, 0.0f, 0.0f }; } - [[nodiscard]] constexpr Vector4 Vector4::y_axis(const f32 y) noexcept { + [[nodiscard]] constexpr Vector4 Vector4::yAxis(const f32 y) noexcept { return { 0.0f, y, 0.0f, 0.0f }; } - [[nodiscard]] constexpr Vector4 Vector4::z_axis(const f32 z) noexcept { + [[nodiscard]] constexpr Vector4 Vector4::zAxis(const f32 z) noexcept { return { 0.0f, 0.0f, z, 0.0f }; } - [[nodiscard]] constexpr Vector4 Vector4::w_axis(const f32 w) noexcept { + [[nodiscard]] constexpr Vector4 Vector4::wAxis(const f32 w) noexcept { return { 0.0f, 0.0f, 0.0f, w }; } diff --git a/Engine/cpp/runtime/core/memory/allocator.cpp b/Engine/cpp/Runtime/Core/Memory/Allocator.cpp similarity index 96% rename from Engine/cpp/runtime/core/memory/allocator.cpp rename to Engine/cpp/Runtime/Core/Memory/Allocator.cpp index 6b7af67a..553cf5b9 100644 --- a/Engine/cpp/runtime/core/memory/allocator.cpp +++ b/Engine/cpp/Runtime/Core/Memory/Allocator.cpp @@ -1,6 +1,8 @@ module; +#ifdef DEBUG #include +#endif module core.memory.allocator; import core.stdtypes; diff --git a/Engine/cpp/runtime/core/memory/allocator.cppm b/Engine/cpp/Runtime/Core/Memory/Allocator.cppm similarity index 98% rename from Engine/cpp/runtime/core/memory/allocator.cppm rename to Engine/cpp/Runtime/Core/Memory/Allocator.cppm index 4d70177e..0b89fc0b 100644 --- a/Engine/cpp/runtime/core/memory/allocator.cppm +++ b/Engine/cpp/Runtime/Core/Memory/Allocator.cppm @@ -1,6 +1,8 @@ module; +#ifdef DEBUG #include +#endif export module core.memory.allocator; export import core.memory.slice; diff --git a/Engine/cpp/runtime/core/memory/bumpAllocator.cpp b/Engine/cpp/Runtime/Core/Memory/BumpAllocator.cpp similarity index 99% rename from Engine/cpp/runtime/core/memory/bumpAllocator.cpp rename to Engine/cpp/Runtime/Core/Memory/BumpAllocator.cpp index f131ea76..14bba71e 100644 --- a/Engine/cpp/runtime/core/memory/bumpAllocator.cpp +++ b/Engine/cpp/Runtime/Core/Memory/BumpAllocator.cpp @@ -4,7 +4,9 @@ module; #include #include #include +#ifdef DEBUG #include +#endif module core.memory.bumpAllocator; import core.stdtypes; diff --git a/Engine/cpp/runtime/core/memory/bumpAllocator.cppm b/Engine/cpp/Runtime/Core/Memory/BumpAllocator.cppm similarity index 98% rename from Engine/cpp/runtime/core/memory/bumpAllocator.cppm rename to Engine/cpp/Runtime/Core/Memory/BumpAllocator.cppm index 630b9ece..ecdb09ed 100644 --- a/Engine/cpp/runtime/core/memory/bumpAllocator.cppm +++ b/Engine/cpp/Runtime/Core/Memory/BumpAllocator.cppm @@ -1,7 +1,8 @@ module; -#include +#ifdef DEBUG #include +#endif export module core.memory.bumpAllocator; export import core.memory.allocator; diff --git a/Engine/cpp/runtime/core/memory/bumpAllocator.test.cpp b/Engine/cpp/Runtime/Core/Memory/BumpAllocator.test.cpp similarity index 100% rename from Engine/cpp/runtime/core/memory/bumpAllocator.test.cpp rename to Engine/cpp/Runtime/Core/Memory/BumpAllocator.test.cpp diff --git a/Engine/cpp/runtime/core/memory/fixedAllocator.cpp b/Engine/cpp/Runtime/Core/Memory/FixedAllocator.cpp similarity index 98% rename from Engine/cpp/runtime/core/memory/fixedAllocator.cpp rename to Engine/cpp/Runtime/Core/Memory/FixedAllocator.cpp index 899f268a..ffd5ad49 100644 --- a/Engine/cpp/runtime/core/memory/fixedAllocator.cpp +++ b/Engine/cpp/Runtime/Core/Memory/FixedAllocator.cpp @@ -2,7 +2,9 @@ module; #include #include +#ifdef DEBUG #include +#endif module core.memory.fixedAllocator; import core.stdtypes; diff --git a/Engine/cpp/runtime/core/memory/fixedAllocator.cppm b/Engine/cpp/Runtime/Core/Memory/FixedAllocator.cppm similarity index 97% rename from Engine/cpp/runtime/core/memory/fixedAllocator.cppm rename to Engine/cpp/Runtime/Core/Memory/FixedAllocator.cppm index 63f5aebd..e45954a5 100644 --- a/Engine/cpp/runtime/core/memory/fixedAllocator.cppm +++ b/Engine/cpp/Runtime/Core/Memory/FixedAllocator.cppm @@ -1,7 +1,8 @@ module; -#include +#ifdef DEBUG #include +#endif export module core.memory.fixedAllocator; export import core.memory.allocator; diff --git a/Engine/cpp/runtime/core/memory/fixedAllocator.test.cpp b/Engine/cpp/Runtime/Core/Memory/FixedAllocator.test.cpp similarity index 100% rename from Engine/cpp/runtime/core/memory/fixedAllocator.test.cpp rename to Engine/cpp/Runtime/Core/Memory/FixedAllocator.test.cpp diff --git a/Engine/cpp/runtime/core/memory/handle.cppm b/Engine/cpp/Runtime/Core/Memory/Handle.cppm similarity index 92% rename from Engine/cpp/runtime/core/memory/handle.cppm rename to Engine/cpp/Runtime/Core/Memory/Handle.cppm index 00ff70d7..a7f92a5d 100644 --- a/Engine/cpp/runtime/core/memory/handle.cppm +++ b/Engine/cpp/Runtime/Core/Memory/Handle.cppm @@ -17,12 +17,12 @@ export namespace draco::core::memory constexpr Handle() = default; constexpr explicit Handle(u32 v) : value(v) {} - constexpr u16 index() const + [[nodiscard]] constexpr u16 index() const { return static_cast(value & 0xFFFF); } - constexpr u16 generation() const + [[nodiscard]] constexpr u16 generation() const { return static_cast(value >> 16); } diff --git a/Engine/cpp/runtime/core/memory/handle_registry.cppm b/Engine/cpp/Runtime/Core/Memory/HandleRegistry.cppm similarity index 94% rename from Engine/cpp/runtime/core/memory/handle_registry.cppm rename to Engine/cpp/Runtime/Core/Memory/HandleRegistry.cppm index 6545d427..b61b8936 100644 --- a/Engine/cpp/runtime/core/memory/handle_registry.cppm +++ b/Engine/cpp/Runtime/Core/Memory/HandleRegistry.cppm @@ -18,7 +18,7 @@ export namespace draco::core::memory return storage.create(value); } - bool valid(HandleType h) const + [[nodiscard]] bool valid(HandleType h) const { return storage.valid(h); } diff --git a/Engine/cpp/runtime/core/memory/root.cppm b/Engine/cpp/Runtime/Core/Memory/Memory.cppm similarity index 100% rename from Engine/cpp/runtime/core/memory/root.cppm rename to Engine/cpp/Runtime/Core/Memory/Memory.cppm diff --git a/Engine/cpp/runtime/core/memory/pageAllocator.cpp b/Engine/cpp/Runtime/Core/Memory/PageAllocator.cpp similarity index 99% rename from Engine/cpp/runtime/core/memory/pageAllocator.cpp rename to Engine/cpp/Runtime/Core/Memory/PageAllocator.cpp index de82bede..f2429580 100644 --- a/Engine/cpp/runtime/core/memory/pageAllocator.cpp +++ b/Engine/cpp/Runtime/Core/Memory/PageAllocator.cpp @@ -1,6 +1,8 @@ module; +#ifdef DEBUG #include +#endif #ifdef __unix__ #include #include diff --git a/Engine/cpp/runtime/core/memory/pageAllocator.cppm b/Engine/cpp/Runtime/Core/Memory/PageAllocator.cppm similarity index 96% rename from Engine/cpp/runtime/core/memory/pageAllocator.cppm rename to Engine/cpp/Runtime/Core/Memory/PageAllocator.cppm index 6a8ee2ea..51730cd9 100644 --- a/Engine/cpp/runtime/core/memory/pageAllocator.cppm +++ b/Engine/cpp/Runtime/Core/Memory/PageAllocator.cppm @@ -1,6 +1,8 @@ module; +#ifdef DEBUG #include +#endif export module core.memory.pageAllocator; export import core.memory.allocator; diff --git a/Engine/cpp/runtime/core/memory/slice.cppm b/Engine/cpp/Runtime/Core/Memory/Slice.cppm similarity index 100% rename from Engine/cpp/runtime/core/memory/slice.cppm rename to Engine/cpp/Runtime/Core/Memory/Slice.cppm diff --git a/Engine/cpp/runtime/core/memory/slot_array.cppm b/Engine/cpp/Runtime/Core/Memory/SlotArray.cppm similarity index 100% rename from Engine/cpp/runtime/core/memory/slot_array.cppm rename to Engine/cpp/Runtime/Core/Memory/SlotArray.cppm diff --git a/Engine/cpp/runtime/core/memory/trackingAllocator.cpp b/Engine/cpp/Runtime/Core/Memory/TrackingAllocator.cpp similarity index 100% rename from Engine/cpp/runtime/core/memory/trackingAllocator.cpp rename to Engine/cpp/Runtime/Core/Memory/TrackingAllocator.cpp diff --git a/Engine/cpp/runtime/core/memory/trackingAllocator.cppm b/Engine/cpp/Runtime/Core/Memory/TrackingAllocator.cppm similarity index 98% rename from Engine/cpp/runtime/core/memory/trackingAllocator.cppm rename to Engine/cpp/Runtime/Core/Memory/TrackingAllocator.cppm index 349e14e8..39979593 100644 --- a/Engine/cpp/runtime/core/memory/trackingAllocator.cppm +++ b/Engine/cpp/Runtime/Core/Memory/TrackingAllocator.cppm @@ -1,6 +1,8 @@ module; +#ifdef DEBUG #include +#endif export module core.memory.trackingAllocator; export import core.memory.allocator; diff --git a/Engine/cpp/runtime/core/memory/trackingAllocator.test.cpp b/Engine/cpp/Runtime/Core/Memory/TrackingAllocator.test.cpp similarity index 100% rename from Engine/cpp/runtime/core/memory/trackingAllocator.test.cpp rename to Engine/cpp/Runtime/Core/Memory/TrackingAllocator.test.cpp diff --git a/Engine/cpp/runtime/core/definitions/version.cppm b/Engine/cpp/Runtime/Core/Version.cppm similarity index 92% rename from Engine/cpp/runtime/core/definitions/version.cppm rename to Engine/cpp/Runtime/Core/Version.cppm index fd1034df..0ade113c 100644 --- a/Engine/cpp/runtime/core/definitions/version.cppm +++ b/Engine/cpp/Runtime/Core/Version.cppm @@ -8,9 +8,9 @@ import core.stdtypes; export namespace draco { struct Version { - u16 major; - u16 minor; - u16 patch; + u16 major = 0; + u16 minor = 0; + u16 patch = 0; }; constexpr Version VERSION{.major = 2026, .minor = 0, .patch = 0}; diff --git a/Engine/cpp/runtime/draconic.cppm b/Engine/cpp/Runtime/Draconic.cppm similarity index 100% rename from Engine/cpp/runtime/draconic.cppm rename to Engine/cpp/Runtime/Draconic.cppm diff --git a/Engine/cpp/runtime/input/input.cpp b/Engine/cpp/Runtime/Input/Input.cpp similarity index 74% rename from Engine/cpp/runtime/input/input.cpp rename to Engine/cpp/Runtime/Input/Input.cpp index 3cf8bf83..5982de82 100644 --- a/Engine/cpp/runtime/input/input.cpp +++ b/Engine/cpp/Runtime/Input/Input.cpp @@ -30,47 +30,47 @@ namespace draco::input } } - void begin_frame() + void beginFrame() { g_mouse_dx = 0; g_mouse_dy = 0; } - void end_frame() + void endFrame() { } - void set_key(Key key, bool down) + void setKey(Key key, bool down) { if (key == Key::Invalid) return; g_keys[(u16)key] = down; } - bool is_down(Key key) + bool isDown(Key key) { return g_keys[(u16)key]; } - void process_event(const SDL_Event& e) + void processEvent(const SDL_Event& e) { switch (e.type) { case SDL_EVENT_KEY_DOWN: - set_key(map_sdl_key(e.key.key), true); + setKey(map_sdl_key(e.key.key), true); break; case SDL_EVENT_KEY_UP: - set_key(map_sdl_key(e.key.key), false); + setKey(map_sdl_key(e.key.key), false); break; case SDL_EVENT_MOUSE_MOTION: - set_mouse_delta((f32)e.motion.xrel, (f32)e.motion.yrel); + setMouseDelta((f32)e.motion.xrel, (f32)e.motion.yrel); break; } } - void set_mouse_captured(SDL_Window* window, bool enabled) + void setMouseCaptured(SDL_Window* window, bool enabled) { g_mouse_captured = enabled; @@ -78,22 +78,22 @@ namespace draco::input SDL_SetWindowMouseGrab(window, enabled); } - bool is_mouse_captured() + bool isMouseCaptured() { return g_mouse_captured; } - void set_mouse_delta(f32 dx, f32 dy) + void setMouseDelta(f32 dx, f32 dy) { g_mouse_dx += dx; g_mouse_dy += dy; } - f32 get_mouse_dx() { + f32 getMouseDx() { return g_mouse_dx; } - f32 get_mouse_dy() { + f32 getMouseDy() { return g_mouse_dy; } } \ No newline at end of file diff --git a/Engine/cpp/runtime/input/input.cppm b/Engine/cpp/Runtime/Input/Input.cppm similarity index 52% rename from Engine/cpp/runtime/input/input.cppm rename to Engine/cpp/Runtime/Input/Input.cppm index 7ce81a75..268e3f12 100644 --- a/Engine/cpp/runtime/input/input.cppm +++ b/Engine/cpp/Runtime/Input/Input.cppm @@ -1,6 +1,5 @@ module; -#include #include export module input; @@ -20,19 +19,19 @@ export namespace draco::input }; // Note: This isn't the same as RHI - void begin_frame(); - void end_frame(); + void beginFrame(); + void endFrame(); - void set_key(Key key, bool down); - bool is_down(Key key); + void setKey(Key key, bool down); + bool isDown(Key key); - void process_event(const SDL_Event& e); + void processEvent(const SDL_Event& e); - void set_mouse_captured(SDL_Window* window, bool enabled); - bool is_mouse_captured(); + void setMouseCaptured(SDL_Window* window, bool enabled); + bool isMouseCaptured(); - void set_mouse_delta(f32 dx, f32 dy); + void setMouseDelta(f32 dx, f32 dy); - f32 get_mouse_dx(); - f32 get_mouse_dy(); + f32 getMouseDx(); + f32 getMouseDy(); } \ No newline at end of file diff --git a/Engine/cpp/runtime/platform/CMakeLists.txt b/Engine/cpp/Runtime/Platform/CMakeLists.txt similarity index 100% rename from Engine/cpp/runtime/platform/CMakeLists.txt rename to Engine/cpp/Runtime/Platform/CMakeLists.txt diff --git a/Engine/cpp/runtime/platform/platform.cppm b/Engine/cpp/Runtime/Platform/Platform.cppm similarity index 54% rename from Engine/cpp/runtime/platform/platform.cppm rename to Engine/cpp/Runtime/Platform/Platform.cppm index 6ee8a0ef..9e1fc413 100644 --- a/Engine/cpp/runtime/platform/platform.cppm +++ b/Engine/cpp/Runtime/Platform/Platform.cppm @@ -1,6 +1,6 @@ module; -#include "impl/platform_impl.h" +#include "platform_impl.h" export module platform; @@ -9,7 +9,7 @@ export namespace draco::platform { using NativeWindowType = impl::NativeWindowType; using NativeWindowFrame = impl::NativeWindowFrame; - NativeWindowFrame get_native_handles(void* sdl_window_ptr) { - return impl::get_native_handles(sdl_window_ptr); + NativeWindowFrame getNativeHandles(void* sdl_window_ptr) { + return impl::getNativeHandles(sdl_window_ptr); } } diff --git a/Engine/cpp/runtime/platform/cpu/cpu_info.h b/Engine/cpp/Runtime/Platform/cpu/cpu_info.h similarity index 100% rename from Engine/cpp/runtime/platform/cpu/cpu_info.h rename to Engine/cpp/Runtime/Platform/cpu/cpu_info.h diff --git a/Engine/cpp/runtime/platform/cpu/cpu_info_neon.cpp b/Engine/cpp/Runtime/Platform/cpu/cpu_info_neon.cpp similarity index 100% rename from Engine/cpp/runtime/platform/cpu/cpu_info_neon.cpp rename to Engine/cpp/Runtime/Platform/cpu/cpu_info_neon.cpp diff --git a/Engine/cpp/runtime/platform/cpu/cpu_info_x64.cpp b/Engine/cpp/Runtime/Platform/cpu/cpu_info_x64.cpp similarity index 100% rename from Engine/cpp/runtime/platform/cpu/cpu_info_x64.cpp rename to Engine/cpp/Runtime/Platform/cpu/cpu_info_x64.cpp diff --git a/Engine/cpp/runtime/platform/impl/CMakeLists.txt b/Engine/cpp/Runtime/Platform/impl/CMakeLists.txt similarity index 80% rename from Engine/cpp/runtime/platform/impl/CMakeLists.txt rename to Engine/cpp/Runtime/Platform/impl/CMakeLists.txt index 3a6608ad..dd7743f4 100644 --- a/Engine/cpp/runtime/platform/impl/CMakeLists.txt +++ b/Engine/cpp/Runtime/Platform/impl/CMakeLists.txt @@ -16,14 +16,14 @@ else() endif() endif() -add_library(platform_impl STATIC +add_library(Platform_impl STATIC ${PLATFORM_SRC} ) -target_include_directories(platform_impl +target_include_directories(Platform_impl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} INTERFACE $ ) -target_link_libraries(platform_impl PUBLIC SDL3::SDL3-static PRIVATE ${PLATFORM_DEPS}) +target_link_libraries(Platform_impl PUBLIC SDL3::SDL3-static PRIVATE ${PLATFORM_DEPS}) if(DRACO_HAS_WAYLAND) - target_compile_definitions(platform_impl PRIVATE DRACO_HAS_WAYLAND=1) + target_compile_definitions(Platform_impl PRIVATE DRACO_HAS_WAYLAND=1) endif() \ No newline at end of file diff --git a/Engine/cpp/runtime/platform/impl/linux/linux.cpp b/Engine/cpp/Runtime/Platform/impl/linux/linux.cpp similarity index 95% rename from Engine/cpp/runtime/platform/impl/linux/linux.cpp rename to Engine/cpp/Runtime/Platform/impl/linux/linux.cpp index c917791a..bb3bd8a3 100644 --- a/Engine/cpp/runtime/platform/impl/linux/linux.cpp +++ b/Engine/cpp/Runtime/Platform/impl/linux/linux.cpp @@ -8,7 +8,7 @@ #include namespace draco::platform::impl { - NativeWindowFrame get_native_handles(void* sdl_window_ptr) { + NativeWindowFrame getNativeHandles(void* sdl_window_ptr) { SDL_Window* window = static_cast(sdl_window_ptr); NativeWindowFrame frame; diff --git a/Engine/cpp/runtime/platform/impl/mac/mac.mm b/Engine/cpp/Runtime/Platform/impl/mac/mac.mm similarity index 89% rename from Engine/cpp/runtime/platform/impl/mac/mac.mm rename to Engine/cpp/Runtime/Platform/impl/mac/mac.mm index 31cbae88..9476d8ee 100644 --- a/Engine/cpp/runtime/platform/impl/mac/mac.mm +++ b/Engine/cpp/Runtime/Platform/impl/mac/mac.mm @@ -3,7 +3,7 @@ #include namespace draco::platform::impl { - NativeWindowFrame get_native_handles(void* sdl_window_ptr) { + NativeWindowFrame getNativeHandles(void* sdl_window_ptr) { SDL_Window* window = static_cast(sdl_window_ptr); NativeWindowFrame frame; diff --git a/Engine/cpp/runtime/platform/impl/platform_impl.h b/Engine/cpp/Runtime/Platform/impl/platform_impl.h similarity index 88% rename from Engine/cpp/runtime/platform/impl/platform_impl.h rename to Engine/cpp/Runtime/Platform/impl/platform_impl.h index 58159ac8..ef5c8be8 100644 --- a/Engine/cpp/runtime/platform/impl/platform_impl.h +++ b/Engine/cpp/Runtime/Platform/impl/platform_impl.h @@ -25,5 +25,5 @@ namespace draco::platform::impl { NativeWindowType type = NativeWindowType::None; // Track the type of the native window }; - NativeWindowFrame get_native_handles(void* sdl_window_ptr); + NativeWindowFrame getNativeHandles(void* sdl_window_ptr); } \ No newline at end of file diff --git a/Engine/cpp/runtime/platform/impl/win32/win32.cpp b/Engine/cpp/Runtime/Platform/impl/win32/win32.cpp similarity index 91% rename from Engine/cpp/runtime/platform/impl/win32/win32.cpp rename to Engine/cpp/Runtime/Platform/impl/win32/win32.cpp index fe89073d..30e98008 100644 --- a/Engine/cpp/runtime/platform/impl/win32/win32.cpp +++ b/Engine/cpp/Runtime/Platform/impl/win32/win32.cpp @@ -3,7 +3,7 @@ #include namespace draco::platform::impl { - NativeWindowFrame get_native_handles(void* sdl_window_ptr) { + NativeWindowFrame getNativeHandles(void* sdl_window_ptr) { SDL_Window* window = static_cast(sdl_window_ptr); NativeWindowFrame frame; diff --git a/Engine/cpp/runtime/platform/simd.h b/Engine/cpp/Runtime/Platform/simd.h similarity index 100% rename from Engine/cpp/runtime/platform/simd.h rename to Engine/cpp/Runtime/Platform/simd.h diff --git a/Engine/cpp/Runtime/Rendering/CMakeLists.txt b/Engine/cpp/Runtime/Rendering/CMakeLists.txt new file mode 100644 index 00000000..c91557e3 --- /dev/null +++ b/Engine/cpp/Runtime/Rendering/CMakeLists.txt @@ -0,0 +1,13 @@ +add_modules_library(RHI PIC) +add_modules_library(RenderGraph) +add_modules_library(Renderer PIC) +add_modules_library(Mesh) +add_modules_library(Material) +add_modules_library(QuadRenderer) + +target_link_libraries(RHI PUBLIC Core Platform bgfx bx) +target_link_libraries(RenderGraph PUBLIC RHI bx) +target_link_libraries(Mesh PUBLIC RHI Core) +target_link_libraries(Material PUBLIC RHI) +target_link_libraries(QuadRenderer PUBLIC RHI RenderGraph bgfx bx) +target_link_libraries(Renderer PUBLIC Core RHI RenderGraph Mesh QuadRenderer Material bgfx bx) \ No newline at end of file diff --git a/Engine/cpp/runtime/rendering/material/material.cppm b/Engine/cpp/Runtime/Rendering/Material/Material.cppm similarity index 90% rename from Engine/cpp/runtime/rendering/material/material.cppm rename to Engine/cpp/Runtime/Rendering/Material/Material.cppm index b531766a..20605bd9 100644 --- a/Engine/cpp/runtime/rendering/material/material.cppm +++ b/Engine/cpp/Runtime/Rendering/Material/Material.cppm @@ -11,14 +11,14 @@ export namespace draco::rendering::material { struct Uniform { - u32 name_hash = 0; + u32 nameHash = 0; const void* data = nullptr; u16 count = 1; }; struct Material { - u32 shader_id = 0; + u32 shaderId = 0; rhi::PipelineHandle pipeline = rhi::InvalidPipeline; diff --git a/Engine/cpp/runtime/rendering/mesh/mesh.cpp b/Engine/cpp/Runtime/Rendering/Mesh/Mesh.cpp similarity index 78% rename from Engine/cpp/runtime/rendering/mesh/mesh.cpp rename to Engine/cpp/Runtime/Rendering/Mesh/Mesh.cpp index 77f72423..3f1e5b60 100644 --- a/Engine/cpp/runtime/rendering/mesh/mesh.cpp +++ b/Engine/cpp/Runtime/Rendering/Mesh/Mesh.cpp @@ -17,24 +17,24 @@ namespace draco::rendering::mesh using namespace draco::rendering; static std::unordered_map g_mesh_cache; - static draco::core::memory::HandleRegistry g_meshes; + static core::memory::HandleRegistry g_meshes; static rhi::LayoutHandle g_mesh_layout = rhi::InvalidLayout; - static usize hash_combine(usize a, usize b) + static usize hashCombine(usize a, usize b) { return a ^ (b + 0x9e3779b9 + (a << 6) + (a >> 2)); } - static usize hash_mesh_params(int a, int b = 0, f32 c = 0.0f) + static usize hashMeshParams(int a, int b = 0, f32 c = 0.0f) { usize h1 = std::hash{}(a); usize h2 = std::hash{}(b); usize h3 = std::hash{}(c); - return hash_combine(hash_combine(h1, h2), h3); + return hashCombine(hashCombine(h1, h2), h3); } - static void ensure_mesh_layout() + static void ensureMeshLayout() { if (g_mesh_layout != rhi::InvalidLayout) return; @@ -47,43 +47,43 @@ namespace draco::rendering::mesh { rhi::Attrib::TexCoord0,2, rhi::AttribType::Float } }; - g_mesh_layout = rhi::create_vertex_layout(desc); + g_mesh_layout = rhi::createVertexLayout(desc); } MeshHandle create(const void* vertex_data, u32 vertex_size, u32 vertex_count, const std::vector& indices, rhi::LayoutHandle layout) { Mesh mesh{}; - mesh.vbh = rhi::create_vertex_buffer(vertex_data, vertex_size, layout); - mesh.ibh = rhi::create_index_buffer(indices.data(), static_cast(indices.size() * sizeof(u32))); + mesh.vbh = rhi::createVertexBuffer(vertex_data, vertex_size, layout); + mesh.ibh = rhi::createIndexBuffer(indices.data(), static_cast(indices.size() * sizeof(u32))); mesh.layout = layout; - mesh.vertex_count = vertex_count; - mesh.index_count = static_cast(indices.size()); + mesh.vertexCount = vertex_count; + mesh.indexCount = static_cast(indices.size()); mesh.valid = (mesh.vbh != rhi::InvalidBuffer) && (mesh.ibh != rhi::InvalidBuffer); if (!mesh.valid) { - if (mesh.vbh != rhi::InvalidBuffer) rhi::destroy_buffer(mesh.vbh); - if (mesh.ibh != rhi::InvalidBuffer) rhi::destroy_buffer(mesh.ibh); + if (mesh.vbh != rhi::InvalidBuffer) rhi::destroyBuffer(mesh.vbh); + if (mesh.ibh != rhi::InvalidBuffer) rhi::destroyBuffer(mesh.ibh); return {}; } return g_meshes.create(mesh); } - MeshHandle create_cube() + MeshHandle createCube() { - ensure_mesh_layout(); + ensureMeshLayout(); usize key = 1; if (auto it = g_mesh_cache.find(key); it != g_mesh_cache.end()) return it->second; - auto v = gen::cube_vertices(); - auto i = gen::cube_indices(); + auto v = gen::cubeVertices(); + auto i = gen::cubeIndices(); MeshHandle h = create(v.data(), v.size()*sizeof(Vertex), (u32)v.size(), i, g_mesh_layout); @@ -91,17 +91,17 @@ namespace draco::rendering::mesh return h; } - MeshHandle create_plane(f32 size) + MeshHandle createPlane(f32 size) { - ensure_mesh_layout(); + ensureMeshLayout(); - usize key = hash_mesh_params(1000, 0, size); + usize key = hashMeshParams(1000, 0, size); if (auto it = g_mesh_cache.find(key); it != g_mesh_cache.end()) return it->second; - auto v = gen::plane_vertices(size); - auto i = gen::plane_indices(); + auto v = gen::planeVertices(size); + auto i = gen::planeIndices(); MeshHandle h = create(v.data(), v.size()*sizeof(Vertex), (u32)v.size(), i, g_mesh_layout); @@ -109,20 +109,20 @@ namespace draco::rendering::mesh return h; } - MeshHandle create_sphere(int segments, int rings) + MeshHandle createSphere(int segments, int rings) { if (segments < 3 || rings < 2) return {}; - ensure_mesh_layout(); + ensureMeshLayout(); - usize key = hash_combine(std::hash{}(segments), std::hash{}(rings)); + usize key = hashCombine(std::hash{}(segments), std::hash{}(rings)); if (auto it = g_mesh_cache.find(key); it != g_mesh_cache.end()) return it->second; - auto v = gen::sphere_vertices(segments, rings); - auto i = gen::sphere_indices(segments, rings); + auto v = gen::sphereVertices(segments, rings); + auto i = gen::sphereIndices(segments, rings); MeshHandle h = create(v.data(), v.size()*sizeof(Vertex), (u32)v.size(), i, g_mesh_layout); @@ -130,20 +130,20 @@ namespace draco::rendering::mesh return h; } - MeshHandle create_cylinder(int segments, f32 height) + MeshHandle createCylinder(int segments, f32 height) { if (segments < 3 || height < 0.0f) return {}; - ensure_mesh_layout(); + ensureMeshLayout(); - usize key = hash_mesh_params(2000, segments, height); + usize key = hashMeshParams(2000, segments, height); if (auto it = g_mesh_cache.find(key); it != g_mesh_cache.end()) return it->second; - auto v = gen::cylinder_vertices(segments, height); - auto i = gen::cylinder_indices(segments); + auto v = gen::cylinderVertices(segments, height); + auto i = gen::cylinderIndices(segments); MeshHandle h = create(v.data(), v.size()*sizeof(Vertex), (u32)v.size(), i, g_mesh_layout); @@ -151,19 +151,19 @@ namespace draco::rendering::mesh return h; } - MeshHandle create_capsule(int segments, int rings, f32 height) + MeshHandle createCapsule(int segments, int rings, f32 height) { if (segments < 3 || rings < 2 || height < 0.0f) return {}; - ensure_mesh_layout(); - usize key = hash_combine(hash_combine(std::hash{}(segments), std::hash{}(rings)), std::hash{}(height)); + ensureMeshLayout(); + usize key = hashCombine(hashCombine(std::hash{}(segments), std::hash{}(rings)), std::hash{}(height)); if (auto it = g_mesh_cache.find(key); it != g_mesh_cache.end()) return it->second; - auto v = gen::capsule_vertices(segments, rings, height); - auto i = gen::capsule_indices(segments, rings); + auto v = gen::capsuleVertices(segments, rings, height); + auto i = gen::capsuleIndices(segments, rings); MeshHandle h = create(v.data(), v.size()*sizeof(Vertex), (u32)v.size(), i, g_mesh_layout); @@ -176,8 +176,8 @@ namespace draco::rendering::mesh auto* mesh = g_meshes.get(handle); if (!mesh) return; - rhi::destroy_buffer(mesh->vbh); - rhi::destroy_buffer(mesh->ibh); + rhi::destroyBuffer(mesh->vbh); + rhi::destroyBuffer(mesh->ibh); // Remove from cache for (auto it = g_mesh_cache.begin(); it != g_mesh_cache.end(); ) @@ -204,7 +204,7 @@ namespace draco::rendering::mesh::gen return { px, py, pz, nx, ny, nz, u, v }; } - std::vector cube_vertices() + std::vector cubeVertices() { return { make(-1,-1, 1, 0,0,1, 0,0), @@ -239,7 +239,7 @@ namespace draco::rendering::mesh::gen }; } - std::vector cube_indices() + std::vector cubeIndices() { return { 0,1,2, 2,3,0, @@ -251,7 +251,7 @@ namespace draco::rendering::mesh::gen }; } - std::vector plane_vertices(f32 size) + std::vector planeVertices(f32 size) { f32 s = size * 0.5f; @@ -263,12 +263,12 @@ namespace draco::rendering::mesh::gen }; } - std::vector plane_indices() + std::vector planeIndices() { return { 0,1,2, 2,3,0 }; } - std::vector sphere_vertices(int segments, int rings) + std::vector sphereVertices(int segments, int rings) { std::vector v; @@ -293,7 +293,7 @@ namespace draco::rendering::mesh::gen return v; } - std::vector sphere_indices(int segments, int rings) + std::vector sphereIndices(int segments, int rings) { std::vector i; @@ -317,7 +317,7 @@ namespace draco::rendering::mesh::gen return i; } - std::vector cylinder_vertices(int segments, f32 height) + std::vector cylinderVertices(int segments, f32 height) { std::vector v; f32 half = height * 0.5f; @@ -356,7 +356,7 @@ namespace draco::rendering::mesh::gen return v; } - std::vector cylinder_indices(int segments) + std::vector cylinderIndices(int segments) { std::vector i; int side_start = 0; @@ -387,7 +387,7 @@ namespace draco::rendering::mesh::gen return i; } - std::vector capsule_vertices(int segments, int rings, f32 height) + std::vector capsuleVertices(int segments, int rings, f32 height) { std::vector v; f32 half = height * 0.5f; @@ -415,7 +415,7 @@ namespace draco::rendering::mesh::gen return v; } - std::vector capsule_indices(int segments, int rings) + std::vector capsuleIndices(int segments, int rings) { std::vector i; for (int r = 0; r < rings; r++) { diff --git a/Engine/cpp/Runtime/Rendering/Mesh/Mesh.cppm b/Engine/cpp/Runtime/Rendering/Mesh/Mesh.cppm new file mode 100644 index 00000000..fac985a9 --- /dev/null +++ b/Engine/cpp/Runtime/Rendering/Mesh/Mesh.cppm @@ -0,0 +1,71 @@ +module; + +#include + +export module rendering.mesh; + +import core.stdtypes; +import core.memory; +import rendering.rhi; + +export namespace draco::rendering::mesh +{ + struct MeshTag {}; + + using MeshHandle = core::memory::Handle; + + struct Vertex + { + f32 px, py, pz; + f32 nx, ny, nz; + f32 u, v; + }; + + struct Mesh + { + rhi::BufferHandle vbh; + rhi::BufferHandle ibh; + + rhi::LayoutHandle layout; + + u32 vertexCount = 0; + u32 indexCount = 0; + + bool valid = false; + }; + + MeshHandle create( + const void* vertexData, + u32 vertexSize, + u32 vertexCount, + const std::vector& indices, + rhi::LayoutHandle layout + ); + + MeshHandle createCube(); + MeshHandle createPlane(float size); + MeshHandle createSphere(int segments, int rings); + MeshHandle createCylinder(int segments, float height); + MeshHandle createCapsule(int segments, int rings, float height); + + void destroy(MeshHandle mesh); + const Mesh* get(MeshHandle mesh); +} + +export namespace draco::rendering::mesh::gen +{ + std::vector cubeVertices(); + std::vector cubeIndices(); + + std::vector planeVertices(float size); + std::vector planeIndices(); + + std::vector sphereVertices(int segments, int rings); + std::vector sphereIndices(int segments, int rings); + + std::vector cylinderVertices(int segments, float height); + std::vector cylinderIndices(int segments); + + std::vector capsuleVertices(int segments, int rings, float height); + std::vector capsuleIndices(int segments, int rings); +} diff --git a/Engine/cpp/runtime/rendering/quad_renderer/quad_renderer.cpp b/Engine/cpp/Runtime/Rendering/QuadRenderer/QuadRenderer.cpp similarity index 68% rename from Engine/cpp/runtime/rendering/quad_renderer/quad_renderer.cpp rename to Engine/cpp/Runtime/Rendering/QuadRenderer/QuadRenderer.cpp index 16478c51..ff67e855 100644 --- a/Engine/cpp/runtime/rendering/quad_renderer/quad_renderer.cpp +++ b/Engine/cpp/Runtime/Rendering/QuadRenderer/QuadRenderer.cpp @@ -6,14 +6,14 @@ module; #include #include -module rendering.quad_renderer; +module rendering.quad; import core.stdtypes; import rendering.rhi; import rendering.rhi.vertex; import rendering.rendergraph; -namespace draco::rendering::quad_renderer { +namespace draco::rendering::quad { static constexpr f32 QuadUV[4][2] = { {0.0f, 0.0f}, @@ -22,7 +22,7 @@ namespace draco::rendering::quad_renderer { {0.0f, 1.0f} }; - void QuadRenderer::init(draco::rendering::rhi::PipelineHandle pipeline) + void QuadRenderer::init(rhi::PipelineHandle pipeline) { using namespace draco::rendering::rhi; @@ -32,15 +32,15 @@ namespace draco::rendering::quad_renderer { layout.elements.push_back({Attrib::Color0, 4, AttribType::Uint8, true}); m_pipeline = pipeline; - m_layout = create_vertex_layout(layout); + m_layout = createVertexLayout(layout); // Allocating dynamic streaming buffers - m_vb = create_dynamic_vertex_buffer(sizeof(TexturedVertex) * MaxVertices, m_layout); + m_vb = createDynamicVertexBuffer(sizeof(TexturedVertex) * MaxVertices, m_layout); // Pass BGFX_BUFFER_NONE implicitly to match tracking - m_ib = create_dynamic_index_buffer(MaxIndices * sizeof(u16), BGFX_BUFFER_NONE); + m_ib = createDynamicIndexBuffer(MaxIndices * sizeof(u16), BGFX_BUFFER_NONE); - m_sampler = create_uniform("s_texColor", UniformType::Sampler); + m_sampler = createUniform("s_texColor", UniformType::Sampler); } void QuadRenderer::begin() @@ -74,12 +74,12 @@ namespace draco::rendering::quad_renderer { return; } - push_quad(cmd); + pushQuad(cmd); m_quad_count++; } - void QuadRenderer::push_quad(const QuadCommand& cmd) + void QuadRenderer::pushQuad(const QuadCommand& cmd) { f32 hw = cmd.width * 0.5f; f32 hh = cmd.height * 0.5f; @@ -125,7 +125,7 @@ namespace draco::rendering::quad_renderer { m_indices.push_back(start + 0); } - void QuadRenderer::flush_to_pass(draco::rendering::rendergraph::Pass& pass) + void QuadRenderer::flushToPass(draco::rendering::rendergraph::Pass& pass) { using namespace draco::rendering::rhi; @@ -133,20 +133,20 @@ namespace draco::rendering::quad_renderer { return; // Upload only the exact slices we are using this frame - update_dynamic_vertex_buffer(m_vb, 0, m_vertices.data(), static_cast(m_vertices.size() * sizeof(TexturedVertex))); - update_dynamic_index_buffer(m_ib, 0, m_indices.data(), static_cast(m_indices.size() * sizeof(u16))); + updateDynamicVertexBuffer(m_vb, 0, m_vertices.data(), static_cast(m_vertices.size() * sizeof(TexturedVertex))); + updateDynamicIndexBuffer(m_ib, 0, m_indices.data(), static_cast(m_indices.size() * sizeof(u16))); RenderPacket pkt{}; - pkt.vertex_buffer = m_vb; - pkt.index_buffer = m_ib; + pkt.vertexBuffer = m_vb; + pkt.indexBuffer = m_ib; pkt.pipeline = m_pipeline; - pkt.texture_handle = m_batch_key.texture; - pkt.sampler_uniform = m_sampler; + pkt.textureHandle = m_batch_key.texture; + pkt.samplerUniform = m_sampler; - pkt.vertex_count = static_cast(m_vertices.size()); - pkt.index_count = static_cast(m_indices.size()); + pkt.vertexCount = static_cast(m_vertices.size()); + pkt.indexCount = static_cast(m_indices.size()); - pkt.sort_key = make_sort_key(0, 0, static_cast(m_pipeline.value), static_cast(m_batch_key.texture.value), 0); + pkt.sortKey = makeSortKey(0, 0, static_cast(m_pipeline.value), static_cast(m_batch_key.texture.value), 0); bx::mtxIdentity(pkt.model); @@ -160,18 +160,18 @@ namespace draco::rendering::quad_renderer { { using namespace draco::rendering::rhi; - destroy_buffer(m_vb); - destroy_buffer(m_ib); + destroyBuffer(m_vb); + destroyBuffer(m_ib); - destroy_uniform(m_sampler); + destroyUniform(m_sampler); } - void QuadRenderer::build_ortho(OrthoCamera& cam, f32 width, f32 height) + void QuadRenderer::buildOrtho(OrthoCamera& cam, f32 width, f32 height) { using namespace draco::rendering::rhi; - identity_matrix(cam.view); - identity_matrix(cam.proj); + identityMatrix(cam.view); + identityMatrix(cam.proj); f32 rl = std::max(width, 1.0f); f32 tb = std::max(height, 1.0f); diff --git a/Engine/cpp/Runtime/Rendering/QuadRenderer/QuadRenderer.cppm b/Engine/cpp/Runtime/Rendering/QuadRenderer/QuadRenderer.cppm new file mode 100644 index 00000000..e3f72bc8 --- /dev/null +++ b/Engine/cpp/Runtime/Rendering/QuadRenderer/QuadRenderer.cppm @@ -0,0 +1,81 @@ +module; + +#include + +export module rendering.quad; + +import core.stdtypes; +import rendering.rhi; +import rendering.rhi.vertex; +import rendering.rendergraph; + +export namespace draco::rendering::quad { + + struct BatchKey { + rhi::TextureHandle texture = rhi::InvalidTexture; + + rhi::PipelineHandle pipeline = rhi::InvalidPipeline; + + rhi::SamplerHandle sampler = rhi::InvalidSampler; + + [[nodiscard]] bool operator==(const BatchKey&) const = default; + }; + + struct QuadCommand { + rhi::TextureHandle texture = rhi::InvalidTexture; + + f32 x = 0.0f; + f32 y = 0.0f; + f32 z = 0.0f; + + f32 width = 1.0f; + f32 height = 1.0f; + + f32 rotation = 0.0f; + + u32 color = 0xffffffff; + }; + + struct OrthoCamera { + f32 view[16]; + f32 proj[16]; + + f32 x = 0.0f; + f32 y = 0.0f; + f32 zoom = 1.0f; + }; + + class QuadRenderer { + public: + static constexpr u32 MaxQuads = 10000; + static constexpr u32 MaxVertices = MaxQuads * 4; + static constexpr u32 MaxIndices = MaxQuads * 6; + + void init(draco::rendering::rhi::PipelineHandle pipeline); + + void begin(); + + void submit(const QuadCommand& cmd); + + void flushToPass(rendergraph::Pass& pass); + + void shutdown(); + + static void buildOrtho(OrthoCamera& cam, f32 width, f32 height); + + private: + void pushQuad(const QuadCommand& cmd); + + BatchKey m_batch_key{}; + + std::vector m_vertices; + std::vector m_indices; + + rhi::BufferHandle m_vb = rhi::InvalidBuffer; + rhi::BufferHandle m_ib = rhi::InvalidBuffer; + rhi::LayoutHandle m_layout = rhi::InvalidLayout; + rhi::PipelineHandle m_pipeline = rhi::InvalidPipeline; + rhi::UniformHandle m_sampler = rhi::InvalidUniform; + u32 m_quad_count = 0; + }; +} diff --git a/Engine/cpp/runtime/rendering/rhi/buffers.cpp b/Engine/cpp/Runtime/Rendering/RHI/Buffers.cpp similarity index 64% rename from Engine/cpp/runtime/rendering/rhi/buffers.cpp rename to Engine/cpp/Runtime/Rendering/RHI/Buffers.cpp index d1e6d11b..fa65dac5 100644 --- a/Engine/cpp/runtime/rendering/rhi/buffers.cpp +++ b/Engine/cpp/Runtime/Rendering/RHI/Buffers.cpp @@ -10,12 +10,12 @@ import core.math.constants; namespace draco::rendering::rhi { - BufferHandle create_vertex_buffer(const void* data, u32 size, LayoutHandle layout_h) + BufferHandle createVertexBuffer(const void* data, u32 size, LayoutHandle layout_h) { RHI_ASSERT(data != nullptr, "Vertex buffer data is null"); RHI_ASSERT(size > 0, "Vertex buffer size is zero"); - auto* layout = get_checked(g_layouts, layout_h, "Layout"); + auto* layout = getChecked(g_layouts, layout_h, "Layout"); RHI_ASSERT(layout, "Invalid vertex layout"); @@ -27,7 +27,7 @@ namespace draco::rendering::rhi return g_buffers.create(buf); } - BufferHandle create_index_buffer(const void* data, u32 size) + BufferHandle createIndexBuffer(const void* data, u32 size) { RHI_ASSERT(data != nullptr, "Index buffer data is null"); RHI_ASSERT(size > 0, "Index buffer size is zero"); @@ -36,14 +36,14 @@ namespace draco::rendering::rhi Buffer buf; // Idk why I named it this, it just sounds funny ;) buf.ibh = ibh; - buf.is_index = true; + buf.isIndex = true; return g_buffers.create(buf); } - BufferHandle create_dynamic_vertex_buffer(u32 size, LayoutHandle layout_h) + BufferHandle createDynamicVertexBuffer(u32 size, LayoutHandle layout_h) { - auto* layout = get_checked(g_layouts, layout_h, "Layout"); + auto* layout = getChecked(g_layouts, layout_h, "Layout"); RHI_ASSERT(layout, "Invalid layout"); bgfx::DynamicVertexBufferHandle dvbh = bgfx::createDynamicVertexBuffer(size, layout->layout); @@ -52,19 +52,19 @@ namespace draco::rendering::rhi Buffer buf; buf.dvbh = dvbh; - buf.is_dynamic = true; + buf.isDynamic = true; return g_buffers.create(buf); } - void update_dynamic_vertex_buffer(BufferHandle handle, u32 start_vertex, const void* data, u32 size) + void updateDynamicVertexBuffer(BufferHandle handle, u32 start_vertex, const void* data, u32 size) { - auto* buf = get_checked(g_buffers, handle, "Buffer"); + auto* buf = getChecked(g_buffers, handle, "Buffer"); if (!buf) return; - RHI_ASSERT(buf->is_dynamic && !buf->is_index, "Not a dynamic vertex buffer"); + RHI_ASSERT(buf->isDynamic && !buf->isIndex, "Not a dynamic vertex buffer"); RHI_ASSERT(bgfx::isValid(buf->dvbh), "Invalid dynamic vertex buffer handle"); const bgfx::Memory* mem = bgfx::copy(data, size); @@ -72,28 +72,28 @@ namespace draco::rendering::rhi bgfx::update(buf->dvbh, start_vertex, mem); } - BufferHandle create_dynamic_index_buffer(u32 size, u16 flags) + BufferHandle createDynamicIndexBuffer(u32 size, u16 flags) { bgfx::DynamicIndexBufferHandle ibh = bgfx::createDynamicIndexBuffer(size, flags); RHI_ASSERT(bgfx::isValid(ibh), "Invalid dynamic index buffer handle"); Buffer buf{}; - buf.is_dynamic = true; - buf.is_index = true; + buf.isDynamic = true; + buf.isIndex = true; buf.dibh = ibh; return g_buffers.create(buf); } - void update_dynamic_index_buffer(BufferHandle handle, u32 start_index, const void* data, u32 size) + void updateDynamicIndexBuffer(BufferHandle handle, u32 start_index, const void* data, u32 size) { - auto* buf = get_checked(g_buffers, handle, "DynamicIndexBuffer"); + auto* buf = getChecked(g_buffers, handle, "DynamicIndexBuffer"); if (!buf) return; - RHI_ASSERT(buf->is_dynamic && buf->is_index, "Not a dynamic index buffer"); + RHI_ASSERT(buf->isDynamic && buf->isIndex, "Not a dynamic index buffer"); const bgfx::Memory* mem = bgfx::copy(data, size); diff --git a/Engine/cpp/runtime/rendering/rhi/commands.cpp b/Engine/cpp/Runtime/Rendering/RHI/Commands.cpp similarity index 60% rename from Engine/cpp/runtime/rendering/rhi/commands.cpp rename to Engine/cpp/Runtime/Rendering/RHI/Commands.cpp index 4b801158..c751d14c 100644 --- a/Engine/cpp/runtime/rendering/rhi/commands.cpp +++ b/Engine/cpp/Runtime/Rendering/RHI/Commands.cpp @@ -17,7 +17,7 @@ namespace draco::rendering::rhi bx::mtxProj(out, fov, aspect, nearp, farp, bgfx::getCaps()->homogeneousDepth); } - void look_at(f32* out, const f32* eye, const f32* at, const f32* up) + void lookAt(f32* out, const f32* eye, const f32* at, const f32* up) { bx::Vec3 eye_v { eye[0], eye[1], eye[2] }; bx::Vec3 at_v { at[0], at[1], at[2] }; @@ -27,15 +27,15 @@ namespace draco::rendering::rhi } // Note: Internal use only, use apply_view() instead - void set_view_rect(ViewID view, u16 x, u16 y, u16 w, u16 h) + void setViewRect(ViewID view, u16 x, u16 y, u16 w, u16 h) { bgfx::setViewRect(view, x, y, w, h); } // Note: Internal use only, use apply_view() instead - void set_view_framebuffer(ViewID view, FramebufferHandle h) + void setViewFramebuffer(ViewID view, FramebufferHandle h) { - auto* fb = get_checked(g_framebuffers, h, "Framebuffer"); + auto* fb = getChecked(g_framebuffers, h, "Framebuffer"); if (!fb) return; @@ -43,12 +43,12 @@ namespace draco::rendering::rhi bgfx::setViewFrameBuffer(view, fb->fbh); } - void set_view_projection(ViewID view, const f32* view_mtx, const f32* proj_mtx) + void setViewProjection(ViewID view, const f32* view_mtx, const f32* proj_mtx) { bgfx::setViewTransform(view, view_mtx, proj_mtx); } - void set_scissor(const ScissorRect& r) + void setScissor(const ScissorRect& r) { if (!r.enabled) bgfx::setScissor(math::UINT16_MAX_VAL); @@ -56,16 +56,16 @@ namespace draco::rendering::rhi bgfx::setScissor(r.x, r.y, r.w, r.h); } - void set_stencil(u32 fstencil, u32 bstencil) + void setStencil(u32 fstencil, u32 bstencil) { bgfx::setStencil(fstencil, bstencil); } - void apply_view(ViewID view, const ViewDesc& desc) + void applyView(ViewID view, const ViewDesc& desc) { if (desc.fb != InvalidFramebuffer) { - auto* fb = get_checked(g_framebuffers, desc.fb, "Framebuffer"); + auto* fb = getChecked(g_framebuffers, desc.fb, "Framebuffer"); if (fb && bgfx::isValid(fb->fbh)) { @@ -79,67 +79,67 @@ namespace draco::rendering::rhi bgfx::setViewRect(view, desc.x, desc.y, desc.w, desc.h); - if (desc.clear_flags != 0) + if (desc.clearFlags != 0) { - bgfx::setViewClear(view, desc.clear_flags, desc.clear_color); + bgfx::setViewClear(view, desc.clearFlags, desc.clearColor); } } - void identity_matrix(f32* mtx) + void identityMatrix(f32* mtx) { bx::mtxIdentity(mtx); } void submit(const RenderPacket& p, ViewID view) { - auto* pipeline = get_checked(g_pipelines, p.pipeline, "Pipeline"); - auto* vb = get_checked(g_buffers, p.vertex_buffer, "VertexBuffer"); + auto* pipeline = getChecked(g_pipelines, p.pipeline, "Pipeline"); + auto* vb = getChecked(g_buffers, p.vertexBuffer, "VertexBuffer"); Buffer* ib = nullptr; if (!pipeline || !vb) return; - if (p.index_buffer != InvalidBuffer) - ib = get_checked(g_buffers, p.index_buffer, "IndexBuffer"); + if (p.indexBuffer != InvalidBuffer) + ib = getChecked(g_buffers, p.indexBuffer, "IndexBuffer"); // Transform matrix (model) bgfx::setTransform(p.model); // Vertex buffer binding with explicit range control - if (vb->is_dynamic) + if (vb->isDynamic) { // If count is UINT32_MAX, bgfx will fallback to drawing the full buffer automatically - bgfx::setVertexBuffer(0, vb->dvbh, 0, p.vertex_count); + bgfx::setVertexBuffer(0, vb->dvbh, 0, p.vertexCount); } else { - bgfx::setVertexBuffer(0, vb->vbh, 0, p.vertex_count); + bgfx::setVertexBuffer(0, vb->vbh, 0, p.vertexCount); } // Index buffer binding with explicit range control - if (ib && ib->is_index) + if (ib && ib->isIndex) { - if (ib->is_dynamic) + if (ib->isDynamic) { - bgfx::setIndexBuffer(ib->dibh, 0, p.index_count); + bgfx::setIndexBuffer(ib->dibh, 0, p.indexCount); } else { - bgfx::setIndexBuffer(ib->ibh, 0, p.index_count); + bgfx::setIndexBuffer(ib->ibh, 0, p.indexCount); } } // Uniforms for (const auto& u : p.uniforms) { - if (auto* handle = get_checked(g_uniforms, u.handle, "UniformBind")) + if (auto* handle = getChecked(g_uniforms, u.handle, "UniformBind")) { bgfx::setUniform(*handle, u.data, u.num); } } // Texture binding - if (auto* tex = get_checked(g_textures, p.texture_handle, "Texture")) + if (auto* tex = getChecked(g_textures, p.textureHandle, "Texture")) { - if (auto* sampler = get_checked(g_uniforms, p.sampler_uniform, "Sampler")) + if (auto* sampler = getChecked(g_uniforms, p.samplerUniform, "Sampler")) { - bgfx::setTexture(p.texture_unit, *sampler, *tex, p.sampler_flags); + bgfx::setTexture(p.textureUnit, *sampler, *tex, p.samplerFlags); } } diff --git a/Engine/cpp/runtime/rendering/rhi/core.cpp b/Engine/cpp/Runtime/Rendering/RHI/Core.cpp similarity index 85% rename from Engine/cpp/runtime/rendering/rhi/core.cpp rename to Engine/cpp/Runtime/Rendering/RHI/Core.cpp index 91700d4a..cb5cc3e5 100644 --- a/Engine/cpp/runtime/rendering/rhi/core.cpp +++ b/Engine/cpp/Runtime/Rendering/RHI/Core.cpp @@ -31,7 +31,7 @@ namespace draco::rendering::rhi u16 g_width = 0; u16 g_height = 0; - void queue_destruction(std::function cb) + void queueDestruction(std::function cb) { g_deletion_queue.push_back({ bgfx::getStats()->gpuFrameNum, @@ -40,63 +40,63 @@ namespace draco::rendering::rhi } // Explicit overloads for each bgfx resource - void destroy_later(bgfx::ShaderHandle handle) + void destroyLater(bgfx::ShaderHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void destroy_later(bgfx::UniformHandle handle) + void destroyLater(bgfx::UniformHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void destroy_later(bgfx::VertexBufferHandle handle) + void destroyLater(bgfx::VertexBufferHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void destroy_later(bgfx::IndexBufferHandle handle) + void destroyLater(bgfx::IndexBufferHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void destroy_later(bgfx::DynamicVertexBufferHandle handle) + void destroyLater(bgfx::DynamicVertexBufferHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void destroy_later(bgfx::DynamicIndexBufferHandle handle) + void destroyLater(bgfx::DynamicIndexBufferHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void destroy_later(bgfx::TextureHandle handle) + void destroyLater(bgfx::TextureHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void destroy_later(bgfx::FrameBufferHandle handle) + void destroyLater(bgfx::FrameBufferHandle handle) { - queue_destruction([handle]() { + queueDestruction([handle]() { bgfx::destroy(handle); }); } - void process_deletions() + void processDeletions() { u64 frame = bgfx::getStats()->gpuFrameNum; @@ -205,29 +205,29 @@ namespace draco::rendering::rhi bgfx::shutdown(); } - void destroy_buffer(BufferHandle h) + void destroyBuffer(BufferHandle h) { - auto* buf = get_checked(g_buffers, h, "Buffer"); + auto* buf = getChecked(g_buffers, h, "Buffer"); if (!buf) return; if (bgfx::isValid(buf->vbh)) - destroy_later(buf->vbh); + destroyLater(buf->vbh); if (bgfx::isValid(buf->ibh)) - destroy_later(buf->ibh); + destroyLater(buf->ibh); if (bgfx::isValid(buf->dvbh)) - destroy_later(buf->dvbh); + destroyLater(buf->dvbh); if (bgfx::isValid(buf->dibh)) - destroy_later(buf->dibh); + destroyLater(buf->dibh); g_buffers.destroy(h); } - u64 map_state(PipelineState s, BlendMode blend, DepthTest depth, CullMode cull, bool depth_write) + u64 mapState(PipelineState s, BlendMode blend, DepthTest depth, CullMode cull, bool depth_write) { u64 state = 0; @@ -320,13 +320,13 @@ namespace draco::rendering::rhi return bgfx::AttribType::Float; } - void begin_frame() + void beginFrame() { // Clean up GPU resources safely - process_deletions(); + processDeletions(); } - void end_frame() + void endFrame() { // Submit frame to GPU bgfx::frame(); diff --git a/Engine/cpp/runtime/rendering/rhi/pipelines.cpp b/Engine/cpp/Runtime/Rendering/RHI/Pipelines.cpp similarity index 70% rename from Engine/cpp/runtime/rendering/rhi/pipelines.cpp rename to Engine/cpp/Runtime/Rendering/RHI/Pipelines.cpp index 15f70d32..ef711c23 100644 --- a/Engine/cpp/runtime/rendering/rhi/pipelines.cpp +++ b/Engine/cpp/Runtime/Rendering/RHI/Pipelines.cpp @@ -11,19 +11,19 @@ import core.math.constants; namespace draco::rendering::rhi { - PipelineHandle create_pipeline(const PipelineDesc& desc) + PipelineHandle createPipeline(const PipelineDesc& desc) { RHI_ASSERT(desc.vs != InvalidShader, "Pipeline missing vertex shader"); RHI_ASSERT(desc.fs != InvalidShader, "Pipeline missing fragment shader"); bgfx::ProgramHandle prog = bgfx::createProgram(resolve(desc.vs), resolve(desc.fs), true); - u64 state = map_state(desc.state, desc.blend, desc.depth, desc.cull, desc.depth_write); + u64 state = mapState(desc.state, desc.blend, desc.depth, desc.cull, desc.depthWrite); return g_pipelines.create({ prog, state }); } - LayoutHandle create_vertex_layout(const VertexLayoutDesc& desc) + LayoutHandle createVertexLayout(const VertexLayoutDesc& desc) { bgfx::VertexLayout layout; layout.begin(); @@ -38,7 +38,7 @@ namespace draco::rendering::rhi return g_layouts.create({ layout }); } - ShaderHandle create_shader(const void* data, u32 size) + ShaderHandle createShader(const void* data, u32 size) { RHI_ASSERT(data && size > 0, "Invalid shader data"); @@ -54,16 +54,16 @@ namespace draco::rendering::rhi } // For debugging/tooling - bgfx::ShaderHandle* get_shader_native(ShaderHandle h) + bgfx::ShaderHandle* getShaderNative(ShaderHandle h) { - return get_checked(g_shaders, h, "Shader"); + return getChecked(g_shaders, h, "Shader"); } - void destroy_shader(ShaderHandle h) + void destroyShader(ShaderHandle h) { - if (auto* sh = get_checked(g_shaders, h, "Shader")) + if (auto* sh = getChecked(g_shaders, h, "Shader")) { - destroy_later(*sh); + destroyLater(*sh); g_shaders.destroy(h); } } diff --git a/Engine/cpp/runtime/rendering/rhi/rhi.cppm b/Engine/cpp/Runtime/Rendering/RHI/RHI.cppm similarity index 65% rename from Engine/cpp/runtime/rendering/rhi/rhi.cppm rename to Engine/cpp/Runtime/Rendering/RHI/RHI.cppm index f750aaf2..10347ba8 100644 --- a/Engine/cpp/runtime/rendering/rhi/rhi.cppm +++ b/Engine/cpp/Runtime/Rendering/RHI/RHI.cppm @@ -66,8 +66,8 @@ export namespace draco::rendering::rhi struct ViewDesc { FramebufferHandle fb = InvalidFramebuffer; u16 x = 0, y = 0, w = 0, h = 0; - u32 clear_flags = 0; - u32 clear_color = 0; + u32 clearFlags = 0; + u32 clearColor = 0; }; enum class UniformType @@ -119,8 +119,8 @@ export namespace draco::rendering::rhi bgfx::DynamicVertexBufferHandle dvbh = BGFX_INVALID_HANDLE; bgfx::IndexBufferHandle ibh = BGFX_INVALID_HANDLE; bgfx::DynamicIndexBufferHandle dibh; - bool is_dynamic = false; - bool is_index = false; + bool isDynamic = false; + bool isIndex = false; }; struct FramebufferResource { @@ -153,28 +153,28 @@ export namespace draco::rendering::rhi DepthTest depth = DepthTest::Less; CullMode cull = CullMode::CCW; - bool depth_write = true; + bool depthWrite = true; }; struct RenderPacket { - u64 sort_key = 0; + u64 sortKey = 0; - BufferHandle vertex_buffer = InvalidBuffer; - BufferHandle index_buffer = InvalidBuffer; + BufferHandle vertexBuffer = InvalidBuffer; + BufferHandle indexBuffer = InvalidBuffer; PipelineHandle pipeline = InvalidPipeline; - u32 vertex_count = math::UINT32_MAX_VAL; - u32 index_count = math::UINT32_MAX_VAL; + u32 vertexCount = math::UINT32_MAX_VAL; + u32 indexCount = math::UINT32_MAX_VAL; - UniformHandle sampler_uniform = InvalidUniform; - SamplerHandle sampler_flags = InvalidSampler; - TextureHandle texture_handle = InvalidTexture; + UniformHandle samplerUniform = InvalidUniform; + SamplerHandle samplerFlags = InvalidSampler; + TextureHandle textureHandle = InvalidTexture; f32 color[4] = {1,1,1,1}; std::vector uniforms; - u8 texture_unit = 0; + u8 textureUnit = 0; f32 model[16] = { 1,0,0,0, @@ -183,7 +183,7 @@ export namespace draco::rendering::rhi 0,0,0,1 }; - u32 draw_tags = 0; + u32 drawTags = 0; }; struct Pipeline { @@ -191,75 +191,75 @@ export namespace draco::rendering::rhi u64 state; }; - bool init(void* display_type, void* window_handle, draco::platform::NativeWindowType window_type, u16 width, u16 height); + bool init(void* display_type, void* window_handle, platform::NativeWindowType window_type, u16 width, u16 height); void resize(u16 width, u16 height); void shutdown(); - PipelineHandle create_pipeline(const PipelineDesc&); + PipelineHandle createPipeline(const PipelineDesc&); - BufferHandle create_vertex_buffer(const void* data, u32 size, LayoutHandle layout_h); - BufferHandle create_index_buffer(const void* data, u32 size); - void destroy_buffer(BufferHandle handle); + BufferHandle createVertexBuffer(const void* data, u32 size, LayoutHandle layout_h); + BufferHandle createIndexBuffer(const void* data, u32 size); + void destroyBuffer(BufferHandle handle); - UniformHandle create_uniform(const char* name, UniformType type, u16 num = 1); - void destroy_uniform(UniformHandle handle); - void set_uniform(UniformHandle handle, const void* value, u16 num = 1); + UniformHandle createUniform(const char* name, UniformType type, u16 num = 1); + void destroyUniform(UniformHandle handle); + void setUniform(UniformHandle handle, const void* value, u16 num = 1); - TextureHandle create_texture(const void* data, u32 width, u32 height, u32 flags = 0); - void destroy_texture(TextureHandle handle); + TextureHandle createTexture(const void* data, u32 width, u32 height, u32 flags = 0); + void destroyTexture(TextureHandle handle); - FramebufferHandle create_framebuffer(u32 width, u32 height, TextureFormat format); - void destroy_framebuffer(FramebufferHandle handle); - TextureHandle get_framebuffer_texture(FramebufferHandle handle); + FramebufferHandle createFramebuffer(u32 width, u32 height, TextureFormat format); + void destroyFramebuffer(FramebufferHandle handle); + TextureHandle getFramebufferTexture(FramebufferHandle handle); - BufferHandle create_dynamic_vertex_buffer(u32 size, LayoutHandle layout); - void update_dynamic_vertex_buffer(BufferHandle handle, u32 start_vertex, const void* data, u32 size); + BufferHandle createDynamicVertexBuffer(u32 size, LayoutHandle layout); + void updateDynamicVertexBuffer(BufferHandle handle, u32 start_vertex, const void* data, u32 size); - BufferHandle create_dynamic_index_buffer(u32 size, u16 flags = BGFX_BUFFER_NONE); - void update_dynamic_index_buffer(BufferHandle handle, u32 start_index, const void* data, u32 size); + BufferHandle createDynamicIndexBuffer(u32 size, u16 flags = BGFX_BUFFER_NONE); + void updateDynamicIndexBuffer(BufferHandle handle, u32 start_index, const void* data, u32 size); - LayoutHandle create_vertex_layout(const VertexLayoutDesc& desc); + LayoutHandle createVertexLayout(const VertexLayoutDesc& desc); - SamplerHandle create_sampler(bool linear, bool clamp); + SamplerHandle createSampler(bool linear, bool clamp); // Expects bgfx compiled shader binary (shaderc output) - ShaderHandle create_shader(const void* data, u32 size); + ShaderHandle createShader(const void* data, u32 size); bgfx::ShaderHandle resolve(ShaderHandle h); // For debugging/tooling - bgfx::ShaderHandle* get_shader_native(ShaderHandle h); - void destroy_shader(ShaderHandle h); + bgfx::ShaderHandle* getShaderNative(ShaderHandle h); + void destroyShader(ShaderHandle h); void perspective(f32* out, f32 fov, f32 aspect, f32 nearp, f32 farp); - void look_at(f32* out, const f32* eye, const f32* at, const f32* up); + void lookAt(f32* out, const f32* eye, const f32* at, const f32* up); // Note: Internal use only, use apply_view() instead - void set_view_rect(ViewID view, u16 x, u16 y, u16 w, u16 h); - void set_view_framebuffer(ViewID view, FramebufferHandle handle); + void setViewRect(ViewID view, u16 x, u16 y, u16 w, u16 h); + void setViewFramebuffer(ViewID view, FramebufferHandle handle); - void set_view_projection(ViewID view, const f32* view_mtx, const f32* proj_mtx); - void set_scissor(const ScissorRect& r); - void set_stencil(u32 f_stencil, u32 b_stencil); + void setViewProjection(ViewID view, const f32* view_mtx, const f32* proj_mtx); + void setScissor(const ScissorRect& r); + void setStencil(u32 f_stencil, u32 b_stencil); - void apply_view(ViewID view, const ViewDesc& desc); + void applyView(ViewID view, const ViewDesc& desc); - void identity_matrix(f32* _mtx); + void identityMatrix(f32* _mtx); - u64 map_state(PipelineState s, BlendMode, DepthTest, CullMode, bool depth_write); + u64 mapState(PipelineState s, BlendMode, DepthTest, CullMode, bool depth_write); bgfx::UniformType::Enum map_uniform_type(UniformType t); bgfx::Attrib::Enum map_attrib(Attrib a); bgfx::AttribType::Enum map_attrib_type(AttribType t); void submit(const RenderPacket&, ViewID); - void begin_frame(); - void end_frame(); + void beginFrame(); + void endFrame(); template - void destroy_resource(T handle); + void destroyResource(T handle); - void process_deletions(); + void processDeletions(); - inline u64 make_sort_key(u8 layer, u8 pass, u16 pipeline, u16 texture, u16 depth = 0) + inline u64 makeSortKey(u8 layer, u8 pass, u16 pipeline, u16 texture, u16 depth = 0) { return (u64(layer) << 56) | (u64(pass) << 48) | (u64(pipeline) << 32) | (u64(texture) << 16) | u64(depth); } @@ -295,7 +295,7 @@ namespace draco::rendering::rhi // Ensures a handle is valid before use // TODO: Replace with something better template - auto* get_checked(Registry& reg, HandleT h, const char* name) + auto* getChecked(Registry& reg, HandleT h, const char* name) { if (!reg.valid(h)) { @@ -314,15 +314,15 @@ namespace draco::rendering::rhi // In a nutshell, they both rely on each other which is why we use this hack (AR-DEV-1) export namespace draco::rendering::rhi { - void queue_destruction(std::function cb); + void queueDestruction(std::function cb); // Explicit overloads for each bgfx resource type - void destroy_later(bgfx::ShaderHandle handle); - void destroy_later(bgfx::UniformHandle handle); - void destroy_later(bgfx::VertexBufferHandle handle); - void destroy_later(bgfx::IndexBufferHandle handle); - void destroy_later(bgfx::DynamicVertexBufferHandle handle); - void destroy_later(bgfx::DynamicIndexBufferHandle handle); - void destroy_later(bgfx::TextureHandle handle); - void destroy_later(bgfx::FrameBufferHandle handle); + void destroyLater(bgfx::ShaderHandle handle); + void destroyLater(bgfx::UniformHandle handle); + void destroyLater(bgfx::VertexBufferHandle handle); + void destroyLater(bgfx::IndexBufferHandle handle); + void destroyLater(bgfx::DynamicVertexBufferHandle handle); + void destroyLater(bgfx::DynamicIndexBufferHandle handle); + void destroyLater(bgfx::TextureHandle handle); + void destroyLater(bgfx::FrameBufferHandle handle); } diff --git a/Engine/cpp/runtime/rendering/rhi/texture.cpp b/Engine/cpp/Runtime/Rendering/RHI/Texture.cpp similarity index 73% rename from Engine/cpp/runtime/rendering/rhi/texture.cpp rename to Engine/cpp/Runtime/Rendering/RHI/Texture.cpp index 346eb6c3..4a9193ce 100644 --- a/Engine/cpp/runtime/rendering/rhi/texture.cpp +++ b/Engine/cpp/Runtime/Rendering/RHI/Texture.cpp @@ -10,7 +10,7 @@ import core.math.constants; namespace draco::rendering::rhi { - UniformHandle create_uniform(const char* name, UniformType type, u16 num) + UniformHandle createUniform(const char* name, UniformType type, u16 num) { RHI_ASSERT(name != nullptr, "Uniform name is null"); @@ -18,9 +18,9 @@ namespace draco::rendering::rhi return g_uniforms.create(u); } - void set_uniform(UniformHandle h, const void* data, u16 num) + void setUniform(UniformHandle h, const void* data, u16 num) { - auto* u = get_checked(g_uniforms, h, "Uniform"); + auto* u = getChecked(g_uniforms, h, "Uniform"); if (!u) return; RHI_ASSERT(data != nullptr, "Uniform data is null"); @@ -28,16 +28,16 @@ namespace draco::rendering::rhi bgfx::setUniform(*u, data, num); } - void destroy_uniform(UniformHandle h) + void destroyUniform(UniformHandle h) { - auto* u = get_checked(g_uniforms, h, "Uniform"); + auto* u = getChecked(g_uniforms, h, "Uniform"); if (!u) return; - destroy_later(*u); + destroyLater(*u); g_uniforms.destroy(h); } - TextureHandle create_texture(const void* data, u32 w, u32 h, u32 flags) + TextureHandle createTexture(const void* data, u32 w, u32 h, u32 flags) { RHI_ASSERT(data != nullptr, "Texture data is null"); RHI_ASSERT(w > 0 && h > 0, "Invalid texture dimensions"); @@ -52,16 +52,16 @@ namespace draco::rendering::rhi return g_textures.create(tex); } - void destroy_texture(TextureHandle h) + void destroyTexture(TextureHandle h) { - auto* tex = get_checked(g_textures, h, "Texture"); + auto* tex = getChecked(g_textures, h, "Texture"); if (!tex) return; - destroy_later(*tex); + destroyLater(*tex); g_textures.destroy(h); } - FramebufferHandle create_framebuffer(u32 width, u32 height, TextureFormat format) + FramebufferHandle createFramebuffer(u32 width, u32 height, TextureFormat format) { // We set render target flags so it can be attached to a framebuffer object u64 flags = BGFX_TEXTURE_RT | BGFX_SAMPLER_U_CLAMP | BGFX_SAMPLER_V_CLAMP; @@ -80,7 +80,7 @@ namespace draco::rendering::rhi { RHI_WARN(false, "Failed to construct native bgfx Framebuffer target!"); // Roll back the allocated texture if the framebuffer generation bricks - destroy_texture(color_tex_h); + destroyTexture(color_tex_h); return InvalidFramebuffer; } @@ -91,19 +91,19 @@ namespace draco::rendering::rhi return g_framebuffers.create(res); } - void destroy_framebuffer(FramebufferHandle handle) + void destroyFramebuffer(FramebufferHandle handle) { - if (auto* fb = get_checked(g_framebuffers, handle, "Framebuffer")) + if (auto* fb = getChecked(g_framebuffers, handle, "Framebuffer")) { // Safely queue the native hardware framebuffer destruction 2 frames out - destroy_later(fb->fbh); + destroyLater(fb->fbh); // Clean up the associated internal texture resource using existing pipelines if (fb->texture != InvalidTexture) { if (auto* th = g_textures.get(fb->texture)) { - destroy_later(*th); + destroyLater(*th); } g_textures.destroy(fb->texture); } @@ -113,9 +113,9 @@ namespace draco::rendering::rhi } } - TextureHandle get_framebuffer_texture(FramebufferHandle handle) + TextureHandle getFramebufferTexture(FramebufferHandle handle) { - auto* fb = get_checked(g_framebuffers, handle, "Framebuffer"); + auto* fb = getChecked(g_framebuffers, handle, "Framebuffer"); if (!fb) { return InvalidTexture; diff --git a/Engine/cpp/runtime/rendering/rhi/uniform_registry.cppm b/Engine/cpp/Runtime/Rendering/RHI/UniformRegistry.cppm similarity index 73% rename from Engine/cpp/runtime/rendering/rhi/uniform_registry.cppm rename to Engine/cpp/Runtime/Rendering/RHI/UniformRegistry.cppm index bdc9afdf..2bf48381 100644 --- a/Engine/cpp/runtime/rendering/rhi/uniform_registry.cppm +++ b/Engine/cpp/Runtime/Rendering/RHI/UniformRegistry.cppm @@ -13,17 +13,17 @@ export namespace draco::rendering::rhi { inline std::unordered_map g_uniform_map; - inline uint32_t hash_uniform(const std::string& name) + inline uint32_t hashUniform(const std::string& name) { return static_cast(std::hash{}(name)); } - inline void register_uniform(uint32_t hash, UniformHandle h) + inline void registerUniform(uint32_t hash, UniformHandle h) { g_uniform_map[hash] = h; } - inline void unregister_uniform(uint32_t hash, UniformHandle h) + inline void unregisterUniform(uint32_t hash, UniformHandle h) { auto it = g_uniform_map.find(hash); @@ -31,12 +31,12 @@ export namespace draco::rendering::rhi g_uniform_map.erase(it); } - inline void clear_uniform_registry() + inline void clearUniformRegistry() { g_uniform_map.clear(); } - inline UniformHandle get_uniform(uint32_t hash) + inline UniformHandle getUniform(uint32_t hash) { auto it = g_uniform_map.find(hash); diff --git a/Engine/cpp/runtime/rendering/rhi/vertex.cppm b/Engine/cpp/Runtime/Rendering/RHI/Vertex.cppm similarity index 83% rename from Engine/cpp/runtime/rendering/rhi/vertex.cppm rename to Engine/cpp/Runtime/Rendering/RHI/Vertex.cppm index ece03c42..fa2356e5 100644 --- a/Engine/cpp/runtime/rendering/rhi/vertex.cppm +++ b/Engine/cpp/Runtime/Rendering/RHI/Vertex.cppm @@ -4,6 +4,7 @@ module; #include export module rendering.rhi.vertex; +import core.stdtypes; export namespace draco::rendering::rhi { enum class Attrib { @@ -21,7 +22,7 @@ export namespace draco::rendering::rhi { struct VertexElement { Attrib attrib; - uint16_t count; + u16 count; AttribType type; bool normalized = false; }; @@ -30,18 +31,15 @@ export namespace draco::rendering::rhi { std::vector elements; }; - #pragma pack(push, 1) - struct TexturedVertex { + struct alignas(u32) TexturedVertex { float x, y, z; float u, v; - uint32_t color; + u32 color; }; - #pragma pack(pop) - static_assert(sizeof(TexturedVertex) == 24); // Helper to get the standard layout for the current vertex struct - inline VertexLayoutDesc get_textured_vertex_layout() { + inline VertexLayoutDesc getTexturedVertexLayout() { return { .elements = { { Attrib::Position, 3, AttribType::Float }, diff --git a/Engine/cpp/runtime/rendering/rhi/macros.h b/Engine/cpp/Runtime/Rendering/RHI/macros.h similarity index 100% rename from Engine/cpp/runtime/rendering/rhi/macros.h rename to Engine/cpp/Runtime/Rendering/RHI/macros.h diff --git a/Engine/cpp/runtime/rendering/rendergraph/rendergraph.cpp b/Engine/cpp/Runtime/Rendering/RenderGraph/RenderGraph.cpp similarity index 50% rename from Engine/cpp/runtime/rendering/rendergraph/rendergraph.cpp rename to Engine/cpp/Runtime/Rendering/RenderGraph/RenderGraph.cpp index 51d8d53a..31d7e2e1 100644 --- a/Engine/cpp/runtime/rendering/rendergraph/rendergraph.cpp +++ b/Engine/cpp/Runtime/Rendering/RenderGraph/RenderGraph.cpp @@ -11,7 +11,7 @@ import rendering.rhi; namespace draco::rendering::rendergraph { - static void sort_material(std::vector& packets) + static void sortMaterial(std::vector& packets) { std::sort(packets.begin(), packets.end(), [](const rhi::RenderPacket& a, const rhi::RenderPacket& b) @@ -21,30 +21,30 @@ namespace draco::rendering::rendergraph { return a.pipeline.value < b.pipeline.value; // Texture second - if (a.texture_handle != b.texture_handle) - return a.texture_handle.value < b.texture_handle.value; + if (a.textureHandle != b.textureHandle) + return a.textureHandle.value < b.textureHandle.value; // Vertex buffer third - if (a.vertex_buffer != b.vertex_buffer) - return a.vertex_buffer.value < b.vertex_buffer.value; + if (a.vertexBuffer != b.vertexBuffer) + return a.vertexBuffer.value < b.vertexBuffer.value; // Index buffer fallback - return a.index_buffer.value < b.index_buffer.value; + return a.indexBuffer.value < b.indexBuffer.value; }); } // Placeholder until depth sorting exists - static void sort_front_to_back(std::vector& packets) + static void sortFrontToBack(std::vector& packets) { - sort_material(packets); + sortMaterial(packets); } - static void sort_back_to_front(std::vector& packets) + static void sortBackToFront(std::vector& packets) { - sort_material(packets); + sortMaterial(packets); } - static void sort_packets(std::vector& packets, SortMode mode) + static void sortPackets(std::vector& packets, SortMode mode) { switch (mode) { @@ -52,37 +52,37 @@ namespace draco::rendering::rendergraph { break; case SortMode::Material: - sort_material(packets); + sortMaterial(packets); break; case SortMode::FrontToBack: - sort_front_to_back(packets); + sortFrontToBack(packets); break; case SortMode::BackToFront: - sort_back_to_front(packets); + sortBackToFront(packets); break; } } void RenderGraph::reset() { - m_passes.clear(); // Directly clear + passes.clear(); // Directly clear } - Pass& RenderGraph::add_pass(const std::string& name) + Pass& RenderGraph::addPass(const std::string& name) { - m_passes.emplace_back(); + passes.emplace_back(); - auto& pass = m_passes.back(); + auto& pass = passes.back(); pass.name = name; return pass; } - Pass* RenderGraph::get_pass(const std::string& name) + Pass* RenderGraph::getPass(const std::string& name) { - for (auto& p : m_passes) + for (auto& p : passes) { if (p.name == name) return &p; @@ -93,7 +93,7 @@ namespace draco::rendering::rendergraph { void RenderGraph::execute() { - for (auto& pass : m_passes) + for (auto& pass : passes) { // Future dependency handling hook for (const auto& dep : pass.dependencies) @@ -101,15 +101,15 @@ namespace draco::rendering::rendergraph { (void)dep; } - sort_packets(pass.packets, pass.sort_mode); + sortPackets(pass.packets, pass.sortMode); - rhi::apply_view(pass.view, {pass.framebuffer, 0, 0, pass.width, pass.height, pass.clear_flags, pass.clear_color}); + rhi::applyView(pass.view, {pass.framebuffer, 0, 0, pass.width, pass.height, pass.clearFlags, pass.clearColor}); - rhi::set_view_projection(pass.view, pass.view_mtx, pass.proj_mtx); + rhi::setViewProjection(pass.view, pass.viewMatrix, pass.projMatrix); - if (pass.clear_flags) + if (pass.clearFlags) { - bgfx::setViewClear(pass.view, pass.clear_flags, pass.clear_color); + bgfx::setViewClear(pass.view, pass.clearFlags, pass.clearColor); } for (auto& pkt : pass.packets) diff --git a/Engine/cpp/runtime/rendering/rendergraph/rendergraph.cppm b/Engine/cpp/Runtime/Rendering/RenderGraph/RenderGraph.cppm similarity index 80% rename from Engine/cpp/runtime/rendering/rendergraph/rendergraph.cppm rename to Engine/cpp/Runtime/Rendering/RenderGraph/RenderGraph.cppm index 6549e1ae..a8616691 100644 --- a/Engine/cpp/runtime/rendering/rendergraph/rendergraph.cppm +++ b/Engine/cpp/Runtime/Rendering/RenderGraph/RenderGraph.cppm @@ -32,7 +32,7 @@ export namespace draco::rendering::rendergraph { std::string name; PassType type = PassType::Graphics; - SortMode sort_mode = SortMode::Material; + SortMode sortMode = SortMode::Material; std::vector dependencies; @@ -41,14 +41,14 @@ export namespace draco::rendering::rendergraph { std::vector packets; - f32 view_mtx[16] = { + f32 viewMatrix[16] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f }; - f32 proj_mtx[16] = { + f32 projMatrix[16] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, @@ -58,8 +58,8 @@ export namespace draco::rendering::rendergraph { u16 width = 0; u16 height = 0; - u32 clear_flags = 0; - u32 clear_color = 0; + u32 clearFlags = 0; + u32 clearColor = 0; }; class RenderGraph @@ -67,13 +67,13 @@ export namespace draco::rendering::rendergraph { public: void reset(); - Pass& add_pass(const std::string& name); + Pass& addPass(const std::string& name); - Pass* get_pass(const std::string& name); + Pass* getPass(const std::string& name); void execute(); private: - std::vector m_passes; + std::vector passes; }; } diff --git a/Engine/cpp/Runtime/Rendering/Renderer/Renderer.cpp b/Engine/cpp/Runtime/Rendering/Renderer/Renderer.cpp new file mode 100644 index 00000000..eaea237b --- /dev/null +++ b/Engine/cpp/Runtime/Rendering/Renderer/Renderer.cpp @@ -0,0 +1,150 @@ +module; + +#include +#include +#include +#include +#include + +#include + +module rendering.renderer; + +import core.stdtypes; +import core.math.transform; +import rendering.rhi; +import rendering.rhi.uniform_registry; +import rendering.rendergraph; +import rendering.mesh; +import rendering.material; +import rendering.quad; + +namespace draco::rendering::renderer +{ + static constexpr const char* MAIN_PASS = "MainPass"; + + void init(u16 width, u16 height) + { + g_ctx.screenWidth = width; + g_ctx.screenHeight = height; + } + + void resize(u16 width, u16 height) + { + g_ctx.screenWidth = width; + g_ctx.screenHeight = height; + } + + void beginFrame(const Camera& cam) + { + rhi::beginFrame(); + + g_ctx.mainCamera = cam; + g_ctx.graph.reset(); + + // Create main pass once per frame + auto& pass = g_ctx.graph.addPass(MAIN_PASS); + + pass.view = 0; + pass.framebuffer = rhi::InvalidFramebuffer; + + pass.width = g_ctx.screenWidth; + pass.height = g_ctx.screenHeight; + + pass.clearFlags = BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH; + pass.clearColor = 0x303030ff; + + rhi::lookAt(pass.viewMatrix, cam.position.data(), cam.target.data(), cam.up.data()); + const f32 aspect = static_cast(g_ctx.screenWidth) / static_cast(std::max(g_ctx.screenHeight, 1)); + rhi::perspective(pass.projMatrix, cam.fov, aspect, cam.nearPlane, cam.farPlane); + } + + static void buildUniforms(const material::Material& mat, std::vector& out) + { + out.clear(); + out.reserve(mat.uniforms.size()); + + for (const auto& u : mat.uniforms) + { + rhi::UniformBind bind{}; + + bind.handle = rhi::getUniform(u.nameHash); + + bind.data = u.data; + bind.num = u.count; + + if (bind.handle == rhi::InvalidUniform) + { + std::println("[Renderer] Missing uniform hash: {}", u.nameHash); + continue; + } + + out.push_back(bind); + } + } + + void submitEntity(const rhi::RenderPacket& packet) + { + auto* pass = g_ctx.graph.getPass(MAIN_PASS); + if (!pass) return; + + pass->packets.push_back(packet); + } + + void submitRenderable(const draco::math::Transform& transform, const material::Material& material, mesh::MeshHandle mesh_id) + { + const auto* m = mesh::get(mesh_id); + if (!m) return; + + rhi::RenderPacket p{}; + + p.vertexBuffer = m->vbh; + p.indexBuffer = m->ibh; + + p.pipeline = material.pipeline; + p.textureHandle = material.texture; + p.textureUnit = material.texture_unit; + p.samplerUniform = material.sampler; + + buildUniforms(material, p.uniforms); + + transform.toMatrix(p.model); + + submitEntity(p); + } + + void submitUI(quad::QuadRenderer& quad_renderer) + { + auto& ui_pass = g_ctx.graph.addPass("UIPass"); + + ui_pass.view = 1; + ui_pass.sortMode = rendergraph::SortMode::None; + + ui_pass.framebuffer = rhi::InvalidFramebuffer; + + ui_pass.width = g_ctx.screenWidth; + ui_pass.height = g_ctx.screenHeight; + + ui_pass.clearFlags = 0; + + quad::OrthoCamera ortho; + + quad::QuadRenderer::buildOrtho(ortho, g_ctx.screenWidth, g_ctx.screenHeight); + + std::memcpy(ui_pass.viewMatrix, ortho.view, sizeof(f32) * 16); + std::memcpy(ui_pass.projMatrix, ortho.proj, sizeof(f32) * 16); + + quad_renderer.flushToPass(ui_pass); + } + + void endFrame() + { + g_ctx.graph.execute(); + rhi::endFrame(); + } + + rendergraph::RenderGraph& getGraph() + { + return g_ctx.graph; + } +} diff --git a/Engine/cpp/Runtime/Rendering/Renderer/Renderer.cppm b/Engine/cpp/Runtime/Rendering/Renderer/Renderer.cppm new file mode 100644 index 00000000..6ab3efb8 --- /dev/null +++ b/Engine/cpp/Runtime/Rendering/Renderer/Renderer.cppm @@ -0,0 +1,48 @@ +module; + +#include + +export module rendering.renderer; + +import core.stdtypes; +import core.math.transform; +import rendering.rhi; +import rendering.rendergraph; +import rendering.quad; +import rendering.material; +import rendering.mesh; + +export namespace draco::rendering::renderer { + + struct Camera { + std::array position = {0.0f, 0.0f, 0.0f}; + std::array target = {0.0f, 0.0f, 0.0f}; + std::array up = {0.0f, 1.0f, 0.0f}; + f32 fov = 60.0f; + f32 nearPlane = 0.1f; + f32 farPlane = 1000.0f; + }; + + struct SceneContext { + u16 screenWidth = 0; + u16 screenHeight = 0; + Camera mainCamera; + + rendergraph::RenderGraph graph; + }; + + inline SceneContext g_ctx; + + void init(u16 width, u16 height); + void resize(u16 width, u16 height); + + void beginFrame(const Camera& cam); + + void submitEntity(rhi::RenderPacket& packet, u16 view); + void submitRenderable(const math::Transform& transform, const material::Material& material, mesh::MeshHandle mesh_id); + void submitUI(quad::QuadRenderer& quad_renderer); + + void endFrame(); + + rendergraph::RenderGraph& getGraph(); +} diff --git a/Engine/cpp/runtime/rendering/rendering.cppm b/Engine/cpp/Runtime/Rendering/Rendering.cppm similarity index 87% rename from Engine/cpp/runtime/rendering/rendering.cppm rename to Engine/cpp/Runtime/Rendering/Rendering.cppm index 9b1f8727..36f000b2 100644 --- a/Engine/cpp/runtime/rendering/rendering.cppm +++ b/Engine/cpp/Runtime/Rendering/Rendering.cppm @@ -6,4 +6,4 @@ export import rendering.rendergraph; export import rendering.renderer; export import rendering.mesh; export import rendering.material; -export import rendering.quad_renderer; +export import rendering.quad; diff --git a/Engine/cpp/runtime/rendering/shaders/fs.sc b/Engine/cpp/Runtime/Rendering/Shaders/fs.sc similarity index 100% rename from Engine/cpp/runtime/rendering/shaders/fs.sc rename to Engine/cpp/Runtime/Rendering/Shaders/fs.sc diff --git a/Engine/cpp/runtime/rendering/shaders/fs_quad.sc b/Engine/cpp/Runtime/Rendering/Shaders/fs_quad.sc similarity index 100% rename from Engine/cpp/runtime/rendering/shaders/fs_quad.sc rename to Engine/cpp/Runtime/Rendering/Shaders/fs_quad.sc diff --git a/Engine/cpp/runtime/rendering/shaders/varying.def.sc b/Engine/cpp/Runtime/Rendering/Shaders/varying.def.sc similarity index 100% rename from Engine/cpp/runtime/rendering/shaders/varying.def.sc rename to Engine/cpp/Runtime/Rendering/Shaders/varying.def.sc diff --git a/Engine/cpp/runtime/rendering/shaders/varying_quad.def.sc b/Engine/cpp/Runtime/Rendering/Shaders/varying_quad.def.sc similarity index 100% rename from Engine/cpp/runtime/rendering/shaders/varying_quad.def.sc rename to Engine/cpp/Runtime/Rendering/Shaders/varying_quad.def.sc diff --git a/Engine/cpp/runtime/rendering/shaders/vs.sc b/Engine/cpp/Runtime/Rendering/Shaders/vs.sc similarity index 100% rename from Engine/cpp/runtime/rendering/shaders/vs.sc rename to Engine/cpp/Runtime/Rendering/Shaders/vs.sc diff --git a/Engine/cpp/runtime/rendering/shaders/vs_quad.sc b/Engine/cpp/Runtime/Rendering/Shaders/vs_quad.sc similarity index 100% rename from Engine/cpp/runtime/rendering/shaders/vs_quad.sc rename to Engine/cpp/Runtime/Rendering/Shaders/vs_quad.sc diff --git a/Engine/cpp/Runtime/Scene/CMakeLists.txt b/Engine/cpp/Runtime/Scene/CMakeLists.txt new file mode 100644 index 00000000..cf75dbbd --- /dev/null +++ b/Engine/cpp/Runtime/Scene/CMakeLists.txt @@ -0,0 +1,7 @@ +add_modules_library(Camera) +add_modules_library(TransformComponent) +add_modules_library(Renderable) + +target_link_libraries(Camera PUBLIC Core Input Rendering bx) +target_link_libraries(TransformComponent PUBLIC Core) +target_link_libraries(Renderable PUBLIC TransformComponent Core Rendering) diff --git a/Engine/cpp/Runtime/Scene/Camera/CameraController.cpp b/Engine/cpp/Runtime/Scene/Camera/CameraController.cpp new file mode 100644 index 00000000..74541db0 --- /dev/null +++ b/Engine/cpp/Runtime/Scene/Camera/CameraController.cpp @@ -0,0 +1,102 @@ +module; + +#include +#include + +module scene.camera.controller; + +import input; + +namespace draco::scene +{ + void CameraController::init(f32 x, f32 y, f32 z) + { + x = x; + y = y; + z = z; + + yaw = 0.0f; + pitch = 0.0f; + + speed = 5.0f; // units per second + sensitivity = 0.002f; // mouse sensitivity + } + + void CameraController::update(f32 dt) + { + using namespace input; + + yaw += getMouseDx() * sensitivity; + pitch -= getMouseDy() * sensitivity; // Temp fix to flip mouse input + + // Clamp pitch + if (pitch > 1.5f) pitch = 1.5f; + if (pitch < -1.5f) pitch = -1.5f; + + bx::Vec3 forward = { + cosf(pitch) * sinf(yaw), + sinf(pitch), + cosf(pitch) * cosf(yaw) + }; + + bx::Vec3 right = { + sinf(yaw - bx::kPiHalf), + 0.0f, + cosf(yaw - bx::kPiHalf) + }; + + f32 velocity = speed * dt; + + if (isDown(Key::W)) + { + x += forward.x * velocity; + y += forward.y * velocity; + z += forward.z * velocity; + } + + if (isDown(Key::S)) + { + x -= forward.x * velocity; + y -= forward.y * velocity; + z -= forward.z * velocity; + } + + if (isDown(Key::A)) + { + x += right.x * velocity; + z += right.z * velocity; + } + + if (isDown(Key::D)) + { + x -= right.x * velocity; + z -= right.z * velocity; + } + } + + rendering::renderer::Camera CameraController::getCamera() const + { + const bx::Vec3 forward = { + cosf(pitch) * sinf(yaw), + sinf(pitch), + cosf(pitch) * cosf(yaw) + }; + + rendering::renderer::Camera cam{}; + + cam.position = { x, y, z }; + cam.target = { + x + forward.x, + y + forward.y, + z + forward.z + }; + + cam.up = { 0.0f, 1.0f, 0.0f }; + + cam.fov = 60.0f; + cam.nearPlane = 0.1f; + cam.farPlane = 100.0f; + + return cam; + } +} diff --git a/Engine/cpp/Runtime/Scene/Camera/CameraController.cppm b/Engine/cpp/Runtime/Scene/Camera/CameraController.cppm new file mode 100644 index 00000000..4855a567 --- /dev/null +++ b/Engine/cpp/Runtime/Scene/Camera/CameraController.cppm @@ -0,0 +1,23 @@ +export module scene.camera.controller; + +import core.stdtypes; +import rendering; + +export namespace draco::scene +{ + struct CameraController + { + void init(f32 x = 0.0f, f32 y = 0.0f, f32 z = -2.0f); + + void update(f32 dt); + + [[nodiscard]] rendering::renderer::Camera getCamera() const; + + private: + f32 x = 0.0f, y = 0.0f, z = 0.0f; + f32 yaw = 0.0f; + f32 pitch = 0.0f; + f32 speed = 5.0f; + f32 sensitivity = 0.1f; + }; +} \ No newline at end of file diff --git a/Engine/cpp/runtime/scene/renderable/renderable.cppm b/Engine/cpp/Runtime/Scene/Renderable/Renderable.cppm similarity index 56% rename from Engine/cpp/runtime/scene/renderable/renderable.cppm rename to Engine/cpp/Runtime/Scene/Renderable/Renderable.cppm index 6d034a43..599fcb35 100644 --- a/Engine/cpp/runtime/scene/renderable/renderable.cppm +++ b/Engine/cpp/Runtime/Scene/Renderable/Renderable.cppm @@ -8,10 +8,8 @@ export namespace draco::scene::renderable { struct Renderable { - draco::rendering::mesh::MeshHandle mesh; - - draco::math::Transform transform; - - draco::rendering::material::Material material; + rendering::mesh::MeshHandle mesh{}; + math::Transform transform{}; + rendering::material::Material material{}; }; } \ No newline at end of file diff --git a/Engine/cpp/runtime/scene/scene.cppm b/Engine/cpp/Runtime/Scene/Scene.cppm similarity index 100% rename from Engine/cpp/runtime/scene/scene.cppm rename to Engine/cpp/Runtime/Scene/Scene.cppm diff --git a/Engine/cpp/runtime/scene/transform_component/transform_component.cpp b/Engine/cpp/Runtime/Scene/TransformComponent/TransformComponent.cpp similarity index 69% rename from Engine/cpp/runtime/scene/transform_component/transform_component.cpp rename to Engine/cpp/Runtime/Scene/TransformComponent/TransformComponent.cpp index 3573a1c2..fbadc4ef 100644 --- a/Engine/cpp/runtime/scene/transform_component/transform_component.cpp +++ b/Engine/cpp/Runtime/Scene/TransformComponent/TransformComponent.cpp @@ -2,7 +2,7 @@ module scene.transform_component; namespace draco::scene { - void mark_dirty(TransformComponent& t) + void markDirty(TransformComponent& t) { t.dirty = true; } diff --git a/Engine/cpp/runtime/scene/transform_component/transform_component.cppm b/Engine/cpp/Runtime/Scene/TransformComponent/TransformComponent.cppm similarity index 61% rename from Engine/cpp/runtime/scene/transform_component/transform_component.cppm rename to Engine/cpp/Runtime/Scene/TransformComponent/TransformComponent.cppm index 98ff5b93..d867f1bd 100644 --- a/Engine/cpp/runtime/scene/transform_component/transform_component.cppm +++ b/Engine/cpp/Runtime/Scene/TransformComponent/TransformComponent.cppm @@ -6,11 +6,10 @@ export namespace draco::scene { struct TransformComponent { - math::Transform local; - math::Transform world; - + math::Transform local{}; + math::Transform world{}; bool dirty = true; }; - void mark_dirty(TransformComponent& t); + void markDirty(TransformComponent& t); } diff --git a/Engine/cpp/thirdparty/CMakeLists.txt b/Engine/cpp/ThirdParty/CMakeLists.txt similarity index 100% rename from Engine/cpp/thirdparty/CMakeLists.txt rename to Engine/cpp/ThirdParty/CMakeLists.txt diff --git a/Engine/cpp/thirdparty/bgfx b/Engine/cpp/ThirdParty/bgfx similarity index 100% rename from Engine/cpp/thirdparty/bgfx rename to Engine/cpp/ThirdParty/bgfx diff --git a/Engine/cpp/thirdparty/bimg b/Engine/cpp/ThirdParty/bimg similarity index 100% rename from Engine/cpp/thirdparty/bimg rename to Engine/cpp/ThirdParty/bimg diff --git a/Engine/cpp/thirdparty/bx b/Engine/cpp/ThirdParty/bx similarity index 100% rename from Engine/cpp/thirdparty/bx rename to Engine/cpp/ThirdParty/bx diff --git a/Engine/cpp/thirdparty/cmake/Config.cmake.in b/Engine/cpp/ThirdParty/cmake/Config.cmake.in similarity index 100% rename from Engine/cpp/thirdparty/cmake/Config.cmake.in rename to Engine/cpp/ThirdParty/cmake/Config.cmake.in diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/dear-imgui.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/dear-imgui.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/dear-imgui.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/dear-imgui.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/fcpp.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/fcpp.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/fcpp.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/fcpp.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/glsl-optimizer.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/glsl-optimizer.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/glsl-optimizer.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/glsl-optimizer.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/glslang.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/glslang.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/glslang.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/glslang.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/meshoptimizer.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/meshoptimizer.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/meshoptimizer.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/meshoptimizer.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/spirv-cross.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/spirv-cross.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/spirv-cross.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/spirv-cross.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/spirv-opt.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/spirv-opt.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/spirv-opt.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/spirv-opt.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/tint.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/tint.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/tint.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/tint.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/3rdparty/webgpu.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/webgpu.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/3rdparty/webgpu.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/3rdparty/webgpu.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/CMakeLists.txt b/Engine/cpp/ThirdParty/cmake/bgfx/CMakeLists.txt similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/CMakeLists.txt rename to Engine/cpp/ThirdParty/cmake/bgfx/CMakeLists.txt diff --git a/Engine/cpp/thirdparty/cmake/bgfx/bgfx.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/bgfx.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/bgfx.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/bgfx.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/examples.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/examples.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/examples.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/examples.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/generated/bounds.cpp.in b/Engine/cpp/ThirdParty/cmake/bgfx/generated/bounds.cpp.in similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/generated/bounds.cpp.in rename to Engine/cpp/ThirdParty/cmake/bgfx/generated/bounds.cpp.in diff --git a/Engine/cpp/thirdparty/cmake/bgfx/generated/shader.cpp.in b/Engine/cpp/ThirdParty/cmake/bgfx/generated/shader.cpp.in similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/generated/shader.cpp.in rename to Engine/cpp/ThirdParty/cmake/bgfx/generated/shader.cpp.in diff --git a/Engine/cpp/thirdparty/cmake/bgfx/generated/vertexlayout.cpp.in b/Engine/cpp/ThirdParty/cmake/bgfx/generated/vertexlayout.cpp.in similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/generated/vertexlayout.cpp.in rename to Engine/cpp/ThirdParty/cmake/bgfx/generated/vertexlayout.cpp.in diff --git a/Engine/cpp/thirdparty/cmake/bgfx/geometryc.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/geometryc.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/geometryc.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/geometryc.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/geometryv.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/geometryv.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/geometryv.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/geometryv.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/shaderc.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/shaderc.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/shaderc.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/shaderc.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/shared.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/shared.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/shared.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/shared.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/texturev.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/texturev.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/texturev.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/texturev.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfx/util/ConfigureDebugging.cmake b/Engine/cpp/ThirdParty/cmake/bgfx/util/ConfigureDebugging.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfx/util/ConfigureDebugging.cmake rename to Engine/cpp/ThirdParty/cmake/bgfx/util/ConfigureDebugging.cmake diff --git a/Engine/cpp/thirdparty/cmake/bgfxToolUtils.cmake b/Engine/cpp/ThirdParty/cmake/bgfxToolUtils.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bgfxToolUtils.cmake rename to Engine/cpp/ThirdParty/cmake/bgfxToolUtils.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/astc_encoder.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/astc_encoder.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/astc_encoder.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/astc_encoder.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/edtaa3.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/edtaa3.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/edtaa3.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/edtaa3.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/etc1.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/etc1.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/etc1.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/etc1.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/etc2.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/etc2.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/etc2.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/etc2.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/iqa.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/iqa.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/iqa.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/iqa.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/libsquish.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/libsquish.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/libsquish.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/libsquish.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/loadpng.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/loadpng.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/loadpng.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/loadpng.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/miniz.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/miniz.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/miniz.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/miniz.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/nvtt.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/nvtt.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/nvtt.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/nvtt.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/pvrtc.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/pvrtc.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/pvrtc.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/pvrtc.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/3rdparty/tinyexr.cmake b/Engine/cpp/ThirdParty/cmake/bimg/3rdparty/tinyexr.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/3rdparty/tinyexr.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/3rdparty/tinyexr.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/CMakeLists.txt b/Engine/cpp/ThirdParty/cmake/bimg/CMakeLists.txt similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/CMakeLists.txt rename to Engine/cpp/ThirdParty/cmake/bimg/CMakeLists.txt diff --git a/Engine/cpp/thirdparty/cmake/bimg/bimg.cmake b/Engine/cpp/ThirdParty/cmake/bimg/bimg.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/bimg.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/bimg.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/bimg_decode.cmake b/Engine/cpp/ThirdParty/cmake/bimg/bimg_decode.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/bimg_decode.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/bimg_decode.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/bimg_encode.cmake b/Engine/cpp/ThirdParty/cmake/bimg/bimg_encode.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/bimg_encode.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/bimg_encode.cmake diff --git a/Engine/cpp/thirdparty/cmake/bimg/texturec.cmake b/Engine/cpp/ThirdParty/cmake/bimg/texturec.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bimg/texturec.cmake rename to Engine/cpp/ThirdParty/cmake/bimg/texturec.cmake diff --git a/Engine/cpp/thirdparty/cmake/bx/CMakeLists.txt b/Engine/cpp/ThirdParty/cmake/bx/CMakeLists.txt similarity index 100% rename from Engine/cpp/thirdparty/cmake/bx/CMakeLists.txt rename to Engine/cpp/ThirdParty/cmake/bx/CMakeLists.txt diff --git a/Engine/cpp/thirdparty/cmake/bx/bin2c.cmake b/Engine/cpp/ThirdParty/cmake/bx/bin2c.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bx/bin2c.cmake rename to Engine/cpp/ThirdParty/cmake/bx/bin2c.cmake diff --git a/Engine/cpp/thirdparty/cmake/bx/bx.cmake b/Engine/cpp/ThirdParty/cmake/bx/bx.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/bx/bx.cmake rename to Engine/cpp/ThirdParty/cmake/bx/bx.cmake diff --git a/Engine/cpp/thirdparty/cmake/version.cmake b/Engine/cpp/ThirdParty/cmake/version.cmake similarity index 100% rename from Engine/cpp/thirdparty/cmake/version.cmake rename to Engine/cpp/ThirdParty/cmake/version.cmake diff --git a/Engine/cpp/thirdparty/doctest/doctest.h b/Engine/cpp/ThirdParty/doctest/doctest.h similarity index 100% rename from Engine/cpp/thirdparty/doctest/doctest.h rename to Engine/cpp/ThirdParty/doctest/doctest.h diff --git a/Engine/cpp/thirdparty/doctest/doctest_with_main.h b/Engine/cpp/ThirdParty/doctest/doctest_with_main.h similarity index 100% rename from Engine/cpp/thirdparty/doctest/doctest_with_main.h rename to Engine/cpp/ThirdParty/doctest/doctest_with_main.h diff --git a/Engine/cpp/thirdparty/sdl b/Engine/cpp/ThirdParty/sdl similarity index 100% rename from Engine/cpp/thirdparty/sdl rename to Engine/cpp/ThirdParty/sdl diff --git a/Engine/cpp/thirdparty/stb/CMakeLists.txt b/Engine/cpp/ThirdParty/stb/CMakeLists.txt similarity index 100% rename from Engine/cpp/thirdparty/stb/CMakeLists.txt rename to Engine/cpp/ThirdParty/stb/CMakeLists.txt diff --git a/Engine/cpp/thirdparty/stb/stb_image.h b/Engine/cpp/ThirdParty/stb/stb_image.h similarity index 100% rename from Engine/cpp/thirdparty/stb/stb_image.h rename to Engine/cpp/ThirdParty/stb/stb_image.h diff --git a/Engine/cpp/runtime/CMakeLists.txt b/Engine/cpp/runtime/CMakeLists.txt deleted file mode 100644 index c9f083ed..00000000 --- a/Engine/cpp/runtime/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -add_modules_library(platform) -add_modules_library(core SHARED) -add_modules_library(input) -add_modules_library(rendering) -add_modules_library(scene) - -target_link_libraries(platform PUBLIC platform_impl) -target_link_libraries(core PUBLIC definitions math io memory) -target_link_libraries(input PRIVATE SDL3::SDL3-static platform core) -target_link_libraries(rendering PUBLIC rhi rendergraph mesh material quad_renderer renderer) -target_link_libraries(scene PUBLIC renderable transform_component camera) diff --git a/Engine/cpp/runtime/core/CMakeLists.txt b/Engine/cpp/runtime/core/CMakeLists.txt deleted file mode 100644 index dd4dfb1b..00000000 --- a/Engine/cpp/runtime/core/CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -add_modules_library(definitions PIC) -add_modules_library(math) -add_modules_library(io) -add_modules_library(memory) - -target_link_libraries(math PUBLIC definitions bx) -target_link_libraries(io PUBLIC definitions stb_image) -target_link_libraries(memory PUBLIC definitions math) diff --git a/Engine/cpp/runtime/rendering/CMakeLists.txt b/Engine/cpp/runtime/rendering/CMakeLists.txt deleted file mode 100644 index 97507a2d..00000000 --- a/Engine/cpp/runtime/rendering/CMakeLists.txt +++ /dev/null @@ -1,13 +0,0 @@ -add_modules_library(rhi) -add_modules_library(rendergraph) -add_modules_library(renderer) -add_modules_library(mesh) -add_modules_library(material) -add_modules_library(quad_renderer) - -target_link_libraries(rhi PUBLIC core math memory platform bgfx bx) -target_link_libraries(rendergraph PUBLIC rhi bx) -target_link_libraries(mesh PUBLIC memory rhi math core) -target_link_libraries(material PUBLIC rhi) -target_link_libraries(quad_renderer PUBLIC rhi rendergraph bgfx bx) -target_link_libraries(renderer PUBLIC core math rhi rendergraph mesh quad_renderer material bgfx bx) \ No newline at end of file diff --git a/Engine/cpp/runtime/rendering/mesh/mesh.cppm b/Engine/cpp/runtime/rendering/mesh/mesh.cppm deleted file mode 100644 index 6b10d932..00000000 --- a/Engine/cpp/runtime/rendering/mesh/mesh.cppm +++ /dev/null @@ -1,71 +0,0 @@ -module; - -#include - -export module rendering.mesh; - -import core.stdtypes; -import core.memory; -import rendering.rhi; - -export namespace draco::rendering::mesh -{ - struct MeshTag {}; - - using MeshHandle = draco::core::memory::Handle; - - struct Vertex - { - f32 px, py, pz; - f32 nx, ny, nz; - f32 u, v; - }; - - struct Mesh - { - draco::rendering::rhi::BufferHandle vbh; - draco::rendering::rhi::BufferHandle ibh; - - draco::rendering::rhi::LayoutHandle layout; - - u32 vertex_count = 0; - u32 index_count = 0; - - bool valid = false; - }; - - MeshHandle create( - const void* vertex_data, - u32 vertex_size, - u32 vertex_count, - const std::vector& indices, - draco::rendering::rhi::LayoutHandle layout - ); - - MeshHandle create_cube(); - MeshHandle create_plane(float size); - MeshHandle create_sphere(int segments, int rings); - MeshHandle create_cylinder(int segments, float height); - MeshHandle create_capsule(int segments, int rings, float height); - - void destroy(MeshHandle mesh); - const Mesh* get(MeshHandle mesh); -} - -export namespace draco::rendering::mesh::gen -{ - std::vector cube_vertices(); - std::vector cube_indices(); - - std::vector plane_vertices(float size); - std::vector plane_indices(); - - std::vector sphere_vertices(int segments, int rings); - std::vector sphere_indices(int segments, int rings); - - std::vector cylinder_vertices(int segments, float height); - std::vector cylinder_indices(int segments); - - std::vector capsule_vertices(int segments, int rings, float height); - std::vector capsule_indices(int segments, int rings); -} diff --git a/Engine/cpp/runtime/rendering/quad_renderer/quad_renderer.cppm b/Engine/cpp/runtime/rendering/quad_renderer/quad_renderer.cppm deleted file mode 100644 index 8a41c14c..00000000 --- a/Engine/cpp/runtime/rendering/quad_renderer/quad_renderer.cppm +++ /dev/null @@ -1,89 +0,0 @@ -module; - -#include -#include - -export module rendering.quad_renderer; - -import core.stdtypes; -import rendering.rhi; -import rendering.rhi.vertex; -import rendering.rendergraph; - -export namespace draco::rendering::quad_renderer { - - struct BatchKey { - draco::rendering::rhi::TextureHandle texture = draco::rendering::rhi::InvalidTexture; - - draco::rendering::rhi::PipelineHandle pipeline = draco::rendering::rhi::InvalidPipeline; - - draco::rendering::rhi::SamplerHandle sampler = draco::rendering::rhi::InvalidSampler; - - bool operator==(const BatchKey&) const = default; - }; - - struct QuadCommand { - draco::rendering::rhi::TextureHandle texture = draco::rendering::rhi::InvalidTexture; - - f32 x = 0.0f; - f32 y = 0.0f; - f32 z = 0.0f; - - f32 width = 1.0f; - f32 height = 1.0f; - - f32 rotation = 0.0f; - - u32 color = 0xffffffff; - }; - - struct OrthoCamera { - f32 view[16]; - f32 proj[16]; - - f32 x = 0.0f; - f32 y = 0.0f; - f32 zoom = 1.0f; - }; - - class QuadRenderer { - public: - static constexpr u32 MaxQuads = 10000; - static constexpr u32 MaxVertices = MaxQuads * 4; - static constexpr u32 MaxIndices = MaxQuads * 6; - - void init(draco::rendering::rhi::PipelineHandle pipeline); - - void begin(); - - void submit(const QuadCommand& cmd); - - void flush_to_pass(draco::rendering::rendergraph::Pass& pass); - - void shutdown(); - - static void build_ortho(OrthoCamera& cam, f32 width, f32 height); - - private: - void push_quad(const QuadCommand& cmd); - - private: - BatchKey m_batch_key{}; - - std::vector m_vertices; - - std::vector m_indices; - - draco::rendering::rhi::BufferHandle m_vb = draco::rendering::rhi::InvalidBuffer; - - draco::rendering::rhi::BufferHandle m_ib = draco::rendering::rhi::InvalidBuffer; - - draco::rendering::rhi::LayoutHandle m_layout = draco::rendering::rhi::InvalidLayout; - - draco::rendering::rhi::PipelineHandle m_pipeline = draco::rendering::rhi::InvalidPipeline; - - draco::rendering::rhi::UniformHandle m_sampler = draco::rendering::rhi::InvalidUniform; - - u32 m_quad_count = 0; - }; -} diff --git a/Engine/cpp/runtime/rendering/renderer/renderer.cpp b/Engine/cpp/runtime/rendering/renderer/renderer.cpp deleted file mode 100644 index e6506a8c..00000000 --- a/Engine/cpp/runtime/rendering/renderer/renderer.cpp +++ /dev/null @@ -1,159 +0,0 @@ -module; - -#include -#include -#include -#include -#include - -#include -#include - -module rendering.renderer; - -import core.stdtypes; -import core.math.transform; -import rendering.rhi; -import rendering.rhi.uniform_registry; -import rendering.rendergraph; -import rendering.mesh; -import rendering.material; -import rendering.quad_renderer; - -namespace draco::rendering::renderer -{ - static constexpr const char* MAIN_PASS = "MainPass"; - - void init(u16 width, u16 height) - { - g_ctx.screen_width = width; - g_ctx.screen_height = height; - } - - void resize(u16 width, u16 height) - { - g_ctx.screen_width = width; - g_ctx.screen_height = height; - } - - void begin_frame(const Camera& cam) - { - rhi::begin_frame(); - - g_ctx.main_camera = cam; - g_ctx.graph.reset(); - - // Create main pass once per frame - auto& pass = g_ctx.graph.add_pass(MAIN_PASS); - - pass.view = 0; - pass.framebuffer = rhi::InvalidFramebuffer; - - pass.width = g_ctx.screen_width; - pass.height = g_ctx.screen_height; - - pass.clear_flags = BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH; - pass.clear_color = 0x303030ff; - - f32 view_mtx[16]; - f32 proj_mtx[16]; - - rhi::look_at(view_mtx, cam.position.data(), cam.target.data(), cam.up.data()); - - f32 aspect = f32(g_ctx.screen_width) / f32(std::max(g_ctx.screen_height, 1)); - - rhi::perspective(proj_mtx, cam.fov, aspect, cam.near_plane, cam.far_plane); - - std::memcpy(pass.view_mtx, view_mtx, sizeof(view_mtx)); - std::memcpy(pass.proj_mtx, proj_mtx, sizeof(proj_mtx)); - } - - static void build_uniforms(const material::Material& mat, std::vector& out) - { - out.clear(); - out.reserve(mat.uniforms.size()); - - for (const auto& u : mat.uniforms) - { - rhi::UniformBind bind{}; - - bind.handle = rhi::get_uniform(u.name_hash); - - bind.data = u.data; - bind.num = u.count; - - if (bind.handle == rhi::InvalidUniform) - { - std::println("[Renderer] Missing uniform hash: {}", u.name_hash); - continue; - } - - out.push_back(bind); - } - } - - void submit_entity(const rhi::RenderPacket& packet) - { - auto* pass = g_ctx.graph.get_pass(MAIN_PASS); - if (!pass) return; - - pass->packets.push_back(packet); - } - - void submit_renderable(const draco::math::Transform& transform, const material::Material& material, mesh::MeshHandle mesh_id) - { - const auto* m = mesh::get(mesh_id); - if (!m) return; - - rhi::RenderPacket p{}; - - p.vertex_buffer = m->vbh; - p.index_buffer = m->ibh; - - p.pipeline = material.pipeline; - p.texture_handle = material.texture; - p.texture_unit = material.texture_unit; - p.sampler_uniform = material.sampler; - - build_uniforms(material, p.uniforms); - - transform.to_matrix(p.model); - - submit_entity(p); - } - - void submit_ui(draco::rendering::quad_renderer::QuadRenderer& quad_renderer) - { - auto& ui_pass = g_ctx.graph.add_pass("UIPass"); - - ui_pass.view = 1; - ui_pass.sort_mode = rendergraph::SortMode::None; - - ui_pass.framebuffer = rhi::InvalidFramebuffer; - - ui_pass.width = g_ctx.screen_width; - ui_pass.height = g_ctx.screen_height; - - ui_pass.clear_flags = 0; - - draco::rendering::quad_renderer::OrthoCamera ortho; - - draco::rendering::quad_renderer::QuadRenderer::build_ortho(ortho, (f32)g_ctx.screen_width, (f32)g_ctx.screen_height); - - std::memcpy(ui_pass.view_mtx, ortho.view, sizeof(f32) * 16); - std::memcpy(ui_pass.proj_mtx, ortho.proj, sizeof(f32) * 16); - - quad_renderer.flush_to_pass(ui_pass); - } - - void end_frame() - { - g_ctx.graph.execute(); - rhi::end_frame(); - } - - rendergraph::RenderGraph& get_graph() - { - return draco::rendering::renderer::g_ctx.graph; - } -} diff --git a/Engine/cpp/runtime/rendering/renderer/renderer.cppm b/Engine/cpp/runtime/rendering/renderer/renderer.cppm deleted file mode 100644 index bcc9d184..00000000 --- a/Engine/cpp/runtime/rendering/renderer/renderer.cppm +++ /dev/null @@ -1,50 +0,0 @@ -module; - -#include - -#include - -export module rendering.renderer; - -import core.stdtypes; -import core.math.transform; -import rendering.rhi; -import rendering.rendergraph; -import rendering.quad_renderer; -import rendering.material; -import rendering.mesh; - -export namespace draco::rendering::renderer { - - struct Camera { - std::array position {0.0f, 0.0f, 0.0f}; - std::array target {0.0f, 0.0f, 0.0f}; - std::array up {0.0f, 1.0f, 0.0f}; - f32 fov = 60.0f; - f32 near_plane = 0.1f; - f32 far_plane = 1000.0f; - }; - - struct SceneContext { - u16 screen_width = 0; - u16 screen_height = 0; - Camera main_camera; - - draco::rendering::rendergraph::RenderGraph graph; - }; - - inline SceneContext g_ctx; - - void init(u16 width, u16 height); - void resize(u16 width, u16 height); - - void begin_frame(const Camera& cam); - - void submit_entity(draco::rendering::rhi::RenderPacket& packet, u16 view); - void submit_renderable(const draco::math::Transform& transform, const material::Material& material, mesh::MeshHandle mesh_id); - void submit_ui(draco::rendering::quad_renderer::QuadRenderer& quad_renderer); - - void end_frame(); - - rendergraph::RenderGraph& get_graph(); -} diff --git a/Engine/cpp/runtime/scene/CMakeLists.txt b/Engine/cpp/runtime/scene/CMakeLists.txt deleted file mode 100644 index 905e8a34..00000000 --- a/Engine/cpp/runtime/scene/CMakeLists.txt +++ /dev/null @@ -1,7 +0,0 @@ -add_modules_library(camera) -add_modules_library(transform_component) -add_modules_library(renderable) - -target_link_libraries(camera PUBLIC core input rendering bx) -target_link_libraries(transform_component PUBLIC core) -target_link_libraries(renderable PUBLIC core mesh transform_component material) diff --git a/Engine/cpp/runtime/scene/camera/camera_controller.cpp b/Engine/cpp/runtime/scene/camera/camera_controller.cpp deleted file mode 100644 index f9a1d224..00000000 --- a/Engine/cpp/runtime/scene/camera/camera_controller.cpp +++ /dev/null @@ -1,100 +0,0 @@ -module; - -#include -#include - -module scene.camera.controller; - -import input; - -namespace draco::scene -{ - void CameraController::init(f32 x, f32 y, f32 z) - { - m_x = x; - m_y = y; - m_z = z; - - m_yaw = 0.0f; - m_pitch = 0.0f; - - m_speed = 5.0f; // units per second - m_sensitivity = 0.002f; // mouse sensitivity - } - - void CameraController::update(f32 dt) - { - m_yaw += draco::input::get_mouse_dx() * m_sensitivity; - m_pitch -= draco::input::get_mouse_dy() * m_sensitivity; // Temp fix to flip mouse input - - // Clamp pitch - if (m_pitch > 1.5f) m_pitch = 1.5f; - if (m_pitch < -1.5f) m_pitch = -1.5f; - - bx::Vec3 forward = { - cosf(m_pitch) * sinf(m_yaw), - sinf(m_pitch), - cosf(m_pitch) * cosf(m_yaw) - }; - - bx::Vec3 right = { - sinf(m_yaw - bx::kPiHalf), - 0.0f, - cosf(m_yaw - bx::kPiHalf) - }; - - f32 velocity = m_speed * dt; - - if (draco::input::is_down(draco::input::Key::W)) - { - m_x += forward.x * velocity; - m_y += forward.y * velocity; - m_z += forward.z * velocity; - } - - if (draco::input::is_down(draco::input::Key::S)) - { - m_x -= forward.x * velocity; - m_y -= forward.y * velocity; - m_z -= forward.z * velocity; - } - - if (draco::input::is_down(draco::input::Key::A)) - { - m_x += right.x * velocity; - m_z += right.z * velocity; - } - - if (draco::input::is_down(draco::input::Key::D)) - { - m_x -= right.x * velocity; - m_z -= right.z * velocity; - } - } - - draco::rendering::renderer::Camera CameraController::get_camera() const - { - bx::Vec3 forward = { - cosf(m_pitch) * sinf(m_yaw), - sinf(m_pitch), - cosf(m_pitch) * cosf(m_yaw) - }; - - draco::rendering::renderer::Camera cam{}; - - cam.position = { m_x, m_y, m_z }; - cam.target = { - m_x + forward.x, - m_y + forward.y, - m_z + forward.z - }; - - cam.up = { 0.0f, 1.0f, 0.0f }; - - cam.fov = 60.0f; - cam.near_plane = 0.1f; - cam.far_plane = 100.0f; - - return cam; - } -} diff --git a/Engine/cpp/runtime/scene/camera/camera_controller.cppm b/Engine/cpp/runtime/scene/camera/camera_controller.cppm deleted file mode 100644 index 7dd607a9..00000000 --- a/Engine/cpp/runtime/scene/camera/camera_controller.cppm +++ /dev/null @@ -1,24 +0,0 @@ -export module scene.camera.controller; - -import core.stdtypes; -import rendering; - -export namespace draco::scene -{ - struct CameraController - { - void init(f32 x = 0.0f, f32 y = 0.0f, f32 z = -2.0f); - - void update(f32 dt); - - draco::rendering::renderer::Camera get_camera() const; - - private: - // Init with default values - f32 m_x = 0.0f, m_y = 0.0f, m_z = 0.0f; - f32 m_yaw = 0.0f; - f32 m_pitch = 0.0f; - f32 m_speed = 5.0f; - f32 m_sensitivity = 0.1f; - }; -} \ No newline at end of file diff --git a/Samples/cpp/CMakeLists.txt b/Samples/cpp/CMakeLists.txt index 5ed5dfae..0d3c9e18 100644 --- a/Samples/cpp/CMakeLists.txt +++ b/Samples/cpp/CMakeLists.txt @@ -1,38 +1,38 @@ # # Rendering Sample # -add_executable(Render rendering.cpp) +add_executable(RenderSample RenderSample.cpp) -target_link_libraries(Render +target_link_libraries(RenderSample PRIVATE - runtime + Runtime bgfx bx bimg ) if(UNIX AND NOT APPLE) - target_link_libraries(Render PRIVATE SDL3::SDL3-static Threads::Threads dl) - target_link_options(Render PRIVATE -Wl,--whole-archive $ -Wl,--no-whole-archive) + target_link_libraries(RenderSample PRIVATE SDL3::SDL3-static Threads::Threads dl) + target_link_options(RenderSample PRIVATE -Wl,--whole-archive $ -Wl,--no-whole-archive) elseif(APPLE) - target_link_libraries(Render PRIVATE SDL3::SDL3-static) - target_link_options(Render PRIVATE -Wl,-force_load,$) + target_link_libraries(RenderSample PRIVATE SDL3::SDL3-static) + target_link_options(RenderSample PRIVATE -Wl,-force_load,$) else() - target_link_libraries(Render PRIVATE SDL3::SDL3-static) + target_link_libraries(RenderSample PRIVATE SDL3::SDL3-static) endif() -compile_shaders(Render) +compile_shaders(RenderSample) set(TEST_IMAGE "${CMAKE_SOURCE_DIR}/Docs/assets/draconic_logo_no_text.png" ) add_custom_command( - TARGET Render POST_BUILD + TARGET RenderSample POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different ${TEST_IMAGE} - $/test.png + $/test.png COMMENT "Copying test texture..." ) diff --git a/Samples/cpp/RenderSample.cpp b/Samples/cpp/RenderSample.cpp new file mode 100644 index 00000000..456ea15b --- /dev/null +++ b/Samples/cpp/RenderSample.cpp @@ -0,0 +1,211 @@ +#include +#include +#include + +#include +#include +#include + +import draconic; + +int main(int argc, char* argv[]) +{ + if (!SDL_Init(SDL_INIT_VIDEO)) { + std::println("SDL init failed: {}", SDL_GetError()); + return -1; + } + + SDL_Window* window = SDL_CreateWindow( + "Draconic Engine Rendering Sample", + 1280, 720, + SDL_WINDOW_RESIZABLE + ); + + if (!window) { + std::println("Failed to create window: {}", SDL_GetError()); + SDL_Quit(); + return -1; + } + + draco::input::setMouseCaptured(window, true); + + auto handles = draco::platform::getNativeHandles(window); + + if (!handles.valid) { + std::println("Failed to get native handles"); + SDL_DestroyWindow(window); + SDL_Quit(); + return -1; + } + + if (!draco::rendering::rhi::init(handles.ndt, handles.nwh, handles.type, 1280, 720)) { + std::println("RHI init failed"); + SDL_DestroyWindow(window); + SDL_Quit(); + return -1; + } + + draco::rendering::renderer::init(1280, 720); + + auto cube_mesh = draco::rendering::mesh::createCube(); + auto plane_mesh = draco::rendering::mesh::createPlane(5.0f); + auto sphere_mesh = draco::rendering::mesh::createSphere(24, 16); + auto cylinder_mesh = draco::rendering::mesh::createCylinder(24, 2.0f); + auto capsule_mesh = draco::rendering::mesh::createCapsule(24, 12, 2.0f); + + auto img = draco::core::io::loader::image::loadImage("test.png"); + + draco::rendering::rhi::TextureHandle tex = draco::rendering::rhi::InvalidTexture; + + if (img.isValid) { + tex = draco::rendering::rhi::createTexture(img.pixels.data(), img.width, img.height); + } + + auto s_texColor = draco::rendering::rhi::createUniform("s_texColor", draco::rendering::rhi::UniformType::Sampler); + + auto vs = draco::core::io::filesystem::loadBinary("vs.bin"); + auto fs = draco::core::io::filesystem::loadBinary("fs.bin"); + + auto vs_quad = draco::core::io::filesystem::loadBinary("vs_quad.bin"); + auto fs_quad = draco::core::io::filesystem::loadBinary("fs_quad.bin"); + + if (vs.empty() || fs.empty() || vs_quad.empty() || fs_quad.empty()) { + std::println("Shader load failed"); + draco::rendering::rhi::shutdown(); + SDL_DestroyWindow(window); + SDL_Quit(); + return -1; + } + + auto vsh = draco::rendering::rhi::createShader(vs.data(), (draco::u32)vs.size()); + auto fsh = draco::rendering::rhi::createShader(fs.data(), (draco::u32)fs.size()); + + auto vsh_quad = draco::rendering::rhi::createShader(vs_quad.data(), (draco::u32)vs_quad.size()); + auto fsh_quad = draco::rendering::rhi::createShader(fs_quad.data(), (draco::u32)fs_quad.size()); + + auto pipeline = draco::rendering::rhi::createPipeline({vsh, fsh, draco::rendering::rhi::PipelineState::WriteRGB | draco::rendering::rhi::PipelineState::WriteAlpha | draco::rendering::rhi::PipelineState::MSAA, draco::rendering::rhi::BlendMode::None, draco::rendering::rhi::DepthTest::Less, draco::rendering::rhi::CullMode::CCW, true}); + + auto pipeline_quad = draco::rendering::rhi::createPipeline({vsh_quad, fsh_quad, draco::rendering::rhi::PipelineState::WriteRGB | draco::rendering::rhi::PipelineState::WriteAlpha | draco::rendering::rhi::PipelineState::MSAA, draco::rendering::rhi::BlendMode::Alpha, draco::rendering::rhi::DepthTest::None, draco::rendering::rhi::CullMode::None, true}); + + draco::rendering::quad::QuadRenderer quad_renderer; + quad_renderer.init(pipeline_quad); + + draco::scene::CameraController camera; + camera.init(); + + auto u_tint = draco::rendering::rhi::createUniform("u_tint", draco::rendering::rhi::UniformType::Vec4); + auto u_offset = draco::rendering::rhi::createUniform("u_offset", draco::rendering::rhi::UniformType::Vec4); + + draco::rendering::rhi::registerUniform(draco::rendering::rhi::hashUniform("u_tint"), u_tint); + + draco::rendering::rhi::registerUniform(draco::rendering::rhi::hashUniform("u_offset"), u_offset); + + draco::f32 tint[4] = {1,1,1,1}; + draco::f32 offset[4] = {0,0,0,0}; + + bool running = true; + bool mouse_captured = true; + + draco::rendering::material::Material mat{}; + mat.pipeline = pipeline; + mat.texture = tex; + mat.sampler = s_texColor; + + mat.uniforms.push_back({.nameHash = draco::rendering::rhi::hashUniform("u_tint"), .data = tint, .count = 1}); + mat.uniforms.push_back({.nameHash = draco::rendering::rhi::hashUniform("u_offset"), .data = offset, .count = 1}); + + draco::scene::Scene scene; + + static constexpr draco::math::Transform tr; + + scene.renderables.push_back({cube_mesh, tr, mat}); + scene.renderables.push_back({plane_mesh, tr, mat}); + scene.renderables.push_back({sphere_mesh, tr, mat}); + scene.renderables.push_back({cylinder_mesh, tr, mat}); + scene.renderables.push_back({capsule_mesh, tr, mat}); + + scene.renderables[0].transform.setPosition(-12.0f, 0.0f, 0.0f); + scene.renderables[1].transform.setPosition(-6.0f, 0.0f, 0.0f); + scene.renderables[2].transform.setPosition(0.0f, 0.0f, 0.0f); + scene.renderables[3].transform.setPosition(6.0f, 0.0f, 0.0f); + scene.renderables[4].transform.setPosition(12.0f, 0.0f, 0.0f); + + scene.renderables[1].transform.setRotation(-bx::kPiHalf, 0.0f, 0.0f); + + while (running) + { + static draco::u64 last = SDL_GetTicks(); + draco::u64 now = SDL_GetTicks(); + draco::f32 dt = static_cast(now - last) / 1000.0f; + last = now; + + SDL_Event e; + draco::input::beginFrame(); + + while (SDL_PollEvent(&e)) + { + if (e.type == SDL_EVENT_QUIT) + running = false; + + if (e.type == SDL_EVENT_KEY_DOWN && + e.key.key == SDLK_ESCAPE) + { + mouse_captured = !mouse_captured; + draco::input::setMouseCaptured(window, mouse_captured); + } + + draco::input::processEvent(e); + } + + int w, h; + SDL_GetWindowSize(window, &w, &h); + + if (w <= 0 || h <= 0) + { + continue; + } + + draco::rendering::rhi::resize((draco::u16)w, (draco::u16)h); + draco::rendering::renderer::resize((draco::u16)w, (draco::u16)h); + + camera.update(dt); + auto cam = camera.getCamera(); + + draco::rendering::renderer::beginFrame(cam); + + for (const auto& renderable : scene.renderables) + { + draco::rendering::renderer::submitRenderable(renderable.transform, renderable.material, renderable.mesh); + } + + quad_renderer.begin(); + + static draco::f32 quad_base_x = 400.0f; + static draco::f32 quad_base_y = 300.0f; + + for (int i = 0; i < 50; i++) + { + draco::rendering::quad::QuadCommand q{}; + + q.texture = tex; + q.color = 0xffffffff; + q.x = quad_base_x + std::sin(SDL_GetTicks() * 0.001f + i) * 50.0f; + q.y = quad_base_y + i * 6.0f; + q.width = 50.0f; + q.height = 50.0f; + q.rotation = SDL_GetTicks() * 0.001f; + + quad_renderer.submit(q); + } + + draco::rendering::renderer::submitUI(quad_renderer); + + draco::rendering::renderer::endFrame(); + } + + draco::rendering::rhi::shutdown(); + SDL_DestroyWindow(window); + SDL_Quit(); + + return 0; +} diff --git a/Samples/cpp/rendering.cpp b/Samples/cpp/rendering.cpp deleted file mode 100644 index 6dd2da9a..00000000 --- a/Samples/cpp/rendering.cpp +++ /dev/null @@ -1,211 +0,0 @@ -#include -#include -#include - -#include -#include -#include - -import draconic; - -int main(int argc, char* argv[]) -{ - if (!SDL_Init(SDL_INIT_VIDEO)) { - std::println("SDL init failed: {}", SDL_GetError()); - return -1; - } - - SDL_Window* window = SDL_CreateWindow( - "Draconic Engine Rendering Sample", - 1280, 720, - SDL_WINDOW_RESIZABLE - ); - - if (!window) { - std::println("Failed to create window: {}", SDL_GetError()); - SDL_Quit(); - return -1; - } - - draco::input::set_mouse_captured(window, true); - - auto handles = draco::platform::get_native_handles(window); - - if (!handles.valid) { - std::println("Failed to get native handles"); - SDL_DestroyWindow(window); - SDL_Quit(); - return -1; - } - - if (!draco::rendering::rhi::init(handles.ndt, handles.nwh, handles.type, 1280, 720)) { - std::println("RHI init failed"); - SDL_DestroyWindow(window); - SDL_Quit(); - return -1; - } - - draco::rendering::renderer::init(1280, 720); - - auto cube_mesh = draco::rendering::mesh::create_cube(); - auto plane_mesh = draco::rendering::mesh::create_plane(5.0f); - auto sphere_mesh = draco::rendering::mesh::create_sphere(24, 16); - auto cylinder_mesh = draco::rendering::mesh::create_cylinder(24, 2.0f); - auto capsule_mesh = draco::rendering::mesh::create_capsule(24, 12, 2.0f); - - auto img = draco::core::io::image_loader::load_image("test.png"); - - draco::rendering::rhi::TextureHandle tex = draco::rendering::rhi::InvalidTexture; - - if (img.is_valid) { - tex = draco::rendering::rhi::create_texture(img.pixels.data(), img.width, img.height); - } - - auto s_texColor = draco::rendering::rhi::create_uniform("s_texColor", draco::rendering::rhi::UniformType::Sampler); - - auto vs = draco::core::io::filesystem::load_binary("vs.bin"); - auto fs = draco::core::io::filesystem::load_binary("fs.bin"); - - auto vs_quad = draco::core::io::filesystem::load_binary("vs_quad.bin"); - auto fs_quad = draco::core::io::filesystem::load_binary("fs_quad.bin"); - - if (vs.empty() || fs.empty() || vs_quad.empty() || fs_quad.empty()) { - std::println("Shader load failed"); - draco::rendering::rhi::shutdown(); - SDL_DestroyWindow(window); - SDL_Quit(); - return -1; - } - - auto vsh = draco::rendering::rhi::create_shader(vs.data(), (draco::u32)vs.size()); - auto fsh = draco::rendering::rhi::create_shader(fs.data(), (draco::u32)fs.size()); - - auto vsh_quad = draco::rendering::rhi::create_shader(vs_quad.data(), (draco::u32)vs_quad.size()); - auto fsh_quad = draco::rendering::rhi::create_shader(fs_quad.data(), (draco::u32)fs_quad.size()); - - auto pipeline = draco::rendering::rhi::create_pipeline({vsh, fsh, draco::rendering::rhi::PipelineState::WriteRGB | draco::rendering::rhi::PipelineState::WriteAlpha | draco::rendering::rhi::PipelineState::MSAA, draco::rendering::rhi::BlendMode::None, draco::rendering::rhi::DepthTest::Less, draco::rendering::rhi::CullMode::CCW, true}); - - auto pipeline_quad = draco::rendering::rhi::create_pipeline({vsh_quad, fsh_quad, draco::rendering::rhi::PipelineState::WriteRGB | draco::rendering::rhi::PipelineState::WriteAlpha | draco::rendering::rhi::PipelineState::MSAA, draco::rendering::rhi::BlendMode::Alpha, draco::rendering::rhi::DepthTest::None, draco::rendering::rhi::CullMode::None, true}); - - draco::rendering::quad_renderer::QuadRenderer quad_renderer; - quad_renderer.init(pipeline_quad); - - draco::scene::CameraController camera; - camera.init(); - - auto u_tint = draco::rendering::rhi::create_uniform("u_tint", draco::rendering::rhi::UniformType::Vec4); - auto u_offset = draco::rendering::rhi::create_uniform("u_offset", draco::rendering::rhi::UniformType::Vec4); - - draco::rendering::rhi::register_uniform(draco::rendering::rhi::hash_uniform("u_tint"), u_tint); - - draco::rendering::rhi::register_uniform(draco::rendering::rhi::hash_uniform("u_offset"), u_offset); - - draco::f32 tint[4] = {1,1,1,1}; - draco::f32 offset[4] = {0,0,0,0}; - - bool running = true; - bool mouse_captured = true; - - draco::rendering::material::Material mat{}; - mat.pipeline = pipeline; - mat.texture = tex; - mat.sampler = s_texColor; - - mat.uniforms.push_back({.name_hash = draco::rendering::rhi::hash_uniform("u_tint"), .data = tint, .count = 1}); - mat.uniforms.push_back({.name_hash = draco::rendering::rhi::hash_uniform("u_offset"), .data = offset, .count = 1}); - - draco::scene::Scene scene; - - static constexpr draco::math::Transform tr; - - scene.renderables.push_back({cube_mesh, tr, mat}); - scene.renderables.push_back({plane_mesh, tr, mat}); - scene.renderables.push_back({sphere_mesh, tr, mat}); - scene.renderables.push_back({cylinder_mesh, tr, mat}); - scene.renderables.push_back({capsule_mesh, tr, mat}); - - scene.renderables[0].transform.set_position(-12.0f, 0.0f, 0.0f); - scene.renderables[1].transform.set_position(-6.0f, 0.0f, 0.0f); - scene.renderables[2].transform.set_position(0.0f, 0.0f, 0.0f); - scene.renderables[3].transform.set_position(6.0f, 0.0f, 0.0f); - scene.renderables[4].transform.set_position(12.0f, 0.0f, 0.0f); - - scene.renderables[1].transform.set_rotation(-bx::kPiHalf, 0.0f, 0.0f); - - while (running) - { - static draco::u64 last = SDL_GetTicks(); - draco::u64 now = SDL_GetTicks(); - draco::f32 dt = static_cast(now - last) / 1000.0f; - last = now; - - SDL_Event e; - draco::input::begin_frame(); - - while (SDL_PollEvent(&e)) - { - if (e.type == SDL_EVENT_QUIT) - running = false; - - if (e.type == SDL_EVENT_KEY_DOWN && - e.key.key == SDLK_ESCAPE) - { - mouse_captured = !mouse_captured; - draco::input::set_mouse_captured(window, mouse_captured); - } - - draco::input::process_event(e); - } - - int w, h; - SDL_GetWindowSize(window, &w, &h); - - if (w <= 0 || h <= 0) - { - continue; - } - - draco::rendering::rhi::resize((draco::u16)w, (draco::u16)h); - draco::rendering::renderer::resize((draco::u16)w, (draco::u16)h); - - camera.update(dt); - auto cam = camera.get_camera(); - - draco::rendering::renderer::begin_frame(cam); - - for (const auto& renderable : scene.renderables) - { - draco::rendering::renderer::submit_renderable(renderable.transform, renderable.material, renderable.mesh); - } - - quad_renderer.begin(); - - static draco::f32 quad_base_x = 400.0f; - static draco::f32 quad_base_y = 300.0f; - - for (int i = 0; i < 50; i++) - { - draco::rendering::quad_renderer::QuadCommand q{}; - - q.texture = tex; - q.color = 0xffffffff; - q.x = quad_base_x + std::sin(SDL_GetTicks() * 0.001f + i) * 50.0f; - q.y = quad_base_y + i * 6.0f; - q.width = 50.0f; - q.height = 50.0f; - q.rotation = SDL_GetTicks() * 0.001f; - - quad_renderer.submit(q); - } - - draco::rendering::renderer::submit_ui(quad_renderer); - - draco::rendering::renderer::end_frame(); - } - - draco::rendering::rhi::shutdown(); - SDL_DestroyWindow(window); - SDL_Quit(); - - return 0; -} diff --git a/cmake/Modules.cmake b/cmake/Modules.cmake index f29d7615..c99068e7 100644 --- a/cmake/Modules.cmake +++ b/cmake/Modules.cmake @@ -2,7 +2,7 @@ include_guard(GLOBAL) set(NATIVE_SOURCE_DIR "${PROJECT_SOURCE_DIR}/Engine/cpp") -set(NATIVE_THIRD_PARTY_DIR "${NATIVE_SOURCE_DIR}/thirdparty") +set(NATIVE_THIRD_PARTY_DIR "${NATIVE_SOURCE_DIR}/ThirdParty") if (BUILD_TESTING) set(DOCTEST_INCLUDE_DIR "${NATIVE_THIRD_PARTY_DIR}/doctest") diff --git a/cmake/Shaders.cmake b/cmake/Shaders.cmake index 5085555b..1d638ed8 100644 --- a/cmake/Shaders.cmake +++ b/cmake/Shaders.cmake @@ -1,8 +1,8 @@ include_guard(GLOBAL) -set(SHADER_SRC_DIR "${CMAKE_SOURCE_DIR}/Engine/cpp/runtime/rendering/shaders") +set(SHADER_SRC_DIR "${CMAKE_SOURCE_DIR}/Engine/cpp/Runtime/Rendering/Shaders") set(SHADER_BIN_DIR "${CMAKE_BINARY_DIR}") -set(BGFX_INCLUDE "${CMAKE_SOURCE_DIR}/Engine/cpp/thirdparty/bgfx/src") +set(BGFX_INCLUDE "${CMAKE_SOURCE_DIR}/Engine/cpp/ThirdParty/bgfx/src") function(compile_shaders TARGET_NAME) file(MAKE_DIRECTORY ${SHADER_BIN_DIR})