From 9d4e7ae0014b15b798bf8b15bd4fcfee4d998c7a Mon Sep 17 00:00:00 2001 From: Arnav Mehta <77837038+ArnavMehta3000@users.noreply.github.com> Date: Wed, 14 Aug 2024 01:44:56 +0100 Subject: [PATCH] Big revert changes (#43) * Revert "Remove unused files + update clang file (#37)" This reverts commit a4cd8c57cc606a8b0302871655953f3f711dd7e6. * Revert "New Clang Format Files (#36)" This reverts commit 589455e56b27376001beb3d45130de444624a925. # Conflicts: # old/entry.cpp # old/metal/renderer.cpp # old/metal/renderer.hpp # old/opengl/Application.cpp # old/opengl/Application.h # old/opengl/Cube.cpp # old/opengl/Cube.h # old/opengl/Shader.cpp # old/opengl/Shader.h * Revert "Update clang format file (#35)" This reverts commit c1de59c34e17d8890df208ff8c6eeb1d68d2449f. * Revert "Feat: added a pre-commit hook for linting" This reverts commit 2dd5343249a7f7173b6020cc74f1e995a6511900. # Conflicts: # old/entry.cpp # old/metal/renderer.cpp # old/metal/renderer.hpp # old/opengl/Application.cpp # old/opengl/Application.h # old/opengl/Cube.cpp # old/opengl/Cube.h # old/opengl/Shader.cpp # old/opengl/Shader.h * Post revert file updates * Added watch dir macro * Update windows.yml --- .clang-format | 34 - .github/workflows/windows.yml | 7 +- .pre-commit-config.yaml | 5 - Core/Application/Application.cpp | 255 ++-- Core/Application/Application.h | 48 +- Core/Application/AssetFinder.cpp | 10 +- Core/Application/AssetFinder.h | 4 +- Core/Common.h | 17 +- Core/External/SimpleMath.cpp | 112 +- Core/External/SimpleMath.h | 1143 ++++++----------- Core/External/SimpleMath.inl | 1005 +++++++-------- Core/Graphics/Buffer.h | 68 +- Core/Graphics/Camera.cpp | 297 +++-- Core/Graphics/Camera.h | 105 +- Core/Graphics/Graphics.h | 1 + Core/Graphics/Material.cpp | 76 +- Core/Graphics/Material.h | 7 +- Core/Graphics/RHI/D3D11/D3D11ConstantBuffer.h | 24 +- Core/Graphics/RHI/D3D11/D3D11IndexBuffer.h | 14 +- Core/Graphics/RHI/D3D11/D3D11PixelShader.h | 12 +- Core/Graphics/RHI/D3D11/D3D11Renderer.cpp | 855 ++++++------ Core/Graphics/RHI/D3D11/D3D11RendererImpl.cpp | 526 ++++---- Core/Graphics/RHI/D3D11/D3D11RendererImpl.h | 75 +- Core/Graphics/RHI/D3D11/D3D11VertexBuffer.h | 14 +- Core/Graphics/RHI/D3D11/D3D11VertexShader.h | 14 +- Core/Graphics/RHI/D3DCommon.h | 121 +- Core/Graphics/RHI/Metal/METALRenderer.cpp | 58 +- Core/Graphics/RHI/Metal/METALRendererImpl.cpp | 36 +- Core/Graphics/RHI/Metal/METALRendererImpl.h | 54 +- Core/Graphics/RHI/OpenGL/OPENGLRenderer.cpp | 20 +- .../RHI/OpenGL/OPENGLRendererImpl.cpp | 10 +- Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.h | 10 +- Core/Graphics/Renderer.cpp | 277 ++-- Core/Graphics/Renderer.h | 155 ++- Core/Graphics/Renderer.inl | 36 +- Core/Graphics/RendererImpl.h | 18 +- Core/Graphics/Shader/Shader.h | 36 +- Core/Graphics/Shader/ShaderCompileResult.h | 24 +- Core/Graphics/Shader/ShaderCompiler.cpp | 159 +-- Core/Graphics/Shader/ShaderCompiler.h | 39 +- Core/Graphics/Shader/ShaderSource.h | 12 +- Core/Graphics/Types.h | 322 ++--- Core/Logging/ILogOutput.h | 16 +- Core/Logging/Log.cpp | 21 +- Core/Logging/Log.h | 165 ++- Core/Logging/LogLevel.h | 20 +- Core/Logging/LogManager.cpp | 32 +- Core/Logging/LogManager.h | 48 +- Core/Math/Math.h | 6 +- .../Platform/Linux/Logging/LinuxLogOutput.cpp | 136 +- Core/Platform/Linux/Logging/LinuxLogOutput.h | 64 +- Core/Platform/LogOutput.h | 36 +- .../MacOSX/Logging/MacOSXLogOutput.cpp | 136 +- .../Platform/MacOSX/Logging/MacOSXLogOutput.h | 64 +- Core/Platform/Win32/Error/HResultError.cpp | 29 +- Core/Platform/Win32/Error/HResultError.h | 2 +- .../Platform/Win32/Logging/Win32LogOutput.cpp | 229 ++-- Core/Platform/Win32/Logging/Win32LogOutput.h | 68 +- Core/Platform/Win32/StringUtils.h | 38 +- Core/Types.h | 4 +- Core/Utils/Singleton.h | 89 +- LoadMacros.bat | 1 + LoadMacros.sh | 1 + Samples/BlankApp/BlankApp.cpp | 86 +- Samples/BlankApp/BlankApp.h | 34 +- Samples/BlankApp/Main.cpp | 24 +- Samples/HelloTriangle/HelloTriangle.cpp | 202 +-- Samples/HelloTriangle/HelloTriangle.h | 40 +- Samples/HelloTriangle/Main.cpp | 24 +- Samples/SpinningCube/Main.cpp | 24 +- Samples/SpinningCube/SpinningCube.cpp | 345 ++--- Samples/SpinningCube/SpinningCube.h | 58 +- Scripts/Macros/WatchDir.lua | 4 + 73 files changed, 3884 insertions(+), 4277 deletions(-) delete mode 100644 .clang-format delete mode 100644 .pre-commit-config.yaml create mode 100644 Scripts/Macros/WatchDir.lua diff --git a/.clang-format b/.clang-format deleted file mode 100644 index ed3b611..0000000 --- a/.clang-format +++ /dev/null @@ -1,34 +0,0 @@ ---- -BasedOnStyle: Microsoft -AccessModifierOffset: -4 -AlignArrayOfStructures: Left -AlignConsecutiveAssignments: - Enabled: true -AlignConsecutiveShortCaseStatements: - AlignCaseColons: true -AlignEscapedNewlines: Left -AlignTrailingComments: - OverEmptyLines: 2 -AllowShortCaseLabelsOnASingleLine: true -AllowShortEnumsOnASingleLine: true -AllowShortFunctionsOnASingleLine: InlineOnly -AlwaysBreakTemplateDeclarations: Yes -BreakAfterAttributes: Never -BreakBeforeBraces: Allman -BreakConstructorInitializers: BeforeComma -BreakInheritanceList: BeforeComma -CommentPragmas: "" -Cpp11BracedListStyle: false -IncludeBlocks: Merge -IndentPPDirectives: BeforeHash -InsertNewlineAtEOF: true -KeepEmptyLinesAtTheStartOfBlocks: false -LineEnding: CRLF -MaxEmptyLinesToKeep: 2 -NamespaceIndentation: All -PackConstructorInitializers: NextLineOnly -PointerAlignment: Left -SpaceAroundPointerQualifiers: Before -SpacesBeforeTrailingComments: 2 -SpacesInLineCommentPrefix: - Maximum: 1 diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 85e0535..24f52cf 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -74,5 +74,8 @@ jobs: - name: Build Visualizer run: xmake --all --yes - # - name: Run tests - # run: xmake test */compile_pass + - name: Run compile tests + run: xmake test */compile_pass + + - name: Run tests + run: xmake test */run_5_seconds diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index 29e6855..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,5 +0,0 @@ -repos: -- repo: https://github.com/pre-commit/mirrors-clang-format - rev: v18.1.8 - hooks: - - id: clang-format diff --git a/Core/Application/Application.cpp b/Core/Application/Application.cpp index dc7792b..f0c1b6e 100644 --- a/Core/Application/Application.cpp +++ b/Core/Application/Application.cpp @@ -1,138 +1,143 @@ #include "Application.h" #include "SDL_scancode.h" -#include #include +#include namespace CGL::Core { - CGL_DEFINE_LOG_CATEGORY(CoreApp); - - bool g_isTestMode{ false }; - - Application::Application(std::string_view name, i32 argc, char** argv) - : m_name(name), m_isRunning(true), m_window(nullptr) - { - // Parse command line arguments - for (int i = 1; i < argc; ++i) - { - if (std::string(argv[i]) == "-test") - { - CGL_LOG(CoreApp, Info, "Running Visualizer in test mode"); - m_name.append(" - TEST"); - g_isTestMode = true; - } - } - - if (SDL_Init(SDL_INIT_VIDEO) != 0) - { - std::string err(SDL_GetError()); - CGL_LOG(CoreApp, Error, "Failed to initialize SDL: {}", err); - } - else - { - CGL_LOG(CoreApp, Trace, "Core aplication created"); - } - } - - void Application::Run() - { - CGL_LOG(CoreApp, Trace, "Running application"); - - auto startTime = std::chrono::steady_clock::now(); - OnInit(); - - SDL_Event e; - while (m_isRunning) - { - // Handle events on queue - while (SDL_PollEvent(&e) != 0) - { - // User requests quit - if (e.type == SDL_QUIT || e.key.keysym.scancode == SDL_SCANCODE_ESCAPE) - { - m_isRunning = false; - } - else if (e.type == SDL_WINDOWEVENT) - { - switch (e.window.event) - { - case SDL_WINDOWEVENT_RESIZED: OnResize(e.window.data1, e.window.data2); break; - } - } - } - - OnUpdate(e); - - // Call begin and end frame before calling render itself - m_renderer->BeginFrame(); - OnRender(); - m_renderer->EndFrame(); - - // Check for test mode and elapsed time - if (g_isTestMode) - { - auto currentTime = std::chrono::steady_clock::now(); - auto elapsedTime = std::chrono::duration_cast(currentTime - startTime).count(); - if (elapsedTime >= 5) // Run for 5 Seconds - { - CGL_LOG(CoreApp, Info, "Test run completed after 5 seconds. Shutting Down..."); - m_isRunning = false; - } - } - } - - OnShutdown(); - } - - bool Application::OnInit() - { - // Create SDL window - u32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; + CGL_DEFINE_LOG_CATEGORY(CoreApp); + + bool g_isTestMode{ false }; + + Application::Application(std::string_view name, i32 argc, char** argv) + : m_name(name) + , m_isRunning(true) + , m_window(nullptr) + { + // Parse command line arguments + for (int i = 1; i < argc; ++i) + { + if (std::string(argv[i]) == "-test") + { + CGL_LOG(CoreApp, Info, "Running Visualizer in test mode"); + m_name.append(" - TEST"); + g_isTestMode = true; + } + } + + if (SDL_Init(SDL_INIT_VIDEO) != 0) + { + std::string err(SDL_GetError()); + CGL_LOG(CoreApp, Error, "Failed to initialize SDL: {}", err); + } + else + { + CGL_LOG(CoreApp, Trace, "Core aplication created"); + } + + } + + void Application::Run() + { + CGL_LOG(CoreApp, Trace, "Running application"); + + auto startTime = std::chrono::steady_clock::now(); + OnInit(); + + SDL_Event e; + while (m_isRunning) + { + // Handle events on queue + while (SDL_PollEvent(&e) != 0) + { + // User requests quit + if (e.type == SDL_QUIT || e.key.keysym.scancode == SDL_SCANCODE_ESCAPE) + { + m_isRunning = false; + } + else if (e.type == SDL_WINDOWEVENT) + { + switch (e.window.event) + { + case SDL_WINDOWEVENT_RESIZED: + OnResize(e.window.data1, e.window.data2); + break; + } + } + } + + OnUpdate(e); + + // Call begin and end frame before calling render itself + m_renderer->BeginFrame(); + OnRender(); + m_renderer->EndFrame(); + + // Check for test mode and elapsed time + if (g_isTestMode) + { + auto currentTime = std::chrono::steady_clock::now(); + auto elapsedTime = std::chrono::duration_cast(currentTime - startTime).count(); + if (elapsedTime >= 5) // Run for 5 Seconds + { + CGL_LOG(CoreApp, Info, "Test run completed after 5 seconds. Shutting Down..."); + m_isRunning = false; + } + } + } + + OnShutdown(); + } + + bool Application::OnInit() + { + // Create SDL window + u32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI; #if defined(CGL_RHI_OPENGL) - flags |= SDL_WINDOW_OPENGL; + flags |= SDL_WINDOW_OPENGL; #elif defined(CGL_RHI_VULKAN) - flags |= SDL_WINDOW_VULKAN; + flags |= SDL_WINDOW_VULKAN; #elif defined(CGL_RHI_METAL) - flags |= SDL_WINDOW_METAL; + flags |= SDL_WINDOW_METAL; #endif - m_window = SDL_CreateWindow(m_name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags); - if (!m_window) - { - std::string err(SDL_GetError()); - CGL_LOG(CoreApp, Error, "Failed to create SDL window: {}", err); - return false; - } - - // Create renderer - m_renderer = std::make_unique(m_window); - if (!m_renderer) - { - CGL_LOG(CoreApp, Error, "Failed to create renderer"); - return false; - } - - CGL_LOG(CoreApp, Debug, "Core application initialized"); - return true; - } - - void Application::OnShutdown() - { - m_renderer.reset(); - - SDL_DestroyWindow(m_window); - SDL_Quit(); - - CGL_LOG(CoreApp, Debug, "Core application shutdown"); - } - - void Application::OnResize(u32 width, u32 height) - { - if (m_renderer) - { - m_renderer->Resize(width, height); - } - } -} // namespace CGL::Core + m_window = SDL_CreateWindow(m_name.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, flags); + if (!m_window) + { + std::string err(SDL_GetError()); + CGL_LOG(CoreApp, Error, "Failed to create SDL window: {}", err); + return false; + } + + // Create renderer + m_renderer = std::make_unique(m_window); + if (!m_renderer) + { + CGL_LOG(CoreApp, Error, "Failed to create renderer"); + return false; + } + + CGL_LOG(CoreApp, Debug, "Core application initialized"); + return true; + } + + void Application::OnShutdown() + { + m_renderer.reset(); + + SDL_DestroyWindow(m_window); + SDL_Quit(); + + CGL_LOG(CoreApp, Debug, "Core application shutdown"); + } + + void Application::OnResize(u32 width, u32 height) + { + if (m_renderer) + { + m_renderer->Resize(width, height); + } + } +} diff --git a/Core/Application/Application.h b/Core/Application/Application.h index 71768d3..539b183 100644 --- a/Core/Application/Application.h +++ b/Core/Application/Application.h @@ -7,34 +7,34 @@ struct SDL_Window; namespace CGL::Core { - CGL_DECLARE_LOG_CATEGORY(CoreApp); + CGL_DECLARE_LOG_CATEGORY(CoreApp); - class Application - { - public: - public: - Application(std::string_view name, i32 argc, char** argv); - ~Application() = default; + class Application + { + public: + public: + Application(std::string_view name, i32 argc, char** argv); + ~Application() = default; - inline SDL_Window* GetWindow() const noexcept { return m_window; } + inline SDL_Window* GetWindow() const noexcept { return m_window; } - void Run(); + void Run(); - protected: - virtual bool OnInit(); - virtual void OnUpdate(const SDL_Event& e) = 0; - virtual void OnRender() = 0; - virtual void OnShutdown(); - virtual void OnResize(u32 width, u32 height); + protected: + virtual bool OnInit(); + virtual void OnUpdate(const SDL_Event& e) = 0; + virtual void OnRender() = 0; + virtual void OnShutdown(); + virtual void OnResize(u32 width, u32 height); - inline Graphics::Renderer* GetRenderer() const { return m_renderer.get(); } + inline Graphics::Renderer* GetRenderer() const { return m_renderer.get(); } - protected: - bool m_isRunning; + protected: + bool m_isRunning; - private: - std::string m_name; - SDL_Window* m_window; - std::unique_ptr m_renderer; - }; -} // namespace CGL::Core + private: + std::string m_name; + SDL_Window* m_window; + std::unique_ptr m_renderer; + }; +} \ No newline at end of file diff --git a/Core/Application/AssetFinder.cpp b/Core/Application/AssetFinder.cpp index d84a646..46b4292 100644 --- a/Core/Application/AssetFinder.cpp +++ b/Core/Application/AssetFinder.cpp @@ -2,8 +2,8 @@ namespace CGL::Core { - std::string DataToString(const byte* data, size_t size) - { - return std::string(reinterpret_cast(data), size); - } -} // namespace CGL::Core + std::string DataToString(const byte* data, size_t size) + { + return std::string(reinterpret_cast(data), size); + } +} diff --git a/Core/Application/AssetFinder.h b/Core/Application/AssetFinder.h index 7b74c70..eec2d7b 100644 --- a/Core/Application/AssetFinder.h +++ b/Core/Application/AssetFinder.h @@ -1,8 +1,8 @@ #pragma once -#include #include +#include namespace CGL::Core { - std::string DataToString(const byte* data, size_t size); + std::string DataToString(const byte* data, size_t size); } diff --git a/Core/Common.h b/Core/Common.h index 76fd6b3..a3102e5 100644 --- a/Core/Common.h +++ b/Core/Common.h @@ -1,14 +1,15 @@ #pragma once -#include -#include -#include #include -#include -#include -#include -#include #include #include -#include +#include +#include +#include +#include #include +#include +#include + +#include +#include diff --git a/Core/External/SimpleMath.cpp b/Core/External/SimpleMath.cpp index fd92188..47784da 100644 --- a/Core/External/SimpleMath.cpp +++ b/Core/External/SimpleMath.cpp @@ -20,37 +20,38 @@ namespace DirectX { namespace SimpleMath { - const Vector2 Vector2::Zero = { 0.f, 0.f }; - const Vector2 Vector2::One = { 1.f, 1.f }; + const Vector2 Vector2::Zero = { 0.f, 0.f }; + const Vector2 Vector2::One = { 1.f, 1.f }; const Vector2 Vector2::UnitX = { 1.f, 0.f }; const Vector2 Vector2::UnitY = { 0.f, 1.f }; - const Vector3 Vector3::Zero = { 0.f, 0.f, 0.f }; - const Vector3 Vector3::One = { 1.f, 1.f, 1.f }; - const Vector3 Vector3::UnitX = { 1.f, 0.f, 0.f }; - const Vector3 Vector3::UnitY = { 0.f, 1.f, 0.f }; - const Vector3 Vector3::UnitZ = { 0.f, 0.f, 1.f }; - const Vector3 Vector3::Up = { 0.f, 1.f, 0.f }; - const Vector3 Vector3::Down = { 0.f, -1.f, 0.f }; - const Vector3 Vector3::Right = { 1.f, 0.f, 0.f }; - const Vector3 Vector3::Left = { -1.f, 0.f, 0.f }; - const Vector3 Vector3::Forward = { 0.f, 0.f, -1.f }; + const Vector3 Vector3::Zero = { 0.f, 0.f, 0.f }; + const Vector3 Vector3::One = { 1.f, 1.f, 1.f }; + const Vector3 Vector3::UnitX = { 1.f, 0.f, 0.f }; + const Vector3 Vector3::UnitY = { 0.f, 1.f, 0.f }; + const Vector3 Vector3::UnitZ = { 0.f, 0.f, 1.f }; + const Vector3 Vector3::Up = { 0.f, 1.f, 0.f }; + const Vector3 Vector3::Down = { 0.f, -1.f, 0.f }; + const Vector3 Vector3::Right = { 1.f, 0.f, 0.f }; + const Vector3 Vector3::Left = { -1.f, 0.f, 0.f }; + const Vector3 Vector3::Forward = { 0.f, 0.f, -1.f }; const Vector3 Vector3::Backward = { 0.f, 0.f, 1.f }; - const Vector4 Vector4::Zero = { 0.f, 0.f, 0.f, 0.f }; - const Vector4 Vector4::One = { 1.f, 1.f, 1.f, 1.f }; + const Vector4 Vector4::Zero = { 0.f, 0.f, 0.f, 0.f }; + const Vector4 Vector4::One = { 1.f, 1.f, 1.f, 1.f }; const Vector4 Vector4::UnitX = { 1.f, 0.f, 0.f, 0.f }; const Vector4 Vector4::UnitY = { 0.f, 1.f, 0.f, 0.f }; const Vector4 Vector4::UnitZ = { 0.f, 0.f, 1.f, 0.f }; const Vector4 Vector4::UnitW = { 0.f, 0.f, 0.f, 1.f }; - const Matrix Matrix::Identity = { - 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, 0.f, 0.f, 0.f, 1.f - }; + const Matrix Matrix::Identity = { 1.f, 0.f, 0.f, 0.f, + 0.f, 1.f, 0.f, 0.f, + 0.f, 0.f, 1.f, 0.f, + 0.f, 0.f, 0.f, 1.f }; const Quaternion Quaternion::Identity = { 0.f, 0.f, 0.f, 1.f }; - } // namespace SimpleMath -} // namespace DirectX + } +} using namespace DirectX; using namespace DirectX::SimpleMath; @@ -65,17 +66,16 @@ void Quaternion::RotateTowards(const Quaternion& target, float maxAngle, Quatern { const XMVECTOR T = XMLoadFloat4(this); - // We can use the conjugate here instead of inverse assuming q1 & q2 are - // normalized. + // We can use the conjugate here instead of inverse assuming q1 & q2 are normalized. const XMVECTOR R = XMQuaternionMultiply(XMQuaternionConjugate(T), target); - const float rs = XMVectorGetW(R); - const XMVECTOR L = XMVector3Length(R); + const float rs = XMVectorGetW(R); + const XMVECTOR L = XMVector3Length(R); const float angle = 2.f * atan2f(XMVectorGetX(L), rs); if (angle > maxAngle) { const XMVECTOR delta = XMQuaternionRotationAxis(R, maxAngle); - const XMVECTOR Q = XMQuaternionMultiply(delta, T); + const XMVECTOR Q = XMQuaternionMultiply(delta, T); XMStoreFloat4(&result, Q); } else @@ -87,8 +87,7 @@ void Quaternion::RotateTowards(const Quaternion& target, float maxAngle, Quatern void Quaternion::FromToRotation(const Vector3& fromDir, const Vector3& toDir, Quaternion& result) noexcept { - // Melax, "The Shortest Arc Quaternion", Game Programming Gems, Charles River - // Media (2000). + // Melax, "The Shortest Arc Quaternion", Game Programming Gems, Charles River Media (2000). const XMVECTOR F = XMVector3Normalize(fromDir); const XMVECTOR T = XMVector3Normalize(toDir); @@ -143,7 +142,8 @@ void Quaternion::LookRotation(const Vector3& forward, const Vector3& up, Quatern XMStoreFloat4(&result, XMQuaternionMultiply(q2, q1)); } -/**************************************************************************** + + /**************************************************************************** * * Viewport * @@ -155,10 +155,8 @@ static_assert(offsetof(DirectX::SimpleMath::Viewport, x) == offsetof(D3D11_VIEWP static_assert(offsetof(DirectX::SimpleMath::Viewport, y) == offsetof(D3D11_VIEWPORT, TopLeftY), "Layout mismatch"); static_assert(offsetof(DirectX::SimpleMath::Viewport, width) == offsetof(D3D11_VIEWPORT, Width), "Layout mismatch"); static_assert(offsetof(DirectX::SimpleMath::Viewport, height) == offsetof(D3D11_VIEWPORT, Height), "Layout mismatch"); -static_assert(offsetof(DirectX::SimpleMath::Viewport, minDepth) == offsetof(D3D11_VIEWPORT, MinDepth), - "Layout mismatch"); -static_assert(offsetof(DirectX::SimpleMath::Viewport, maxDepth) == offsetof(D3D11_VIEWPORT, MaxDepth), - "Layout mismatch"); +static_assert(offsetof(DirectX::SimpleMath::Viewport, minDepth) == offsetof(D3D11_VIEWPORT, MinDepth), "Layout mismatch"); +static_assert(offsetof(DirectX::SimpleMath::Viewport, maxDepth) == offsetof(D3D11_VIEWPORT, MaxDepth), "Layout mismatch"); #endif #if defined(__d3d12_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) @@ -167,16 +165,13 @@ static_assert(offsetof(DirectX::SimpleMath::Viewport, x) == offsetof(D3D12_VIEWP static_assert(offsetof(DirectX::SimpleMath::Viewport, y) == offsetof(D3D12_VIEWPORT, TopLeftY), "Layout mismatch"); static_assert(offsetof(DirectX::SimpleMath::Viewport, width) == offsetof(D3D12_VIEWPORT, Width), "Layout mismatch"); static_assert(offsetof(DirectX::SimpleMath::Viewport, height) == offsetof(D3D12_VIEWPORT, Height), "Layout mismatch"); -static_assert(offsetof(DirectX::SimpleMath::Viewport, minDepth) == offsetof(D3D12_VIEWPORT, MinDepth), - "Layout mismatch"); -static_assert(offsetof(DirectX::SimpleMath::Viewport, maxDepth) == offsetof(D3D12_VIEWPORT, MaxDepth), - "Layout mismatch"); +static_assert(offsetof(DirectX::SimpleMath::Viewport, minDepth) == offsetof(D3D12_VIEWPORT, MinDepth), "Layout mismatch"); +static_assert(offsetof(DirectX::SimpleMath::Viewport, maxDepth) == offsetof(D3D12_VIEWPORT, MaxDepth), "Layout mismatch"); #endif #ifdef CGL_PLATFORM_WINDOWS - #if defined(__dxgi1_2_h__) || defined(__d3d11_x_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) -RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight, int outputWidth, - int outputHeight) noexcept +#if defined(__dxgi1_2_h__) || defined(__d3d11_x_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) +RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight, int outputWidth, int outputHeight) noexcept { RECT rct = {}; @@ -184,42 +179,41 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI { case DXGI_SCALING_STRETCH: // Output fills the entire window area - rct.top = 0; - rct.left = 0; - rct.right = outputWidth; + rct.top = 0; + rct.left = 0; + rct.right = outputWidth; rct.bottom = outputHeight; break; case 2 /*DXGI_SCALING_ASPECT_RATIO_STRETCH*/: - // Output fills the window area but respects the original aspect ratio, - // using pillar boxing or letter boxing as required Note: This scaling - // option is not supported for legacy Win32 windows swap chains + // Output fills the window area but respects the original aspect ratio, using pillar boxing or letter boxing as required + // Note: This scaling option is not supported for legacy Win32 windows swap chains { assert(backBufferHeight > 0); const float aspectRatio = float(backBufferWidth) / float(backBufferHeight); // Horizontal fill - float scaledWidth = float(outputWidth); + float scaledWidth = float(outputWidth); float scaledHeight = float(outputWidth) / aspectRatio; if (scaledHeight >= float(outputHeight)) { // Do vertical fill - scaledWidth = float(outputHeight) * aspectRatio; + scaledWidth = float(outputHeight) * aspectRatio; scaledHeight = float(outputHeight); } const float offsetX = (float(outputWidth) - scaledWidth) * 0.5f; const float offsetY = (float(outputHeight) - scaledHeight) * 0.5f; - rct.left = static_cast(offsetX); - rct.top = static_cast(offsetY); - rct.right = static_cast(offsetX + scaledWidth); + rct.left = static_cast(offsetX); + rct.top = static_cast(offsetY); + rct.right = static_cast(offsetX + scaledWidth); rct.bottom = static_cast(offsetY + scaledHeight); // Clip to display window - rct.left = std::max(0, rct.left); - rct.top = std::max(0, rct.top); - rct.right = std::min(outputWidth, rct.right); + rct.left = std::max(0, rct.left); + rct.top = std::max(0, rct.top); + rct.right = std::min(outputWidth, rct.right); rct.bottom = std::min(outputHeight, rct.bottom); } break; @@ -227,16 +221,16 @@ RECT Viewport::ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UI case DXGI_SCALING_NONE: default: // Output is displayed in the upper left corner of the window area - rct.top = 0; - rct.left = 0; - rct.right = std::min(static_cast(backBufferWidth), outputWidth); + rct.top = 0; + rct.left = 0; + rct.right = std::min(static_cast(backBufferWidth), outputWidth); rct.bottom = std::min(static_cast(backBufferHeight), outputHeight); break; } return rct; } - #endif +#endif RECT Viewport::ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight) noexcept { @@ -244,9 +238,9 @@ RECT Viewport::ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight) const float safeh = (float(backBufferHeight) + 19.f) / 20.f; RECT rct; - rct.left = static_cast(safew); - rct.top = static_cast(safeh); - rct.right = static_cast(float(backBufferWidth) - safew + 0.5f); + rct.left = static_cast(safew); + rct.top = static_cast(safeh); + rct.right = static_cast(float(backBufferWidth) - safew + 0.5f); rct.bottom = static_cast(float(backBufferHeight) - safeh + 0.5f); return rct; diff --git a/Core/External/SimpleMath.h b/Core/External/SimpleMath.h index 5df676e..46080c8 100644 --- a/Core/External/SimpleMath.h +++ b/Core/External/SimpleMath.h @@ -11,7 +11,7 @@ #pragma once #if (defined(_WIN32) || defined(WINAPI_FAMILY)) && !(defined(_XBOX_ONE) && defined(_TITLE)) && !defined(_GAMING_XBOX) - #include +#include #endif #include @@ -20,20 +20,21 @@ #include #if (__cplusplus >= 202002L) - #include +#include #endif -#include #include #include +#include #ifdef __clang__ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wfloat-equal" - #pragma clang diagnostic ignored "-Wunknown-warning-option" - #pragma clang diagnostic ignored "-Wunsafe-buffer-usage" +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wunsafe-buffer-usage" #endif + namespace DirectX { namespace SimpleMath @@ -54,78 +55,37 @@ namespace DirectX long height; // Creators - Rectangle() noexcept - : x(0), y(0), width(0), height(0) - { - } - constexpr Rectangle(long ix, long iy, long iw, long ih) noexcept - : x(ix), y(iy), width(iw), height(ih) - { - } + Rectangle() noexcept : x(0), y(0), width(0), height(0) {} + constexpr Rectangle(long ix, long iy, long iw, long ih) noexcept : x(ix), y(iy), width(iw), height(ih) {} #ifdef CGL_PLATFORM_WINDOWS - explicit Rectangle(const RECT& rct) noexcept - : x(rct.left), y(rct.top), width(rct.right - rct.left), height(rct.bottom - rct.top) - { - } + explicit Rectangle(const RECT& rct) noexcept : x(rct.left), y(rct.top), width(rct.right - rct.left), height(rct.bottom - rct.top) {} #endif - Rectangle(const Rectangle&) = default; + Rectangle(const Rectangle&) = default; Rectangle& operator=(const Rectangle&) = default; - Rectangle(Rectangle&&) = default; + Rectangle(Rectangle&&) = default; Rectangle& operator=(Rectangle&&) = default; #ifdef CGL_PLATFORM_WINDOWS - operator RECT() noexcept - { - RECT rct; - rct.left = x; - rct.top = y; - rct.right = (x + width); - rct.bottom = (y + height); - return rct; - } - #ifdef __cplusplus_winrt - operator Windows::Foundation::Rect() noexcept - { - return Windows::Foundation::Rect(float(x), float(y), float(width), float(height)); - } - #endif + operator RECT() noexcept { RECT rct; rct.left = x; rct.top = y; rct.right = (x + width); rct.bottom = (y + height); return rct; } + #ifdef __cplusplus_winrt + operator Windows::Foundation::Rect() noexcept { return Windows::Foundation::Rect(float(x), float(y), float(width), float(height)); } + #endif #endif // Comparison operators -#if (__cplusplus >= 202002L) - bool operator==(const Rectangle&) const = default; - auto operator<=>(const Rectangle&) const = default; -#else - bool operator==(const Rectangle& r) const noexcept - { - return (x == r.x) && (y == r.y) && (width == r.width) && (height == r.height); - } - bool operator!=(const Rectangle& r) const noexcept - { - return (x != r.x) || (y != r.y) || (width != r.width) || (height != r.height); - } -#endif + #if (__cplusplus >= 202002L) + bool operator == (const Rectangle&) const = default; + auto operator <=> (const Rectangle&) const = default; + #else + bool operator == (const Rectangle& r) const noexcept { return (x == r.x) && (y == r.y) && (width == r.width) && (height == r.height); } + bool operator != (const Rectangle& r) const noexcept { return (x != r.x) || (y != r.y) || (width != r.width) || (height != r.height); } + #endif #ifdef CGL_PLATFORM_WINDOWS - bool operator==(const RECT& rct) const noexcept - { - return (x == rct.left) && (y == rct.top) && (width == (rct.right - rct.left)) && - (height == (rct.bottom - rct.top)); - } - bool operator!=(const RECT& rct) const noexcept - { - return (x != rct.left) || (y != rct.top) || (width != (rct.right - rct.left)) || - (height != (rct.bottom - rct.top)); - } + bool operator == (const RECT& rct) const noexcept { return (x == rct.left) && (y == rct.top) && (width == (rct.right - rct.left)) && (height == (rct.bottom - rct.top)); } + bool operator != (const RECT& rct) const noexcept { return (x != rct.left) || (y != rct.top) || (width != (rct.right - rct.left)) || (height != (rct.bottom - rct.top)); } // Assignment operators - Rectangle& operator=(_In_ const RECT& rct) noexcept - { - x = rct.left; - y = rct.top; - width = (rct.right - rct.left); - height = (rct.bottom - rct.top); - return *this; - } + Rectangle& operator=(_In_ const RECT& rct) noexcept { x = rct.left; y = rct.top; width = (rct.right - rct.left); height = (rct.bottom - rct.top); return *this; } #endif // Rectangle operations @@ -134,39 +94,19 @@ namespace DirectX bool IsEmpty() const noexcept { return (width == 0 && height == 0 && x == 0 && y == 0); } - bool Contains(long ix, long iy) const noexcept - { - return (x <= ix) && (ix < (x + width)) && (y <= iy) && (iy < (y + height)); - } + bool Contains(long ix, long iy) const noexcept { return (x <= ix) && (ix < (x + width)) && (y <= iy) && (iy < (y + height)); } bool Contains(const Vector2& point) const noexcept; - bool Contains(const Rectangle& r) const noexcept - { - return (x <= r.x) && ((r.x + r.width) <= (x + width)) && (y <= r.y) && - ((r.y + r.height) <= (y + height)); - } + bool Contains(const Rectangle& r) const noexcept { return (x <= r.x) && ((r.x + r.width) <= (x + width)) && (y <= r.y) && ((r.y + r.height) <= (y + height)); } #ifdef CGL_PLATFORM_WINDOWS - bool Contains(const RECT& rct) const noexcept - { - return (x <= rct.left) && (rct.right <= (x + width)) && (y <= rct.top) && (rct.bottom <= (y + height)); - } + bool Contains(const RECT& rct) const noexcept { return (x <= rct.left) && (rct.right <= (x + width)) && (y <= rct.top) && (rct.bottom <= (y + height)); } #endif void Inflate(long horizAmount, long vertAmount) noexcept; - bool Intersects(const Rectangle& r) const noexcept - { - return (r.x < (x + width)) && (x < (r.x + r.width)) && (r.y < (y + height)) && (y < (r.y + r.height)); - } + bool Intersects(const Rectangle& r) const noexcept { return (r.x < (x + width)) && (x < (r.x + r.width)) && (r.y < (y + height)) && (y < (r.y + r.height)); } #ifdef CGL_PLATFORM_WINDOWS - bool Intersects(const RECT& rct) const noexcept - { - return (rct.left < (x + width)) && (x < rct.right) && (rct.top < (y + height)) && (y < rct.bottom); - } + bool Intersects(const RECT& rct) const noexcept { return (rct.left < (x + width)) && (x < rct.right) && (rct.top < (y + height)) && (y < rct.bottom); } #endif - void Offset(long ox, long oy) noexcept - { - x += ox; - y += oy; - } + void Offset(long ox, long oy) noexcept { x += ox; y += oy; } // Static functions static Rectangle Intersect(const Rectangle& ra, const Rectangle& rb) noexcept; @@ -184,62 +124,37 @@ namespace DirectX // 2D vector struct Vector2 : public XMFLOAT2 { - Vector2() noexcept - : XMFLOAT2(0.f, 0.f) - { - } - constexpr explicit Vector2(float ix) noexcept - : XMFLOAT2(ix, ix) - { - } - constexpr Vector2(float ix, float iy) noexcept - : XMFLOAT2(ix, iy) - { - } - explicit Vector2(_In_reads_(2) const float* pArray) noexcept - : XMFLOAT2(pArray) - { - } + Vector2() noexcept : XMFLOAT2(0.f, 0.f) {} + constexpr explicit Vector2(float ix) noexcept : XMFLOAT2(ix, ix) {} + constexpr Vector2(float ix, float iy) noexcept : XMFLOAT2(ix, iy) {} + explicit Vector2(_In_reads_(2) const float *pArray) noexcept : XMFLOAT2(pArray) {} Vector2(FXMVECTOR V) noexcept { XMStoreFloat2(this, V); } - Vector2(const XMFLOAT2& V) noexcept - { - this->x = V.x; - this->y = V.y; - } - explicit Vector2(const XMVECTORF32& F) noexcept - { - this->x = F.f[0]; - this->y = F.f[1]; - } + Vector2(const XMFLOAT2& V) noexcept { this->x = V.x; this->y = V.y; } + explicit Vector2(const XMVECTORF32& F) noexcept { this->x = F.f[0]; this->y = F.f[1]; } - Vector2(const Vector2&) = default; + Vector2(const Vector2&) = default; Vector2& operator=(const Vector2&) = default; - Vector2(Vector2&&) = default; + Vector2(Vector2&&) = default; Vector2& operator=(Vector2&&) = default; operator XMVECTOR() const noexcept { return XMLoadFloat2(this); } // Comparison operators - bool operator==(const Vector2& V) const noexcept; - bool operator!=(const Vector2& V) const noexcept; + bool operator == (const Vector2& V) const noexcept; + bool operator != (const Vector2& V) const noexcept; // Assignment operators - Vector2& operator=(const XMVECTORF32& F) noexcept - { - x = F.f[0]; - y = F.f[1]; - return *this; - } - Vector2& operator+=(const Vector2& V) noexcept; - Vector2& operator-=(const Vector2& V) noexcept; - Vector2& operator*=(const Vector2& V) noexcept; - Vector2& operator*=(float S) noexcept; - Vector2& operator/=(float S) noexcept; + Vector2& operator= (const XMVECTORF32& F) noexcept { x = F.f[0]; y = F.f[1]; return *this; } + Vector2& operator+= (const Vector2& V) noexcept; + Vector2& operator-= (const Vector2& V) noexcept; + Vector2& operator*= (const Vector2& V) noexcept; + Vector2& operator*= (float S) noexcept; + Vector2& operator/= (float S) noexcept; // Unary operators - Vector2 operator+() const noexcept { return *this; } - Vector2 operator-() const noexcept { return Vector2(-x, -y); } + Vector2 operator+ () const noexcept { return *this; } + Vector2 operator- () const noexcept { return Vector2(-x, -y); } // Vector operations bool InBounds(const Vector2& Bounds) const noexcept; @@ -273,26 +188,19 @@ namespace DirectX static void SmoothStep(const Vector2& v1, const Vector2& v2, float t, Vector2& result) noexcept; static Vector2 SmoothStep(const Vector2& v1, const Vector2& v2, float t) noexcept; - static void Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, - Vector2& result) noexcept; - static Vector2 Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, - float g) noexcept; + static void Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result) noexcept; + static Vector2 Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g) noexcept; - static void CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, - Vector2& result) noexcept; - static Vector2 CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, - float t) noexcept; + static void CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result) noexcept; + static Vector2 CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t) noexcept; - static void Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, - Vector2& result) noexcept; - static Vector2 Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, - float t) noexcept; + static void Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result) noexcept; + static Vector2 Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t) noexcept; static void Reflect(const Vector2& ivec, const Vector2& nvec, Vector2& result) noexcept; static Vector2 Reflect(const Vector2& ivec, const Vector2& nvec) noexcept; - static void Refract(const Vector2& ivec, const Vector2& nvec, float refractionIndex, - Vector2& result) noexcept; + static void Refract(const Vector2& ivec, const Vector2& nvec, float refractionIndex, Vector2& result) noexcept; static Vector2 Refract(const Vector2& ivec, const Vector2& nvec, float refractionIndex) noexcept; static void Transform(const Vector2& v, const Quaternion& quat, Vector2& result) noexcept; @@ -300,17 +208,14 @@ namespace DirectX static void Transform(const Vector2& v, const Matrix& m, Vector2& result) noexcept; static Vector2 Transform(const Vector2& v, const Matrix& m) noexcept; - static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, - _Out_writes_(count) Vector2* resultArray) noexcept; + static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray) noexcept; static void Transform(const Vector2& v, const Matrix& m, Vector4& result) noexcept; - static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, - _Out_writes_(count) Vector4* resultArray) noexcept; + static void Transform(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray) noexcept; static void TransformNormal(const Vector2& v, const Matrix& m, Vector2& result) noexcept; static Vector2 TransformNormal(const Vector2& v, const Matrix& m) noexcept; - static void TransformNormal(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, - _Out_writes_(count) Vector2* resultArray) noexcept; + static void TransformNormal(_In_reads_(count) const Vector2* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector2* resultArray) noexcept; // Constants static const Vector2 Zero; @@ -320,77 +225,49 @@ namespace DirectX }; // Binary operators - Vector2 operator+(const Vector2& V1, const Vector2& V2) noexcept; - Vector2 operator-(const Vector2& V1, const Vector2& V2) noexcept; - Vector2 operator*(const Vector2& V1, const Vector2& V2) noexcept; - Vector2 operator*(const Vector2& V, float S) noexcept; - Vector2 operator/(const Vector2& V1, const Vector2& V2) noexcept; - Vector2 operator/(const Vector2& V, float S) noexcept; - Vector2 operator*(float S, const Vector2& V) noexcept; + Vector2 operator+ (const Vector2& V1, const Vector2& V2) noexcept; + Vector2 operator- (const Vector2& V1, const Vector2& V2) noexcept; + Vector2 operator* (const Vector2& V1, const Vector2& V2) noexcept; + Vector2 operator* (const Vector2& V, float S) noexcept; + Vector2 operator/ (const Vector2& V1, const Vector2& V2) noexcept; + Vector2 operator/ (const Vector2& V, float S) noexcept; + Vector2 operator* (float S, const Vector2& V) noexcept; //------------------------------------------------------------------------------ // 3D vector struct Vector3 : public XMFLOAT3 { - Vector3() noexcept - : XMFLOAT3(0.f, 0.f, 0.f) - { - } - constexpr explicit Vector3(float ix) noexcept - : XMFLOAT3(ix, ix, ix) - { - } - constexpr Vector3(float ix, float iy, float iz) noexcept - : XMFLOAT3(ix, iy, iz) - { - } - explicit Vector3(_In_reads_(3) const float* pArray) noexcept - : XMFLOAT3(pArray) - { - } + Vector3() noexcept : XMFLOAT3(0.f, 0.f, 0.f) {} + constexpr explicit Vector3(float ix) noexcept : XMFLOAT3(ix, ix, ix) {} + constexpr Vector3(float ix, float iy, float iz) noexcept : XMFLOAT3(ix, iy, iz) {} + explicit Vector3(_In_reads_(3) const float *pArray) noexcept : XMFLOAT3(pArray) {} Vector3(FXMVECTOR V) noexcept { XMStoreFloat3(this, V); } - Vector3(const XMFLOAT3& V) noexcept - { - this->x = V.x; - this->y = V.y; - this->z = V.z; - } - explicit Vector3(const XMVECTORF32& F) noexcept - { - this->x = F.f[0]; - this->y = F.f[1]; - this->z = F.f[2]; - } + Vector3(const XMFLOAT3& V) noexcept { this->x = V.x; this->y = V.y; this->z = V.z; } + explicit Vector3(const XMVECTORF32& F) noexcept { this->x = F.f[0]; this->y = F.f[1]; this->z = F.f[2]; } - Vector3(const Vector3&) = default; + Vector3(const Vector3&) = default; Vector3& operator=(const Vector3&) = default; - Vector3(Vector3&&) = default; + Vector3(Vector3&&) = default; Vector3& operator=(Vector3&&) = default; operator XMVECTOR() const noexcept { return XMLoadFloat3(this); } // Comparison operators - bool operator==(const Vector3& V) const noexcept; - bool operator!=(const Vector3& V) const noexcept; + bool operator == (const Vector3& V) const noexcept; + bool operator != (const Vector3& V) const noexcept; // Assignment operators - Vector3& operator=(const XMVECTORF32& F) noexcept - { - x = F.f[0]; - y = F.f[1]; - z = F.f[2]; - return *this; - } - Vector3& operator+=(const Vector3& V) noexcept; - Vector3& operator-=(const Vector3& V) noexcept; - Vector3& operator*=(const Vector3& V) noexcept; - Vector3& operator*=(float S) noexcept; - Vector3& operator/=(float S) noexcept; + Vector3& operator= (const XMVECTORF32& F) noexcept { x = F.f[0]; y = F.f[1]; z = F.f[2]; return *this; } + Vector3& operator+= (const Vector3& V) noexcept; + Vector3& operator-= (const Vector3& V) noexcept; + Vector3& operator*= (const Vector3& V) noexcept; + Vector3& operator*= (float S) noexcept; + Vector3& operator/= (float S) noexcept; // Unary operators - Vector3 operator+() const noexcept { return *this; } - Vector3 operator-() const noexcept; + Vector3 operator+ () const noexcept { return *this; } + Vector3 operator- () const noexcept; // Vector operations bool InBounds(const Vector3& Bounds) const noexcept; @@ -424,26 +301,19 @@ namespace DirectX static void SmoothStep(const Vector3& v1, const Vector3& v2, float t, Vector3& result) noexcept; static Vector3 SmoothStep(const Vector3& v1, const Vector3& v2, float t) noexcept; - static void Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, - Vector3& result) noexcept; - static Vector3 Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, - float g) noexcept; + static void Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result) noexcept; + static Vector3 Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g) noexcept; - static void CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, - Vector3& result) noexcept; - static Vector3 CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, - float t) noexcept; + static void CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result) noexcept; + static Vector3 CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t) noexcept; - static void Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, - Vector3& result) noexcept; - static Vector3 Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, - float t) noexcept; + static void Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result) noexcept; + static Vector3 Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t) noexcept; static void Reflect(const Vector3& ivec, const Vector3& nvec, Vector3& result) noexcept; static Vector3 Reflect(const Vector3& ivec, const Vector3& nvec) noexcept; - static void Refract(const Vector3& ivec, const Vector3& nvec, float refractionIndex, - Vector3& result) noexcept; + static void Refract(const Vector3& ivec, const Vector3& nvec, float refractionIndex, Vector3& result) noexcept; static Vector3 Refract(const Vector3& ivec, const Vector3& nvec, float refractionIndex) noexcept; static void Transform(const Vector3& v, const Quaternion& quat, Vector3& result) noexcept; @@ -451,17 +321,14 @@ namespace DirectX static void Transform(const Vector3& v, const Matrix& m, Vector3& result) noexcept; static Vector3 Transform(const Vector3& v, const Matrix& m) noexcept; - static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, - _Out_writes_(count) Vector3* resultArray) noexcept; + static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray) noexcept; static void Transform(const Vector3& v, const Matrix& m, Vector4& result) noexcept; - static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, - _Out_writes_(count) Vector4* resultArray) noexcept; + static void Transform(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray) noexcept; static void TransformNormal(const Vector3& v, const Matrix& m, Vector3& result) noexcept; static Vector3 TransformNormal(const Vector3& v, const Matrix& m) noexcept; - static void TransformNormal(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, - _Out_writes_(count) Vector3* resultArray) noexcept; + static void TransformNormal(_In_reads_(count) const Vector3* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector3* resultArray) noexcept; // Constants static const Vector3 Zero; @@ -478,80 +345,49 @@ namespace DirectX }; // Binary operators - Vector3 operator+(const Vector3& V1, const Vector3& V2) noexcept; - Vector3 operator-(const Vector3& V1, const Vector3& V2) noexcept; - Vector3 operator*(const Vector3& V1, const Vector3& V2) noexcept; - Vector3 operator*(const Vector3& V, float S) noexcept; - Vector3 operator/(const Vector3& V1, const Vector3& V2) noexcept; - Vector3 operator/(const Vector3& V, float S) noexcept; - Vector3 operator*(float S, const Vector3& V) noexcept; + Vector3 operator+ (const Vector3& V1, const Vector3& V2) noexcept; + Vector3 operator- (const Vector3& V1, const Vector3& V2) noexcept; + Vector3 operator* (const Vector3& V1, const Vector3& V2) noexcept; + Vector3 operator* (const Vector3& V, float S) noexcept; + Vector3 operator/ (const Vector3& V1, const Vector3& V2) noexcept; + Vector3 operator/ (const Vector3& V, float S) noexcept; + Vector3 operator* (float S, const Vector3& V) noexcept; //------------------------------------------------------------------------------ // 4D vector struct Vector4 : public XMFLOAT4 { - Vector4() noexcept - : XMFLOAT4(0.f, 0.f, 0.f, 0.f) - { - } - constexpr explicit Vector4(float ix) noexcept - : XMFLOAT4(ix, ix, ix, ix) - { - } - constexpr Vector4(float ix, float iy, float iz, float iw) noexcept - : XMFLOAT4(ix, iy, iz, iw) - { - } - explicit Vector4(_In_reads_(4) const float* pArray) noexcept - : XMFLOAT4(pArray) - { - } + Vector4() noexcept : XMFLOAT4(0.f, 0.f, 0.f, 0.f) {} + constexpr explicit Vector4(float ix) noexcept : XMFLOAT4(ix, ix, ix, ix) {} + constexpr Vector4(float ix, float iy, float iz, float iw) noexcept : XMFLOAT4(ix, iy, iz, iw) {} + explicit Vector4(_In_reads_(4) const float *pArray) noexcept : XMFLOAT4(pArray) {} Vector4(FXMVECTOR V) noexcept { XMStoreFloat4(this, V); } - Vector4(const XMFLOAT4& V) noexcept - { - this->x = V.x; - this->y = V.y; - this->z = V.z; - this->w = V.w; - } - explicit Vector4(const XMVECTORF32& F) noexcept - { - this->x = F.f[0]; - this->y = F.f[1]; - this->z = F.f[2]; - this->w = F.f[3]; - } + Vector4(const XMFLOAT4& V) noexcept { this->x = V.x; this->y = V.y; this->z = V.z; this->w = V.w; } + explicit Vector4(const XMVECTORF32& F) noexcept { this->x = F.f[0]; this->y = F.f[1]; this->z = F.f[2]; this->w = F.f[3]; } - Vector4(const Vector4&) = default; + Vector4(const Vector4&) = default; Vector4& operator=(const Vector4&) = default; - Vector4(Vector4&&) = default; + Vector4(Vector4&&) = default; Vector4& operator=(Vector4&&) = default; - operator XMVECTOR() const noexcept { return XMLoadFloat4(this); } + operator XMVECTOR() const noexcept { return XMLoadFloat4(this); } // Comparison operators - bool operator==(const Vector4& V) const noexcept; - bool operator!=(const Vector4& V) const noexcept; + bool operator == (const Vector4& V) const noexcept; + bool operator != (const Vector4& V) const noexcept; // Assignment operators - Vector4& operator=(const XMVECTORF32& F) noexcept - { - x = F.f[0]; - y = F.f[1]; - z = F.f[2]; - w = F.f[3]; - return *this; - } - Vector4& operator+=(const Vector4& V) noexcept; - Vector4& operator-=(const Vector4& V) noexcept; - Vector4& operator*=(const Vector4& V) noexcept; - Vector4& operator*=(float S) noexcept; - Vector4& operator/=(float S) noexcept; + Vector4& operator= (const XMVECTORF32& F) noexcept { x = F.f[0]; y = F.f[1]; z = F.f[2]; w = F.f[3]; return *this; } + Vector4& operator+= (const Vector4& V) noexcept; + Vector4& operator-= (const Vector4& V) noexcept; + Vector4& operator*= (const Vector4& V) noexcept; + Vector4& operator*= (float S) noexcept; + Vector4& operator/= (float S) noexcept; // Unary operators - Vector4 operator+() const noexcept { return *this; } - Vector4 operator-() const noexcept; + Vector4 operator+ () const noexcept { return *this; } + Vector4 operator- () const noexcept; // Vector operations bool InBounds(const Vector4& Bounds) const noexcept; @@ -585,26 +421,19 @@ namespace DirectX static void SmoothStep(const Vector4& v1, const Vector4& v2, float t, Vector4& result) noexcept; static Vector4 SmoothStep(const Vector4& v1, const Vector4& v2, float t) noexcept; - static void Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, - Vector4& result) noexcept; - static Vector4 Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, - float g) noexcept; + static void Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result) noexcept; + static Vector4 Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g) noexcept; - static void CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, - Vector4& result) noexcept; - static Vector4 CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, - float t) noexcept; + static void CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result) noexcept; + static Vector4 CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t) noexcept; - static void Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, - Vector4& result) noexcept; - static Vector4 Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, - float t) noexcept; + static void Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result) noexcept; + static Vector4 Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t) noexcept; static void Reflect(const Vector4& ivec, const Vector4& nvec, Vector4& result) noexcept; static Vector4 Reflect(const Vector4& ivec, const Vector4& nvec) noexcept; - static void Refract(const Vector4& ivec, const Vector4& nvec, float refractionIndex, - Vector4& result) noexcept; + static void Refract(const Vector4& ivec, const Vector4& nvec, float refractionIndex, Vector4& result) noexcept; static Vector4 Refract(const Vector4& ivec, const Vector4& nvec, float refractionIndex) noexcept; static void Transform(const Vector2& v, const Quaternion& quat, Vector4& result) noexcept; @@ -618,8 +447,7 @@ namespace DirectX static void Transform(const Vector4& v, const Matrix& m, Vector4& result) noexcept; static Vector4 Transform(const Vector4& v, const Matrix& m) noexcept; - static void Transform(_In_reads_(count) const Vector4* varray, size_t count, const Matrix& m, - _Out_writes_(count) Vector4* resultArray) noexcept; + static void Transform(_In_reads_(count) const Vector4* varray, size_t count, const Matrix& m, _Out_writes_(count) Vector4* resultArray) noexcept; // Constants static const Vector4 Zero; @@ -631,131 +459,105 @@ namespace DirectX }; // Binary operators - Vector4 operator+(const Vector4& V1, const Vector4& V2) noexcept; - Vector4 operator-(const Vector4& V1, const Vector4& V2) noexcept; - Vector4 operator*(const Vector4& V1, const Vector4& V2) noexcept; - Vector4 operator*(const Vector4& V, float S) noexcept; - Vector4 operator/(const Vector4& V1, const Vector4& V2) noexcept; - Vector4 operator/(const Vector4& V, float S) noexcept; - Vector4 operator*(float S, const Vector4& V) noexcept; + Vector4 operator+ (const Vector4& V1, const Vector4& V2) noexcept; + Vector4 operator- (const Vector4& V1, const Vector4& V2) noexcept; + Vector4 operator* (const Vector4& V1, const Vector4& V2) noexcept; + Vector4 operator* (const Vector4& V, float S) noexcept; + Vector4 operator/ (const Vector4& V1, const Vector4& V2) noexcept; + Vector4 operator/ (const Vector4& V, float S) noexcept; + Vector4 operator* (float S, const Vector4& V) noexcept; //------------------------------------------------------------------------------ // 4x4 Matrix (assumes right-handed cooordinates) struct Matrix : public XMFLOAT4X4 { Matrix() noexcept - : XMFLOAT4X4(1.f, 0, 0, 0, 0, 1.f, 0, 0, 0, 0, 1.f, 0, 0, 0, 0, 1.f) + : XMFLOAT4X4(1.f, 0, 0, 0, + 0, 1.f, 0, 0, + 0, 0, 1.f, 0, + 0, 0, 0, 1.f) { } - constexpr Matrix(float m00, float m01, float m02, float m03, float m10, float m11, float m12, float m13, - float m20, float m21, float m22, float m23, float m30, float m31, float m32, - float m33) noexcept - : XMFLOAT4X4(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) + constexpr Matrix(float m00, float m01, float m02, float m03, + float m10, float m11, float m12, float m13, + float m20, float m21, float m22, float m23, + float m30, float m31, float m32, float m33) noexcept + : XMFLOAT4X4(m00, m01, m02, m03, + m10, m11, m12, m13, + m20, m21, m22, m23, + m30, m31, m32, m33) { } explicit Matrix(const Vector3& r0, const Vector3& r1, const Vector3& r2) noexcept - : XMFLOAT4X4(r0.x, r0.y, r0.z, 0, r1.x, r1.y, r1.z, 0, r2.x, r2.y, r2.z, 0, 0, 0, 0, 1.f) + : XMFLOAT4X4(r0.x, r0.y, r0.z, 0, + r1.x, r1.y, r1.z, 0, + r2.x, r2.y, r2.z, 0, + 0, 0, 0, 1.f) { } explicit Matrix(const Vector4& r0, const Vector4& r1, const Vector4& r2, const Vector4& r3) noexcept - : XMFLOAT4X4(r0.x, r0.y, r0.z, r0.w, r1.x, r1.y, r1.z, r1.w, r2.x, r2.y, r2.z, r2.w, r3.x, r3.y, r3.z, - r3.w) + : XMFLOAT4X4(r0.x, r0.y, r0.z, r0.w, + r1.x, r1.y, r1.z, r1.w, + r2.x, r2.y, r2.z, r2.w, + r3.x, r3.y, r3.z, r3.w) { } Matrix(const XMFLOAT4X4& M) noexcept { memcpy(this, &M, sizeof(XMFLOAT4X4)); } Matrix(const XMFLOAT3X3& M) noexcept; Matrix(const XMFLOAT4X3& M) noexcept; - explicit Matrix(_In_reads_(16) const float* pArray) noexcept - : XMFLOAT4X4(pArray) - { - } + explicit Matrix(_In_reads_(16) const float *pArray) noexcept : XMFLOAT4X4(pArray) {} Matrix(CXMMATRIX M) noexcept { XMStoreFloat4x4(this, M); } - Matrix(const Matrix&) = default; + Matrix(const Matrix&) = default; Matrix& operator=(const Matrix&) = default; - Matrix(Matrix&&) = default; + Matrix(Matrix&&) = default; Matrix& operator=(Matrix&&) = default; operator XMMATRIX() const noexcept { return XMLoadFloat4x4(this); } // Comparison operators - bool operator==(const Matrix& M) const noexcept; - bool operator!=(const Matrix& M) const noexcept; + bool operator == (const Matrix& M) const noexcept; + bool operator != (const Matrix& M) const noexcept; // Assignment operators - Matrix& operator=(const XMFLOAT3X3& M) noexcept; - Matrix& operator=(const XMFLOAT4X3& M) noexcept; - Matrix& operator+=(const Matrix& M) noexcept; - Matrix& operator-=(const Matrix& M) noexcept; - Matrix& operator*=(const Matrix& M) noexcept; - Matrix& operator*=(float S) noexcept; - Matrix& operator/=(float S) noexcept; - - Matrix& operator/=(const Matrix& M) noexcept; - // Element-wise divide + Matrix& operator= (const XMFLOAT3X3& M) noexcept; + Matrix& operator= (const XMFLOAT4X3& M) noexcept; + Matrix& operator+= (const Matrix& M) noexcept; + Matrix& operator-= (const Matrix& M) noexcept; + Matrix& operator*= (const Matrix& M) noexcept; + Matrix& operator*= (float S) noexcept; + Matrix& operator/= (float S) noexcept; + + Matrix& operator/= (const Matrix& M) noexcept; + // Element-wise divide // Unary operators - Matrix operator+() const noexcept { return *this; } - Matrix operator-() const noexcept; + Matrix operator+ () const noexcept { return *this; } + Matrix operator- () const noexcept; // Properties Vector3 Up() const noexcept { return Vector3(_21, _22, _23); } - void Up(const Vector3& v) noexcept - { - _21 = v.x; - _22 = v.y; - _23 = v.z; - } + void Up(const Vector3& v) noexcept { _21 = v.x; _22 = v.y; _23 = v.z; } - Vector3 Down() const noexcept { return Vector3(-_21, -_22, -_23); } - void Down(const Vector3& v) noexcept - { - _21 = -v.x; - _22 = -v.y; - _23 = -v.z; - } + Vector3 Down() const noexcept { return Vector3(-_21, -_22, -_23); } + void Down(const Vector3& v) noexcept { _21 = -v.x; _22 = -v.y; _23 = -v.z; } Vector3 Right() const noexcept { return Vector3(_11, _12, _13); } - void Right(const Vector3& v) noexcept - { - _11 = v.x; - _12 = v.y; - _13 = v.z; - } + void Right(const Vector3& v) noexcept { _11 = v.x; _12 = v.y; _13 = v.z; } Vector3 Left() const noexcept { return Vector3(-_11, -_12, -_13); } - void Left(const Vector3& v) noexcept - { - _11 = -v.x; - _12 = -v.y; - _13 = -v.z; - } + void Left(const Vector3& v) noexcept { _11 = -v.x; _12 = -v.y; _13 = -v.z; } Vector3 Forward() const noexcept { return Vector3(-_31, -_32, -_33); } - void Forward(const Vector3& v) noexcept - { - _31 = -v.x; - _32 = -v.y; - _33 = -v.z; - } + void Forward(const Vector3& v) noexcept { _31 = -v.x; _32 = -v.y; _33 = -v.z; } Vector3 Backward() const noexcept { return Vector3(_31, _32, _33); } - void Backward(const Vector3& v) noexcept - { - _31 = v.x; - _32 = v.y; - _33 = v.z; - } + void Backward(const Vector3& v) noexcept { _31 = v.x; _32 = v.y; _33 = v.z; } - Vector3 Translation() const noexcept { return Vector3(_41, _42, _43); } - void Translation(const Vector3& v) noexcept - { - _41 = v.x; - _42 = v.y; - _43 = v.z; - } + Vector3 Translation() const noexcept { return Vector3(_41, _42, _43); } + void Translation(const Vector3& v) noexcept { _41 = v.x; _42 = v.y; _43 = v.z; } // Matrix operations bool Decompose(Vector3& scale, Quaternion& rotation, Vector3& translation) noexcept; @@ -772,13 +574,12 @@ namespace DirectX Vector3 ToEuler() const noexcept; // Static functions - static Matrix CreateBillboard(const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, - _In_opt_ const Vector3* cameraForward = nullptr) noexcept; + static Matrix CreateBillboard( + const Vector3& object, const Vector3& cameraPosition, const Vector3& cameraUp, _In_opt_ const Vector3* cameraForward = nullptr) noexcept; - static Matrix CreateConstrainedBillboard(const Vector3& object, const Vector3& cameraPosition, - const Vector3& rotateAxis, - _In_opt_ const Vector3* cameraForward = nullptr, - _In_opt_ const Vector3* objectForward = nullptr) noexcept; + static Matrix CreateConstrainedBillboard( + const Vector3& object, const Vector3& cameraPosition, const Vector3& rotateAxis, + _In_opt_ const Vector3* cameraForward = nullptr, _In_opt_ const Vector3* objectForward = nullptr) noexcept; static Matrix CreateTranslation(const Vector3& position) noexcept; static Matrix CreateTranslation(float x, float y, float z) noexcept; @@ -793,14 +594,11 @@ namespace DirectX static Matrix CreateFromAxisAngle(const Vector3& axis, float angle) noexcept; - static Matrix CreatePerspectiveFieldOfView(float fov, float aspectRatio, float nearPlane, - float farPlane) noexcept; + static Matrix CreatePerspectiveFieldOfView(float fov, float aspectRatio, float nearPlane, float farPlane) noexcept; static Matrix CreatePerspective(float width, float height, float nearPlane, float farPlane) noexcept; - static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, - float farPlane) noexcept; + static Matrix CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, float farPlane) noexcept; static Matrix CreateOrthographic(float width, float height, float zNearPlane, float zFarPlane) noexcept; - static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, - float zNearPlane, float zFarPlane) noexcept; + static Matrix CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) noexcept; static Matrix CreateLookAt(const Vector3& position, const Vector3& target, const Vector3& up) noexcept; static Matrix CreateWorld(const Vector3& position, const Vector3& forward, const Vector3& up) noexcept; @@ -810,8 +608,7 @@ namespace DirectX // Rotates about y-axis (yaw), then x-axis (pitch), then z-axis (roll) static Matrix CreateFromYawPitchRoll(float yaw, float pitch, float roll) noexcept; - // Rotates about y-axis (angles.y), then x-axis (angles.x), then z-axis - // (angles.z) + // Rotates about y-axis (angles.y), then x-axis (angles.x), then z-axis (angles.z) static Matrix CreateFromYawPitchRoll(const Vector3& angles) noexcept; static Matrix CreateShadow(const Vector3& lightDir, const Plane& plane) noexcept; @@ -829,87 +626,49 @@ namespace DirectX }; // Binary operators - Matrix operator+(const Matrix& M1, const Matrix& M2) noexcept; - Matrix operator-(const Matrix& M1, const Matrix& M2) noexcept; - Matrix operator*(const Matrix& M1, const Matrix& M2) noexcept; - Matrix operator*(const Matrix& M, float S) noexcept; - Matrix operator/(const Matrix& M, float S) noexcept; - Matrix operator/(const Matrix& M1, const Matrix& M2) noexcept; - // Element-wise divide - Matrix operator*(float S, const Matrix& M) noexcept; + Matrix operator+ (const Matrix& M1, const Matrix& M2) noexcept; + Matrix operator- (const Matrix& M1, const Matrix& M2) noexcept; + Matrix operator* (const Matrix& M1, const Matrix& M2) noexcept; + Matrix operator* (const Matrix& M, float S) noexcept; + Matrix operator/ (const Matrix& M, float S) noexcept; + Matrix operator/ (const Matrix& M1, const Matrix& M2) noexcept; + // Element-wise divide + Matrix operator* (float S, const Matrix& M) noexcept; + //----------------------------------------------------------------------------- // Plane struct Plane : public XMFLOAT4 { - Plane() noexcept - : XMFLOAT4(0.f, 1.f, 0.f, 0.f) - { - } - constexpr Plane(float ix, float iy, float iz, float iw) noexcept - : XMFLOAT4(ix, iy, iz, iw) - { - } - Plane(const Vector3& normal, float d) noexcept - : XMFLOAT4(normal.x, normal.y, normal.z, d) - { - } + Plane() noexcept : XMFLOAT4(0.f, 1.f, 0.f, 0.f) {} + constexpr Plane(float ix, float iy, float iz, float iw) noexcept : XMFLOAT4(ix, iy, iz, iw) {} + Plane(const Vector3& normal, float d) noexcept : XMFLOAT4(normal.x, normal.y, normal.z, d) {} Plane(const Vector3& point1, const Vector3& point2, const Vector3& point3) noexcept; Plane(const Vector3& point, const Vector3& normal) noexcept; - explicit Plane(const Vector4& v) noexcept - : XMFLOAT4(v.x, v.y, v.z, v.w) - { - } - explicit Plane(_In_reads_(4) const float* pArray) noexcept - : XMFLOAT4(pArray) - { - } + explicit Plane(const Vector4& v) noexcept : XMFLOAT4(v.x, v.y, v.z, v.w) {} + explicit Plane(_In_reads_(4) const float *pArray) noexcept : XMFLOAT4(pArray) {} Plane(FXMVECTOR V) noexcept { XMStoreFloat4(this, V); } - Plane(const XMFLOAT4& p) noexcept - { - this->x = p.x; - this->y = p.y; - this->z = p.z; - this->w = p.w; - } - explicit Plane(const XMVECTORF32& F) noexcept - { - this->x = F.f[0]; - this->y = F.f[1]; - this->z = F.f[2]; - this->w = F.f[3]; - } + Plane(const XMFLOAT4& p) noexcept { this->x = p.x; this->y = p.y; this->z = p.z; this->w = p.w; } + explicit Plane(const XMVECTORF32& F) noexcept { this->x = F.f[0]; this->y = F.f[1]; this->z = F.f[2]; this->w = F.f[3]; } - Plane(const Plane&) = default; + Plane(const Plane&) = default; Plane& operator=(const Plane&) = default; - Plane(Plane&&) = default; + Plane(Plane&&) = default; Plane& operator=(Plane&&) = default; operator XMVECTOR() const noexcept { return XMLoadFloat4(this); } // Comparison operators - bool operator==(const Plane& p) const noexcept; - bool operator!=(const Plane& p) const noexcept; + bool operator == (const Plane& p) const noexcept; + bool operator != (const Plane& p) const noexcept; // Assignment operators - Plane& operator=(const XMVECTORF32& F) noexcept - { - x = F.f[0]; - y = F.f[1]; - z = F.f[2]; - w = F.f[3]; - return *this; - } + Plane& operator= (const XMVECTORF32& F) noexcept { x = F.f[0]; y = F.f[1]; z = F.f[2]; w = F.f[3]; return *this; } // Properties Vector3 Normal() const noexcept { return Vector3(x, y, z); } - void Normal(const Vector3& normal) noexcept - { - x = normal.x; - y = normal.y; - z = normal.z; - } + void Normal(const Vector3& normal) noexcept { x = normal.x; y = normal.y; z = normal.z; } float D() const noexcept { return w; } void D(float d) noexcept { w = d; } @@ -928,79 +687,45 @@ namespace DirectX static void Transform(const Plane& plane, const Quaternion& rotation, Plane& result) noexcept; static Plane Transform(const Plane& plane, const Quaternion& rotation) noexcept; - // Input quaternion must be the inverse transpose of the transformation + // Input quaternion must be the inverse transpose of the transformation }; //------------------------------------------------------------------------------ // Quaternion struct Quaternion : public XMFLOAT4 { - Quaternion() noexcept - : XMFLOAT4(0, 0, 0, 1.f) - { - } - constexpr Quaternion(float ix, float iy, float iz, float iw) noexcept - : XMFLOAT4(ix, iy, iz, iw) - { - } - Quaternion(const Vector3& v, float scalar) noexcept - : XMFLOAT4(v.x, v.y, v.z, scalar) - { - } - explicit Quaternion(const Vector4& v) noexcept - : XMFLOAT4(v.x, v.y, v.z, v.w) - { - } - explicit Quaternion(_In_reads_(4) const float* pArray) noexcept - : XMFLOAT4(pArray) - { - } + Quaternion() noexcept : XMFLOAT4(0, 0, 0, 1.f) {} + constexpr Quaternion(float ix, float iy, float iz, float iw) noexcept : XMFLOAT4(ix, iy, iz, iw) {} + Quaternion(const Vector3& v, float scalar) noexcept : XMFLOAT4(v.x, v.y, v.z, scalar) {} + explicit Quaternion(const Vector4& v) noexcept : XMFLOAT4(v.x, v.y, v.z, v.w) {} + explicit Quaternion(_In_reads_(4) const float *pArray) noexcept : XMFLOAT4(pArray) {} Quaternion(FXMVECTOR V) noexcept { XMStoreFloat4(this, V); } - Quaternion(const XMFLOAT4& q) noexcept - { - this->x = q.x; - this->y = q.y; - this->z = q.z; - this->w = q.w; - } - explicit Quaternion(const XMVECTORF32& F) noexcept - { - this->x = F.f[0]; - this->y = F.f[1]; - this->z = F.f[2]; - this->w = F.f[3]; - } + Quaternion(const XMFLOAT4& q) noexcept { this->x = q.x; this->y = q.y; this->z = q.z; this->w = q.w; } + explicit Quaternion(const XMVECTORF32& F) noexcept { this->x = F.f[0]; this->y = F.f[1]; this->z = F.f[2]; this->w = F.f[3]; } - Quaternion(const Quaternion&) = default; + Quaternion(const Quaternion&) = default; Quaternion& operator=(const Quaternion&) = default; - Quaternion(Quaternion&&) = default; + Quaternion(Quaternion&&) = default; Quaternion& operator=(Quaternion&&) = default; operator XMVECTOR() const noexcept { return XMLoadFloat4(this); } // Comparison operators - bool operator==(const Quaternion& q) const noexcept; - bool operator!=(const Quaternion& q) const noexcept; + bool operator == (const Quaternion& q) const noexcept; + bool operator != (const Quaternion& q) const noexcept; // Assignment operators - Quaternion& operator=(const XMVECTORF32& F) noexcept - { - x = F.f[0]; - y = F.f[1]; - z = F.f[2]; - w = F.f[3]; - return *this; - } - Quaternion& operator+=(const Quaternion& q) noexcept; - Quaternion& operator-=(const Quaternion& q) noexcept; - Quaternion& operator*=(const Quaternion& q) noexcept; - Quaternion& operator*=(float S) noexcept; - Quaternion& operator/=(const Quaternion& q) noexcept; + Quaternion& operator= (const XMVECTORF32& F) noexcept { x = F.f[0]; y = F.f[1]; z = F.f[2]; w = F.f[3]; return *this; } + Quaternion& operator+= (const Quaternion& q) noexcept; + Quaternion& operator-= (const Quaternion& q) noexcept; + Quaternion& operator*= (const Quaternion& q) noexcept; + Quaternion& operator*= (float S) noexcept; + Quaternion& operator/= (const Quaternion& q) noexcept; // Unary operators - Quaternion operator+() const noexcept { return *this; } - Quaternion operator-() const noexcept; + Quaternion operator+ () const noexcept { return *this; } + Quaternion operator- () const noexcept; // Quaternion operations float Length() const noexcept; @@ -1028,8 +753,7 @@ namespace DirectX // Rotates about y-axis (yaw), then x-axis (pitch), then z-axis (roll) static Quaternion CreateFromYawPitchRoll(float yaw, float pitch, float roll) noexcept; - // Rotates about y-axis (angles.y), then x-axis (angles.x), then z-axis - // (angles.z) + // Rotates about y-axis (angles.y), then x-axis (angles.x), then z-axis (angles.z) static Quaternion CreateFromYawPitchRoll(const Vector3& angles) noexcept; static Quaternion CreateFromRotationMatrix(const Matrix& M) noexcept; @@ -1043,8 +767,7 @@ namespace DirectX static void Concatenate(const Quaternion& q1, const Quaternion& q2, Quaternion& result) noexcept; static Quaternion Concatenate(const Quaternion& q1, const Quaternion& q2) noexcept; - static void __cdecl FromToRotation(const Vector3& fromDir, const Vector3& toDir, - Quaternion& result) noexcept; + static void __cdecl FromToRotation(const Vector3& fromDir, const Vector3& toDir, Quaternion& result) noexcept; static Quaternion FromToRotation(const Vector3& fromDir, const Vector3& toDir) noexcept; static void __cdecl LookRotation(const Vector3& forward, const Vector3& up, Quaternion& result) noexcept; @@ -1057,56 +780,26 @@ namespace DirectX }; // Binary operators - Quaternion operator+(const Quaternion& Q1, const Quaternion& Q2) noexcept; - Quaternion operator-(const Quaternion& Q1, const Quaternion& Q2) noexcept; - Quaternion operator*(const Quaternion& Q1, const Quaternion& Q2) noexcept; - Quaternion operator*(const Quaternion& Q, float S) noexcept; - Quaternion operator/(const Quaternion& Q1, const Quaternion& Q2) noexcept; - Quaternion operator*(float S, const Quaternion& Q) noexcept; + Quaternion operator+ (const Quaternion& Q1, const Quaternion& Q2) noexcept; + Quaternion operator- (const Quaternion& Q1, const Quaternion& Q2) noexcept; + Quaternion operator* (const Quaternion& Q1, const Quaternion& Q2) noexcept; + Quaternion operator* (const Quaternion& Q, float S) noexcept; + Quaternion operator/ (const Quaternion& Q1, const Quaternion& Q2) noexcept; + Quaternion operator* (float S, const Quaternion& Q) noexcept; //------------------------------------------------------------------------------ // Color struct Color : public XMFLOAT4 { - Color() noexcept - : XMFLOAT4(0, 0, 0, 1.f) - { - } - constexpr Color(float _r, float _g, float _b) noexcept - : XMFLOAT4(_r, _g, _b, 1.f) - { - } - constexpr Color(float _r, float _g, float _b, float _a) noexcept - : XMFLOAT4(_r, _g, _b, _a) - { - } - explicit Color(const Vector3& clr) noexcept - : XMFLOAT4(clr.x, clr.y, clr.z, 1.f) - { - } - explicit Color(const Vector4& clr) noexcept - : XMFLOAT4(clr.x, clr.y, clr.z, clr.w) - { - } - explicit Color(_In_reads_(4) const float* pArray) noexcept - : XMFLOAT4(pArray) - { - } + Color() noexcept : XMFLOAT4(0, 0, 0, 1.f) {} + constexpr Color(float _r, float _g, float _b) noexcept : XMFLOAT4(_r, _g, _b, 1.f) {} + constexpr Color(float _r, float _g, float _b, float _a) noexcept : XMFLOAT4(_r, _g, _b, _a) {} + explicit Color(const Vector3& clr) noexcept : XMFLOAT4(clr.x, clr.y, clr.z, 1.f) {} + explicit Color(const Vector4& clr) noexcept : XMFLOAT4(clr.x, clr.y, clr.z, clr.w) {} + explicit Color(_In_reads_(4) const float *pArray) noexcept : XMFLOAT4(pArray) {} Color(FXMVECTOR V) noexcept { XMStoreFloat4(this, V); } - Color(const XMFLOAT4& c) noexcept - { - this->x = c.x; - this->y = c.y; - this->z = c.z; - this->w = c.w; - } - explicit Color(const XMVECTORF32& F) noexcept - { - this->x = F.f[0]; - this->y = F.f[1]; - this->z = F.f[2]; - this->w = F.f[3]; - } + Color(const XMFLOAT4& c) noexcept { this->x = c.x; this->y = c.y; this->z = c.z; this->w = c.w; } + explicit Color(const XMVECTORF32& F) noexcept { this->x = F.f[0]; this->y = F.f[1]; this->z = F.f[2]; this->w = F.f[3]; } // BGRA Direct3D 9 D3DCOLOR packed color explicit Color(const DirectX::PackedVector::XMCOLOR& Packed) noexcept; @@ -1114,39 +807,32 @@ namespace DirectX // RGBA XNA Game Studio packed color explicit Color(const DirectX::PackedVector::XMUBYTEN4& Packed) noexcept; - Color(const Color&) = default; + Color(const Color&) = default; Color& operator=(const Color&) = default; - Color(Color&&) = default; + Color(Color&&) = default; Color& operator=(Color&&) = default; operator XMVECTOR() const noexcept { return XMLoadFloat4(this); } operator const float*() const noexcept { return reinterpret_cast(this); } // Comparison operators - bool operator==(const Color& c) const noexcept; - bool operator!=(const Color& c) const noexcept; + bool operator == (const Color& c) const noexcept; + bool operator != (const Color& c) const noexcept; // Assignment operators - Color& operator=(const XMVECTORF32& F) noexcept - { - x = F.f[0]; - y = F.f[1]; - z = F.f[2]; - w = F.f[3]; - return *this; - } - Color& operator=(const DirectX::PackedVector::XMCOLOR& Packed) noexcept; - Color& operator=(const DirectX::PackedVector::XMUBYTEN4& Packed) noexcept; - Color& operator+=(const Color& c) noexcept; - Color& operator-=(const Color& c) noexcept; - Color& operator*=(const Color& c) noexcept; - Color& operator*=(float S) noexcept; - Color& operator/=(const Color& c) noexcept; + Color& operator= (const XMVECTORF32& F) noexcept { x = F.f[0]; y = F.f[1]; z = F.f[2]; w = F.f[3]; return *this; } + Color& operator= (const DirectX::PackedVector::XMCOLOR& Packed) noexcept; + Color& operator= (const DirectX::PackedVector::XMUBYTEN4& Packed) noexcept; + Color& operator+= (const Color& c) noexcept; + Color& operator-= (const Color& c) noexcept; + Color& operator*= (const Color& c) noexcept; + Color& operator*= (float S) noexcept; + Color& operator/= (const Color& c) noexcept; // Unary operators - Color operator+() const noexcept { return *this; } - Color operator-() const noexcept; + Color operator+ () const noexcept { return *this; } + Color operator- () const noexcept; // Properties float R() const noexcept { return x; } @@ -1192,12 +878,12 @@ namespace DirectX }; // Binary operators - Color operator+(const Color& C1, const Color& C2) noexcept; - Color operator-(const Color& C1, const Color& C2) noexcept; - Color operator*(const Color& C1, const Color& C2) noexcept; - Color operator*(const Color& C, float S) noexcept; - Color operator/(const Color& C1, const Color& C2) noexcept; - Color operator*(float S, const Color& C) noexcept; + Color operator+ (const Color& C1, const Color& C2) noexcept; + Color operator- (const Color& C1, const Color& C2) noexcept; + Color operator* (const Color& C1, const Color& C2) noexcept; + Color operator* (const Color& C, float S) noexcept; + Color operator/ (const Color& C1, const Color& C2) noexcept; + Color operator* (float S, const Color& C) noexcept; //------------------------------------------------------------------------------ // Ray @@ -1207,30 +893,23 @@ namespace DirectX Vector3 position; Vector3 direction; - Ray() noexcept - : position(0, 0, 0), direction(0, 0, 1) - { - } - Ray(const Vector3& pos, const Vector3& dir) noexcept - : position(pos), direction(dir) - { - } + Ray() noexcept : position(0, 0, 0), direction(0, 0, 1) {} + Ray(const Vector3& pos, const Vector3& dir) noexcept : position(pos), direction(dir) {} - Ray(const Ray&) = default; + Ray(const Ray&) = default; Ray& operator=(const Ray&) = default; - Ray(Ray&&) = default; + Ray(Ray&&) = default; Ray& operator=(Ray&&) = default; // Comparison operators - bool operator==(const Ray& r) const noexcept; - bool operator!=(const Ray& r) const noexcept; + bool operator == (const Ray& r) const noexcept; + bool operator != (const Ray& r) const noexcept; // Ray operations bool Intersects(const BoundingSphere& sphere, _Out_ float& Dist) const noexcept; bool Intersects(const BoundingBox& box, _Out_ float& Dist) const noexcept; - bool Intersects(const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, - _Out_ float& Dist) const noexcept; + bool Intersects(const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist) const noexcept; bool Intersects(const Plane& plane, _Out_ float& Dist) const noexcept; }; @@ -1246,124 +925,109 @@ namespace DirectX float minDepth; float maxDepth; - Viewport() noexcept - : x(0.f), y(0.f), width(0.f), height(0.f), minDepth(0.f), maxDepth(1.f) + Viewport() noexcept : + x(0.f), y(0.f), width(0.f), height(0.f), minDepth(0.f), maxDepth(1.f) { } - constexpr Viewport(float ix, float iy, float iw, float ih, float iminz = 0.f, float imaxz = 1.f) noexcept - : x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz) + constexpr Viewport(float ix, float iy, float iw, float ih, float iminz = 0.f, float imaxz = 1.f) noexcept : + x(ix), y(iy), width(iw), height(ih), minDepth(iminz), maxDepth(imaxz) { } - explicit Viewport(const RECT& rct) noexcept - : x(float(rct.left)) - , y(float(rct.top)) - , width(float(rct.right - rct.left)) - , height(float(rct.bottom - rct.top)) - , minDepth(0.f) - , maxDepth(1.f) + explicit Viewport(const RECT& rct) noexcept : + x(float(rct.left)), y(float(rct.top)), + width(float(rct.right - rct.left)), + height(float(rct.bottom - rct.top)), + minDepth(0.f), maxDepth(1.f) { } -#if defined(__d3d11_h__) || defined(__d3d11_x_h__) + #if defined(__d3d11_h__) || defined(__d3d11_x_h__) // Direct3D 11 interop - explicit Viewport(const D3D11_VIEWPORT& vp) noexcept - : x(vp.TopLeftX) - , y(vp.TopLeftY) - , width(vp.Width) - , height(vp.Height) - , minDepth(vp.MinDepth) - , maxDepth(vp.MaxDepth) + explicit Viewport(const D3D11_VIEWPORT& vp) noexcept : + x(vp.TopLeftX), y(vp.TopLeftY), + width(vp.Width), height(vp.Height), + minDepth(vp.MinDepth), maxDepth(vp.MaxDepth) { } operator D3D11_VIEWPORT() noexcept { return *reinterpret_cast(this); } const D3D11_VIEWPORT* Get11() const noexcept { return reinterpret_cast(this); } - Viewport& operator=(const D3D11_VIEWPORT& vp) noexcept; -#endif + Viewport& operator= (const D3D11_VIEWPORT& vp) noexcept; + #endif -#if defined(__d3d12_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) + #if defined(__d3d12_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) // Direct3D 12 interop - explicit Viewport(const D3D12_VIEWPORT& vp) noexcept - : x(vp.TopLeftX) - , y(vp.TopLeftY) - , width(vp.Width) - , height(vp.Height) - , minDepth(vp.MinDepth) - , maxDepth(vp.MaxDepth) + explicit Viewport(const D3D12_VIEWPORT& vp) noexcept : + x(vp.TopLeftX), y(vp.TopLeftY), + width(vp.Width), height(vp.Height), + minDepth(vp.MinDepth), maxDepth(vp.MaxDepth) { } operator D3D12_VIEWPORT() noexcept { return *reinterpret_cast(this); } const D3D12_VIEWPORT* Get12() const noexcept { return reinterpret_cast(this); } - Viewport& operator=(const D3D12_VIEWPORT& vp) noexcept; -#endif + Viewport& operator= (const D3D12_VIEWPORT& vp) noexcept; + #endif - Viewport(const Viewport&) = default; + Viewport(const Viewport&) = default; Viewport& operator=(const Viewport&) = default; - Viewport(Viewport&&) = default; + Viewport(Viewport&&) = default; Viewport& operator=(Viewport&&) = default; // Comparison operators -#if (__cplusplus >= 202002L) - bool operator==(const Viewport&) const = default; - auto operator<=>(const Viewport&) const = default; -#else - bool operator==(const Viewport& vp) const noexcept; - bool operator!=(const Viewport& vp) const noexcept; -#endif + #if (__cplusplus >= 202002L) + bool operator == (const Viewport&) const = default; + auto operator <=> (const Viewport&) const = default; + #else + bool operator == (const Viewport& vp) const noexcept; + bool operator != (const Viewport& vp) const noexcept; + #endif // Assignment operators - Viewport& operator=(const RECT& rct) noexcept; + Viewport& operator= (const RECT& rct) noexcept; // Viewport operations float AspectRatio() const noexcept; - Vector3 Project(const Vector3& p, const Matrix& proj, const Matrix& view, - const Matrix& world) const noexcept; - void Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, - Vector3& result) const noexcept; + Vector3 Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const noexcept; + void Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const noexcept; - Vector3 Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, - const Matrix& world) const noexcept; - void Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, - Vector3& result) const noexcept; + Vector3 Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const noexcept; + void Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const noexcept; // Static methods #ifdef CGL_PLATFORM_WINDOWS - #if defined(__dxgi1_2_h__) || defined(__d3d11_x_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) - static RECT __cdecl ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight, - int outputWidth, int outputHeight) noexcept; - #endif + #if defined(__dxgi1_2_h__) || defined(__d3d11_x_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) + static RECT __cdecl ComputeDisplayArea(DXGI_SCALING scaling, UINT backBufferWidth, UINT backBufferHeight, int outputWidth, int outputHeight) noexcept; + #endif static RECT __cdecl ComputeTitleSafeArea(UINT backBufferWidth, UINT backBufferHeight) noexcept; #endif }; -#include "SimpleMath.inl" + #include "SimpleMath.inl" - } // namespace SimpleMath + } // namespace SimpleMath -} // namespace DirectX +} // namespace DirectX //------------------------------------------------------------------------------ // Support for SimpleMath and Standard C++ Library containers namespace std { - template <> - struct less + template<> struct less { - bool operator()(const DirectX::SimpleMath::Rectangle& r1, - const DirectX::SimpleMath::Rectangle& r2) const noexcept + bool operator()(const DirectX::SimpleMath::Rectangle& r1, const DirectX::SimpleMath::Rectangle& r2) const noexcept { - return ((r1.x < r2.x) || ((r1.x == r2.x) && (r1.y < r2.y)) || - ((r1.x == r2.x) && (r1.y == r2.y) && (r1.width < r2.width)) || - ((r1.x == r2.x) && (r1.y == r2.y) && (r1.width == r2.width) && (r1.height < r2.height))); + return ((r1.x < r2.x) + || ((r1.x == r2.x) && (r1.y < r2.y)) + || ((r1.x == r2.x) && (r1.y == r2.y) && (r1.width < r2.width)) + || ((r1.x == r2.x) && (r1.y == r2.y) && (r1.width == r2.width) && (r1.height < r2.height))); } }; - template <> - struct less + template<> struct less { bool operator()(const DirectX::SimpleMath::Vector2& V1, const DirectX::SimpleMath::Vector2& V2) const noexcept { @@ -1371,153 +1035,120 @@ namespace std } }; - template <> - struct less + template<> struct less { bool operator()(const DirectX::SimpleMath::Vector3& V1, const DirectX::SimpleMath::Vector3& V2) const noexcept { - return ((V1.x < V2.x) || ((V1.x == V2.x) && (V1.y < V2.y)) || - ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z))); + return ((V1.x < V2.x) + || ((V1.x == V2.x) && (V1.y < V2.y)) + || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z))); } }; - template <> - struct less + template<> struct less { bool operator()(const DirectX::SimpleMath::Vector4& V1, const DirectX::SimpleMath::Vector4& V2) const noexcept { - return ((V1.x < V2.x) || ((V1.x == V2.x) && (V1.y < V2.y)) || - ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z)) || - ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z) && (V1.w < V2.w))); + return ((V1.x < V2.x) + || ((V1.x == V2.x) && (V1.y < V2.y)) + || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z < V2.z)) + || ((V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z) && (V1.w < V2.w))); } }; - template <> - struct less + template<> struct less { bool operator()(const DirectX::SimpleMath::Matrix& M1, const DirectX::SimpleMath::Matrix& M2) const noexcept { - if (M1._11 != M2._11) - return M1._11 < M2._11; - if (M1._12 != M2._12) - return M1._12 < M2._12; - if (M1._13 != M2._13) - return M1._13 < M2._13; - if (M1._14 != M2._14) - return M1._14 < M2._14; - if (M1._21 != M2._21) - return M1._21 < M2._21; - if (M1._22 != M2._22) - return M1._22 < M2._22; - if (M1._23 != M2._23) - return M1._23 < M2._23; - if (M1._24 != M2._24) - return M1._24 < M2._24; - if (M1._31 != M2._31) - return M1._31 < M2._31; - if (M1._32 != M2._32) - return M1._32 < M2._32; - if (M1._33 != M2._33) - return M1._33 < M2._33; - if (M1._34 != M2._34) - return M1._34 < M2._34; - if (M1._41 != M2._41) - return M1._41 < M2._41; - if (M1._42 != M2._42) - return M1._42 < M2._42; - if (M1._43 != M2._43) - return M1._43 < M2._43; - if (M1._44 != M2._44) - return M1._44 < M2._44; + if (M1._11 != M2._11) return M1._11 < M2._11; + if (M1._12 != M2._12) return M1._12 < M2._12; + if (M1._13 != M2._13) return M1._13 < M2._13; + if (M1._14 != M2._14) return M1._14 < M2._14; + if (M1._21 != M2._21) return M1._21 < M2._21; + if (M1._22 != M2._22) return M1._22 < M2._22; + if (M1._23 != M2._23) return M1._23 < M2._23; + if (M1._24 != M2._24) return M1._24 < M2._24; + if (M1._31 != M2._31) return M1._31 < M2._31; + if (M1._32 != M2._32) return M1._32 < M2._32; + if (M1._33 != M2._33) return M1._33 < M2._33; + if (M1._34 != M2._34) return M1._34 < M2._34; + if (M1._41 != M2._41) return M1._41 < M2._41; + if (M1._42 != M2._42) return M1._42 < M2._42; + if (M1._43 != M2._43) return M1._43 < M2._43; + if (M1._44 != M2._44) return M1._44 < M2._44; return false; } }; - template <> - struct less + template<> struct less { bool operator()(const DirectX::SimpleMath::Plane& P1, const DirectX::SimpleMath::Plane& P2) const noexcept { - return ((P1.x < P2.x) || ((P1.x == P2.x) && (P1.y < P2.y)) || - ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z < P2.z)) || - ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z == P2.z) && (P1.w < P2.w))); + return ((P1.x < P2.x) + || ((P1.x == P2.x) && (P1.y < P2.y)) + || ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z < P2.z)) + || ((P1.x == P2.x) && (P1.y == P2.y) && (P1.z == P2.z) && (P1.w < P2.w))); } }; - template <> - struct less + template<> struct less { - bool operator()(const DirectX::SimpleMath::Quaternion& Q1, - const DirectX::SimpleMath::Quaternion& Q2) const noexcept + bool operator()(const DirectX::SimpleMath::Quaternion& Q1, const DirectX::SimpleMath::Quaternion& Q2) const noexcept { - return ((Q1.x < Q2.x) || ((Q1.x == Q2.x) && (Q1.y < Q2.y)) || - ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z < Q2.z)) || - ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z == Q2.z) && (Q1.w < Q2.w))); + return ((Q1.x < Q2.x) + || ((Q1.x == Q2.x) && (Q1.y < Q2.y)) + || ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z < Q2.z)) + || ((Q1.x == Q2.x) && (Q1.y == Q2.y) && (Q1.z == Q2.z) && (Q1.w < Q2.w))); } }; - template <> - struct less + template<> struct less { bool operator()(const DirectX::SimpleMath::Color& C1, const DirectX::SimpleMath::Color& C2) const noexcept { - return ((C1.x < C2.x) || ((C1.x == C2.x) && (C1.y < C2.y)) || - ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z < C2.z)) || - ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z == C2.z) && (C1.w < C2.w))); + return ((C1.x < C2.x) + || ((C1.x == C2.x) && (C1.y < C2.y)) + || ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z < C2.z)) + || ((C1.x == C2.x) && (C1.y == C2.y) && (C1.z == C2.z) && (C1.w < C2.w))); } }; - template <> - struct less + template<> struct less { bool operator()(const DirectX::SimpleMath::Ray& R1, const DirectX::SimpleMath::Ray& R2) const noexcept { - if (R1.position.x != R2.position.x) - return R1.position.x < R2.position.x; - if (R1.position.y != R2.position.y) - return R1.position.y < R2.position.y; - if (R1.position.z != R2.position.z) - return R1.position.z < R2.position.z; - - if (R1.direction.x != R2.direction.x) - return R1.direction.x < R2.direction.x; - if (R1.direction.y != R2.direction.y) - return R1.direction.y < R2.direction.y; - if (R1.direction.z != R2.direction.z) - return R1.direction.z < R2.direction.z; + if (R1.position.x != R2.position.x) return R1.position.x < R2.position.x; + if (R1.position.y != R2.position.y) return R1.position.y < R2.position.y; + if (R1.position.z != R2.position.z) return R1.position.z < R2.position.z; + + if (R1.direction.x != R2.direction.x) return R1.direction.x < R2.direction.x; + if (R1.direction.y != R2.direction.y) return R1.direction.y < R2.direction.y; + if (R1.direction.z != R2.direction.z) return R1.direction.z < R2.direction.z; return false; } }; - template <> - struct less + template<> struct less { - bool operator()(const DirectX::SimpleMath::Viewport& vp1, - const DirectX::SimpleMath::Viewport& vp2) const noexcept + bool operator()(const DirectX::SimpleMath::Viewport& vp1, const DirectX::SimpleMath::Viewport& vp2) const noexcept { - if (vp1.x != vp2.x) - return (vp1.x < vp2.x); - if (vp1.y != vp2.y) - return (vp1.y < vp2.y); + if (vp1.x != vp2.x) return (vp1.x < vp2.x); + if (vp1.y != vp2.y) return (vp1.y < vp2.y); - if (vp1.width != vp2.width) - return (vp1.width < vp2.width); - if (vp1.height != vp2.height) - return (vp1.height < vp2.height); + if (vp1.width != vp2.width) return (vp1.width < vp2.width); + if (vp1.height != vp2.height) return (vp1.height < vp2.height); - if (vp1.minDepth != vp2.minDepth) - return (vp1.minDepth < vp2.minDepth); - if (vp1.maxDepth != vp2.maxDepth) - return (vp1.maxDepth < vp2.maxDepth); + if (vp1.minDepth != vp2.minDepth) return (vp1.minDepth < vp2.minDepth); + if (vp1.maxDepth != vp2.maxDepth) return (vp1.maxDepth < vp2.maxDepth); return false; } }; -} // namespace std +} // namespace std #ifdef __clang__ - #pragma clang diagnostic pop +#pragma clang diagnostic pop #endif diff --git a/Core/External/SimpleMath.inl b/Core/External/SimpleMath.inl index 83cf820..c2cd1f3 100644 --- a/Core/External/SimpleMath.inl +++ b/Core/External/SimpleMath.inl @@ -11,10 +11,10 @@ #pragma once /**************************************************************************** - * - * Rectangle - * - ****************************************************************************/ +* +* Rectangle +* +****************************************************************************/ //------------------------------------------------------------------------------ // Rectangle operations @@ -31,8 +31,7 @@ inline Vector2 Rectangle::Center() const noexcept inline bool Rectangle::Contains(const Vector2& point) const noexcept { - return (float(x) <= point.x) && (point.x < float(x + width)) && (float(y) <= point.y) && - (point.y < float(y + height)); + return (float(x) <= point.x) && (point.x < float(x + width)) && (float(y) <= point.y) && (point.y < float(y + height)); } inline void Rectangle::Inflate(long horizAmount, long vertAmount) noexcept @@ -58,23 +57,23 @@ inline Rectangle Rectangle::Intersect(const Rectangle& ra, const Rectangle& rb) const long maxX = ra.x > rb.x ? ra.x : rb.x; const long maxY = ra.y > rb.y ? ra.y : rb.y; - const long minRight = righta < rightb ? righta : rightb; + const long minRight = righta < rightb ? righta : rightb; const long minBottom = bottoma < bottomb ? bottoma : bottomb; Rectangle result; if ((minRight > maxX) && (minBottom > maxY)) { - result.x = maxX; - result.y = maxY; - result.width = minRight - maxX; + result.x = maxX; + result.y = maxY; + result.width = minRight - maxX; result.height = minBottom - maxY; } else { - result.x = 0; - result.y = 0; - result.width = 0; + result.x = 0; + result.y = 0; + result.width = 0; result.height = 0; } @@ -86,23 +85,23 @@ inline RECT Rectangle::Intersect(const RECT& rcta, const RECT& rctb) noexcept const long maxX = rcta.left > rctb.left ? rcta.left : rctb.left; const long maxY = rcta.top > rctb.top ? rcta.top : rctb.top; - const long minRight = rcta.right < rctb.right ? rcta.right : rctb.right; + const long minRight = rcta.right < rctb.right ? rcta.right : rctb.right; const long minBottom = rcta.bottom < rctb.bottom ? rcta.bottom : rctb.bottom; RECT result; if ((minRight > maxX) && (minBottom > maxY)) { - result.left = maxX; - result.top = maxY; - result.right = minRight; + result.left = maxX; + result.top = maxY; + result.right = minRight; result.bottom = minBottom; } else { - result.left = 0; - result.top = 0; - result.right = 0; + result.left = 0; + result.top = 0; + result.right = 0; result.bottom = 0; } @@ -120,13 +119,13 @@ inline Rectangle Rectangle::Union(const Rectangle& ra, const Rectangle& rb) noex const int minX = ra.x < rb.x ? ra.x : rb.x; const int minY = ra.y < rb.y ? ra.y : rb.y; - const int maxRight = righta > rightb ? righta : rightb; + const int maxRight = righta > rightb ? righta : rightb; const int maxBottom = bottoma > bottomb ? bottoma : bottomb; Rectangle result; - result.x = minX; - result.y = minY; - result.width = maxRight - minX; + result.x = minX; + result.y = minY; + result.width = maxRight - minX; result.height = maxBottom - minY; return result; } @@ -135,14 +134,15 @@ inline Rectangle Rectangle::Union(const Rectangle& ra, const Rectangle& rb) noex inline RECT Rectangle::Union(const RECT& rcta, const RECT& rctb) noexcept { RECT result; - result.left = rcta.left < rctb.left ? rcta.left : rctb.left; - result.top = rcta.top < rctb.top ? rcta.top : rctb.top; - result.right = rcta.right > rctb.right ? rcta.right : rctb.right; + result.left = rcta.left < rctb.left ? rcta.left : rctb.left; + result.top = rcta.top < rctb.top ? rcta.top : rctb.top; + result.right = rcta.right > rctb.right ? rcta.right : rctb.right; result.bottom = rcta.bottom > rctb.bottom ? rcta.bottom : rctb.bottom; return result; } #endif + /**************************************************************************** * * Vector2 @@ -153,7 +153,7 @@ inline RECT Rectangle::Union(const RECT& rcta, const RECT& rctb) noexcept // Comparision operators //------------------------------------------------------------------------------ -inline bool Vector2::operator==(const Vector2& V) const noexcept +inline bool Vector2::operator == (const Vector2& V) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); @@ -161,7 +161,7 @@ inline bool Vector2::operator==(const Vector2& V) const noexcept return XMVector2Equal(v1, v2); } -inline bool Vector2::operator!=(const Vector2& V) const noexcept +inline bool Vector2::operator != (const Vector2& V) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); @@ -173,51 +173,51 @@ inline bool Vector2::operator!=(const Vector2& V) const noexcept // Assignment operators //------------------------------------------------------------------------------ -inline Vector2& Vector2::operator+=(const Vector2& V) noexcept +inline Vector2& Vector2::operator+= (const Vector2& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&V); - const XMVECTOR X = XMVectorAdd(v1, v2); + const XMVECTOR X = XMVectorAdd(v1, v2); XMStoreFloat2(this, X); return *this; } -inline Vector2& Vector2::operator-=(const Vector2& V) noexcept +inline Vector2& Vector2::operator-= (const Vector2& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&V); - const XMVECTOR X = XMVectorSubtract(v1, v2); + const XMVECTOR X = XMVectorSubtract(v1, v2); XMStoreFloat2(this, X); return *this; } -inline Vector2& Vector2::operator*=(const Vector2& V) noexcept +inline Vector2& Vector2::operator*= (const Vector2& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&V); - const XMVECTOR X = XMVectorMultiply(v1, v2); + const XMVECTOR X = XMVectorMultiply(v1, v2); XMStoreFloat2(this, X); return *this; } -inline Vector2& Vector2::operator*=(float S) noexcept +inline Vector2& Vector2::operator*= (float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); XMStoreFloat2(this, X); return *this; } -inline Vector2& Vector2::operator/=(float S) noexcept +inline Vector2& Vector2::operator/= (float S) noexcept { using namespace DirectX; assert(S != 0.0f); const XMVECTOR v1 = XMLoadFloat2(this); - const XMVECTOR X = XMVectorScale(v1, 1.f / S); + const XMVECTOR X = XMVectorScale(v1, 1.f / S); XMStoreFloat2(this, X); return *this; } @@ -226,75 +226,75 @@ inline Vector2& Vector2::operator/=(float S) noexcept // Binary operators //------------------------------------------------------------------------------ -inline Vector2 operator+(const Vector2& V1, const Vector2& V2) noexcept +inline Vector2 operator+ (const Vector2& V1, const Vector2& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&V1); const XMVECTOR v2 = XMLoadFloat2(&V2); - const XMVECTOR X = XMVectorAdd(v1, v2); + const XMVECTOR X = XMVectorAdd(v1, v2); Vector2 R; XMStoreFloat2(&R, X); return R; } -inline Vector2 operator-(const Vector2& V1, const Vector2& V2) noexcept +inline Vector2 operator- (const Vector2& V1, const Vector2& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&V1); const XMVECTOR v2 = XMLoadFloat2(&V2); - const XMVECTOR X = XMVectorSubtract(v1, v2); + const XMVECTOR X = XMVectorSubtract(v1, v2); Vector2 R; XMStoreFloat2(&R, X); return R; } -inline Vector2 operator*(const Vector2& V1, const Vector2& V2) noexcept +inline Vector2 operator* (const Vector2& V1, const Vector2& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&V1); const XMVECTOR v2 = XMLoadFloat2(&V2); - const XMVECTOR X = XMVectorMultiply(v1, v2); + const XMVECTOR X = XMVectorMultiply(v1, v2); Vector2 R; XMStoreFloat2(&R, X); return R; } -inline Vector2 operator*(const Vector2& V, float S) noexcept +inline Vector2 operator* (const Vector2& V, float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&V); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); Vector2 R; XMStoreFloat2(&R, X); return R; } -inline Vector2 operator/(const Vector2& V1, const Vector2& V2) noexcept +inline Vector2 operator/ (const Vector2& V1, const Vector2& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&V1); const XMVECTOR v2 = XMLoadFloat2(&V2); - const XMVECTOR X = XMVectorDivide(v1, v2); + const XMVECTOR X = XMVectorDivide(v1, v2); Vector2 R; XMStoreFloat2(&R, X); return R; } -inline Vector2 operator/(const Vector2& V, float S) noexcept +inline Vector2 operator/ (const Vector2& V, float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&V); - const XMVECTOR X = XMVectorScale(v1, 1.f / S); + const XMVECTOR X = XMVectorScale(v1, 1.f / S); Vector2 R; XMStoreFloat2(&R, X); return R; } -inline Vector2 operator*(float S, const Vector2& V) noexcept +inline Vector2 operator* (float S, const Vector2& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&V); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); Vector2 R; XMStoreFloat2(&R, X); return R; @@ -316,7 +316,7 @@ inline float Vector2::Length() const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); - const XMVECTOR X = XMVector2Length(v1); + const XMVECTOR X = XMVector2Length(v1); return XMVectorGetX(X); } @@ -324,7 +324,7 @@ inline float Vector2::LengthSquared() const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); - const XMVECTOR X = XMVector2LengthSq(v1); + const XMVECTOR X = XMVector2LengthSq(v1); return XMVectorGetX(X); } @@ -333,7 +333,7 @@ inline float Vector2::Dot(const Vector2& V) const noexcept using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&V); - const XMVECTOR X = XMVector2Dot(v1, v2); + const XMVECTOR X = XMVector2Dot(v1, v2); return XMVectorGetX(X); } @@ -342,7 +342,7 @@ inline void Vector2::Cross(const Vector2& V, Vector2& result) const noexcept using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&V); - const XMVECTOR R = XMVector2Cross(v1, v2); + const XMVECTOR R = XMVector2Cross(v1, v2); XMStoreFloat2(&result, R); } @@ -351,7 +351,7 @@ inline Vector2 Vector2::Cross(const Vector2& V) const noexcept using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&V); - const XMVECTOR R = XMVector2Cross(v1, v2); + const XMVECTOR R = XMVector2Cross(v1, v2); Vector2 result; XMStoreFloat2(&result, R); @@ -362,7 +362,7 @@ inline void Vector2::Normalize() noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); - const XMVECTOR X = XMVector2Normalize(v1); + const XMVECTOR X = XMVector2Normalize(v1); XMStoreFloat2(this, X); } @@ -370,7 +370,7 @@ inline void Vector2::Normalize(Vector2& result) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(this); - const XMVECTOR X = XMVector2Normalize(v1); + const XMVECTOR X = XMVector2Normalize(v1); XMStoreFloat2(&result, X); } @@ -380,7 +380,7 @@ inline void Vector2::Clamp(const Vector2& vmin, const Vector2& vmax) noexcept const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&vmin); const XMVECTOR v3 = XMLoadFloat2(&vmax); - const XMVECTOR X = XMVectorClamp(v1, v2, v3); + const XMVECTOR X = XMVectorClamp(v1, v2, v3); XMStoreFloat2(this, X); } @@ -390,7 +390,7 @@ inline void Vector2::Clamp(const Vector2& vmin, const Vector2& vmax, Vector2& re const XMVECTOR v1 = XMLoadFloat2(this); const XMVECTOR v2 = XMLoadFloat2(&vmin); const XMVECTOR v3 = XMLoadFloat2(&vmax); - const XMVECTOR X = XMVectorClamp(v1, v2, v3); + const XMVECTOR X = XMVectorClamp(v1, v2, v3); XMStoreFloat2(&result, X); } @@ -403,8 +403,8 @@ inline float Vector2::Distance(const Vector2& v1, const Vector2& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR V = XMVectorSubtract(x2, x1); - const XMVECTOR X = XMVector2Length(V); + const XMVECTOR V = XMVectorSubtract(x2, x1); + const XMVECTOR X = XMVector2Length(V); return XMVectorGetX(X); } @@ -413,8 +413,8 @@ inline float Vector2::DistanceSquared(const Vector2& v1, const Vector2& v2) noex using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR V = XMVectorSubtract(x2, x1); - const XMVECTOR X = XMVector2LengthSq(V); + const XMVECTOR V = XMVectorSubtract(x2, x1); + const XMVECTOR X = XMVector2LengthSq(V); return XMVectorGetX(X); } @@ -423,7 +423,7 @@ inline void Vector2::Min(const Vector2& v1, const Vector2& v2, Vector2& result) using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorMin(x1, x2); + const XMVECTOR X = XMVectorMin(x1, x2); XMStoreFloat2(&result, X); } @@ -432,7 +432,7 @@ inline Vector2 Vector2::Min(const Vector2& v1, const Vector2& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorMin(x1, x2); + const XMVECTOR X = XMVectorMin(x1, x2); Vector2 result; XMStoreFloat2(&result, X); @@ -444,7 +444,7 @@ inline void Vector2::Max(const Vector2& v1, const Vector2& v2, Vector2& result) using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorMax(x1, x2); + const XMVECTOR X = XMVectorMax(x1, x2); XMStoreFloat2(&result, X); } @@ -453,7 +453,7 @@ inline Vector2 Vector2::Max(const Vector2& v1, const Vector2& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorMax(x1, x2); + const XMVECTOR X = XMVectorMax(x1, x2); Vector2 result; XMStoreFloat2(&result, X); @@ -465,7 +465,7 @@ inline void Vector2::Lerp(const Vector2& v1, const Vector2& v2, float t, Vector2 using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); XMStoreFloat2(&result, X); } @@ -474,7 +474,7 @@ inline Vector2 Vector2::Lerp(const Vector2& v1, const Vector2& v2, float t) noex using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); Vector2 result; XMStoreFloat2(&result, X); @@ -484,36 +484,35 @@ inline Vector2 Vector2::Lerp(const Vector2& v1, const Vector2& v2, float t) noex inline void Vector2::SmoothStep(const Vector2& v1, const Vector2& v2, float t, Vector2& result) noexcept { using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t * t * (3.f - 2.f * t); + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t*(3.f - 2.f*t); const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); XMStoreFloat2(&result, X); } inline Vector2 Vector2::SmoothStep(const Vector2& v1, const Vector2& v2, float t) noexcept { using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t * t * (3.f - 2.f * t); + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t*(3.f - 2.f*t); const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); Vector2 result; XMStoreFloat2(&result, X); return result; } -inline void Vector2::Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, - Vector2& result) noexcept +inline void Vector2::Barycentric(const Vector2& v1, const Vector2& v2, const Vector2& v3, float f, float g, Vector2& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); const XMVECTOR x3 = XMLoadFloat2(&v3); - const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); XMStoreFloat2(&result, X); } @@ -523,61 +522,57 @@ inline Vector2 Vector2::Barycentric(const Vector2& v1, const Vector2& v2, const const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); const XMVECTOR x3 = XMLoadFloat2(&v3); - const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); Vector2 result; XMStoreFloat2(&result, X); return result; } -inline void Vector2::CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, - Vector2& result) noexcept +inline void Vector2::CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t, Vector2& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); const XMVECTOR x3 = XMLoadFloat2(&v3); const XMVECTOR x4 = XMLoadFloat2(&v4); - const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); XMStoreFloat2(&result, X); } -inline Vector2 Vector2::CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, - float t) noexcept +inline Vector2 Vector2::CatmullRom(const Vector2& v1, const Vector2& v2, const Vector2& v3, const Vector2& v4, float t) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&v2); const XMVECTOR x3 = XMLoadFloat2(&v3); const XMVECTOR x4 = XMLoadFloat2(&v4); - const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); Vector2 result; XMStoreFloat2(&result, X); return result; } -inline void Vector2::Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, - Vector2& result) noexcept +inline void Vector2::Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t, Vector2& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&t1); const XMVECTOR x3 = XMLoadFloat2(&v2); const XMVECTOR x4 = XMLoadFloat2(&t2); - const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); XMStoreFloat2(&result, X); } -inline Vector2 Vector2::Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, - float t) noexcept +inline Vector2 Vector2::Hermite(const Vector2& v1, const Vector2& t1, const Vector2& v2, const Vector2& t2, float t) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat2(&v1); const XMVECTOR x2 = XMLoadFloat2(&t1); const XMVECTOR x3 = XMLoadFloat2(&v2); const XMVECTOR x4 = XMLoadFloat2(&t2); - const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); Vector2 result; XMStoreFloat2(&result, X); @@ -630,8 +625,8 @@ inline void Vector2::Transform(const Vector2& v, const Quaternion& quat, Vector2 { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - const XMVECTOR X = XMVector3Rotate(v1, q); + const XMVECTOR q = XMLoadFloat4(&quat); + const XMVECTOR X = XMVector3Rotate(v1, q); XMStoreFloat2(&result, X); } @@ -639,8 +634,8 @@ inline Vector2 Vector2::Transform(const Vector2& v, const Quaternion& quat) noex { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - const XMVECTOR X = XMVector3Rotate(v1, q); + const XMVECTOR q = XMLoadFloat4(&quat); + const XMVECTOR X = XMVector3Rotate(v1, q); Vector2 result; XMStoreFloat2(&result, X); @@ -651,8 +646,8 @@ inline void Vector2::Transform(const Vector2& v, const Matrix& m, Vector2& resul { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector2TransformCoord(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector2TransformCoord(v1, M); XMStoreFloat2(&result, X); } @@ -660,16 +655,16 @@ inline Vector2 Vector2::Transform(const Vector2& v, const Matrix& m) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector2TransformCoord(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector2TransformCoord(v1, M); Vector2 result; XMStoreFloat2(&result, X); return result; } -_Use_decl_annotations_ inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, - Vector2* resultArray) noexcept +_Use_decl_annotations_ +inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray) noexcept { using namespace DirectX; const XMMATRIX M = XMLoadFloat4x4(&m); @@ -680,13 +675,13 @@ inline void Vector2::Transform(const Vector2& v, const Matrix& m, Vector4& resul { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector2Transform(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector2Transform(v1, M); XMStoreFloat4(&result, X); } -_Use_decl_annotations_ inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, - Vector4* resultArray) noexcept +_Use_decl_annotations_ +inline void Vector2::Transform(const Vector2* varray, size_t count, const Matrix& m, Vector4* resultArray) noexcept { using namespace DirectX; const XMMATRIX M = XMLoadFloat4x4(&m); @@ -697,8 +692,8 @@ inline void Vector2::TransformNormal(const Vector2& v, const Matrix& m, Vector2& { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector2TransformNormal(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector2TransformNormal(v1, M); XMStoreFloat2(&result, X); } @@ -706,22 +701,23 @@ inline Vector2 Vector2::TransformNormal(const Vector2& v, const Matrix& m) noexc { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector2TransformNormal(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector2TransformNormal(v1, M); Vector2 result; XMStoreFloat2(&result, X); return result; } -_Use_decl_annotations_ inline void Vector2::TransformNormal(const Vector2* varray, size_t count, const Matrix& m, - Vector2* resultArray) noexcept +_Use_decl_annotations_ +inline void Vector2::TransformNormal(const Vector2* varray, size_t count, const Matrix& m, Vector2* resultArray) noexcept { using namespace DirectX; const XMMATRIX M = XMLoadFloat4x4(&m); XMVector2TransformNormalStream(resultArray, sizeof(XMFLOAT2), varray, sizeof(XMFLOAT2), count, M); } + /**************************************************************************** * * Vector3 @@ -732,7 +728,7 @@ _Use_decl_annotations_ inline void Vector2::TransformNormal(const Vector2* varra // Comparision operators //------------------------------------------------------------------------------ -inline bool Vector3::operator==(const Vector3& V) const noexcept +inline bool Vector3::operator == (const Vector3& V) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); @@ -740,7 +736,7 @@ inline bool Vector3::operator==(const Vector3& V) const noexcept return XMVector3Equal(v1, v2); } -inline bool Vector3::operator!=(const Vector3& V) const noexcept +inline bool Vector3::operator != (const Vector3& V) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); @@ -752,51 +748,51 @@ inline bool Vector3::operator!=(const Vector3& V) const noexcept // Assignment operators //------------------------------------------------------------------------------ -inline Vector3& Vector3::operator+=(const Vector3& V) noexcept +inline Vector3& Vector3::operator+= (const Vector3& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&V); - const XMVECTOR X = XMVectorAdd(v1, v2); + const XMVECTOR X = XMVectorAdd(v1, v2); XMStoreFloat3(this, X); return *this; } -inline Vector3& Vector3::operator-=(const Vector3& V) noexcept +inline Vector3& Vector3::operator-= (const Vector3& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&V); - const XMVECTOR X = XMVectorSubtract(v1, v2); + const XMVECTOR X = XMVectorSubtract(v1, v2); XMStoreFloat3(this, X); return *this; } -inline Vector3& Vector3::operator*=(const Vector3& V) noexcept +inline Vector3& Vector3::operator*= (const Vector3& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&V); - const XMVECTOR X = XMVectorMultiply(v1, v2); + const XMVECTOR X = XMVectorMultiply(v1, v2); XMStoreFloat3(this, X); return *this; } -inline Vector3& Vector3::operator*=(float S) noexcept +inline Vector3& Vector3::operator*= (float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); XMStoreFloat3(this, X); return *this; } -inline Vector3& Vector3::operator/=(float S) noexcept +inline Vector3& Vector3::operator/= (float S) noexcept { using namespace DirectX; assert(S != 0.0f); const XMVECTOR v1 = XMLoadFloat3(this); - const XMVECTOR X = XMVectorScale(v1, 1.f / S); + const XMVECTOR X = XMVectorScale(v1, 1.f / S); XMStoreFloat3(this, X); return *this; } @@ -805,11 +801,11 @@ inline Vector3& Vector3::operator/=(float S) noexcept // Urnary operators //------------------------------------------------------------------------------ -inline Vector3 Vector3::operator-() const noexcept +inline Vector3 Vector3::operator- () const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); - const XMVECTOR X = XMVectorNegate(v1); + const XMVECTOR X = XMVectorNegate(v1); Vector3 R; XMStoreFloat3(&R, X); return R; @@ -819,75 +815,75 @@ inline Vector3 Vector3::operator-() const noexcept // Binary operators //------------------------------------------------------------------------------ -inline Vector3 operator+(const Vector3& V1, const Vector3& V2) noexcept +inline Vector3 operator+ (const Vector3& V1, const Vector3& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&V1); const XMVECTOR v2 = XMLoadFloat3(&V2); - const XMVECTOR X = XMVectorAdd(v1, v2); + const XMVECTOR X = XMVectorAdd(v1, v2); Vector3 R; XMStoreFloat3(&R, X); return R; } -inline Vector3 operator-(const Vector3& V1, const Vector3& V2) noexcept +inline Vector3 operator- (const Vector3& V1, const Vector3& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&V1); const XMVECTOR v2 = XMLoadFloat3(&V2); - const XMVECTOR X = XMVectorSubtract(v1, v2); + const XMVECTOR X = XMVectorSubtract(v1, v2); Vector3 R; XMStoreFloat3(&R, X); return R; } -inline Vector3 operator*(const Vector3& V1, const Vector3& V2) noexcept +inline Vector3 operator* (const Vector3& V1, const Vector3& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&V1); const XMVECTOR v2 = XMLoadFloat3(&V2); - const XMVECTOR X = XMVectorMultiply(v1, v2); + const XMVECTOR X = XMVectorMultiply(v1, v2); Vector3 R; XMStoreFloat3(&R, X); return R; } -inline Vector3 operator*(const Vector3& V, float S) noexcept +inline Vector3 operator* (const Vector3& V, float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&V); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); Vector3 R; XMStoreFloat3(&R, X); return R; } -inline Vector3 operator/(const Vector3& V1, const Vector3& V2) noexcept +inline Vector3 operator/ (const Vector3& V1, const Vector3& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&V1); const XMVECTOR v2 = XMLoadFloat3(&V2); - const XMVECTOR X = XMVectorDivide(v1, v2); + const XMVECTOR X = XMVectorDivide(v1, v2); Vector3 R; XMStoreFloat3(&R, X); return R; } -inline Vector3 operator/(const Vector3& V, float S) noexcept +inline Vector3 operator/ (const Vector3& V, float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&V); - const XMVECTOR X = XMVectorScale(v1, 1.f / S); + const XMVECTOR X = XMVectorScale(v1, 1.f / S); Vector3 R; XMStoreFloat3(&R, X); return R; } -inline Vector3 operator*(float S, const Vector3& V) noexcept +inline Vector3 operator* (float S, const Vector3& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&V); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); Vector3 R; XMStoreFloat3(&R, X); return R; @@ -909,7 +905,7 @@ inline float Vector3::Length() const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); - const XMVECTOR X = XMVector3Length(v1); + const XMVECTOR X = XMVector3Length(v1); return XMVectorGetX(X); } @@ -917,7 +913,7 @@ inline float Vector3::LengthSquared() const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); - const XMVECTOR X = XMVector3LengthSq(v1); + const XMVECTOR X = XMVector3LengthSq(v1); return XMVectorGetX(X); } @@ -926,7 +922,7 @@ inline float Vector3::Dot(const Vector3& V) const noexcept using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&V); - const XMVECTOR X = XMVector3Dot(v1, v2); + const XMVECTOR X = XMVector3Dot(v1, v2); return XMVectorGetX(X); } @@ -935,7 +931,7 @@ inline void Vector3::Cross(const Vector3& V, Vector3& result) const noexcept using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&V); - const XMVECTOR R = XMVector3Cross(v1, v2); + const XMVECTOR R = XMVector3Cross(v1, v2); XMStoreFloat3(&result, R); } @@ -944,7 +940,7 @@ inline Vector3 Vector3::Cross(const Vector3& V) const noexcept using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&V); - const XMVECTOR R = XMVector3Cross(v1, v2); + const XMVECTOR R = XMVector3Cross(v1, v2); Vector3 result; XMStoreFloat3(&result, R); @@ -955,7 +951,7 @@ inline void Vector3::Normalize() noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); - const XMVECTOR X = XMVector3Normalize(v1); + const XMVECTOR X = XMVector3Normalize(v1); XMStoreFloat3(this, X); } @@ -963,7 +959,7 @@ inline void Vector3::Normalize(Vector3& result) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(this); - const XMVECTOR X = XMVector3Normalize(v1); + const XMVECTOR X = XMVector3Normalize(v1); XMStoreFloat3(&result, X); } @@ -973,7 +969,7 @@ inline void Vector3::Clamp(const Vector3& vmin, const Vector3& vmax) noexcept const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&vmin); const XMVECTOR v3 = XMLoadFloat3(&vmax); - const XMVECTOR X = XMVectorClamp(v1, v2, v3); + const XMVECTOR X = XMVectorClamp(v1, v2, v3); XMStoreFloat3(this, X); } @@ -983,7 +979,7 @@ inline void Vector3::Clamp(const Vector3& vmin, const Vector3& vmax, Vector3& re const XMVECTOR v1 = XMLoadFloat3(this); const XMVECTOR v2 = XMLoadFloat3(&vmin); const XMVECTOR v3 = XMLoadFloat3(&vmax); - const XMVECTOR X = XMVectorClamp(v1, v2, v3); + const XMVECTOR X = XMVectorClamp(v1, v2, v3); XMStoreFloat3(&result, X); } @@ -996,8 +992,8 @@ inline float Vector3::Distance(const Vector3& v1, const Vector3& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR V = XMVectorSubtract(x2, x1); - const XMVECTOR X = XMVector3Length(V); + const XMVECTOR V = XMVectorSubtract(x2, x1); + const XMVECTOR X = XMVector3Length(V); return XMVectorGetX(X); } @@ -1006,8 +1002,8 @@ inline float Vector3::DistanceSquared(const Vector3& v1, const Vector3& v2) noex using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR V = XMVectorSubtract(x2, x1); - const XMVECTOR X = XMVector3LengthSq(V); + const XMVECTOR V = XMVectorSubtract(x2, x1); + const XMVECTOR X = XMVector3LengthSq(V); return XMVectorGetX(X); } @@ -1016,7 +1012,7 @@ inline void Vector3::Min(const Vector3& v1, const Vector3& v2, Vector3& result) using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorMin(x1, x2); + const XMVECTOR X = XMVectorMin(x1, x2); XMStoreFloat3(&result, X); } @@ -1025,7 +1021,7 @@ inline Vector3 Vector3::Min(const Vector3& v1, const Vector3& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorMin(x1, x2); + const XMVECTOR X = XMVectorMin(x1, x2); Vector3 result; XMStoreFloat3(&result, X); @@ -1037,7 +1033,7 @@ inline void Vector3::Max(const Vector3& v1, const Vector3& v2, Vector3& result) using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorMax(x1, x2); + const XMVECTOR X = XMVectorMax(x1, x2); XMStoreFloat3(&result, X); } @@ -1046,7 +1042,7 @@ inline Vector3 Vector3::Max(const Vector3& v1, const Vector3& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorMax(x1, x2); + const XMVECTOR X = XMVectorMax(x1, x2); Vector3 result; XMStoreFloat3(&result, X); @@ -1058,7 +1054,7 @@ inline void Vector3::Lerp(const Vector3& v1, const Vector3& v2, float t, Vector3 using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); XMStoreFloat3(&result, X); } @@ -1067,7 +1063,7 @@ inline Vector3 Vector3::Lerp(const Vector3& v1, const Vector3& v2, float t) noex using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); Vector3 result; XMStoreFloat3(&result, X); @@ -1077,36 +1073,35 @@ inline Vector3 Vector3::Lerp(const Vector3& v1, const Vector3& v2, float t) noex inline void Vector3::SmoothStep(const Vector3& v1, const Vector3& v2, float t, Vector3& result) noexcept { using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t * t * (3.f - 2.f * t); + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t*(3.f - 2.f*t); const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); XMStoreFloat3(&result, X); } inline Vector3 Vector3::SmoothStep(const Vector3& v1, const Vector3& v2, float t) noexcept { using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t * t * (3.f - 2.f * t); + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t*(3.f - 2.f*t); const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); Vector3 result; XMStoreFloat3(&result, X); return result; } -inline void Vector3::Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, - Vector3& result) noexcept +inline void Vector3::Barycentric(const Vector3& v1, const Vector3& v2, const Vector3& v3, float f, float g, Vector3& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); const XMVECTOR x3 = XMLoadFloat3(&v3); - const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); XMStoreFloat3(&result, X); } @@ -1116,61 +1111,57 @@ inline Vector3 Vector3::Barycentric(const Vector3& v1, const Vector3& v2, const const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); const XMVECTOR x3 = XMLoadFloat3(&v3); - const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); Vector3 result; XMStoreFloat3(&result, X); return result; } -inline void Vector3::CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, - Vector3& result) noexcept +inline void Vector3::CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t, Vector3& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); const XMVECTOR x3 = XMLoadFloat3(&v3); const XMVECTOR x4 = XMLoadFloat3(&v4); - const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); XMStoreFloat3(&result, X); } -inline Vector3 Vector3::CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, - float t) noexcept +inline Vector3 Vector3::CatmullRom(const Vector3& v1, const Vector3& v2, const Vector3& v3, const Vector3& v4, float t) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&v2); const XMVECTOR x3 = XMLoadFloat3(&v3); const XMVECTOR x4 = XMLoadFloat3(&v4); - const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); Vector3 result; XMStoreFloat3(&result, X); return result; } -inline void Vector3::Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, - Vector3& result) noexcept +inline void Vector3::Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t, Vector3& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&t1); const XMVECTOR x3 = XMLoadFloat3(&v2); const XMVECTOR x4 = XMLoadFloat3(&t2); - const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); XMStoreFloat3(&result, X); } -inline Vector3 Vector3::Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, - float t) noexcept +inline Vector3 Vector3::Hermite(const Vector3& v1, const Vector3& t1, const Vector3& v2, const Vector3& t2, float t) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat3(&v1); const XMVECTOR x2 = XMLoadFloat3(&t1); const XMVECTOR x3 = XMLoadFloat3(&v2); const XMVECTOR x4 = XMLoadFloat3(&t2); - const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); Vector3 result; XMStoreFloat3(&result, X); @@ -1223,8 +1214,8 @@ inline void Vector3::Transform(const Vector3& v, const Quaternion& quat, Vector3 { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - const XMVECTOR X = XMVector3Rotate(v1, q); + const XMVECTOR q = XMLoadFloat4(&quat); + const XMVECTOR X = XMVector3Rotate(v1, q); XMStoreFloat3(&result, X); } @@ -1232,8 +1223,8 @@ inline Vector3 Vector3::Transform(const Vector3& v, const Quaternion& quat) noex { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - const XMVECTOR X = XMVector3Rotate(v1, q); + const XMVECTOR q = XMLoadFloat4(&quat); + const XMVECTOR X = XMVector3Rotate(v1, q); Vector3 result; XMStoreFloat3(&result, X); @@ -1244,8 +1235,8 @@ inline void Vector3::Transform(const Vector3& v, const Matrix& m, Vector3& resul { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector3TransformCoord(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector3TransformCoord(v1, M); XMStoreFloat3(&result, X); } @@ -1253,16 +1244,16 @@ inline Vector3 Vector3::Transform(const Vector3& v, const Matrix& m) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector3TransformCoord(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector3TransformCoord(v1, M); Vector3 result; XMStoreFloat3(&result, X); return result; } -_Use_decl_annotations_ inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, - Vector3* resultArray) noexcept +_Use_decl_annotations_ +inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray) noexcept { using namespace DirectX; const XMMATRIX M = XMLoadFloat4x4(&m); @@ -1273,13 +1264,13 @@ inline void Vector3::Transform(const Vector3& v, const Matrix& m, Vector4& resul { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector3Transform(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector3Transform(v1, M); XMStoreFloat4(&result, X); } -_Use_decl_annotations_ inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, - Vector4* resultArray) noexcept +_Use_decl_annotations_ +inline void Vector3::Transform(const Vector3* varray, size_t count, const Matrix& m, Vector4* resultArray) noexcept { using namespace DirectX; const XMMATRIX M = XMLoadFloat4x4(&m); @@ -1290,8 +1281,8 @@ inline void Vector3::TransformNormal(const Vector3& v, const Matrix& m, Vector3& { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector3TransformNormal(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector3TransformNormal(v1, M); XMStoreFloat3(&result, X); } @@ -1299,22 +1290,23 @@ inline Vector3 Vector3::TransformNormal(const Vector3& v, const Matrix& m) noexc { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector3TransformNormal(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector3TransformNormal(v1, M); Vector3 result; XMStoreFloat3(&result, X); return result; } -_Use_decl_annotations_ inline void Vector3::TransformNormal(const Vector3* varray, size_t count, const Matrix& m, - Vector3* resultArray) noexcept +_Use_decl_annotations_ +inline void Vector3::TransformNormal(const Vector3* varray, size_t count, const Matrix& m, Vector3* resultArray) noexcept { using namespace DirectX; const XMMATRIX M = XMLoadFloat4x4(&m); XMVector3TransformNormalStream(resultArray, sizeof(XMFLOAT3), varray, sizeof(XMFLOAT3), count, M); } + /**************************************************************************** * * Vector4 @@ -1325,7 +1317,7 @@ _Use_decl_annotations_ inline void Vector3::TransformNormal(const Vector3* varra // Comparision operators //------------------------------------------------------------------------------ -inline bool Vector4::operator==(const Vector4& V) const noexcept +inline bool Vector4::operator == (const Vector4& V) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); @@ -1333,7 +1325,7 @@ inline bool Vector4::operator==(const Vector4& V) const noexcept return XMVector4Equal(v1, v2); } -inline bool Vector4::operator!=(const Vector4& V) const noexcept +inline bool Vector4::operator != (const Vector4& V) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); @@ -1345,51 +1337,51 @@ inline bool Vector4::operator!=(const Vector4& V) const noexcept // Assignment operators //------------------------------------------------------------------------------ -inline Vector4& Vector4::operator+=(const Vector4& V) noexcept +inline Vector4& Vector4::operator+= (const Vector4& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); const XMVECTOR v2 = XMLoadFloat4(&V); - const XMVECTOR X = XMVectorAdd(v1, v2); + const XMVECTOR X = XMVectorAdd(v1, v2); XMStoreFloat4(this, X); return *this; } -inline Vector4& Vector4::operator-=(const Vector4& V) noexcept +inline Vector4& Vector4::operator-= (const Vector4& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); const XMVECTOR v2 = XMLoadFloat4(&V); - const XMVECTOR X = XMVectorSubtract(v1, v2); + const XMVECTOR X = XMVectorSubtract(v1, v2); XMStoreFloat4(this, X); return *this; } -inline Vector4& Vector4::operator*=(const Vector4& V) noexcept +inline Vector4& Vector4::operator*= (const Vector4& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); const XMVECTOR v2 = XMLoadFloat4(&V); - const XMVECTOR X = XMVectorMultiply(v1, v2); + const XMVECTOR X = XMVectorMultiply(v1, v2); XMStoreFloat4(this, X); return *this; } -inline Vector4& Vector4::operator*=(float S) noexcept +inline Vector4& Vector4::operator*= (float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); XMStoreFloat4(this, X); return *this; } -inline Vector4& Vector4::operator/=(float S) noexcept +inline Vector4& Vector4::operator/= (float S) noexcept { using namespace DirectX; assert(S != 0.0f); const XMVECTOR v1 = XMLoadFloat4(this); - const XMVECTOR X = XMVectorScale(v1, 1.f / S); + const XMVECTOR X = XMVectorScale(v1, 1.f / S); XMStoreFloat4(this, X); return *this; } @@ -1398,11 +1390,11 @@ inline Vector4& Vector4::operator/=(float S) noexcept // Urnary operators //------------------------------------------------------------------------------ -inline Vector4 Vector4::operator-() const noexcept +inline Vector4 Vector4::operator- () const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); - const XMVECTOR X = XMVectorNegate(v1); + const XMVECTOR X = XMVectorNegate(v1); Vector4 R; XMStoreFloat4(&R, X); return R; @@ -1412,75 +1404,75 @@ inline Vector4 Vector4::operator-() const noexcept // Binary operators //------------------------------------------------------------------------------ -inline Vector4 operator+(const Vector4& V1, const Vector4& V2) noexcept +inline Vector4 operator+ (const Vector4& V1, const Vector4& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&V1); const XMVECTOR v2 = XMLoadFloat4(&V2); - const XMVECTOR X = XMVectorAdd(v1, v2); + const XMVECTOR X = XMVectorAdd(v1, v2); Vector4 R; XMStoreFloat4(&R, X); return R; } -inline Vector4 operator-(const Vector4& V1, const Vector4& V2) noexcept +inline Vector4 operator- (const Vector4& V1, const Vector4& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&V1); const XMVECTOR v2 = XMLoadFloat4(&V2); - const XMVECTOR X = XMVectorSubtract(v1, v2); + const XMVECTOR X = XMVectorSubtract(v1, v2); Vector4 R; XMStoreFloat4(&R, X); return R; } -inline Vector4 operator*(const Vector4& V1, const Vector4& V2) noexcept +inline Vector4 operator* (const Vector4& V1, const Vector4& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&V1); const XMVECTOR v2 = XMLoadFloat4(&V2); - const XMVECTOR X = XMVectorMultiply(v1, v2); + const XMVECTOR X = XMVectorMultiply(v1, v2); Vector4 R; XMStoreFloat4(&R, X); return R; } -inline Vector4 operator*(const Vector4& V, float S) noexcept +inline Vector4 operator* (const Vector4& V, float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&V); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); Vector4 R; XMStoreFloat4(&R, X); return R; } -inline Vector4 operator/(const Vector4& V1, const Vector4& V2) noexcept +inline Vector4 operator/ (const Vector4& V1, const Vector4& V2) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&V1); const XMVECTOR v2 = XMLoadFloat4(&V2); - const XMVECTOR X = XMVectorDivide(v1, v2); + const XMVECTOR X = XMVectorDivide(v1, v2); Vector4 R; XMStoreFloat4(&R, X); return R; } -inline Vector4 operator/(const Vector4& V, float S) noexcept +inline Vector4 operator/ (const Vector4& V, float S) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&V); - const XMVECTOR X = XMVectorScale(v1, 1.f / S); + const XMVECTOR X = XMVectorScale(v1, 1.f / S); Vector4 R; XMStoreFloat4(&R, X); return R; } -inline Vector4 operator*(float S, const Vector4& V) noexcept +inline Vector4 operator* (float S, const Vector4& V) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&V); - const XMVECTOR X = XMVectorScale(v1, S); + const XMVECTOR X = XMVectorScale(v1, S); Vector4 R; XMStoreFloat4(&R, X); return R; @@ -1502,7 +1494,7 @@ inline float Vector4::Length() const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); - const XMVECTOR X = XMVector4Length(v1); + const XMVECTOR X = XMVector4Length(v1); return XMVectorGetX(X); } @@ -1510,7 +1502,7 @@ inline float Vector4::LengthSquared() const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); - const XMVECTOR X = XMVector4LengthSq(v1); + const XMVECTOR X = XMVector4LengthSq(v1); return XMVectorGetX(X); } @@ -1519,7 +1511,7 @@ inline float Vector4::Dot(const Vector4& V) const noexcept using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); const XMVECTOR v2 = XMLoadFloat4(&V); - const XMVECTOR X = XMVector4Dot(v1, v2); + const XMVECTOR X = XMVector4Dot(v1, v2); return XMVectorGetX(X); } @@ -1529,7 +1521,7 @@ inline void Vector4::Cross(const Vector4& v1, const Vector4& v2, Vector4& result const XMVECTOR x1 = XMLoadFloat4(this); const XMVECTOR x2 = XMLoadFloat4(&v1); const XMVECTOR x3 = XMLoadFloat4(&v2); - const XMVECTOR R = XMVector4Cross(x1, x2, x3); + const XMVECTOR R = XMVector4Cross(x1, x2, x3); XMStoreFloat4(&result, R); } @@ -1539,7 +1531,7 @@ inline Vector4 Vector4::Cross(const Vector4& v1, const Vector4& v2) const noexce const XMVECTOR x1 = XMLoadFloat4(this); const XMVECTOR x2 = XMLoadFloat4(&v1); const XMVECTOR x3 = XMLoadFloat4(&v2); - const XMVECTOR R = XMVector4Cross(x1, x2, x3); + const XMVECTOR R = XMVector4Cross(x1, x2, x3); Vector4 result; XMStoreFloat4(&result, R); @@ -1550,7 +1542,7 @@ inline void Vector4::Normalize() noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); - const XMVECTOR X = XMVector4Normalize(v1); + const XMVECTOR X = XMVector4Normalize(v1); XMStoreFloat4(this, X); } @@ -1558,7 +1550,7 @@ inline void Vector4::Normalize(Vector4& result) const noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(this); - const XMVECTOR X = XMVector4Normalize(v1); + const XMVECTOR X = XMVector4Normalize(v1); XMStoreFloat4(&result, X); } @@ -1568,7 +1560,7 @@ inline void Vector4::Clamp(const Vector4& vmin, const Vector4& vmax) noexcept const XMVECTOR v1 = XMLoadFloat4(this); const XMVECTOR v2 = XMLoadFloat4(&vmin); const XMVECTOR v3 = XMLoadFloat4(&vmax); - const XMVECTOR X = XMVectorClamp(v1, v2, v3); + const XMVECTOR X = XMVectorClamp(v1, v2, v3); XMStoreFloat4(this, X); } @@ -1578,7 +1570,7 @@ inline void Vector4::Clamp(const Vector4& vmin, const Vector4& vmax, Vector4& re const XMVECTOR v1 = XMLoadFloat4(this); const XMVECTOR v2 = XMLoadFloat4(&vmin); const XMVECTOR v3 = XMLoadFloat4(&vmax); - const XMVECTOR X = XMVectorClamp(v1, v2, v3); + const XMVECTOR X = XMVectorClamp(v1, v2, v3); XMStoreFloat4(&result, X); } @@ -1591,8 +1583,8 @@ inline float Vector4::Distance(const Vector4& v1, const Vector4& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR V = XMVectorSubtract(x2, x1); - const XMVECTOR X = XMVector4Length(V); + const XMVECTOR V = XMVectorSubtract(x2, x1); + const XMVECTOR X = XMVector4Length(V); return XMVectorGetX(X); } @@ -1601,8 +1593,8 @@ inline float Vector4::DistanceSquared(const Vector4& v1, const Vector4& v2) noex using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR V = XMVectorSubtract(x2, x1); - const XMVECTOR X = XMVector4LengthSq(V); + const XMVECTOR V = XMVectorSubtract(x2, x1); + const XMVECTOR X = XMVector4LengthSq(V); return XMVectorGetX(X); } @@ -1611,7 +1603,7 @@ inline void Vector4::Min(const Vector4& v1, const Vector4& v2, Vector4& result) using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorMin(x1, x2); + const XMVECTOR X = XMVectorMin(x1, x2); XMStoreFloat4(&result, X); } @@ -1620,7 +1612,7 @@ inline Vector4 Vector4::Min(const Vector4& v1, const Vector4& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorMin(x1, x2); + const XMVECTOR X = XMVectorMin(x1, x2); Vector4 result; XMStoreFloat4(&result, X); @@ -1632,7 +1624,7 @@ inline void Vector4::Max(const Vector4& v1, const Vector4& v2, Vector4& result) using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorMax(x1, x2); + const XMVECTOR X = XMVectorMax(x1, x2); XMStoreFloat4(&result, X); } @@ -1641,7 +1633,7 @@ inline Vector4 Vector4::Max(const Vector4& v1, const Vector4& v2) noexcept using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorMax(x1, x2); + const XMVECTOR X = XMVectorMax(x1, x2); Vector4 result; XMStoreFloat4(&result, X); @@ -1653,7 +1645,7 @@ inline void Vector4::Lerp(const Vector4& v1, const Vector4& v2, float t, Vector4 using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); XMStoreFloat4(&result, X); } @@ -1662,7 +1654,7 @@ inline Vector4 Vector4::Lerp(const Vector4& v1, const Vector4& v2, float t) noex using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); Vector4 result; XMStoreFloat4(&result, X); @@ -1672,36 +1664,35 @@ inline Vector4 Vector4::Lerp(const Vector4& v1, const Vector4& v2, float t) noex inline void Vector4::SmoothStep(const Vector4& v1, const Vector4& v2, float t, Vector4& result) noexcept { using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t * t * (3.f - 2.f * t); + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t*(3.f - 2.f*t); const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); XMStoreFloat4(&result, X); } inline Vector4 Vector4::SmoothStep(const Vector4& v1, const Vector4& v2, float t) noexcept { using namespace DirectX; - t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 - t = t * t * (3.f - 2.f * t); + t = (t > 1.0f) ? 1.0f : ((t < 0.0f) ? 0.0f : t); // Clamp value to 0 to 1 + t = t * t*(3.f - 2.f*t); const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); - const XMVECTOR X = XMVectorLerp(x1, x2, t); + const XMVECTOR X = XMVectorLerp(x1, x2, t); Vector4 result; XMStoreFloat4(&result, X); return result; } -inline void Vector4::Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, - Vector4& result) noexcept +inline void Vector4::Barycentric(const Vector4& v1, const Vector4& v2, const Vector4& v3, float f, float g, Vector4& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); const XMVECTOR x3 = XMLoadFloat4(&v3); - const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); XMStoreFloat4(&result, X); } @@ -1711,61 +1702,57 @@ inline Vector4 Vector4::Barycentric(const Vector4& v1, const Vector4& v2, const const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); const XMVECTOR x3 = XMLoadFloat4(&v3); - const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); + const XMVECTOR X = XMVectorBaryCentric(x1, x2, x3, f, g); Vector4 result; XMStoreFloat4(&result, X); return result; } -inline void Vector4::CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, - Vector4& result) noexcept +inline void Vector4::CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t, Vector4& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); const XMVECTOR x3 = XMLoadFloat4(&v3); const XMVECTOR x4 = XMLoadFloat4(&v4); - const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); XMStoreFloat4(&result, X); } -inline Vector4 Vector4::CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, - float t) noexcept +inline Vector4 Vector4::CatmullRom(const Vector4& v1, const Vector4& v2, const Vector4& v3, const Vector4& v4, float t) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&v2); const XMVECTOR x3 = XMLoadFloat4(&v3); const XMVECTOR x4 = XMLoadFloat4(&v4); - const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorCatmullRom(x1, x2, x3, x4, t); Vector4 result; XMStoreFloat4(&result, X); return result; } -inline void Vector4::Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, - Vector4& result) noexcept +inline void Vector4::Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t, Vector4& result) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&t1); const XMVECTOR x3 = XMLoadFloat4(&v2); const XMVECTOR x4 = XMLoadFloat4(&t2); - const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); XMStoreFloat4(&result, X); } -inline Vector4 Vector4::Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, - float t) noexcept +inline Vector4 Vector4::Hermite(const Vector4& v1, const Vector4& t1, const Vector4& v2, const Vector4& t2, float t) noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(&v1); const XMVECTOR x2 = XMLoadFloat4(&t1); const XMVECTOR x3 = XMLoadFloat4(&v2); const XMVECTOR x4 = XMLoadFloat4(&t2); - const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); + const XMVECTOR X = XMVectorHermite(x1, x2, x3, x4, t); Vector4 result; XMStoreFloat4(&result, X); @@ -1818,9 +1805,9 @@ inline void Vector4::Transform(const Vector2& v, const Quaternion& quat, Vector4 { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - XMVECTOR X = XMVector3Rotate(v1, q); - X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f + const XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f XMStoreFloat4(&result, X); } @@ -1828,9 +1815,9 @@ inline Vector4 Vector4::Transform(const Vector2& v, const Quaternion& quat) noex { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat2(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - XMVECTOR X = XMVector3Rotate(v1, q); - X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f + const XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f Vector4 result; XMStoreFloat4(&result, X); @@ -1841,9 +1828,9 @@ inline void Vector4::Transform(const Vector3& v, const Quaternion& quat, Vector4 { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - XMVECTOR X = XMVector3Rotate(v1, q); - X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f + const XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f XMStoreFloat4(&result, X); } @@ -1851,9 +1838,9 @@ inline Vector4 Vector4::Transform(const Vector3& v, const Quaternion& quat) noex { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat3(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - XMVECTOR X = XMVector3Rotate(v1, q); - X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f + const XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(g_XMIdentityR3, X, g_XMSelect1110); // result.w = 1.f Vector4 result; XMStoreFloat4(&result, X); @@ -1864,9 +1851,9 @@ inline void Vector4::Transform(const Vector4& v, const Quaternion& quat, Vector4 { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - XMVECTOR X = XMVector3Rotate(v1, q); - X = XMVectorSelect(v1, X, g_XMSelect1110); // result.w = v.w + const XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(v1, X, g_XMSelect1110); // result.w = v.w XMStoreFloat4(&result, X); } @@ -1874,9 +1861,9 @@ inline Vector4 Vector4::Transform(const Vector4& v, const Quaternion& quat) noex { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&v); - const XMVECTOR q = XMLoadFloat4(&quat); - XMVECTOR X = XMVector3Rotate(v1, q); - X = XMVectorSelect(v1, X, g_XMSelect1110); // result.w = v.w + const XMVECTOR q = XMLoadFloat4(&quat); + XMVECTOR X = XMVector3Rotate(v1, q); + X = XMVectorSelect(v1, X, g_XMSelect1110); // result.w = v.w Vector4 result; XMStoreFloat4(&result, X); @@ -1887,8 +1874,8 @@ inline void Vector4::Transform(const Vector4& v, const Matrix& m, Vector4& resul { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector4Transform(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector4Transform(v1, M); XMStoreFloat4(&result, X); } @@ -1896,22 +1883,23 @@ inline Vector4 Vector4::Transform(const Vector4& v, const Matrix& m) noexcept { using namespace DirectX; const XMVECTOR v1 = XMLoadFloat4(&v); - const XMMATRIX M = XMLoadFloat4x4(&m); - const XMVECTOR X = XMVector4Transform(v1, M); + const XMMATRIX M = XMLoadFloat4x4(&m); + const XMVECTOR X = XMVector4Transform(v1, M); Vector4 result; XMStoreFloat4(&result, X); return result; } -_Use_decl_annotations_ inline void Vector4::Transform(const Vector4* varray, size_t count, const Matrix& m, - Vector4* resultArray) noexcept +_Use_decl_annotations_ +inline void Vector4::Transform(const Vector4* varray, size_t count, const Matrix& m, Vector4* resultArray) noexcept { using namespace DirectX; const XMMATRIX M = XMLoadFloat4x4(&m); XMVector4TransformStream(resultArray, sizeof(XMFLOAT4), varray, sizeof(XMFLOAT4), count, M); } + /**************************************************************************** * * Matrix @@ -1922,7 +1910,7 @@ _Use_decl_annotations_ inline void Vector4::Transform(const Vector4* varray, siz // Comparision operators //------------------------------------------------------------------------------ -inline bool Matrix::operator==(const Matrix& M) const noexcept +inline bool Matrix::operator == (const Matrix& M) const noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); @@ -1935,10 +1923,13 @@ inline bool Matrix::operator==(const Matrix& M) const noexcept const XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M._31)); const XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M._41)); - return (XMVector4Equal(x1, y1) && XMVector4Equal(x2, y2) && XMVector4Equal(x3, y3) && XMVector4Equal(x4, y4)) != 0; + return (XMVector4Equal(x1, y1) + && XMVector4Equal(x2, y2) + && XMVector4Equal(x3, y3) + && XMVector4Equal(x4, y4)) != 0; } -inline bool Matrix::operator!=(const Matrix& M) const noexcept +inline bool Matrix::operator != (const Matrix& M) const noexcept { using namespace DirectX; const XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); @@ -1951,8 +1942,10 @@ inline bool Matrix::operator!=(const Matrix& M) const noexcept const XMVECTOR y3 = XMLoadFloat4(reinterpret_cast(&M._31)); const XMVECTOR y4 = XMLoadFloat4(reinterpret_cast(&M._41)); - return (XMVector4NotEqual(x1, y1) || XMVector4NotEqual(x2, y2) || XMVector4NotEqual(x3, y3) || - XMVector4NotEqual(x4, y4)) != 0; + return (XMVector4NotEqual(x1, y1) + || XMVector4NotEqual(x2, y2) + || XMVector4NotEqual(x3, y3) + || XMVector4NotEqual(x4, y4)) != 0; } //------------------------------------------------------------------------------ @@ -1961,87 +1954,39 @@ inline bool Matrix::operator!=(const Matrix& M) const noexcept inline Matrix::Matrix(const XMFLOAT3X3& M) noexcept { - _11 = M._11; - _12 = M._12; - _13 = M._13; - _14 = 0.f; - _21 = M._21; - _22 = M._22; - _23 = M._23; - _24 = 0.f; - _31 = M._31; - _32 = M._32; - _33 = M._33; - _34 = 0.f; - _41 = 0.f; - _42 = 0.f; - _43 = 0.f; - _44 = 1.f; + _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; + _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; + _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; + _41 = 0.f; _42 = 0.f; _43 = 0.f; _44 = 1.f; } inline Matrix::Matrix(const XMFLOAT4X3& M) noexcept { - _11 = M._11; - _12 = M._12; - _13 = M._13; - _14 = 0.f; - _21 = M._21; - _22 = M._22; - _23 = M._23; - _24 = 0.f; - _31 = M._31; - _32 = M._32; - _33 = M._33; - _34 = 0.f; - _41 = M._41; - _42 = M._42; - _43 = M._43; - _44 = 1.f; -} - -inline Matrix& Matrix::operator=(const XMFLOAT3X3& M) noexcept -{ - _11 = M._11; - _12 = M._12; - _13 = M._13; - _14 = 0.f; - _21 = M._21; - _22 = M._22; - _23 = M._23; - _24 = 0.f; - _31 = M._31; - _32 = M._32; - _33 = M._33; - _34 = 0.f; - _41 = 0.f; - _42 = 0.f; - _43 = 0.f; - _44 = 1.f; + _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; + _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; + _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; + _41 = M._41; _42 = M._42; _43 = M._43; _44 = 1.f; +} + +inline Matrix& Matrix::operator= (const XMFLOAT3X3& M) noexcept +{ + _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; + _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; + _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; + _41 = 0.f; _42 = 0.f; _43 = 0.f; _44 = 1.f; return *this; } -inline Matrix& Matrix::operator=(const XMFLOAT4X3& M) noexcept -{ - _11 = M._11; - _12 = M._12; - _13 = M._13; - _14 = 0.f; - _21 = M._21; - _22 = M._22; - _23 = M._23; - _24 = 0.f; - _31 = M._31; - _32 = M._32; - _33 = M._33; - _34 = 0.f; - _41 = M._41; - _42 = M._42; - _43 = M._43; - _44 = 1.f; +inline Matrix& Matrix::operator= (const XMFLOAT4X3& M) noexcept +{ + _11 = M._11; _12 = M._12; _13 = M._13; _14 = 0.f; + _21 = M._21; _22 = M._22; _23 = M._23; _24 = 0.f; + _31 = M._31; _32 = M._32; _33 = M._33; _34 = 0.f; + _41 = M._41; _42 = M._42; _43 = M._43; _44 = 1.f; return *this; } -inline Matrix& Matrix::operator+=(const Matrix& M) noexcept +inline Matrix& Matrix::operator+= (const Matrix& M) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); @@ -2066,7 +2011,7 @@ inline Matrix& Matrix::operator+=(const Matrix& M) noexcept return *this; } -inline Matrix& Matrix::operator-=(const Matrix& M) noexcept +inline Matrix& Matrix::operator-= (const Matrix& M) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); @@ -2091,17 +2036,17 @@ inline Matrix& Matrix::operator-=(const Matrix& M) noexcept return *this; } -inline Matrix& Matrix::operator*=(const Matrix& M) noexcept +inline Matrix& Matrix::operator*= (const Matrix& M) noexcept { using namespace DirectX; const XMMATRIX M1 = XMLoadFloat4x4(this); const XMMATRIX M2 = XMLoadFloat4x4(&M); - const XMMATRIX X = XMMatrixMultiply(M1, M2); + const XMMATRIX X = XMMatrixMultiply(M1, M2); XMStoreFloat4x4(this, X); return *this; } -inline Matrix& Matrix::operator*=(float S) noexcept +inline Matrix& Matrix::operator*= (float S) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); @@ -2121,7 +2066,7 @@ inline Matrix& Matrix::operator*=(float S) noexcept return *this; } -inline Matrix& Matrix::operator/=(float S) noexcept +inline Matrix& Matrix::operator/= (float S) noexcept { using namespace DirectX; assert(S != 0.f); @@ -2144,7 +2089,7 @@ inline Matrix& Matrix::operator/=(float S) noexcept return *this; } -inline Matrix& Matrix::operator/=(const Matrix& M) noexcept +inline Matrix& Matrix::operator/= (const Matrix& M) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&_11)); @@ -2173,7 +2118,7 @@ inline Matrix& Matrix::operator/=(const Matrix& M) noexcept // Urnary operators //------------------------------------------------------------------------------ -inline Matrix Matrix::operator-() const noexcept +inline Matrix Matrix::operator- () const noexcept { using namespace DirectX; XMVECTOR v1 = XMLoadFloat4(reinterpret_cast(&_11)); @@ -2198,7 +2143,7 @@ inline Matrix Matrix::operator-() const noexcept // Binary operators //------------------------------------------------------------------------------ -inline Matrix operator+(const Matrix& M1, const Matrix& M2) noexcept +inline Matrix operator+ (const Matrix& M1, const Matrix& M2) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); @@ -2224,7 +2169,7 @@ inline Matrix operator+(const Matrix& M1, const Matrix& M2) noexcept return R; } -inline Matrix operator-(const Matrix& M1, const Matrix& M2) noexcept +inline Matrix operator- (const Matrix& M1, const Matrix& M2) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); @@ -2250,19 +2195,19 @@ inline Matrix operator-(const Matrix& M1, const Matrix& M2) noexcept return R; } -inline Matrix operator*(const Matrix& M1, const Matrix& M2) noexcept +inline Matrix operator* (const Matrix& M1, const Matrix& M2) noexcept { using namespace DirectX; const XMMATRIX m1 = XMLoadFloat4x4(&M1); const XMMATRIX m2 = XMLoadFloat4x4(&M2); - const XMMATRIX X = XMMatrixMultiply(m1, m2); + const XMMATRIX X = XMMatrixMultiply(m1, m2); Matrix R; XMStoreFloat4x4(&R, X); return R; } -inline Matrix operator*(const Matrix& M, float S) noexcept +inline Matrix operator* (const Matrix& M, float S) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M._11)); @@ -2283,7 +2228,7 @@ inline Matrix operator*(const Matrix& M, float S) noexcept return R; } -inline Matrix operator/(const Matrix& M, float S) noexcept +inline Matrix operator/ (const Matrix& M, float S) noexcept { using namespace DirectX; assert(S != 0.f); @@ -2308,7 +2253,7 @@ inline Matrix operator/(const Matrix& M, float S) noexcept return R; } -inline Matrix operator/(const Matrix& M1, const Matrix& M2) noexcept +inline Matrix operator/ (const Matrix& M1, const Matrix& M2) noexcept { using namespace DirectX; XMVECTOR x1 = XMLoadFloat4(reinterpret_cast(&M1._11)); @@ -2334,7 +2279,7 @@ inline Matrix operator/(const Matrix& M1, const Matrix& M2) noexcept return R; } -inline Matrix operator*(float S, const Matrix& M) noexcept +inline Matrix operator* (float S, const Matrix& M) noexcept { using namespace DirectX; @@ -2435,14 +2380,17 @@ inline Vector3 Matrix::ToEuler() const noexcept // Static functions //------------------------------------------------------------------------------ -_Use_decl_annotations_ inline Matrix Matrix::CreateBillboard(const Vector3& object, const Vector3& cameraPosition, - const Vector3& cameraUp, - const Vector3* cameraForward) noexcept +_Use_decl_annotations_ +inline Matrix Matrix::CreateBillboard( + const Vector3& object, + const Vector3& cameraPosition, + const Vector3& cameraUp, + const Vector3* cameraForward) noexcept { using namespace DirectX; const XMVECTOR O = XMLoadFloat3(&object); const XMVECTOR C = XMLoadFloat3(&cameraPosition); - XMVECTOR Z = XMVectorSubtract(O, C); + XMVECTOR Z = XMVectorSubtract(O, C); const XMVECTOR N = XMVector3LengthSq(Z); if (XMVector3Less(N, g_XMEpsilon)) @@ -2450,7 +2398,7 @@ _Use_decl_annotations_ inline Matrix Matrix::CreateBillboard(const Vector3& obje if (cameraForward) { const XMVECTOR F = XMLoadFloat3(cameraForward); - Z = XMVectorNegate(F); + Z = XMVectorNegate(F); } else Z = g_XMNegIdentityR2; @@ -2461,8 +2409,8 @@ _Use_decl_annotations_ inline Matrix Matrix::CreateBillboard(const Vector3& obje } const XMVECTOR up = XMLoadFloat3(&cameraUp); - XMVECTOR X = XMVector3Cross(up, Z); - X = XMVector3Normalize(X); + XMVECTOR X = XMVector3Cross(up, Z); + X = XMVector3Normalize(X); const XMVECTOR Y = XMVector3Cross(Z, X); @@ -2477,16 +2425,17 @@ _Use_decl_annotations_ inline Matrix Matrix::CreateBillboard(const Vector3& obje return R; } -_Use_decl_annotations_ inline Matrix Matrix::CreateConstrainedBillboard(const Vector3& object, - const Vector3& cameraPosition, - const Vector3& rotateAxis, - const Vector3* cameraForward, - const Vector3* objectForward) noexcept +_Use_decl_annotations_ +inline Matrix Matrix::CreateConstrainedBillboard( + const Vector3& object, + const Vector3& cameraPosition, + const Vector3& rotateAxis, + const Vector3* cameraForward, + const Vector3* objectForward) noexcept { using namespace DirectX; - static const XMVECTORF32 s_minAngle = { { { 0.99825467075f, 0.99825467075f, 0.99825467075f, - 0.99825467075f } } }; // 1.0 - XMConvertToRadians( 0.1f ); + static const XMVECTORF32 s_minAngle = { { { 0.99825467075f, 0.99825467075f, 0.99825467075f, 0.99825467075f } } }; // 1.0 - XMConvertToRadians( 0.1f ); const XMVECTOR O = XMLoadFloat3(&object); const XMVECTOR C = XMLoadFloat3(&cameraPosition); @@ -2498,7 +2447,7 @@ _Use_decl_annotations_ inline Matrix Matrix::CreateConstrainedBillboard(const Ve if (cameraForward) { const XMVECTOR F = XMLoadFloat3(cameraForward); - faceDir = XMVectorNegate(F); + faceDir = XMVectorNegate(F); } else faceDir = g_XMNegIdentityR2; @@ -2516,18 +2465,18 @@ _Use_decl_annotations_ inline Matrix Matrix::CreateConstrainedBillboard(const Ve { if (objectForward) { - Z = XMLoadFloat3(objectForward); + Z = XMLoadFloat3(objectForward); dot = XMVectorAbs(XMVector3Dot(Y, Z)); if (XMVector3Greater(dot, s_minAngle)) { dot = XMVectorAbs(XMVector3Dot(Y, g_XMNegIdentityR2)); - Z = (XMVector3Greater(dot, s_minAngle)) ? g_XMIdentityR0 : g_XMNegIdentityR2; + Z = (XMVector3Greater(dot, s_minAngle)) ? g_XMIdentityR0 : g_XMNegIdentityR2; } } else { dot = XMVectorAbs(XMVector3Dot(Y, g_XMNegIdentityR2)); - Z = (XMVector3Greater(dot, s_minAngle)) ? g_XMIdentityR0 : g_XMNegIdentityR2; + Z = (XMVector3Greater(dot, s_minAngle)) ? g_XMIdentityR0 : g_XMNegIdentityR2; } X = XMVector3Cross(Y, Z); @@ -2629,8 +2578,7 @@ inline Matrix Matrix::CreateFromAxisAngle(const Vector3& axis, float angle) noex return R; } -inline Matrix Matrix::CreatePerspectiveFieldOfView(float fov, float aspectRatio, float nearPlane, - float farPlane) noexcept +inline Matrix Matrix::CreatePerspectiveFieldOfView(float fov, float aspectRatio, float nearPlane, float farPlane) noexcept { using namespace DirectX; Matrix R; @@ -2646,8 +2594,7 @@ inline Matrix Matrix::CreatePerspective(float width, float height, float nearPla return R; } -inline Matrix Matrix::CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, - float farPlane) noexcept +inline Matrix Matrix::CreatePerspectiveOffCenter(float left, float right, float bottom, float top, float nearPlane, float farPlane) noexcept { using namespace DirectX; Matrix R; @@ -2663,8 +2610,7 @@ inline Matrix Matrix::CreateOrthographic(float width, float height, float zNearP return R; } -inline Matrix Matrix::CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, - float zFarPlane) noexcept +inline Matrix Matrix::CreateOrthographicOffCenter(float left, float right, float bottom, float top, float zNearPlane, float zFarPlane) noexcept { using namespace DirectX; Matrix R; @@ -2676,9 +2622,9 @@ inline Matrix Matrix::CreateLookAt(const Vector3& eye, const Vector3& target, co { using namespace DirectX; Matrix R; - const XMVECTOR eyev = XMLoadFloat3(&eye); + const XMVECTOR eyev = XMLoadFloat3(&eye); const XMVECTOR targetv = XMLoadFloat3(&target); - const XMVECTOR upv = XMLoadFloat3(&up); + const XMVECTOR upv = XMLoadFloat3(&up); XMStoreFloat4x4(&R, XMMatrixLookAtRH(eyev, targetv, upv)); return R; } @@ -2687,19 +2633,17 @@ inline Matrix Matrix::CreateWorld(const Vector3& position, const Vector3& forwar { using namespace DirectX; const XMVECTOR zaxis = XMVector3Normalize(XMVectorNegate(XMLoadFloat3(&forward))); - XMVECTOR yaxis = XMLoadFloat3(&up); + XMVECTOR yaxis = XMLoadFloat3(&up); const XMVECTOR xaxis = XMVector3Normalize(XMVector3Cross(yaxis, zaxis)); - yaxis = XMVector3Cross(zaxis, xaxis); + yaxis = XMVector3Cross(zaxis, xaxis); Matrix R; XMStoreFloat3(reinterpret_cast(&R._11), xaxis); XMStoreFloat3(reinterpret_cast(&R._21), yaxis); XMStoreFloat3(reinterpret_cast(&R._31), zaxis); R._14 = R._24 = R._34 = 0.f; - R._41 = position.x; - R._42 = position.y; - R._43 = position.z; - R._44 = 1.f; + R._41 = position.x; R._42 = position.y; R._43 = position.z; + R._44 = 1.f; return R; } @@ -2731,7 +2675,7 @@ inline Matrix Matrix::CreateFromYawPitchRoll(const Vector3& angles) noexcept inline Matrix Matrix::CreateShadow(const Vector3& lightDir, const Plane& plane) noexcept { using namespace DirectX; - const XMVECTOR light = XMLoadFloat3(&lightDir); + const XMVECTOR light = XMLoadFloat3(&lightDir); const XMVECTOR planev = XMLoadFloat4(&plane); Matrix R; XMStoreFloat4x4(&R, XMMatrixShadow(planev, light)); @@ -2821,6 +2765,7 @@ inline Matrix Matrix::Transform(const Matrix& M, const Quaternion& rotation) noe return result; } + /**************************************************************************** * * Plane @@ -2848,7 +2793,7 @@ inline Plane::Plane(const Vector3& point, const Vector3& normal) noexcept // Comparision operators //------------------------------------------------------------------------------ -inline bool Plane::operator==(const Plane& p) const noexcept +inline bool Plane::operator == (const Plane& p) const noexcept { using namespace DirectX; const XMVECTOR p1 = XMLoadFloat4(this); @@ -2856,7 +2801,7 @@ inline bool Plane::operator==(const Plane& p) const noexcept return XMPlaneEqual(p1, p2); } -inline bool Plane::operator!=(const Plane& p) const noexcept +inline bool Plane::operator != (const Plane& p) const noexcept { using namespace DirectX; const XMVECTOR p1 = XMLoadFloat4(this); @@ -2885,7 +2830,7 @@ inline void Plane::Normalize(Plane& result) const noexcept inline float Plane::Dot(const Vector4& v) const noexcept { using namespace DirectX; - const XMVECTOR p = XMLoadFloat4(this); + const XMVECTOR p = XMLoadFloat4(this); const XMVECTOR v0 = XMLoadFloat4(&v); return XMVectorGetX(XMPlaneDot(p, v0)); } @@ -2893,7 +2838,7 @@ inline float Plane::Dot(const Vector4& v) const noexcept inline float Plane::DotCoordinate(const Vector3& position) const noexcept { using namespace DirectX; - const XMVECTOR p = XMLoadFloat4(this); + const XMVECTOR p = XMLoadFloat4(this); const XMVECTOR v0 = XMLoadFloat3(&position); return XMVectorGetX(XMPlaneDotCoord(p, v0)); } @@ -2901,7 +2846,7 @@ inline float Plane::DotCoordinate(const Vector3& position) const noexcept inline float Plane::DotNormal(const Vector3& normal) const noexcept { using namespace DirectX; - const XMVECTOR p = XMLoadFloat4(this); + const XMVECTOR p = XMLoadFloat4(this); const XMVECTOR n0 = XMLoadFloat3(&normal); return XMVectorGetX(XMPlaneDotNormal(p, n0)); } @@ -2913,7 +2858,7 @@ inline float Plane::DotNormal(const Vector3& normal) const noexcept inline void Plane::Transform(const Plane& plane, const Matrix& M, Plane& result) noexcept { using namespace DirectX; - const XMVECTOR p = XMLoadFloat4(&plane); + const XMVECTOR p = XMLoadFloat4(&plane); const XMMATRIX m0 = XMLoadFloat4x4(&M); XMStoreFloat4(&result, XMPlaneTransform(p, m0)); } @@ -2921,7 +2866,7 @@ inline void Plane::Transform(const Plane& plane, const Matrix& M, Plane& result) inline Plane Plane::Transform(const Plane& plane, const Matrix& M) noexcept { using namespace DirectX; - const XMVECTOR p = XMLoadFloat4(&plane); + const XMVECTOR p = XMLoadFloat4(&plane); const XMMATRIX m0 = XMLoadFloat4x4(&M); Plane result; @@ -2934,8 +2879,8 @@ inline void Plane::Transform(const Plane& plane, const Quaternion& rotation, Pla using namespace DirectX; const XMVECTOR p = XMLoadFloat4(&plane); const XMVECTOR q = XMLoadFloat4(&rotation); - XMVECTOR X = XMVector3Rotate(p, q); - X = XMVectorSelect(p, X, g_XMSelect1110); // result.d = plane.d + XMVECTOR X = XMVector3Rotate(p, q); + X = XMVectorSelect(p, X, g_XMSelect1110); // result.d = plane.d XMStoreFloat4(&result, X); } @@ -2944,14 +2889,15 @@ inline Plane Plane::Transform(const Plane& plane, const Quaternion& rotation) no using namespace DirectX; const XMVECTOR p = XMLoadFloat4(&plane); const XMVECTOR q = XMLoadFloat4(&rotation); - XMVECTOR X = XMVector3Rotate(p, q); - X = XMVectorSelect(p, X, g_XMSelect1110); // result.d = plane.d + XMVECTOR X = XMVector3Rotate(p, q); + X = XMVectorSelect(p, X, g_XMSelect1110); // result.d = plane.d Plane result; XMStoreFloat4(&result, X); return result; } + /**************************************************************************** * * Quaternion @@ -2962,7 +2908,7 @@ inline Plane Plane::Transform(const Plane& plane, const Quaternion& rotation) no // Comparision operators //------------------------------------------------------------------------------ -inline bool Quaternion::operator==(const Quaternion& q) const noexcept +inline bool Quaternion::operator == (const Quaternion& q) const noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(this); @@ -2970,7 +2916,7 @@ inline bool Quaternion::operator==(const Quaternion& q) const noexcept return XMQuaternionEqual(q1, q2); } -inline bool Quaternion::operator!=(const Quaternion& q) const noexcept +inline bool Quaternion::operator != (const Quaternion& q) const noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(this); @@ -2982,7 +2928,7 @@ inline bool Quaternion::operator!=(const Quaternion& q) const noexcept // Assignment operators //------------------------------------------------------------------------------ -inline Quaternion& Quaternion::operator+=(const Quaternion& q) noexcept +inline Quaternion& Quaternion::operator+= (const Quaternion& q) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(this); @@ -2991,7 +2937,7 @@ inline Quaternion& Quaternion::operator+=(const Quaternion& q) noexcept return *this; } -inline Quaternion& Quaternion::operator-=(const Quaternion& q) noexcept +inline Quaternion& Quaternion::operator-= (const Quaternion& q) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(this); @@ -3000,7 +2946,7 @@ inline Quaternion& Quaternion::operator-=(const Quaternion& q) noexcept return *this; } -inline Quaternion& Quaternion::operator*=(const Quaternion& q) noexcept +inline Quaternion& Quaternion::operator*= (const Quaternion& q) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(this); @@ -3009,7 +2955,7 @@ inline Quaternion& Quaternion::operator*=(const Quaternion& q) noexcept return *this; } -inline Quaternion& Quaternion::operator*=(float S) noexcept +inline Quaternion& Quaternion::operator*= (float S) noexcept { using namespace DirectX; const XMVECTOR q = XMLoadFloat4(this); @@ -3017,12 +2963,12 @@ inline Quaternion& Quaternion::operator*=(float S) noexcept return *this; } -inline Quaternion& Quaternion::operator/=(const Quaternion& q) noexcept +inline Quaternion& Quaternion::operator/= (const Quaternion& q) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(this); - XMVECTOR q2 = XMLoadFloat4(&q); - q2 = XMQuaternionInverse(q2); + XMVECTOR q2 = XMLoadFloat4(&q); + q2 = XMQuaternionInverse(q2); XMStoreFloat4(this, XMQuaternionMultiply(q1, q2)); return *this; } @@ -3031,7 +2977,7 @@ inline Quaternion& Quaternion::operator/=(const Quaternion& q) noexcept // Urnary operators //------------------------------------------------------------------------------ -inline Quaternion Quaternion::operator-() const noexcept +inline Quaternion Quaternion::operator- () const noexcept { using namespace DirectX; const XMVECTOR q = XMLoadFloat4(this); @@ -3045,7 +2991,7 @@ inline Quaternion Quaternion::operator-() const noexcept // Binary operators //------------------------------------------------------------------------------ -inline Quaternion operator+(const Quaternion& Q1, const Quaternion& Q2) noexcept +inline Quaternion operator+ (const Quaternion& Q1, const Quaternion& Q2) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(&Q1); @@ -3056,7 +3002,7 @@ inline Quaternion operator+(const Quaternion& Q1, const Quaternion& Q2) noexcept return R; } -inline Quaternion operator-(const Quaternion& Q1, const Quaternion& Q2) noexcept +inline Quaternion operator- (const Quaternion& Q1, const Quaternion& Q2) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(&Q1); @@ -3067,7 +3013,7 @@ inline Quaternion operator-(const Quaternion& Q1, const Quaternion& Q2) noexcept return R; } -inline Quaternion operator*(const Quaternion& Q1, const Quaternion& Q2) noexcept +inline Quaternion operator* (const Quaternion& Q1, const Quaternion& Q2) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(&Q1); @@ -3078,7 +3024,7 @@ inline Quaternion operator*(const Quaternion& Q1, const Quaternion& Q2) noexcept return R; } -inline Quaternion operator*(const Quaternion& Q, float S) noexcept +inline Quaternion operator* (const Quaternion& Q, float S) noexcept { using namespace DirectX; const XMVECTOR q = XMLoadFloat4(&Q); @@ -3088,19 +3034,19 @@ inline Quaternion operator*(const Quaternion& Q, float S) noexcept return R; } -inline Quaternion operator/(const Quaternion& Q1, const Quaternion& Q2) noexcept +inline Quaternion operator/ (const Quaternion& Q1, const Quaternion& Q2) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(&Q1); - XMVECTOR q2 = XMLoadFloat4(&Q2); - q2 = XMQuaternionInverse(q2); + XMVECTOR q2 = XMLoadFloat4(&Q2); + q2 = XMQuaternionInverse(q2); Quaternion R; XMStoreFloat4(&R, XMQuaternionMultiply(q1, q2)); return R; } -inline Quaternion operator*(float S, const Quaternion& Q) noexcept +inline Quaternion operator* (float S, const Quaternion& Q) noexcept { using namespace DirectX; const XMVECTOR q1 = XMLoadFloat4(&Q); @@ -3259,11 +3205,11 @@ inline void Quaternion::Lerp(const Quaternion& q1, const Quaternion& q2, float t } else { - const XMVECTOR tv = XMVectorReplicate(t); + const XMVECTOR tv = XMVectorReplicate(t); const XMVECTOR t1v = XMVectorReplicate(1.f - t); - const XMVECTOR X0 = XMVectorMultiply(Q0, t1v); - const XMVECTOR X1 = XMVectorMultiply(Q1, tv); - R = XMVectorSubtract(X0, X1); + const XMVECTOR X0 = XMVectorMultiply(Q0, t1v); + const XMVECTOR X1 = XMVectorMultiply(Q1, tv); + R = XMVectorSubtract(X0, X1); } XMStoreFloat4(&result, XMQuaternionNormalize(R)); @@ -3284,11 +3230,11 @@ inline Quaternion Quaternion::Lerp(const Quaternion& q1, const Quaternion& q2, f } else { - const XMVECTOR tv = XMVectorReplicate(t); + const XMVECTOR tv = XMVectorReplicate(t); const XMVECTOR t1v = XMVectorReplicate(1.f - t); - const XMVECTOR X0 = XMVectorMultiply(Q0, t1v); - const XMVECTOR X1 = XMVectorMultiply(Q1, tv); - R = XMVectorSubtract(X0, X1); + const XMVECTOR X0 = XMVectorMultiply(Q0, t1v); + const XMVECTOR X1 = XMVectorMultiply(Q1, tv); + R = XMVectorSubtract(X0, X1); } Quaternion result; @@ -3354,15 +3300,15 @@ inline float Quaternion::Angle(const Quaternion& q1, const Quaternion& q2) noexc const XMVECTOR Q0 = XMLoadFloat4(&q1); const XMVECTOR Q1 = XMLoadFloat4(&q2); - // We can use the conjugate here instead of inverse assuming q1 & q2 are - // normalized. + // We can use the conjugate here instead of inverse assuming q1 & q2 are normalized. XMVECTOR R = XMQuaternionMultiply(XMQuaternionConjugate(Q0), Q1); const float rs = XMVectorGetW(R); - R = XMVector3Length(R); + R = XMVector3Length(R); return 2.f * atan2f(XMVectorGetX(R), rs); } + /**************************************************************************** * * Color @@ -3384,7 +3330,7 @@ inline Color::Color(const DirectX::PackedVector::XMUBYTEN4& Packed) noexcept //------------------------------------------------------------------------------ // Comparision operators //------------------------------------------------------------------------------ -inline bool Color::operator==(const Color& c) const noexcept +inline bool Color::operator == (const Color& c) const noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(this); @@ -3392,7 +3338,7 @@ inline bool Color::operator==(const Color& c) const noexcept return XMColorEqual(c1, c2); } -inline bool Color::operator!=(const Color& c) const noexcept +inline bool Color::operator != (const Color& c) const noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(this); @@ -3404,21 +3350,21 @@ inline bool Color::operator!=(const Color& c) const noexcept // Assignment operators //------------------------------------------------------------------------------ -inline Color& Color::operator=(const DirectX::PackedVector::XMCOLOR& Packed) noexcept +inline Color& Color::operator= (const DirectX::PackedVector::XMCOLOR& Packed) noexcept { using namespace DirectX; XMStoreFloat4(this, PackedVector::XMLoadColor(&Packed)); return *this; } -inline Color& Color::operator=(const DirectX::PackedVector::XMUBYTEN4& Packed) noexcept +inline Color& Color::operator= (const DirectX::PackedVector::XMUBYTEN4& Packed) noexcept { using namespace DirectX; XMStoreFloat4(this, PackedVector::XMLoadUByteN4(&Packed)); return *this; } -inline Color& Color::operator+=(const Color& c) noexcept +inline Color& Color::operator+= (const Color& c) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(this); @@ -3427,7 +3373,7 @@ inline Color& Color::operator+=(const Color& c) noexcept return *this; } -inline Color& Color::operator-=(const Color& c) noexcept +inline Color& Color::operator-= (const Color& c) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(this); @@ -3436,7 +3382,7 @@ inline Color& Color::operator-=(const Color& c) noexcept return *this; } -inline Color& Color::operator*=(const Color& c) noexcept +inline Color& Color::operator*= (const Color& c) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(this); @@ -3445,7 +3391,7 @@ inline Color& Color::operator*=(const Color& c) noexcept return *this; } -inline Color& Color::operator*=(float S) noexcept +inline Color& Color::operator*= (float S) noexcept { using namespace DirectX; const XMVECTOR c = XMLoadFloat4(this); @@ -3453,7 +3399,7 @@ inline Color& Color::operator*=(float S) noexcept return *this; } -inline Color& Color::operator/=(const Color& c) noexcept +inline Color& Color::operator/= (const Color& c) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(this); @@ -3466,7 +3412,7 @@ inline Color& Color::operator/=(const Color& c) noexcept // Urnary operators //------------------------------------------------------------------------------ -inline Color Color::operator-() const noexcept +inline Color Color::operator- () const noexcept { using namespace DirectX; const XMVECTOR c = XMLoadFloat4(this); @@ -3479,7 +3425,7 @@ inline Color Color::operator-() const noexcept // Binary operators //------------------------------------------------------------------------------ -inline Color operator+(const Color& C1, const Color& C2) noexcept +inline Color operator+ (const Color& C1, const Color& C2) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(&C1); @@ -3489,7 +3435,7 @@ inline Color operator+(const Color& C1, const Color& C2) noexcept return R; } -inline Color operator-(const Color& C1, const Color& C2) noexcept +inline Color operator- (const Color& C1, const Color& C2) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(&C1); @@ -3499,7 +3445,7 @@ inline Color operator-(const Color& C1, const Color& C2) noexcept return R; } -inline Color operator*(const Color& C1, const Color& C2) noexcept +inline Color operator* (const Color& C1, const Color& C2) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(&C1); @@ -3509,7 +3455,7 @@ inline Color operator*(const Color& C1, const Color& C2) noexcept return R; } -inline Color operator*(const Color& C, float S) noexcept +inline Color operator* (const Color& C, float S) noexcept { using namespace DirectX; const XMVECTOR c = XMLoadFloat4(&C); @@ -3518,7 +3464,7 @@ inline Color operator*(const Color& C, float S) noexcept return R; } -inline Color operator/(const Color& C1, const Color& C2) noexcept +inline Color operator/ (const Color& C1, const Color& C2) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(&C1); @@ -3528,7 +3474,7 @@ inline Color operator/(const Color& C1, const Color& C2) noexcept return R; } -inline Color operator*(float S, const Color& C) noexcept +inline Color operator* (float S, const Color& C) noexcept { using namespace DirectX; const XMVECTOR c1 = XMLoadFloat4(&C); @@ -3601,8 +3547,8 @@ inline void Color::Premultiply() noexcept { using namespace DirectX; const XMVECTOR c = XMLoadFloat4(this); - XMVECTOR a = XMVectorSplatW(c); - a = XMVectorSelect(g_XMIdentityR3, a, g_XMSelect1110); + XMVECTOR a = XMVectorSplatW(c); + a = XMVectorSelect(g_XMIdentityR3, a, g_XMSelect1110); XMStoreFloat4(this, XMVectorMultiply(c, a)); } @@ -3610,8 +3556,8 @@ inline void Color::Premultiply(Color& result) const noexcept { using namespace DirectX; const XMVECTOR c = XMLoadFloat4(this); - XMVECTOR a = XMVectorSplatW(c); - a = XMVectorSelect(g_XMIdentityR3, a, g_XMSelect1110); + XMVECTOR a = XMVectorSplatW(c); + a = XMVectorSelect(g_XMIdentityR3, a, g_XMSelect1110); XMStoreFloat4(&result, XMVectorMultiply(c, a)); } @@ -3685,6 +3631,7 @@ inline Color Color::Lerp(const Color& c1, const Color& c2, float t) noexcept return result; } + /**************************************************************************** * * Ray @@ -3694,7 +3641,7 @@ inline Color Color::Lerp(const Color& c1, const Color& c2, float t) noexcept //----------------------------------------------------------------------------- // Comparision operators //------------------------------------------------------------------------------ -inline bool Ray::operator==(const Ray& r) const noexcept +inline bool Ray::operator == (const Ray& r) const noexcept { using namespace DirectX; const XMVECTOR r1p = XMLoadFloat3(&position); @@ -3704,7 +3651,7 @@ inline bool Ray::operator==(const Ray& r) const noexcept return XMVector3Equal(r1p, r2p) && XMVector3Equal(r1d, r2d); } -inline bool Ray::operator!=(const Ray& r) const noexcept +inline bool Ray::operator != (const Ray& r) const noexcept { using namespace DirectX; const XMVECTOR r1p = XMLoadFloat3(&position); @@ -3728,8 +3675,7 @@ inline bool Ray::Intersects(const BoundingBox& box, _Out_ float& Dist) const noe return box.Intersects(position, direction, Dist); } -inline bool Ray::Intersects(const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, - _Out_ float& Dist) const noexcept +inline bool Ray::Intersects(const Vector3& tri0, const Vector3& tri1, const Vector3& tri2, _Out_ float& Dist) const noexcept { return DirectX::TriangleTests::Intersects(position, direction, tri0, tri1, tri2, Dist); } @@ -3738,7 +3684,7 @@ inline bool Ray::Intersects(const Plane& plane, _Out_ float& Dist) const noexcep { using namespace DirectX; - const XMVECTOR p = XMLoadFloat4(&plane); + const XMVECTOR p = XMLoadFloat4(&plane); const XMVECTOR dir = XMLoadFloat3(&direction); const XMVECTOR nd = XMPlaneDotNormal(p, dir); @@ -3752,10 +3698,10 @@ inline bool Ray::Intersects(const Plane& plane, _Out_ float& Dist) const noexcep { // t = -(dot(n,origin) + D) / dot(n,dir) const XMVECTOR pos = XMLoadFloat3(&position); - XMVECTOR v = XMPlaneDotNormal(p, pos); - v = XMVectorAdd(v, XMVectorSplatW(p)); - v = XMVectorDivide(v, nd); - float dist = -XMVectorGetX(v); + XMVECTOR v = XMPlaneDotNormal(p, pos); + v = XMVectorAdd(v, XMVectorSplatW(p)); + v = XMVectorDivide(v, nd); + float dist = -XMVectorGetX(v); if (dist < 0) { Dist = 0.f; @@ -3769,6 +3715,7 @@ inline bool Ray::Intersects(const Plane& plane, _Out_ float& Dist) const noexcep } } + /**************************************************************************** * * Viewport @@ -3780,16 +3727,18 @@ inline bool Ray::Intersects(const Plane& plane, _Out_ float& Dist) const noexcep //------------------------------------------------------------------------------ #if (__cplusplus < 202002L) -inline bool Viewport::operator==(const Viewport& vp) const noexcept +inline bool Viewport::operator == (const Viewport& vp) const noexcept { - return (x == vp.x && y == vp.y && width == vp.width && height == vp.height && minDepth == vp.minDepth && - maxDepth == vp.maxDepth); + return (x == vp.x && y == vp.y + && width == vp.width && height == vp.height + && minDepth == vp.minDepth && maxDepth == vp.maxDepth); } -inline bool Viewport::operator!=(const Viewport& vp) const noexcept +inline bool Viewport::operator != (const Viewport& vp) const noexcept { - return (x != vp.x || y != vp.y || width != vp.width || height != vp.height || minDepth != vp.minDepth || - maxDepth != vp.maxDepth); + return (x != vp.x || y != vp.y + || width != vp.width || height != vp.height + || minDepth != vp.minDepth || maxDepth != vp.maxDepth); } #endif @@ -3797,39 +3746,31 @@ inline bool Viewport::operator!=(const Viewport& vp) const noexcept // Assignment operators //------------------------------------------------------------------------------ -inline Viewport& Viewport::operator=(const RECT& rct) noexcept +inline Viewport& Viewport::operator= (const RECT& rct) noexcept { - x = float(rct.left); - y = float(rct.top); - width = float(rct.right - rct.left); - height = float(rct.bottom - rct.top); - minDepth = 0.f; - maxDepth = 1.f; + x = float(rct.left); y = float(rct.top); + width = float(rct.right - rct.left); + height = float(rct.bottom - rct.top); + minDepth = 0.f; maxDepth = 1.f; return *this; } #if defined(__d3d11_h__) || defined(__d3d11_x_h__) -inline Viewport& Viewport::operator=(const D3D11_VIEWPORT& vp) noexcept -{ - x = vp.TopLeftX; - y = vp.TopLeftY; - width = vp.Width; - height = vp.Height; - minDepth = vp.MinDepth; - maxDepth = vp.MaxDepth; +inline Viewport& Viewport::operator= (const D3D11_VIEWPORT& vp) noexcept +{ + x = vp.TopLeftX; y = vp.TopLeftY; + width = vp.Width; height = vp.Height; + minDepth = vp.MinDepth; maxDepth = vp.MaxDepth; return *this; } #endif #if defined(__d3d12_h__) || defined(__d3d12_x_h__) || defined(__XBOX_D3D12_X__) -inline Viewport& Viewport::operator=(const D3D12_VIEWPORT& vp) noexcept -{ - x = vp.TopLeftX; - y = vp.TopLeftY; - width = vp.Width; - height = vp.Height; - minDepth = vp.MinDepth; - maxDepth = vp.MaxDepth; +inline Viewport& Viewport::operator= (const D3D12_VIEWPORT& vp) noexcept +{ + x = vp.TopLeftX; y = vp.TopLeftY; + width = vp.Width; height = vp.Height; + minDepth = vp.MinDepth; maxDepth = vp.MaxDepth; return *this; } #endif @@ -3846,46 +3787,42 @@ inline float Viewport::AspectRatio() const noexcept return (width / height); } -inline Vector3 Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, - const Matrix& world) const noexcept +inline Vector3 Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const noexcept { using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); + XMVECTOR v = XMLoadFloat3(&p); const XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); Vector3 result; XMStoreFloat3(&result, v); return result; } -inline void Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, - Vector3& result) const noexcept +inline void Viewport::Project(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const noexcept { using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); + XMVECTOR v = XMLoadFloat3(&p); const XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + v = XMVector3Project(v, x, y, width, height, minDepth, maxDepth, projection, view, world); XMStoreFloat3(&result, v); } -inline Vector3 Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, - const Matrix& world) const noexcept +inline Vector3 Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world) const noexcept { using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); + XMVECTOR v = XMLoadFloat3(&p); const XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); Vector3 result; XMStoreFloat3(&result, v); return result; } -inline void Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, - Vector3& result) const noexcept +inline void Viewport::Unproject(const Vector3& p, const Matrix& proj, const Matrix& view, const Matrix& world, Vector3& result) const noexcept { using namespace DirectX; - XMVECTOR v = XMLoadFloat3(&p); + XMVECTOR v = XMLoadFloat3(&p); const XMMATRIX projection = XMLoadFloat4x4(&proj); - v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); + v = XMVector3Unproject(v, x, y, width, height, minDepth, maxDepth, projection, view, world); XMStoreFloat3(&result, v); } diff --git a/Core/Graphics/Buffer.h b/Core/Graphics/Buffer.h index aa5a819..890167b 100644 --- a/Core/Graphics/Buffer.h +++ b/Core/Graphics/Buffer.h @@ -1,61 +1,61 @@ #pragma once -#include +#include + #if defined(CGL_RHI_DX11) - #include - #include - #include +#include +#include +#include #endif #if defined(CGL_RHI_DX12) - #include - #include +#include +#include #endif #if defined(CGL_RHI_OPENGL) - #include - #include +#include +#include #endif #if defined(CGL_RHI_METAL) - #include - #include +#include +#include #endif #if defined(CGL_RHI_VULKAN) - #include - #include +#include +#include #endif namespace CGL::Graphics { - struct BufferSource - { - BufferType Type = BufferType::None; - BufferUsage Usage = BufferUsage::Default; - u32 TypeSize = 0; - u32 Count = 0; - void* Data = nullptr; - }; + struct BufferSource + { + BufferType Type = BufferType::None; + BufferUsage Usage = BufferUsage::Default; + u32 TypeSize = 0; + u32 Count = 0; + void* Data = nullptr; + }; #if defined(CGL_RHI_DX11) - using VertexBuffer = D3D11VertexBuffer; - using IndexBuffer = D3D11IndexBuffer; - template - using ConstantBuffer = D3D11ConstantBuffer; + using VertexBuffer = D3D11VertexBuffer; + using IndexBuffer = D3D11IndexBuffer; + template using ConstantBuffer = D3D11ConstantBuffer; #elif defined(CGL_RHI_DX12) - using VertexBuffer = D3D12VertexBuffer; - using IndexBuffer = D3D12IndexBuffer; + using VertexBuffer = D3D12VertexBuffer; + using IndexBuffer = D3D12IndexBuffer; #elif defined(CGL_RHI_OPENGL) - using VertexBuffer = OPENGLVertexBuffer; - using IndexBuffer = OPENGLIndexBuffer; + using VertexBuffer = OPENGLVertexBuffer; + using IndexBuffer = OPENGLIndexBuffer; #elif defined(CGL_RHI_METAL) - using VertexBuffer = METALVertexBuffer; - using IndexBuffer = METALIndexBuffer; + using VertexBuffer = METALVertexBuffer; + using IndexBuffer = METALIndexBuffer; #elif defined(CGL_RHI_VULKAN) - using VertexBuffer = VULKANVertexBuffer; - using IndexBuffer = VULKANIndexBuffer; + using VertexBuffer = VULKANVertexBuffer; + using IndexBuffer = VULKANIndexBuffer; #else - #error Unsupported buffer types for RHI + #error Unsupported buffer types for RHI #endif -} // namespace CGL::Graphics +} \ No newline at end of file diff --git a/Core/Graphics/Camera.cpp b/Core/Graphics/Camera.cpp index 7b12bad..097de73 100644 --- a/Core/Graphics/Camera.cpp +++ b/Core/Graphics/Camera.cpp @@ -2,153 +2,150 @@ namespace CGL::Graphics { - CGL_DEFINE_LOG_CATEGORY(Camera); - - Camera::Camera() - : m_position(0.0f, 0.0f, -1.0f) - , m_target(0.0f, 0.0f, 0.0f) - , m_angle(0.0f) - , m_width(0.0f) - , m_height(0.0f) - , m_nearPlane(0.1f) - , m_farPlane(1000.0f) - , m_view(SM::Matrix::Identity) - , m_proj(SM::Matrix::Identity) - , m_ortho(SM::Matrix::Identity) - { - m_up = m_position + SM::Vector3::Up; - - InitViewMatrix(); - } - - void Camera::InitAsPerspective(const f32 angle, const f32 width, const f32 height, const f32 nearPlane, - const f32 farPlane) - { - m_angle = angle; - m_width = width; - m_height = height; - m_nearPlane = nearPlane; - m_farPlane = farPlane; - - m_proj = XMMatrixPerspectiveFovLH(m_angle, (m_width / m_height), m_nearPlane, m_farPlane); - } - - void Camera::InitAsOrthographic(const f32 width, const f32 height, const f32 nearPlane, const f32 farPlane) - { - m_width = width; - m_height = height; - m_nearPlane = nearPlane; - m_farPlane = farPlane; - - m_ortho = XMMatrixOrthographicLH(m_width, m_height, m_nearPlane, m_farPlane); - } - - void Camera::OnResize(u32 width, u32 height) - { - m_width = f32(width); - m_height = f32(height); - - InitAsPerspective(m_angle, m_width, m_height, m_nearPlane, m_farPlane); - InitAsOrthographic(m_width, m_height, m_nearPlane, m_farPlane); - } - - void Camera::Translate(SM::Vector3 direction) - { - SM::Matrix translation = SM::Matrix::CreateTranslation(direction); - - m_up = SM::Vector3::Transform(m_up, translation); - m_target = SM::Vector3::Transform(m_target, translation); - m_position = SM::Vector3::Transform(m_position, translation); - - InitViewMatrix(); - } - - void Camera::Rotate(SM::Vector3 axis, f32 angle) - { - if (axis == SM::Vector3::Zero || angle == 0.0f) - { - CGL_LOG(Camera, Warn, "Failed to rotate camera! Either axis or angle was 0"); - return; - } - - SM::Matrix rotation = SM::Matrix::CreateFromAxisAngle(axis, XMConvertToRadians(angle)); - SM::Vector3 lookAtTarget = m_target - m_position; - SM::Vector3 lookAtUp = m_up - m_position; - - lookAtTarget = SM::Vector3::Transform(lookAtTarget, rotation); - lookAtUp = SM::Vector3::Transform(lookAtUp, rotation); - - // Restore end points for m_target and m_up from new rotated vectors - m_target = m_position + lookAtTarget; - m_up = m_position + lookAtUp; - - InitViewMatrix(); - } - - void Camera::LookAt(SM::Vector3 target) - { - if (target == m_position || target == m_target) - { - CGL_LOG(Camera, Warn, - "Failed to set camera LookAt! Either targets are same or the " - "target is same as the position."); - return; - } - - SM::Vector3 oldLookAtTarget = m_target - m_position; - SM::Vector3 newLookAtTarget = target - m_position; - - SM::Vector3 oldLookAtTargetNormalized = oldLookAtTarget; - SM::Vector3 newLookAtTargetNormalized = newLookAtTarget; - oldLookAtTargetNormalized.Normalize(); - newLookAtTargetNormalized.Normalize(); - - SM::Vector3 angleVec = XMVector3AngleBetweenNormals(oldLookAtTargetNormalized, newLookAtTargetNormalized); - f32 angle = XMConvertToDegrees(angleVec.x); - - if (angle != 0.0f && angle != 360.0f && angle != 180.0f) - { - SM::Vector3 axis = oldLookAtTarget.Cross(newLookAtTarget); - Rotate(axis, angle); - } - - m_target = target; - InitViewMatrix(); - } - - const SM::Vector3 Camera::GetLookAtTarget() const - { - return m_target - m_position; - } - - void Camera::SetPosition(const SM::Vector3& position) - { - SM::Vector3 moveVector = position - m_position; - SM::Vector3 target = m_target; - Translate(moveVector); - LookAt(target); - } - - void Camera::SetAngle(const f32 angle) - { - m_angle = angle; - InitAsPerspective(m_angle, m_width, m_height, m_nearPlane, m_farPlane); - } - - void Camera::SetNearPlane(const f32 nearPlane) - { - m_nearPlane = nearPlane; - OnResize(u32(m_width), u32(m_height)); - } - - void Camera::SetFarPlane(const f32 farPlane) - { - m_farPlane = farPlane; - OnResize(u32(m_width), u32(m_height)); - } - - void Camera::InitViewMatrix() - { - m_view = XMMatrixLookAtLH(m_position, m_target, m_up); - } -} // namespace CGL::Graphics + CGL_DEFINE_LOG_CATEGORY(Camera); + + Camera::Camera() + : m_position(0.0f, 0.0f, -1.0f) + , m_target(0.0f, 0.0f, 0.0f) + , m_angle(0.0f) + , m_width(0.0f) + , m_height(0.0f) + , m_nearPlane(0.1f) + , m_farPlane(1000.0f) + , m_view(SM::Matrix::Identity) + , m_proj(SM::Matrix::Identity) + , m_ortho(SM::Matrix::Identity) + { + m_up = m_position + SM::Vector3::Up; + + InitViewMatrix(); + } + + void Camera::InitAsPerspective(const f32 angle, const f32 width, const f32 height, const f32 nearPlane, const f32 farPlane) + { + m_angle = angle; + m_width = width; + m_height = height; + m_nearPlane = nearPlane; + m_farPlane = farPlane; + + m_proj = XMMatrixPerspectiveFovLH(m_angle, (m_width / m_height), m_nearPlane, m_farPlane); + } + + void Camera::InitAsOrthographic(const f32 width, const f32 height, const f32 nearPlane, const f32 farPlane) + { + m_width = width; + m_height = height; + m_nearPlane = nearPlane; + m_farPlane = farPlane; + + m_ortho = XMMatrixOrthographicLH(m_width, m_height, m_nearPlane, m_farPlane); + } + + void Camera::OnResize(u32 width, u32 height) + { + m_width = f32(width); + m_height = f32(height); + + InitAsPerspective(m_angle, m_width, m_height, m_nearPlane, m_farPlane); + InitAsOrthographic(m_width, m_height, m_nearPlane, m_farPlane); + } + + void Camera::Translate(SM::Vector3 direction) + { + SM::Matrix translation = SM::Matrix::CreateTranslation(direction); + + m_up = SM::Vector3::Transform(m_up, translation); + m_target = SM::Vector3::Transform(m_target, translation); + m_position = SM::Vector3::Transform(m_position, translation); + + InitViewMatrix(); + } + + void Camera::Rotate(SM::Vector3 axis, f32 angle) + { + if (axis == SM::Vector3::Zero || angle == 0.0f) + { + CGL_LOG(Camera, Warn, "Failed to rotate camera! Either axis or angle was 0"); + return; + } + + SM::Matrix rotation = SM::Matrix::CreateFromAxisAngle(axis, XMConvertToRadians(angle)); + SM::Vector3 lookAtTarget = m_target - m_position; + SM::Vector3 lookAtUp = m_up - m_position; + + lookAtTarget = SM::Vector3::Transform(lookAtTarget, rotation); + lookAtUp = SM::Vector3::Transform(lookAtUp, rotation); + + // Restore end points for m_target and m_up from new rotated vectors + m_target = m_position + lookAtTarget; + m_up = m_position + lookAtUp; + + InitViewMatrix(); + } + + void Camera::LookAt(SM::Vector3 target) + { + if (target == m_position || target == m_target) + { + CGL_LOG(Camera, Warn, "Failed to set camera LookAt! Either targets are same or the target is same as the position."); + return; + } + + SM::Vector3 oldLookAtTarget = m_target - m_position; + SM::Vector3 newLookAtTarget = target - m_position; + + SM::Vector3 oldLookAtTargetNormalized = oldLookAtTarget; + SM::Vector3 newLookAtTargetNormalized = newLookAtTarget; + oldLookAtTargetNormalized.Normalize(); + newLookAtTargetNormalized.Normalize(); + + SM::Vector3 angleVec = XMVector3AngleBetweenNormals(oldLookAtTargetNormalized, newLookAtTargetNormalized); + f32 angle = XMConvertToDegrees(angleVec.x); + + if (angle != 0.0f && angle != 360.0f && angle != 180.0f) + { + SM::Vector3 axis = oldLookAtTarget.Cross(newLookAtTarget); + Rotate(axis, angle); + } + + m_target = target; + InitViewMatrix(); + } + + const SM::Vector3 Camera::GetLookAtTarget() const + { + return m_target - m_position; + } + + void Camera::SetPosition(const SM::Vector3& position) + { + SM::Vector3 moveVector = position - m_position; + SM::Vector3 target = m_target; + Translate(moveVector); + LookAt(target); + } + + void Camera::SetAngle(const f32 angle) + { + m_angle = angle; + InitAsPerspective(m_angle, m_width, m_height, m_nearPlane, m_farPlane); + } + + void Camera::SetNearPlane(const f32 nearPlane) + { + m_nearPlane = nearPlane; + OnResize(u32(m_width), u32(m_height)); + } + + void Camera::SetFarPlane(const f32 farPlane) + { + m_farPlane = farPlane; + OnResize(u32(m_width), u32(m_height)); + } + + void Camera::InitViewMatrix() + { + m_view = XMMatrixLookAtLH(m_position, m_target, m_up); + } +} diff --git a/Core/Graphics/Camera.h b/Core/Graphics/Camera.h index 2222904..c297d5a 100644 --- a/Core/Graphics/Camera.h +++ b/Core/Graphics/Camera.h @@ -1,58 +1,57 @@ -#pragma once + #pragma once #include #include +#include namespace CGL::Graphics { - CGL_DECLARE_LOG_CATEGORY(Camera); - - class Camera - { - public: - Camera(); - ~Camera() = default; - - void InitAsPerspective(const f32 angle, const f32 width, const f32 height, const f32 nearPlane = 0.1f, - const f32 farPlane = 1000.0f); - void InitAsOrthographic(const f32 width, const f32 height, const f32 nearPlane = 0.1f, - const f32 farPlane = 1000.0f); - void OnResize(u32 width, u32 height); - - void Translate(SM::Vector3 direction); - void Rotate(SM::Vector3 axis, f32 angle); - void LookAt(SM::Vector3 target); - - const SM::Vector3 GetLookAtTarget() const; - - inline const SM::Vector3& GetPosition() const noexcept { return m_position; } - inline const SM::Vector3& GetTarget() const noexcept { return m_target; } - inline const SM::Vector3& GetUp() const noexcept { return m_up; } - inline const f32& GetAngle() const noexcept { return m_angle; } - inline const f32& GetNearPlane() const noexcept { return m_nearPlane; } - inline const f32& GetFarPlane() const noexcept { return m_farPlane; } - inline const SM::Matrix& GetViewMatrix() const { return m_view; } - inline const SM::Matrix& GetProjectionMatrix() const { return m_proj; } - inline const SM::Matrix& GetOrthoMatrix() const { return m_ortho; } - - void SetPosition(const SM::Vector3& position); - void SetAngle(const f32 angle); - void SetNearPlane(const f32 nearPlane); - void SetFarPlane(const f32 farPlane); - - private: - void InitViewMatrix(); - - private: - SM::Vector3 m_position; - SM::Vector3 m_target; - SM::Vector3 m_up; - f32 m_angle; - f32 m_width; - f32 m_height; - f32 m_nearPlane; - f32 m_farPlane; - SM::Matrix m_view; - SM::Matrix m_proj; - SM::Matrix m_ortho; - }; -} // namespace CGL::Graphics + CGL_DECLARE_LOG_CATEGORY(Camera); + + class Camera + { + public: + Camera(); + ~Camera() = default; + + void InitAsPerspective(const f32 angle, const f32 width, const f32 height, const f32 nearPlane = 0.1f, const f32 farPlane = 1000.0f); + void InitAsOrthographic(const f32 width, const f32 height, const f32 nearPlane = 0.1f, const f32 farPlane = 1000.0f); + void OnResize(u32 width, u32 height); + + void Translate(SM::Vector3 direction); + void Rotate(SM::Vector3 axis, f32 angle); + void LookAt(SM::Vector3 target); + + const SM::Vector3 GetLookAtTarget() const; + + inline const SM::Vector3& GetPosition() const noexcept { return m_position; } + inline const SM::Vector3& GetTarget() const noexcept { return m_target; } + inline const SM::Vector3& GetUp() const noexcept { return m_up; } + inline const f32& GetAngle() const noexcept { return m_angle; } + inline const f32& GetNearPlane() const noexcept { return m_nearPlane; } + inline const f32& GetFarPlane() const noexcept { return m_farPlane; } + inline const SM::Matrix& GetViewMatrix() const { return m_view; } + inline const SM::Matrix& GetProjectionMatrix() const { return m_proj; } + inline const SM::Matrix& GetOrthoMatrix() const { return m_ortho; } + + void SetPosition(const SM::Vector3& position); + void SetAngle(const f32 angle); + void SetNearPlane(const f32 nearPlane); + void SetFarPlane(const f32 farPlane); + + private: + void InitViewMatrix(); + + private: + SM::Vector3 m_position; + SM::Vector3 m_target; + SM::Vector3 m_up; + f32 m_angle; + f32 m_width; + f32 m_height; + f32 m_nearPlane; + f32 m_farPlane; + SM::Matrix m_view; + SM::Matrix m_proj; + SM::Matrix m_ortho; + }; +} diff --git a/Core/Graphics/Graphics.h b/Core/Graphics/Graphics.h index a488086..c4b7174 100644 --- a/Core/Graphics/Graphics.h +++ b/Core/Graphics/Graphics.h @@ -3,4 +3,5 @@ namespace CGL::Graphics { + } diff --git a/Core/Graphics/Material.cpp b/Core/Graphics/Material.cpp index 5136d24..f0b0064 100644 --- a/Core/Graphics/Material.cpp +++ b/Core/Graphics/Material.cpp @@ -2,48 +2,46 @@ namespace CGL::Graphics { - CGL_DEFINE_LOG_CATEGORY(Material); + CGL_DEFINE_LOG_CATEGORY(Material); - Material::Material() - : m_id(0) - { - m_vs = std::make_unique>(); - m_ps = std::make_unique>(); + Material::Material() + : m_id(0) + { + m_vs = std::make_unique>(); + m_ps = std::make_unique>(); - m_vs->State = ShaderState::Invalid; - m_ps->State = ShaderState::Invalid; - } + m_vs->State = ShaderState::Invalid; + m_ps->State = ShaderState::Invalid; + } - Material::~Material() - { - m_vs.reset(); - m_ps.reset(); - } + Material::~Material() + { + m_vs.reset(); + m_ps.reset(); + } - void Material::AddSource(const ShaderSource& source) - { - switch (source.Type) - { - case ShaderType::Vertex: - { - assert(m_vs); - m_vs->State = ShaderState::CompilePending; - m_vs->Source = source; - break; - } + void Material::AddSource(const ShaderSource& source) + { + switch (source.Type) + { + case ShaderType::Vertex: + { + assert(m_vs); + m_vs->State = ShaderState::CompilePending; + m_vs->Source = source; + break; + } - case ShaderType::Pixel: - { - assert(m_ps); - m_ps->State = ShaderState::CompilePending; - m_ps->Source = source; - break; - } + case ShaderType::Pixel: + { + assert(m_ps); + m_ps->State = ShaderState::CompilePending; + m_ps->Source = source; + break; + } - default: - CGL_LOG(Material, Error, - "Unable to set shader source for given shader source! Error: " - "Undefined shader type!"); - } - } -} // namespace CGL::Graphics + default: + CGL_LOG(Material, Error, "Unable to set shader source for given shader source! Error: Undefined shader type!"); + } + } +} \ No newline at end of file diff --git a/Core/Graphics/Material.h b/Core/Graphics/Material.h index c103d78..d839e68 100644 --- a/Core/Graphics/Material.h +++ b/Core/Graphics/Material.h @@ -25,7 +25,6 @@ namespace CGL::Graphics class Material { friend class Renderer; - public: #if defined(CGL_RHI_OPENGL) using ID = GLuint; @@ -43,9 +42,9 @@ namespace CGL::Graphics inline const ShaderProgram* GetPixelShader() const noexcept { return m_ps.get(); } private: - ID m_id; + ID m_id; std::unique_ptr> m_vs; - std::unique_ptr> m_ps; + std::unique_ptr> m_ps; // TODO: Add other shader types }; -} // namespace CGL::Graphics +} \ No newline at end of file diff --git a/Core/Graphics/RHI/D3D11/D3D11ConstantBuffer.h b/Core/Graphics/RHI/D3D11/D3D11ConstantBuffer.h index 17fe652..ca8dfe7 100644 --- a/Core/Graphics/RHI/D3D11/D3D11ConstantBuffer.h +++ b/Core/Graphics/RHI/D3D11/D3D11ConstantBuffer.h @@ -3,17 +3,17 @@ namespace CGL::Graphics { - template - struct D3D11ConstantBuffer - { - using value_type = T; + template + struct D3D11ConstantBuffer + { + using value_type = T; - D3D11ConstantBuffer() - { - // Ensure 16-byte alignment - static_assert((sizeof(T) % 16) == 0, "Constant buffer size must be 16-byte aligned."); - } + D3D11ConstantBuffer() + { + // Ensure 16-byte alignment + static_assert((sizeof(T) % 16) == 0, "Constant buffer size must be 16-byte aligned."); + } - ComPtr Buffer; - }; -} // namespace CGL::Graphics + ComPtr Buffer; + }; +} \ No newline at end of file diff --git a/Core/Graphics/RHI/D3D11/D3D11IndexBuffer.h b/Core/Graphics/RHI/D3D11/D3D11IndexBuffer.h index 03473c5..e0a4280 100644 --- a/Core/Graphics/RHI/D3D11/D3D11IndexBuffer.h +++ b/Core/Graphics/RHI/D3D11/D3D11IndexBuffer.h @@ -3,11 +3,11 @@ namespace CGL::Graphics { - struct D3D11IndexBuffer - { - u32 IndicesCount; - DXGI_FORMAT Format; - ComPtr Buffer; - }; + struct D3D11IndexBuffer + { + u32 IndicesCount; + DXGI_FORMAT Format; + ComPtr Buffer; + }; -} // namespace CGL::Graphics +} diff --git a/Core/Graphics/RHI/D3D11/D3D11PixelShader.h b/Core/Graphics/RHI/D3D11/D3D11PixelShader.h index e2d07dc..23a41ed 100644 --- a/Core/Graphics/RHI/D3D11/D3D11PixelShader.h +++ b/Core/Graphics/RHI/D3D11/D3D11PixelShader.h @@ -3,9 +3,9 @@ namespace CGL::Graphics { - struct D3D11PixelShader - { - ComPtr Shader; - ComPtr Blob; - }; -} // namespace CGL::Graphics + struct D3D11PixelShader + { + ComPtr Shader; + ComPtr Blob; + }; +} diff --git a/Core/Graphics/RHI/D3D11/D3D11Renderer.cpp b/Core/Graphics/RHI/D3D11/D3D11Renderer.cpp index bbbd347..e49b1f5 100644 --- a/Core/Graphics/RHI/D3D11/D3D11Renderer.cpp +++ b/Core/Graphics/RHI/D3D11/D3D11Renderer.cpp @@ -1,5 +1,5 @@ -#include #include +#include #include #include #include @@ -8,416 +8,443 @@ namespace CGL::Graphics { #if defined(CGL_RHI_DX11) - namespace - { - template - inline void SetDebugObjectName([[maybe_unused]] _In_ T* resource, - [[maybe_unused]] _In_z_ const char (&name)[TNameLength]) - { - #ifdef CGL_BUILD_DEBUG - if (resource) - { - resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); - } - #endif // CGL_BUILD_DEBUG - } - - } // namespace - - namespace Mapping - { - static constexpr std::array PrimitiveTopology = { - D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, D3D_PRIMITIVE_TOPOLOGY_LINELIST, D3D_PRIMITIVE_TOPOLOGY_POINTLIST, - D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, - }; - - static constexpr std::array BufferUsage = { D3D11_USAGE_DEFAULT, D3D11_USAGE_IMMUTABLE, - D3D11_USAGE_DYNAMIC, D3D11_USAGE_STAGING }; - - static_assert(PrimitiveTopology.size() == size_t(PrimitiveType::COUNT)); - static_assert(BufferUsage.size() == size_t(BufferUsage::COUNT)); - } // namespace Mapping - - void Renderer::Constructor_D3D11(SDL_Window* window) - { - // Get Win32 window handle from SDL_Window - SDL_SysWMinfo systemInfo; - SDL_VERSION(&systemInfo.version); - SDL_GetWindowWMInfo(window, &systemInfo); - HWND handle = systemInfo.info.win.window; - - m_impl = new D3D11RendererImpl(handle); - - CGL_LOG(Renderer, Info, "D3D11 Renderer Initialized"); - } - - void Renderer::Destructor_D3D11() - { - delete static_cast(m_impl); - m_impl = nullptr; - - CGL_LOG(Renderer, Info, "D3D11 Renderer Destroyed"); - } - - D3D11RendererImpl* Renderer::GetImpl() const - { - return static_cast(m_impl); - } - - void Renderer::BeginFrame_D3D11() - { - const auto impl = GetImpl(); - assert(impl && impl->GetContext()); - - auto renderTarget = impl->GetBackBuffer(); - impl->GetContext()->RSSetViewports(1, &impl->GetViewport()); - impl->GetContext()->OMSetRenderTargets(1, &renderTarget, nullptr); - impl->GetContext()->ClearRenderTargetView(renderTarget, m_clearColor.data()); - } - - void Renderer::EndFrame_D3D11() - { - const auto impl = GetImpl(); - assert(impl && impl->GetSwapChain()); - - impl->GetSwapChain()->Present(0, 0); - } - - void Renderer::Resize_D3D11(u32 width, u32 height) - { - const auto impl = GetImpl(); - assert(impl && impl->GetSwapChain()); - - // Clear and flush context - impl->GetContext()->ClearState(); - impl->GetContext()->Flush(); - - impl->ReleaseSizeDependentResources(); - impl->CreateSizeDependentResources(width, height); - } - - void Renderer::SetPrimitiveTopology_D3D11(PrimitiveType topology) - { - const auto impl = GetImpl(); - assert(impl && impl->GetContext()); - - impl->GetContext()->IASetPrimitiveTopology(Mapping::PrimitiveTopology[size_t(topology)]); - } - - void Renderer::SetVertexShader_D3D11(const VertexShader& shader) - { - assert(GetImpl() && GetImpl()->GetContext()); - GetImpl()->GetContext()->VSSetShader(shader.Shader.Get(), nullptr, 0); - GetImpl()->GetContext()->IASetInputLayout(shader.InputLayout.Get()); - } - - void Renderer::SetPixelShader_D3D11(const PixelShader& shader) - { - assert(GetImpl() && GetImpl()->GetContext()); - GetImpl()->GetContext()->PSSetShader(shader.Shader.Get(), nullptr, 0); - } - - void Renderer::SetVertexBuffer_D3D11(const VertexBuffer& buffer) - { - assert(GetImpl() && GetImpl()->GetContext()); - GetImpl()->GetContext()->IASetVertexBuffers(0, 1, buffer.Buffer.GetAddressOf(), &buffer.Stride, &buffer.Offset); - } - - void Renderer::SetIndexBuffer_D3D11(const IndexBuffer& buffer) - { - assert(GetImpl() && GetImpl()->GetContext()); - GetImpl()->GetContext()->IASetIndexBuffer(buffer.Buffer.Get(), buffer.Format, 0); - } - - ShaderCompileResult Renderer::CompileVertexShader_D3D11(const ShaderSource& source, VertexShader* outShader) - { - assert(GetImpl() && GetImpl()->GetDevice() && outShader); - - CompileConfig cfg{}; - cfg.Target = "vs_5_0"; - cfg.EntryPoint = "main"; - #ifdef CGL_BUILD_DEBUG - cfg.Debug = true; - cfg.Optimize = false; - #endif - - ShaderCompileResult result = ShaderCompiler::Compile(source, cfg, outShader->Blob); - - if (result.Status != ShaderCompileStatus::Failure) - { - assert(outShader->Blob); - - HRESULT hr{ S_OK }; - // Shader compiled with warnings, try creating the shader - DXCall(hr = GetImpl()->GetDevice()->CreateVertexShader(outShader->Blob->GetBufferPointer(), - outShader->Blob->GetBufferSize(), nullptr, - &outShader->Shader)); - - #ifdef CGL_BUILD_DEBUG - { - char name[64]; - sprintf_s(name, "[VS] %s", source.Name.c_str()); - SetDebugObjectName(outShader->Shader.Get(), name); - } - #endif // CGL_BUILD_DEBUG - - // Create reflection - ComPtr vsReflection = nullptr; - - DXCall(hr = D3DReflect(outShader->Blob->GetBufferPointer(), outShader->Blob->GetBufferSize(), - IID_PPV_ARGS(&vsReflection))); - - D3D11_SHADER_DESC desc{}; - DXCall(hr = vsReflection->GetDesc(&desc)); - - // Create input layout - std::vector inputLayout; - for (u32 i = 0; i < desc.InputParameters; i++) - { - // Get input parameter at index - D3D11_SIGNATURE_PARAMETER_DESC paramDesc; - ZeroMemory(¶mDesc, sizeof(paramDesc)); - DXCall(hr = vsReflection->GetInputParameterDesc(i, ¶mDesc)); - - // Create input element description - D3D11_INPUT_ELEMENT_DESC elementDesc; - ZeroMemory(&elementDesc, sizeof(D3D11_INPUT_ELEMENT_DESC)); - - elementDesc.SemanticName = paramDesc.SemanticName; - elementDesc.SemanticIndex = paramDesc.SemanticIndex; - elementDesc.InputSlot = 0; - elementDesc.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - elementDesc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - elementDesc.InstanceDataStepRate = 0; - - // Determine DXGI format - if (paramDesc.Mask == 1) - { - if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) - elementDesc.Format = DXGI_FORMAT_R32_UINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) - elementDesc.Format = DXGI_FORMAT_R32_SINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) - elementDesc.Format = DXGI_FORMAT_R32_FLOAT; - } - else if (paramDesc.Mask <= 3) - { - if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) - elementDesc.Format = DXGI_FORMAT_R32G32_UINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) - elementDesc.Format = DXGI_FORMAT_R32G32_SINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) - elementDesc.Format = DXGI_FORMAT_R32G32_FLOAT; - } - else if (paramDesc.Mask <= 7) - { - if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) - elementDesc.Format = DXGI_FORMAT_R32G32B32_UINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) - elementDesc.Format = DXGI_FORMAT_R32G32B32_SINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) - elementDesc.Format = DXGI_FORMAT_R32G32B32_FLOAT; - } - else if (paramDesc.Mask <= 15) - { - if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) - elementDesc.Format = DXGI_FORMAT_R32G32B32A32_UINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) - elementDesc.Format = DXGI_FORMAT_R32G32B32A32_SINT; - else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) - elementDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; - } - - inputLayout.push_back(elementDesc); - } - - DXCall(hr = GetImpl()->GetDevice()->CreateInputLayout( - inputLayout.data(), (u32)inputLayout.size(), outShader->Blob->GetBufferPointer(), - outShader->Blob->GetBufferSize(), &outShader->InputLayout)); - - #ifdef CGL_BUILD_DEBUG - { - char name[64]; - sprintf_s(name, "[VS ~ Input Layout] %s", source.Name.c_str()); - SetDebugObjectName(outShader->Shader.Get(), name); - } - #endif // CGL_BUILD_DEBUG - } - - return result; - } - - ShaderCompileResult Renderer::CompilePixelShader_D3D11(const ShaderSource& source, PixelShader* outShader) - { - assert(GetImpl() && GetImpl()->GetDevice() && outShader); - - CompileConfig cfg{}; - cfg.Target = "ps_5_0"; - cfg.EntryPoint = "main"; - #ifdef CGL_BUILD_DEBUG - cfg.Debug = true; - cfg.Optimize = false; - #endif - - ShaderCompileResult result = ShaderCompiler::Compile(source, cfg, outShader->Blob); - - if (result.Status != ShaderCompileStatus::Failure) - { - HRESULT hr{ S_OK }; - // Shader compiled with warnings, try creating the shader - DXCall(hr = GetImpl()->GetDevice()->CreatePixelShader(outShader->Blob->GetBufferPointer(), - outShader->Blob->GetBufferSize(), nullptr, - &outShader->Shader)); - - #ifdef CGL_BUILD_DEBUG - { - char name[64]; - sprintf_s(name, "[PS] %s", source.Name.c_str()); - SetDebugObjectName(outShader->Shader.Get(), name); - } - #endif // CGL_BUILD_DEBUG - } - - return result; - } - - VertexBuffer Renderer::CreateVertexBuffer_D3D11(const BufferSource& source) - { - assert(source.Type == BufferType::Vertex); - assert(GetImpl() && GetImpl()->GetDevice()); - - CD3D11_BUFFER_DESC desc{}; - desc.Usage = Mapping::BufferUsage[size_t(source.Usage)]; - desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - desc.ByteWidth = source.TypeSize * source.Count; - desc.CPUAccessFlags = 0; - - D3D11_SUBRESOURCE_DATA resourceData{}; - resourceData.pSysMem = source.Data; - resourceData.SysMemPitch = 0; - resourceData.SysMemSlicePitch = 0; - - ID3D11Buffer* buffer = nullptr; - DXCall(GetImpl()->GetDevice()->CreateBuffer(&desc, &resourceData, &buffer)); - - CGL_LOG(Renderer, Trace, "D3D11 Vertex Buffer Created"); - - VertexBuffer vb; - vb.Buffer.Attach(buffer); - vb.Stride = source.TypeSize; - vb.Offset = 0; - - SetDebugObjectName(vb.Buffer.Get(), "D3D11VertexBuffer"); - - return vb; - } - - IndexBuffer Renderer::CreateIndexBuffer_D3D11(const BufferSource& source) - { - assert(source.Type == BufferType::Index); - assert(GetImpl() && GetImpl()->GetDevice()); - - CD3D11_BUFFER_DESC desc{}; - desc.Usage = Mapping::BufferUsage[size_t(source.Usage)]; - desc.BindFlags = D3D11_BIND_INDEX_BUFFER; - desc.ByteWidth = source.TypeSize * source.Count; - desc.CPUAccessFlags = 0; - - D3D11_SUBRESOURCE_DATA resourceData{}; - resourceData.pSysMem = source.Data; - resourceData.SysMemPitch = 0; - resourceData.SysMemSlicePitch = 0; - - ID3D11Buffer* buffer = nullptr; - DXCall(GetImpl()->GetDevice()->CreateBuffer(&desc, &resourceData, &buffer)); - - CGL_LOG(Renderer, Trace, "D3D11 Index Buffer Created"); - - IndexBuffer ib; - ib.Buffer.Attach(buffer); - ib.IndicesCount = source.Count; - ib.Format = (source.TypeSize == sizeof(u16) ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT); - - SetDebugObjectName(ib.Buffer.Get(), "D3D11IndexBuffer"); - - return ib; - } - - void Renderer::CreateContantBuffer_D3D11(const BufferSource& source, ComPtr& outBuffer) - { - assert(source.Type == BufferType::Constant); - assert(GetImpl() && GetImpl()->GetDevice()); - - CD3D11_BUFFER_DESC desc{}; - desc.Usage = Mapping::BufferUsage[size_t(source.Usage)]; - desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; - desc.ByteWidth = source.TypeSize; - desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - - DXCall(GetImpl()->GetDevice()->CreateBuffer(&desc, nullptr, &outBuffer)); - - SetDebugObjectName(outBuffer.Get(), "D3D11ConstantBuffer"); - } - - void Renderer::SetConstantBufferData_D3D11(ID3D11Buffer* buffer, const void* data, size_t size) - { - assert(buffer && GetImpl() && GetImpl()->GetContext()); - - D3D11_MAPPED_SUBRESOURCE mappedResource; - if (SUCCEEDED(GetImpl()->GetContext()->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource))) - { - // Ensure the data size fits within the mapped resource - assert(size <= mappedResource.RowPitch); // RowPitch is used for 1D and 2D data - memcpy(mappedResource.pData, data, size); - - GetImpl()->GetContext()->Unmap(buffer, 0); - } - else - { - CGL_LOG(Renderer, Error, "Failed to map constant buffer data"); - } - } - - void Renderer::SetContantBuffer_D3D11(ShaderType type, u32 startSlot, const ComPtr& buffer) - { - assert(GetImpl() && GetImpl()->GetContext() && buffer); - - switch (type) - { - case CGL::Graphics::ShaderType::Vertex: - GetImpl()->GetContext()->VSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); - break; - case CGL::Graphics::ShaderType::Hull: - GetImpl()->GetContext()->HSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); - break; - case CGL::Graphics::ShaderType::Domain: - GetImpl()->GetContext()->DSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); - break; - case CGL::Graphics::ShaderType::Geometry: - GetImpl()->GetContext()->GSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); - break; - case CGL::Graphics::ShaderType::Pixel: - GetImpl()->GetContext()->PSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); - break; - case CGL::Graphics::ShaderType::Compute: - GetImpl()->GetContext()->CSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); - break; - - default: CGL_LOG(Renderer, Error, "Unable set contant buffer for input shader type"); break; - } - } - - void Renderer::Draw_D3D11(u32 vertexCount, u32 startVertex) - { - assert(GetImpl() && GetImpl()->GetContext()); - GetImpl()->GetContext()->Draw(vertexCount, startVertex); - } - - void Renderer::DrawIndexed_D3D11(u32 indexCount, u32 startIndex, u32 baseVertex) - { - assert(GetImpl() && GetImpl()->GetContext()); - GetImpl()->GetContext()->DrawIndexed(indexCount, startIndex, baseVertex); - } - -#endif // CGL_RHI_DX11 -} // namespace CGL::Graphics + namespace + { + template + inline void SetDebugObjectName([[maybe_unused]] _In_ T* resource, [[maybe_unused]] _In_z_ const char(&name)[TNameLength]) + { +#ifdef CGL_BUILD_DEBUG + if (resource) + { + resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); + } +#endif // CGL_BUILD_DEBUG + } + + } + + namespace Mapping + { + static constexpr std::array< D3D_PRIMITIVE_TOPOLOGY, 5> PrimitiveTopology = + { + D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST, + D3D_PRIMITIVE_TOPOLOGY_LINELIST, + D3D_PRIMITIVE_TOPOLOGY_POINTLIST, + D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, + D3D_PRIMITIVE_TOPOLOGY_LINESTRIP, + }; + + static constexpr std::array BufferUsage = + { + D3D11_USAGE_DEFAULT, + D3D11_USAGE_IMMUTABLE, + D3D11_USAGE_DYNAMIC, + D3D11_USAGE_STAGING + }; + + static_assert(PrimitiveTopology.size() == size_t(PrimitiveType::COUNT)); + static_assert(BufferUsage.size() == size_t(BufferUsage::COUNT)); + } + + void Renderer::Constructor_D3D11(SDL_Window* window) + { + // Get Win32 window handle from SDL_Window + SDL_SysWMinfo systemInfo; + SDL_VERSION(&systemInfo.version); + SDL_GetWindowWMInfo(window, &systemInfo); + HWND handle = systemInfo.info.win.window; + + m_impl = new D3D11RendererImpl(handle); + + CGL_LOG(Renderer, Info, "D3D11 Renderer Initialized"); + } + + void Renderer::Destructor_D3D11() + { + delete static_cast(m_impl); + m_impl = nullptr; + + CGL_LOG(Renderer, Info, "D3D11 Renderer Destroyed"); + } + + D3D11RendererImpl* Renderer::GetImpl() const + { + return static_cast(m_impl); + } + + void Renderer::BeginFrame_D3D11() + { + const auto impl = GetImpl(); + assert(impl && impl->GetContext()); + + auto renderTarget = impl->GetBackBuffer(); + impl->GetContext()->RSSetViewports(1, &impl->GetViewport()); + impl->GetContext()->OMSetRenderTargets(1, &renderTarget, nullptr); + impl->GetContext()->ClearRenderTargetView(renderTarget, m_clearColor.data()); + } + + void Renderer::EndFrame_D3D11() + { + const auto impl = GetImpl(); + assert(impl && impl->GetSwapChain()); + + impl->GetSwapChain()->Present(0, 0); + } + + void Renderer::Resize_D3D11(u32 width, u32 height) + { + const auto impl = GetImpl(); + assert(impl && impl->GetSwapChain()); + + // Clear and flush context + impl->GetContext()->ClearState(); + impl->GetContext()->Flush(); + + impl->ReleaseSizeDependentResources(); + impl->CreateSizeDependentResources(width, height); + } + + void Renderer::SetPrimitiveTopology_D3D11(PrimitiveType topology) + { + const auto impl = GetImpl(); + assert(impl && impl->GetContext()); + + impl->GetContext()->IASetPrimitiveTopology(Mapping::PrimitiveTopology[size_t(topology)]); + } + + void Renderer::SetVertexShader_D3D11(const VertexShader& shader) + { + assert(GetImpl() && GetImpl()->GetContext()); + GetImpl()->GetContext()->VSSetShader(shader.Shader.Get(), nullptr, 0); + GetImpl()->GetContext()->IASetInputLayout(shader.InputLayout.Get()); + } + + void Renderer::SetPixelShader_D3D11(const PixelShader& shader) + { + assert(GetImpl() && GetImpl()->GetContext()); + GetImpl()->GetContext()->PSSetShader(shader.Shader.Get(), nullptr, 0); + } + + void Renderer::SetVertexBuffer_D3D11(const VertexBuffer& buffer) + { + assert(GetImpl() && GetImpl()->GetContext()); + GetImpl()->GetContext()->IASetVertexBuffers(0, 1, buffer.Buffer.GetAddressOf(), &buffer.Stride, &buffer.Offset); + } + + void Renderer::SetIndexBuffer_D3D11(const IndexBuffer& buffer) + { + assert(GetImpl() && GetImpl()->GetContext()); + GetImpl()->GetContext()->IASetIndexBuffer(buffer.Buffer.Get(), buffer.Format, 0); + } + + ShaderCompileResult Renderer::CompileVertexShader_D3D11(const ShaderSource& source, VertexShader* outShader) + { + assert(GetImpl() && GetImpl()->GetDevice() && outShader); + + CompileConfig cfg{}; + cfg.Target = "vs_5_0"; + cfg.EntryPoint = "main"; +#ifdef CGL_BUILD_DEBUG + cfg.Debug = true; + cfg.Optimize = false; +#endif + + ShaderCompileResult result = ShaderCompiler::Compile(source, cfg, outShader->Blob); + + if (result.Status != ShaderCompileStatus::Failure) + { + assert(outShader->Blob); + + HRESULT hr{ S_OK }; + // Shader compiled with warnings, try creating the shader + DXCall(hr = GetImpl()->GetDevice()->CreateVertexShader( + outShader->Blob->GetBufferPointer(), + outShader->Blob->GetBufferSize(), + nullptr, + &outShader->Shader + )); + +#ifdef CGL_BUILD_DEBUG + { + char name[64]; + sprintf_s(name, "[VS] %s", source.Name.c_str()); + SetDebugObjectName(outShader->Shader.Get(), name); + } +#endif // CGL_BUILD_DEBUG + + + // Create reflection + ComPtr vsReflection = nullptr; + + DXCall(hr = D3DReflect( + outShader->Blob->GetBufferPointer(), + outShader->Blob->GetBufferSize(), + IID_PPV_ARGS(&vsReflection) + )); + + D3D11_SHADER_DESC desc{}; + DXCall(hr = vsReflection->GetDesc(&desc)); + + // Create input layout + std::vector inputLayout; + for (u32 i = 0; i < desc.InputParameters; i++) + { + // Get input parameter at index + D3D11_SIGNATURE_PARAMETER_DESC paramDesc; + ZeroMemory(¶mDesc, sizeof(paramDesc)); + DXCall(hr = vsReflection->GetInputParameterDesc(i, ¶mDesc)); + + // Create input element description + D3D11_INPUT_ELEMENT_DESC elementDesc; + ZeroMemory(&elementDesc, sizeof(D3D11_INPUT_ELEMENT_DESC)); + + elementDesc.SemanticName = paramDesc.SemanticName; + elementDesc.SemanticIndex = paramDesc.SemanticIndex; + elementDesc.InputSlot = 0; + elementDesc.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + elementDesc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; + elementDesc.InstanceDataStepRate = 0; + + // Determine DXGI format + if (paramDesc.Mask == 1) + { + if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) + elementDesc.Format = DXGI_FORMAT_R32_UINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) + elementDesc.Format = DXGI_FORMAT_R32_SINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) + elementDesc.Format = DXGI_FORMAT_R32_FLOAT; + } + else if (paramDesc.Mask <= 3) + { + if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) + elementDesc.Format = DXGI_FORMAT_R32G32_UINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) + elementDesc.Format = DXGI_FORMAT_R32G32_SINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) + elementDesc.Format = DXGI_FORMAT_R32G32_FLOAT; + } + else if (paramDesc.Mask <= 7) + { + if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) + elementDesc.Format = DXGI_FORMAT_R32G32B32_UINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) + elementDesc.Format = DXGI_FORMAT_R32G32B32_SINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) + elementDesc.Format = DXGI_FORMAT_R32G32B32_FLOAT; + } + else if (paramDesc.Mask <= 15) + { + if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_UINT32) + elementDesc.Format = DXGI_FORMAT_R32G32B32A32_UINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_SINT32) + elementDesc.Format = DXGI_FORMAT_R32G32B32A32_SINT; + else if (paramDesc.ComponentType == D3D_REGISTER_COMPONENT_FLOAT32) + elementDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + } + + inputLayout.push_back(elementDesc); + } + + DXCall(hr = GetImpl()->GetDevice()->CreateInputLayout( + inputLayout.data(), + (u32)inputLayout.size(), + outShader->Blob->GetBufferPointer(), + outShader->Blob->GetBufferSize(), + &outShader->InputLayout + )); + +#ifdef CGL_BUILD_DEBUG + { + char name[64]; + sprintf_s(name, "[VS ~ Input Layout] %s", source.Name.c_str()); + SetDebugObjectName(outShader->Shader.Get(), name); + } +#endif // CGL_BUILD_DEBUG + + } + + return result; + } + + ShaderCompileResult Renderer::CompilePixelShader_D3D11(const ShaderSource& source, PixelShader* outShader) + { + assert(GetImpl() && GetImpl()->GetDevice() && outShader); + + CompileConfig cfg{}; + cfg.Target = "ps_5_0"; + cfg.EntryPoint = "main"; +#ifdef CGL_BUILD_DEBUG + cfg.Debug = true; + cfg.Optimize = false; +#endif + + ShaderCompileResult result = ShaderCompiler::Compile(source, cfg, outShader->Blob); + + if (result.Status != ShaderCompileStatus::Failure) + { + HRESULT hr{ S_OK }; + // Shader compiled with warnings, try creating the shader + DXCall(hr = GetImpl()->GetDevice()->CreatePixelShader( + outShader->Blob->GetBufferPointer(), + outShader->Blob->GetBufferSize(), + nullptr, + &outShader->Shader + )); + +#ifdef CGL_BUILD_DEBUG + { + char name[64]; + sprintf_s(name, "[PS] %s", source.Name.c_str()); + SetDebugObjectName(outShader->Shader.Get(), name); + } +#endif // CGL_BUILD_DEBUG + + } + + return result; + } + + VertexBuffer Renderer::CreateVertexBuffer_D3D11(const BufferSource& source) + { + assert(source.Type == BufferType::Vertex); + assert(GetImpl() && GetImpl()->GetDevice()); + + CD3D11_BUFFER_DESC desc{}; + desc.Usage = Mapping::BufferUsage[size_t(source.Usage)]; + desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + desc.ByteWidth = source.TypeSize * source.Count; + desc.CPUAccessFlags = 0; + + D3D11_SUBRESOURCE_DATA resourceData{}; + resourceData.pSysMem = source.Data; + resourceData.SysMemPitch = 0; + resourceData.SysMemSlicePitch = 0; + + ID3D11Buffer* buffer = nullptr; + DXCall(GetImpl()->GetDevice()->CreateBuffer(&desc, &resourceData, &buffer)); + + CGL_LOG(Renderer, Trace, "D3D11 Vertex Buffer Created"); + + VertexBuffer vb; + vb.Buffer.Attach(buffer); + vb.Stride = source.TypeSize; + vb.Offset = 0; + + SetDebugObjectName(vb.Buffer.Get(), "D3D11VertexBuffer"); + + return vb; + } + + IndexBuffer Renderer::CreateIndexBuffer_D3D11(const BufferSource& source) + { + assert(source.Type == BufferType::Index); + assert(GetImpl() && GetImpl()->GetDevice()); + + CD3D11_BUFFER_DESC desc{}; + desc.Usage = Mapping::BufferUsage[size_t(source.Usage)]; + desc.BindFlags = D3D11_BIND_INDEX_BUFFER; + desc.ByteWidth = source.TypeSize * source.Count; + desc.CPUAccessFlags = 0; + + + D3D11_SUBRESOURCE_DATA resourceData{}; + resourceData.pSysMem = source.Data; + resourceData.SysMemPitch = 0; + resourceData.SysMemSlicePitch = 0; + + ID3D11Buffer* buffer = nullptr; + DXCall(GetImpl()->GetDevice()->CreateBuffer(&desc, &resourceData, &buffer)); + + CGL_LOG(Renderer, Trace, "D3D11 Index Buffer Created"); + + IndexBuffer ib; + ib.Buffer.Attach(buffer); + ib.IndicesCount = source.Count; + ib.Format = (source.TypeSize == sizeof(u16) ? DXGI_FORMAT_R16_UINT : DXGI_FORMAT_R32_UINT); + + SetDebugObjectName(ib.Buffer.Get(), "D3D11IndexBuffer"); + + return ib; + } + + void Renderer::CreateContantBuffer_D3D11(const BufferSource& source, ComPtr& outBuffer) + { + assert(source.Type == BufferType::Constant); + assert(GetImpl() && GetImpl()->GetDevice()); + + CD3D11_BUFFER_DESC desc{}; + desc.Usage = Mapping::BufferUsage[size_t(source.Usage)]; + desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; + desc.ByteWidth = source.TypeSize; + desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; + + DXCall(GetImpl()->GetDevice()->CreateBuffer(&desc, nullptr , &outBuffer)); + + SetDebugObjectName(outBuffer.Get(), "D3D11ConstantBuffer"); + } + + void Renderer::SetConstantBufferData_D3D11(ID3D11Buffer* buffer, const void* data, size_t size) + { + assert(buffer && GetImpl() && GetImpl()->GetContext()); + + D3D11_MAPPED_SUBRESOURCE mappedResource; + if (SUCCEEDED(GetImpl()->GetContext()->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource))) + { + // Ensure the data size fits within the mapped resource + assert(size <= mappedResource.RowPitch); // RowPitch is used for 1D and 2D data + memcpy(mappedResource.pData, data, size); + + GetImpl()->GetContext()->Unmap(buffer, 0); + } + else + { + CGL_LOG(Renderer, Error, "Failed to map constant buffer data"); + } + } + + void Renderer::SetContantBuffer_D3D11(ShaderType type, u32 startSlot, const ComPtr& buffer) + { + assert(GetImpl() && GetImpl()->GetContext() && buffer); + + switch (type) + { + case CGL::Graphics::ShaderType::Vertex: + GetImpl()->GetContext()->VSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); + break; + case CGL::Graphics::ShaderType::Hull: + GetImpl()->GetContext()->HSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); + break; + case CGL::Graphics::ShaderType::Domain: + GetImpl()->GetContext()->DSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); + break; + case CGL::Graphics::ShaderType::Geometry: + GetImpl()->GetContext()->GSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); + break; + case CGL::Graphics::ShaderType::Pixel: + GetImpl()->GetContext()->PSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); + break; + case CGL::Graphics::ShaderType::Compute: + GetImpl()->GetContext()->CSSetConstantBuffers(startSlot, 1, buffer.GetAddressOf()); + break; + + default: + CGL_LOG(Renderer, Error, "Unable set contant buffer for input shader type"); + break; + } + } + + void Renderer::Draw_D3D11(u32 vertexCount, u32 startVertex) + { + assert(GetImpl() && GetImpl()->GetContext()); + GetImpl()->GetContext()->Draw(vertexCount, startVertex); + } + + void Renderer::DrawIndexed_D3D11(u32 indexCount, u32 startIndex, u32 baseVertex) + { + assert(GetImpl() && GetImpl()->GetContext()); + GetImpl()->GetContext()->DrawIndexed(indexCount, startIndex, baseVertex); + } + +#endif // CGL_RHI_DX11 +} \ No newline at end of file diff --git a/Core/Graphics/RHI/D3D11/D3D11RendererImpl.cpp b/Core/Graphics/RHI/D3D11/D3D11RendererImpl.cpp index 8d537c3..2273eaf 100644 --- a/Core/Graphics/RHI/D3D11/D3D11RendererImpl.cpp +++ b/Core/Graphics/RHI/D3D11/D3D11RendererImpl.cpp @@ -4,275 +4,283 @@ namespace CGL::Graphics { - namespace - { - template - inline void SetDebugObjectName([[maybe_unused]] _In_ T* resource, - [[maybe_unused]] _In_z_ const char (&name)[TNameLength]) - { + namespace + { + template + inline void SetDebugObjectName([[maybe_unused]]_In_ T* resource, [[maybe_unused]]_In_z_ const char(&name)[TNameLength]) + { #ifdef CGL_BUILD_DEBUG - if (resource) - { - resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); - } + if (resource) + { + resource->SetPrivateData(WKPDID_D3DDebugObjectName, TNameLength - 1, name); + } #endif // CGL_BUILD_DEBUG - } - - } // namespace - - CGL_DEFINE_LOG_CATEGORY(D3D11RendererImpl); - - D3D11RendererImpl::D3D11RendererImpl(HWND window) - : m_window(window) - { - Init(); - } - - D3D11RendererImpl::~D3D11RendererImpl() - { - Shutdown(); - } - - void Graphics::D3D11RendererImpl::CreateSizeDependentResources(u32 width, u32 height) - { - // This will resize if needed - CreateSwapChain(width, height); - - // Update viewport - m_viewport.Width = f32(width); - m_viewport.Height = f32(height); - m_viewport.MinDepth = 0.0f; - m_viewport.MaxDepth = 1.0f; - m_viewport.TopLeftX = 0; - m_viewport.TopLeftY = 0; - - HRESULT hr{ S_OK }; - assert(m_swapChain && m_context); - - // Get back buffer - DXCall(hr = m_swapChain->GetBuffer(0, IID_PPV_ARGS(&m_backBufferTexture))); - - // Create render target view - DXCall(hr = m_device->CreateRenderTargetView(m_backBufferTexture.Get(), nullptr, &m_backBuffer)); - } - - void Graphics::D3D11RendererImpl::ReleaseSizeDependentResources() - { - m_backBufferTexture.Reset(); - m_backBuffer.Reset(); - } - - void D3D11RendererImpl::Init() - { - RECT rect; - ::GetClientRect(m_window, &rect); - const u32 width = rect.right - rect.left; - const u32 height = rect.bottom - rect.top; - - CreateDevice(); - CreateSizeDependentResources(width, height); - } - - void D3D11RendererImpl::Shutdown() - { - m_context->ClearState(); - m_context->Flush(); - - m_backBuffer.Reset(); - m_backBufferTexture.Reset(); - m_swapChain.Reset(); - m_context.Reset(); - m_device.Reset(); + } + + } + + + CGL_DEFINE_LOG_CATEGORY(D3D11RendererImpl); + + D3D11RendererImpl::D3D11RendererImpl(HWND window) + : m_window(window) + { + Init(); + } + + D3D11RendererImpl::~D3D11RendererImpl() + { + Shutdown(); + } + + void Graphics::D3D11RendererImpl::CreateSizeDependentResources(u32 width, u32 height) + { + // This will resize if needed + CreateSwapChain(width, height); + + // Update viewport + m_viewport.Width = f32(width); + m_viewport.Height = f32(height); + m_viewport.MinDepth = 0.0f; + m_viewport.MaxDepth = 1.0f; + m_viewport.TopLeftX = 0; + m_viewport.TopLeftY = 0; + + HRESULT hr{ S_OK }; + assert(m_swapChain && m_context); + + // Get back buffer + DXCall(hr = m_swapChain->GetBuffer(0, IID_PPV_ARGS(&m_backBufferTexture))); + + // Create render target view + DXCall(hr = m_device->CreateRenderTargetView(m_backBufferTexture.Get(), nullptr, &m_backBuffer)); + } + + void Graphics::D3D11RendererImpl::ReleaseSizeDependentResources() + { + m_backBufferTexture.Reset(); + m_backBuffer.Reset(); + } + + void D3D11RendererImpl::Init() + { + RECT rect; + ::GetClientRect(m_window, &rect); + const u32 width = rect.right - rect.left; + const u32 height = rect.bottom - rect.top; + + CreateDevice(); + CreateSizeDependentResources(width, height); + } + + void D3D11RendererImpl::Shutdown() + { + m_context->ClearState(); + m_context->Flush(); + + m_backBuffer.Reset(); + m_backBufferTexture.Reset(); + m_swapChain.Reset(); + m_context.Reset(); + m_device.Reset(); #ifdef CGL_BUILD_DEBUG - { - ComPtr dxgiDebug; - if (SUCCEEDED(::DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug)))) - { - dxgiDebug->ReportLiveObjects( - DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_FLAGS(DXGI_DEBUG_RLO_SUMMARY | DXGI_DEBUG_RLO_IGNORE_INTERNAL)); - } - } + { + ComPtr dxgiDebug; + if (SUCCEEDED(::DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug)))) + { + dxgiDebug->ReportLiveObjects(DXGI_DEBUG_ALL, DXGI_DEBUG_RLO_FLAGS(DXGI_DEBUG_RLO_SUMMARY | DXGI_DEBUG_RLO_IGNORE_INTERNAL)); + } + } #endif - CGL_LOG(D3D11RendererImpl, Trace, "D3D11 Renderer Shutdown"); - } + CGL_LOG(D3D11RendererImpl, Trace, "D3D11 Renderer Shutdown"); + } - void D3D11RendererImpl::CreateDevice() - { - // Device only needs to be created once - if (!m_device) - { - HRESULT hr{ S_OK }; - u32 flags = 0; + void D3D11RendererImpl::CreateDevice() + { + // Device only needs to be created once + if (!m_device) + { + HRESULT hr{ S_OK }; + u32 flags = 0; #ifdef CGL_BUILD_DEBUG - CGL_LOG(D3D11RendererImpl, Debug, "Enabling debug layer for D3D11 device"); - flags |= D3D11_CREATE_DEVICE_DEBUG; + CGL_LOG(D3D11RendererImpl, Debug, "Enabling debug layer for D3D11 device"); + flags |= D3D11_CREATE_DEVICE_DEBUG; #endif - DXCall(hr = ::D3D11CreateDevice(nullptr, D3D_DRIVER_TYPE_HARDWARE, nullptr, flags, nullptr, 0, - D3D11_SDK_VERSION, &m_device, nullptr, &m_context)); - - assert(m_device && m_context); - - SetDebugObjectName(m_device.Get(), "D3D11Device"); - SetDebugObjectName(m_context.Get(), "D3D11DeviceContext"); - - // Create debug interface + DXCall(hr = ::D3D11CreateDevice( + nullptr, + D3D_DRIVER_TYPE_HARDWARE, + nullptr, + flags, + nullptr, + 0, + D3D11_SDK_VERSION, + &m_device, + nullptr, + &m_context + )); + + assert(m_device && m_context); + + SetDebugObjectName(m_device.Get(), "D3D11Device"); + SetDebugObjectName(m_context.Get(), "D3D11DeviceContext"); + + // Create debug interface #ifdef CGL_BUILD_DEBUG - { - ComPtr debug = nullptr; - if (SUCCEEDED(m_device.As(&debug))) - { - ComPtr infoQueue = nullptr; - if (SUCCEEDED(debug.As(&infoQueue))) - { - infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true); - infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true); - - D3D11_MESSAGE_ID hide[] = { - D3D11_MESSAGE_ID_SETPRIVATEDATA_CHANGINGPARAMS, - }; - - D3D11_INFO_QUEUE_FILTER filter = {}; - filter.DenyList.NumIDs = _countof(hide); - filter.DenyList.pIDList = hide; - infoQueue->AddStorageFilterEntries(&filter); - } - } - } -#endif // CGL_BUILD_DEBUG - } - - CGL_LOG(D3D11RendererImpl, Trace, "D3D11 Device Created"); - } - - void D3D11RendererImpl::CreateSwapChain(u32 width, u32 height) - { - if (m_swapChain) - { - // Swapchain already exists, just resize it - ResizeSwapchain(width, height); - return; - } - - assert(m_device && m_window); - HRESULT hr{ S_OK }; - - ComPtr dxgiDevice; - ComPtr dxgiAdapter; - ComPtr dxgiFactory; - - DXCall(hr = m_device.As(&dxgiDevice)); - DXCall(hr = dxgiDevice->GetParent(IID_IDXGIAdapter, (void**)&dxgiAdapter)); - DXCall(hr = dxgiAdapter->GetParent(IID_IDXGIFactory, (void**)&dxgiFactory)); - - SetDebugObjectName(dxgiDevice.Get(), "DXGIDevice"); - SetDebugObjectName(dxgiAdapter.Get(), "DXGIAdapter"); - SetDebugObjectName(dxgiFactory.Get(), "DXGIFactory"); + { + ComPtr debug = nullptr; + if (SUCCEEDED(m_device.As(&debug))) + { + ComPtr infoQueue = nullptr; + if (SUCCEEDED(debug.As(&infoQueue))) + { + infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_CORRUPTION, true); + infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true); + + D3D11_MESSAGE_ID hide[] = + { + D3D11_MESSAGE_ID_SETPRIVATEDATA_CHANGINGPARAMS, + }; + + D3D11_INFO_QUEUE_FILTER filter = {}; + filter.DenyList.NumIDs = _countof(hide); + filter.DenyList.pIDList = hide; + infoQueue->AddStorageFilterEntries(&filter); + } + } + } +#endif // CGL_BUILD_DEBUG + } + + CGL_LOG(D3D11RendererImpl, Trace, "D3D11 Device Created"); + } + + void D3D11RendererImpl::CreateSwapChain(u32 width, u32 height) + { + if (m_swapChain) + { + // Swapchain already exists, just resize it + ResizeSwapchain(width, height); + return; + } + + assert(m_device && m_window); + HRESULT hr{ S_OK }; + + ComPtr dxgiDevice; + ComPtr dxgiAdapter; + ComPtr dxgiFactory; + + DXCall(hr = m_device.As(&dxgiDevice)); + DXCall(hr = dxgiDevice->GetParent(IID_IDXGIAdapter, (void**)&dxgiAdapter)); + DXCall(hr = dxgiAdapter->GetParent(IID_IDXGIFactory, (void**)&dxgiFactory)); + + SetDebugObjectName(dxgiDevice.Get(), "DXGIDevice"); + SetDebugObjectName(dxgiAdapter.Get(), "DXGIAdapter"); + SetDebugObjectName(dxgiFactory.Get(), "DXGIFactory"); #ifdef CGL_BUILD_DEBUG - { - ComPtr dxgiDebug; - if (SUCCEEDED(::DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug)))) - { - ComPtr infoQueue; - if (SUCCEEDED(dxgiDebug.As(&infoQueue))) - { - infoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, true); - infoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, true); - } - } - } -#endif // CGL_BUILD_DEBUG - - DXGI_RATIONAL refreshRateRational = {}; - IDXGIOutput* dxgiOutput = nullptr; - u32 numModes = 0; - - // Use primary monitor - DXCall(hr = dxgiAdapter->EnumOutputs(0, &dxgiOutput)); - DXCall(hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, nullptr)); - - // Get refresh rate - if (numModes > 0) - { - DXGI_MODE_DESC* modes = new DXGI_MODE_DESC[numModes]; - - DXCall(hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, modes)); - - u32 bestMatchIndex = u32(-1); - u32 bestError = u32max; - for (u32 i = 0; i < numModes; ++i) - { - if (width != modes[i].Width || height != modes[i].Height) - continue; - - f32 rate = (f32)modes[i].RefreshRate.Numerator / modes[i].RefreshRate.Denominator; - u32 error = (u32)(abs(rate - 60)); // 60 is default refresh rate - - if (error < bestError) - { - bestMatchIndex = i; - bestError = error; - } - } - - if (bestMatchIndex != -1) - { - refreshRateRational.Numerator = modes[bestMatchIndex].RefreshRate.Denominator; - refreshRateRational.Denominator = modes[bestMatchIndex].RefreshRate.Numerator; - } - - delete[] modes; - } - - DXGI_SWAP_CHAIN_DESC swapChainDesc; - ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); - - swapChainDesc.BufferCount = 1; - swapChainDesc.BufferDesc.Width = width; - swapChainDesc.BufferDesc.Height = height; - swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; - swapChainDesc.BufferDesc.RefreshRate.Numerator = refreshRateRational.Numerator; - swapChainDesc.BufferDesc.RefreshRate.Denominator = refreshRateRational.Denominator; - swapChainDesc.OutputWindow = m_window; - swapChainDesc.SampleDesc.Count = 1; - swapChainDesc.SampleDesc.Quality = 0; - swapChainDesc.Windowed = TRUE; - swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; - - DXCall(hr = dxgiFactory->CreateSwapChain(m_device.Get(), &swapChainDesc, &m_swapChain)); - assert(m_swapChain); - - SetDebugObjectName(m_swapChain.Get(), "D3D11Swapchain"); - - dxgiFactory.Reset(); - dxgiAdapter.Reset(); - dxgiDevice.Reset(); - - CGL_LOG(D3D11RendererImpl, Trace, "D3D11 SwapChain Created"); - } - - void D3D11RendererImpl::ResizeSwapchain(u32 width, u32 height) - { - // Ensure to call clear state + flush on the context before calling this - assert(m_swapChain); - - HRESULT hr = - m_swapChain->ResizeBuffers(1, width, height, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH); - if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) - { - // Shutdown and restart the DX11 renderer - std::string err = - (hr == DXGI_ERROR_DEVICE_REMOVED) ? "The device was removed" : "Error during device reset"; - CGL_LOG(D3D11RendererImpl, Error, "Swapchain resize error: {0}. Restarting...", err); - - Shutdown(); - Init(); - } - - CGL_LOG(D3D11RendererImpl, Trace, "D3D11 SwapChain Resized to {0}x{1}", width, height); - } -} // namespace CGL::Graphics + { + ComPtr dxgiDebug; + if (SUCCEEDED(::DXGIGetDebugInterface1(0, IID_PPV_ARGS(&dxgiDebug)))) + { + ComPtr infoQueue; + if (SUCCEEDED(dxgiDebug.As(&infoQueue))) + { + infoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_ERROR, true); + infoQueue->SetBreakOnSeverity(DXGI_DEBUG_ALL, DXGI_INFO_QUEUE_MESSAGE_SEVERITY_CORRUPTION, true); + } + } + } +#endif // CGL_BUILD_DEBUG + + DXGI_RATIONAL refreshRateRational = {}; + IDXGIOutput* dxgiOutput = nullptr; + u32 numModes = 0; + + // Use primary monitor + DXCall(hr = dxgiAdapter->EnumOutputs(0, &dxgiOutput)); + DXCall(hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, nullptr)); + + // Get refresh rate + if (numModes > 0) + { + DXGI_MODE_DESC* modes = new DXGI_MODE_DESC[numModes]; + + DXCall(hr = dxgiOutput->GetDisplayModeList(DXGI_FORMAT_R8G8B8A8_UNORM, 0, &numModes, modes)); + + u32 bestMatchIndex = u32(- 1); + u32 bestError = u32max; + for (u32 i = 0; i < numModes; ++i) + { + if (width != modes[i].Width || height != modes[i].Height) + continue; + + f32 rate = (f32)modes[i].RefreshRate.Numerator / modes[i].RefreshRate.Denominator; + u32 error = (u32)(abs(rate - 60)); // 60 is default refresh rate + + if (error < bestError) + { + bestMatchIndex = i; + bestError = error; + } + } + + if (bestMatchIndex != -1) + { + refreshRateRational.Numerator = modes[bestMatchIndex].RefreshRate.Denominator; + refreshRateRational.Denominator = modes[bestMatchIndex].RefreshRate.Numerator; + } + + delete[] modes; + } + + DXGI_SWAP_CHAIN_DESC swapChainDesc; + ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC)); + + swapChainDesc.BufferCount = 1; + swapChainDesc.BufferDesc.Width = width; + swapChainDesc.BufferDesc.Height = height; + swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + swapChainDesc.BufferDesc.RefreshRate.Numerator = refreshRateRational.Numerator; + swapChainDesc.BufferDesc.RefreshRate.Denominator = refreshRateRational.Denominator; + swapChainDesc.OutputWindow = m_window; + swapChainDesc.SampleDesc.Count = 1; + swapChainDesc.SampleDesc.Quality = 0; + swapChainDesc.Windowed = TRUE; + swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + + DXCall(hr = dxgiFactory->CreateSwapChain(m_device.Get(), &swapChainDesc, &m_swapChain)); + assert(m_swapChain); + + SetDebugObjectName(m_swapChain.Get(), "D3D11Swapchain"); + + dxgiFactory.Reset(); + dxgiAdapter.Reset(); + dxgiDevice.Reset(); + + CGL_LOG(D3D11RendererImpl, Trace, "D3D11 SwapChain Created"); + } + + void D3D11RendererImpl::ResizeSwapchain(u32 width, u32 height) + { + // Ensure to call clear state + flush on the context before calling this + assert(m_swapChain); + + HRESULT hr = m_swapChain->ResizeBuffers(1, width, height, DXGI_FORMAT_UNKNOWN, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH); + if (hr == DXGI_ERROR_DEVICE_REMOVED || hr == DXGI_ERROR_DEVICE_RESET) + { + // Shutdown and restart the DX11 renderer + std::string err = (hr == DXGI_ERROR_DEVICE_REMOVED) ? "The device was removed" : "Error during device reset"; + CGL_LOG(D3D11RendererImpl, Error, "Swapchain resize error: {0}. Restarting...", err); + + Shutdown(); + Init(); + } + + CGL_LOG(D3D11RendererImpl, Trace, "D3D11 SwapChain Resized to {0}x{1}", width, height); + } +} diff --git a/Core/Graphics/RHI/D3D11/D3D11RendererImpl.h b/Core/Graphics/RHI/D3D11/D3D11RendererImpl.h index 74f573d..605a7e1 100644 --- a/Core/Graphics/RHI/D3D11/D3D11RendererImpl.h +++ b/Core/Graphics/RHI/D3D11/D3D11RendererImpl.h @@ -4,41 +4,40 @@ namespace CGL::Graphics { - CGL_DECLARE_LOG_CATEGORY(D3D11RendererImpl); - - class D3D11RendererImpl - { - friend class Renderer; - - public: - D3D11RendererImpl(HWND window); - ~D3D11RendererImpl(); - - void CreateSizeDependentResources(u32 width, u32 height); - void ReleaseSizeDependentResources(); - - inline ID3D11Device* GetDevice() const { return m_device.Get(); } - inline ID3D11DeviceContext* GetContext() const { return m_context.Get(); } - inline IDXGISwapChain* GetSwapChain() const { return m_swapChain.Get(); } - inline ID3D11RenderTargetView* GetBackBuffer() const { return m_backBuffer.Get(); } - inline ID3D11Texture2D* GetBackBufferTexture() const { return m_backBufferTexture.Get(); } - inline const D3D11_VIEWPORT& GetViewport() const { return m_viewport; } - - private: - void Init(); - void Shutdown(); - - void CreateDevice(); - void CreateSwapChain(u32 width, u32 height); - void ResizeSwapchain(u32 width, u32 height); - - private: - HWND m_window{ nullptr }; - D3D11_VIEWPORT m_viewport; - ComPtr m_device; - ComPtr m_context; - ComPtr m_swapChain; - ComPtr m_backBuffer; - ComPtr m_backBufferTexture; - }; -} // namespace CGL::Graphics + CGL_DECLARE_LOG_CATEGORY(D3D11RendererImpl); + + class D3D11RendererImpl + { + friend class Renderer; + public: + D3D11RendererImpl(HWND window); + ~D3D11RendererImpl(); + + void CreateSizeDependentResources(u32 width, u32 height); + void ReleaseSizeDependentResources(); + + inline ID3D11Device* GetDevice() const { return m_device.Get(); } + inline ID3D11DeviceContext* GetContext() const { return m_context.Get(); } + inline IDXGISwapChain* GetSwapChain() const { return m_swapChain.Get(); } + inline ID3D11RenderTargetView* GetBackBuffer() const { return m_backBuffer.Get(); } + inline ID3D11Texture2D* GetBackBufferTexture() const { return m_backBufferTexture.Get(); } + inline const D3D11_VIEWPORT& GetViewport() const { return m_viewport; } + + private: + void Init(); + void Shutdown(); + + void CreateDevice(); + void CreateSwapChain(u32 width, u32 height); + void ResizeSwapchain(u32 width, u32 height); + + private: + HWND m_window{ nullptr }; + D3D11_VIEWPORT m_viewport; + ComPtr m_device; + ComPtr m_context; + ComPtr m_swapChain; + ComPtr m_backBuffer; + ComPtr m_backBufferTexture; + }; +} diff --git a/Core/Graphics/RHI/D3D11/D3D11VertexBuffer.h b/Core/Graphics/RHI/D3D11/D3D11VertexBuffer.h index d3f7d27..89c21a6 100644 --- a/Core/Graphics/RHI/D3D11/D3D11VertexBuffer.h +++ b/Core/Graphics/RHI/D3D11/D3D11VertexBuffer.h @@ -3,10 +3,10 @@ namespace CGL::Graphics { - struct D3D11VertexBuffer - { - ComPtr Buffer; - u32 Stride; - u32 Offset; - }; -} // namespace CGL::Graphics + struct D3D11VertexBuffer + { + ComPtr Buffer; + u32 Stride; + u32 Offset; + }; +} diff --git a/Core/Graphics/RHI/D3D11/D3D11VertexShader.h b/Core/Graphics/RHI/D3D11/D3D11VertexShader.h index dfe7458..bf2ebf7 100644 --- a/Core/Graphics/RHI/D3D11/D3D11VertexShader.h +++ b/Core/Graphics/RHI/D3D11/D3D11VertexShader.h @@ -3,10 +3,10 @@ namespace CGL::Graphics { - struct D3D11VertexShader - { - ComPtr Blob; - ComPtr Shader; - ComPtr InputLayout; - }; -} // namespace CGL::Graphics + struct D3D11VertexShader + { + ComPtr Blob; + ComPtr Shader; + ComPtr InputLayout; + }; +} diff --git a/Core/Graphics/RHI/D3DCommon.h b/Core/Graphics/RHI/D3DCommon.h index 7e917e4..904ab63 100644 --- a/Core/Graphics/RHI/D3DCommon.h +++ b/Core/Graphics/RHI/D3DCommon.h @@ -1,87 +1,84 @@ #pragma once #include -#include #include -#include +#include #include -#include +#include #include +#include #if defined(CGL_RHI_DX11) - #include +#include #elif defined(CGL_RHI_DX12) - #include +#include #endif #ifdef CGL_BUILD_DEBUG - #include -#endif // CGL_BUILD_DEBUG +#include +#endif // CGL_BUILD_DEBUG namespace DirectX { - // Helper class for COM exceptions - class com_exception : public std::exception - { - public: - com_exception(HRESULT hr) noexcept - : result(hr) - { - } + // Helper class for COM exceptions + class com_exception : public std::exception + { + public: + com_exception(HRESULT hr) noexcept : result(hr) {} - const char* what() const noexcept override - { - static char s_str[64] = {}; - sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast(result)); - return s_str; - } + const char* what() const noexcept override + { + static char s_str[64] = {}; + sprintf_s(s_str, "Failure with HRESULT of %08X", static_cast(result)); + return s_str; + } - HRESULT get_result() const noexcept { return result; } + HRESULT get_result() const noexcept { return result; } - private: - HRESULT result; - }; + private: + HRESULT result; + }; - // Helper utility converts D3D API failures into exceptions. - inline void ThrowIfFailed(HRESULT hr) noexcept(false) - { - if (FAILED(hr)) - { - throw com_exception(hr); - } - } -} // namespace DirectX + // Helper utility converts D3D API failures into exceptions. + inline void ThrowIfFailed(HRESULT hr) noexcept(false) + { + if (FAILED(hr)) + { + throw com_exception(hr); + } + } +} namespace CGL::Graphics { #ifdef CGL_BUILD_DEBUG - #define DXCall(x) \ - { \ - try \ - { \ - DirectX::ThrowIfFailed(x); \ - } \ - catch (const DirectX::com_exception& e) \ - { \ - CGL_DECLARE_LOG_CATEGORY_INLINE(D3DException); \ - std::string msg(e.what()); \ - msg += " (" + ::CGL::Platform::Win32::GetErrorString(e.get_result()) + ")"; \ - CGL_LOG(D3DException, Fatal, msg); \ - } \ - } +#define DXCall(x) \ +{ \ + try \ + { \ + DirectX::ThrowIfFailed(x); \ + } \ + catch (const DirectX::com_exception& e) \ + { \ + CGL_DECLARE_LOG_CATEGORY_INLINE(D3DException); \ + std::string msg(e.what()); \ + msg += " (" + ::CGL::Platform::Win32::GetErrorString(e.get_result()) + ")";\ + CGL_LOG(D3DException, Fatal, msg); \ + } \ +} #else - #define DXCall(x) x -#endif // CGL_BUILD_DEBUG +#define DXCall(x) x +#endif // CGL_BUILD_DEBUG - template - using ComPtr = Microsoft::WRL::ComPtr; + template + using ComPtr = Microsoft::WRL::ComPtr; - template - void SafeRelease(T** ppT) - { - if (*ppT) - { - (*ppT)->Release(); - *ppT = NULL; - } - } -} // namespace CGL::Graphics + template + void SafeRelease(T** ppT) + { + if (*ppT) + { + (*ppT)->Release(); + *ppT = NULL; + } + } +} diff --git a/Core/Graphics/RHI/Metal/METALRenderer.cpp b/Core/Graphics/RHI/Metal/METALRenderer.cpp index 3ad64fa..0a1660e 100644 --- a/Core/Graphics/RHI/Metal/METALRenderer.cpp +++ b/Core/Graphics/RHI/Metal/METALRenderer.cpp @@ -1,64 +1,66 @@ -#include "Core/Graphics/RHI/Metal/METALRendererImpl.h" #include "Core/Graphics/Renderer.h" +#include "Core/Graphics/RHI/Metal/METALRendererImpl.h" #include "Metal/MTLRenderPass.hpp" namespace CGL::Graphics { void Renderer::Constructor_METAL(SDL_Window* window) { - this->m_impl = new METALRendererImpl(window); + this->m_impl = new METALRendererImpl(window); - CGL_LOG(Renderer, Info, "Metal Renderer Initialized"); + CGL_LOG(Renderer, Info, "Metal Renderer Initialized"); } void Renderer::Destructor_METAL() { - delete static_cast(m_impl); - m_impl = nullptr; + delete static_cast(m_impl); + m_impl = nullptr; - CGL_LOG(Renderer, Info, "Metal Renderer Destroyed"); + CGL_LOG(Renderer, Info, "Metal Renderer Destroyed"); } void Renderer::BeginFrame_METAL() { - GetImpl()->GetPoolRef()->alloc()->init(); - GetImpl()->SetDrawable(GetImpl()->GetMetalLayer()->nextDrawable()); + GetImpl()->GetPoolRef()->alloc()->init(); + GetImpl()->SetDrawable(GetImpl()->GetMetalLayer()->nextDrawable()); - GetImpl()->SetCmdBuffer(GetImpl()->GetQueue()->commandBuffer()); + GetImpl()->SetCmdBuffer(GetImpl()->GetQueue()->commandBuffer()); - const f32 r = m_clearColor[0]; - const f32 g = m_clearColor[1]; - const f32 b = m_clearColor[2]; - const f32 a = m_clearColor[3]; + const f32 r = m_clearColor[0]; + const f32 g = m_clearColor[1]; + const f32 b = m_clearColor[2]; + const f32 a = m_clearColor[3]; - auto rpDescriptor = MTL::RenderPassDescriptor::alloc()->init(); - rpDescriptor->colorAttachments()->object(0)->setTexture(GetImpl()->GetDrawable()->texture()); - rpDescriptor->colorAttachments()->object(0)->setLoadAction(MTL::LoadActionClear); - rpDescriptor->colorAttachments()->object(0)->setClearColor(MTL::ClearColor{ r, g, b, a }); - rpDescriptor->colorAttachments()->object(0)->setStoreAction(MTL::StoreActionStore); + auto rpDescriptor = MTL::RenderPassDescriptor::alloc()->init(); + rpDescriptor->colorAttachments()->object(0)->setTexture(GetImpl()->GetDrawable()->texture()); + rpDescriptor->colorAttachments()->object(0)->setLoadAction(MTL::LoadActionClear); + rpDescriptor->colorAttachments()->object(0)->setClearColor(MTL::ClearColor{ r, g, b, a }); + rpDescriptor->colorAttachments()->object(0)->setStoreAction(MTL::StoreActionStore); - auto rCmdEncoder = GetImpl()->GetCmdBuffer()->renderCommandEncoder(rpDescriptor); + auto rCmdEncoder = GetImpl()->GetCmdBuffer()->renderCommandEncoder(rpDescriptor); - rCmdEncoder->endEncoding(); - rpDescriptor->release(); + rCmdEncoder->endEncoding(); + rpDescriptor->release(); } void Renderer::EndFrame_METAL() { - GetImpl()->GetCmdBuffer()->presentDrawable(GetImpl()->GetDrawable()); - GetImpl()->GetCmdBuffer()->commit(); + GetImpl()->GetCmdBuffer()->presentDrawable(GetImpl()->GetDrawable()); + GetImpl()->GetCmdBuffer()->commit(); - GetImpl()->GetPoolRef()->release(); + GetImpl()->GetPoolRef()->release(); } void Renderer::Resize_METAL(u32 width, u32 height) { - GetImpl()->GetMetalLayer()->setDrawableSize(CGSize{ (f32)width, (f32)height }); + GetImpl()->GetMetalLayer()->setDrawableSize( + CGSize { (f32)width, (f32)height } + ); } METALRendererImpl* Renderer::GetImpl() const { - assert(GetAPI() == RHIType::Metal); - return static_cast(m_impl); + assert(GetAPI() == RHIType::Metal); + return static_cast(m_impl); } -} // namespace CGL::Graphics +} diff --git a/Core/Graphics/RHI/Metal/METALRendererImpl.cpp b/Core/Graphics/RHI/Metal/METALRendererImpl.cpp index c5f17f1..95a663c 100644 --- a/Core/Graphics/RHI/Metal/METALRendererImpl.cpp +++ b/Core/Graphics/RHI/Metal/METALRendererImpl.cpp @@ -2,32 +2,34 @@ #define CA_PRIVATE_IMPLEMENTATION #define MTL_PRIVATE_IMPLEMENTATION -#include "METALRendererImpl.h" #include #include #include +#include "METALRendererImpl.h" + namespace CGL::Graphics { - METALRendererImpl::METALRendererImpl(SDL_Window* window) - { - mView = SDL_Metal_CreateView(window); + METALRendererImpl::METALRendererImpl(SDL_Window* window) + { + mView = SDL_Metal_CreateView(window); + + mLayer = static_cast(SDL_Metal_GetLayer(mView)); + mLayer->setDevice(MTL::CreateSystemDefaultDevice()); + mLayer->setPixelFormat(MTL::PixelFormatRGBA8Unorm_sRGB); - mLayer = static_cast(SDL_Metal_GetLayer(mView)); - mLayer->setDevice(MTL::CreateSystemDefaultDevice()); - mLayer->setPixelFormat(MTL::PixelFormatRGBA8Unorm_sRGB); + mDevice = mLayer->device(); - mDevice = mLayer->device(); + mQueue = mDevice->newCommandQueue(); - mQueue = mDevice->newCommandQueue(); + arPool = nullptr; - arPool = nullptr; - } + } - METALRendererImpl::~METALRendererImpl() - { - mDevice->release(); - SDL_Metal_DestroyView(mView); - } + METALRendererImpl::~METALRendererImpl() + { + mDevice->release(); + SDL_Metal_DestroyView(mView); + } -} // namespace CGL::Graphics +} diff --git a/Core/Graphics/RHI/Metal/METALRendererImpl.h b/Core/Graphics/RHI/Metal/METALRendererImpl.h index bdbb6d1..edbfb78 100644 --- a/Core/Graphics/RHI/Metal/METALRendererImpl.h +++ b/Core/Graphics/RHI/Metal/METALRendererImpl.h @@ -1,46 +1,48 @@ #pragma once -#include "Core/Logging/Log.h" #include "Foundation/Foundation.hpp" #include "Metal/Metal.hpp" #include "QuartzCore/QuartzCore.hpp" + #include "SDL2/SDL_metal.h" #include "SDL2/SDL_video.h" +#include "Core/Logging/Log.h" + namespace CGL::Graphics { - CGL_DECLARE_LOG_CATEGORY(METALRendererImpl); + CGL_DECLARE_LOG_CATEGORY(METALRendererImpl); - class METALRendererImpl - { - public: - METALRendererImpl(SDL_Window* window); - ~METALRendererImpl(); + class METALRendererImpl + { + public: + METALRendererImpl(SDL_Window* window); + ~METALRendererImpl(); - inline CA::MetalLayer* GetMetalLayer() const { return mLayer; } + inline CA::MetalLayer* GetMetalLayer() const { return mLayer; } - inline MTL::Device* GetDevice() const { return mDevice; } - inline MTL::CommandQueue* GetQueue() const { return mQueue; } + inline MTL::Device* GetDevice() const { return mDevice; } + inline MTL::CommandQueue* GetQueue() const { return mQueue; } - inline void SetCmdBuffer(MTL::CommandBuffer* cBuffer) { cmdBuffer = cBuffer; } - inline MTL::CommandBuffer* GetCmdBuffer() { return cmdBuffer; } + inline void SetCmdBuffer(MTL::CommandBuffer* cBuffer) { cmdBuffer = cBuffer; } + inline MTL::CommandBuffer* GetCmdBuffer() { return cmdBuffer; } - inline NS::AutoreleasePool* GetPoolRef() const { return arPool; } + inline NS::AutoreleasePool* GetPoolRef() const { return arPool; } - inline void SetDrawable(CA::MetalDrawable* drawable) { mDrawable = drawable; } - inline CA::MetalDrawable* GetDrawable() const { return mDrawable; } + inline void SetDrawable(CA::MetalDrawable* drawable) { mDrawable = drawable; } + inline CA::MetalDrawable* GetDrawable() const { return mDrawable; } - METALRendererImpl() = delete; + METALRendererImpl() = delete; - private: - SDL_MetalView mView; - CA::MetalLayer* mLayer; - CA::MetalDrawable* mDrawable; + private: + SDL_MetalView mView; + CA::MetalLayer* mLayer; + CA::MetalDrawable* mDrawable; - MTL::Device* mDevice; - MTL::CommandQueue* mQueue; - MTL::CommandBuffer* cmdBuffer; + MTL::Device* mDevice; + MTL::CommandQueue* mQueue; + MTL::CommandBuffer* cmdBuffer; - NS::AutoreleasePool* arPool; - }; -} // namespace CGL::Graphics + NS::AutoreleasePool* arPool; + }; +} diff --git a/Core/Graphics/RHI/OpenGL/OPENGLRenderer.cpp b/Core/Graphics/RHI/OpenGL/OPENGLRenderer.cpp index b341166..b8ed2e9 100644 --- a/Core/Graphics/RHI/OpenGL/OPENGLRenderer.cpp +++ b/Core/Graphics/RHI/OpenGL/OPENGLRenderer.cpp @@ -1,9 +1,9 @@ -#include #include +#include namespace CGL::Graphics { -#ifdef CGL_RHI_OPENGL + #ifdef CGL_RHI_OPENGL void Renderer::Constructor_OPENGL(SDL_Window* window) { this->m_impl = new OPENGLRendererImpl(window); @@ -28,18 +28,18 @@ namespace CGL::Graphics void Renderer::BeginFrame_OPENGL() { glClearDepth(1.0); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } - + void Renderer::EndFrame_OPENGL() - { + { GetImpl()->SwapWindow(); } void Renderer::Resize_OPENGL(u32 width, u32 height) - { - glViewport(0, 0, width, height); - } + { + glViewport(0, 0, width, height); + } -#endif // CGL_RHI_OPENGL -} // namespace CGL::Graphics + #endif // CGL_RHI_OPENGL +} \ No newline at end of file diff --git a/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.cpp b/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.cpp index c39b14e..b559cdf 100644 --- a/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.cpp +++ b/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.cpp @@ -1,7 +1,7 @@ #include "OPENGLRendererImpl.h" namespace CGL::Graphics -{ +{ CGL_DEFINE_LOG_CATEGORY(OPENGLRendererImpl); OPENGLRendererImpl::OPENGLRendererImpl(SDL_Window* window) @@ -17,18 +17,18 @@ namespace CGL::Graphics glewExperimental = GL_TRUE; glewError = glewInit(); - + glClearColor(0.0f, 1.0f, 1.0f, 1.0f); - SDL_GL_SetSwapInterval(1); + SDL_GL_SetSwapInterval(1); } OPENGLRendererImpl::~OPENGLRendererImpl() { SDL_GL_DeleteContext(gContext); } - + void OPENGLRendererImpl::SwapWindow() { SDL_GL_SwapWindow(gWindow); } -} // namespace CGL::Graphics +} \ No newline at end of file diff --git a/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.h b/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.h index 33f4c96..3084cc0 100644 --- a/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.h +++ b/Core/Graphics/RHI/OpenGL/OPENGLRendererImpl.h @@ -1,9 +1,11 @@ #pragma once -#include "Core/Logging/Log.h" -#include "SDL2/SDL_opengl.h" #include + #include #include +#include "SDL2/SDL_opengl.h" + +#include "Core/Logging/Log.h" namespace CGL::Graphics { @@ -14,7 +16,7 @@ namespace CGL::Graphics public: explicit OPENGLRendererImpl(SDL_Window* window); ~OPENGLRendererImpl(); - + void SwapWindow(); private: @@ -22,4 +24,4 @@ namespace CGL::Graphics SDL_GLContext gContext; GLenum glewError; }; -} // namespace CGL::Graphics +} \ No newline at end of file diff --git a/Core/Graphics/Renderer.cpp b/Core/Graphics/Renderer.cpp index 123add8..223932d 100644 --- a/Core/Graphics/Renderer.cpp +++ b/Core/Graphics/Renderer.cpp @@ -4,214 +4,217 @@ namespace CGL::Graphics { - CGL_DEFINE_LOG_CATEGORY(Renderer); + CGL_DEFINE_LOG_CATEGORY(Renderer); - Renderer::Renderer(SDL_Window* window) - : m_impl(nullptr), m_clearColor({ 1.0f, 0.0f, 1.0f, 1.0f }) - { - i32 width, height; - SDL_GetWindowSize(window, &width, &height); - m_width = u32(width); - m_height = u32(height); + Renderer::Renderer(SDL_Window* window) + : m_impl(nullptr) + , m_clearColor({ 1.0f, 0.0f, 1.0f, 1.0f }) + { + i32 width, height; + SDL_GetWindowSize(window, &width, &height); + m_width = u32(width); + m_height = u32(height); #if defined(CGL_RHI_DX11) - CGL_LOG(Renderer, Debug, "Using RHI: DirectX11"); - Constructor_D3D11(window); + CGL_LOG(Renderer, Debug, "Using RHI: DirectX11"); + Constructor_D3D11(window); #elif defined(CGL_RHI_OPENGL) - CGL_LOG(Renderer, Debug, "Using RHI: OpenGL"); - Constructor_OPENGL(window); + CGL_LOG(Renderer, Debug, "Using RHI: OpenGL"); + Constructor_OPENGL(window); #elif defined(CGL_RHI_METAL) - CGL_LOG(Renderer, Debug, "Using RHI: Metal"); - Constructor_METAL(window); + CGL_LOG(Renderer, Debug, "Using RHI: Metal"); + Constructor_METAL(window); #endif - } + } - Renderer::~Renderer() - { + Renderer::~Renderer() + { #if defined(CGL_RHI_DX11) - CGL_LOG(Renderer, Info, "Destructing RHI: DirectX11"); - Destructor_D3D11(); + CGL_LOG(Renderer, Info, "Destructing RHI: DirectX11"); + Destructor_D3D11(); #elif defined(CGL_RHI_OPENGL) - CGL_LOG(Renderer, Info, "Destructing RHI: OpenGL"); - Destructor_OPENGL(); + CGL_LOG(Renderer, Info, "Destructing RHI: OpenGL"); + Destructor_OPENGL(); #elif defined(CGL_RHI_METAL) - CGL_LOG(Renderer, Info, "Destructing RHI: Metal"); - Destructor_METAL(); + CGL_LOG(Renderer, Info, "Destructing RHI: Metal"); + Destructor_METAL(); #endif - } + } - void Renderer::BeginFrame() - { + void Renderer::BeginFrame() + { #if defined(CGL_RHI_DX11) - BeginFrame_D3D11(); + BeginFrame_D3D11(); #elif defined(CGL_RHI_OPENGL) - BeginFrame_OPENGL(); + BeginFrame_OPENGL(); #elif defined(CGL_RHI_METAL_) - BeginFrame_METAL(); + BeginFrame_METAL(); #endif - } + } - void Renderer::EndFrame() - { + void Renderer::EndFrame() + { #if defined(CGL_RHI_DX11) - EndFrame_D3D11(); + EndFrame_D3D11(); #elif defined(CGL_RHI_OPENGL) - EndFrame_OPENGL(); + EndFrame_OPENGL(); #elif defined(CGL_RHI_METAL) - EndFrame_METAL(); + EndFrame_METAL(); #endif - } + } - void Renderer::Resize(u32 width, u32 height) - { - if (m_width == width && m_height == height) - { - return; - } + void Renderer::Resize(u32 width, u32 height) + { + if (m_width == width && m_height == height) + { + return; + } - m_width = width; - m_height = height; + m_width = width; + m_height = height; #if defined(CGL_RHI_DX11) - Resize_D3D11(width, height); + Resize_D3D11(width, height); #elif defined(CGL_RHI_OPENGL) - Resize_OPENGL(width, height); + Resize_OPENGL(width, height); #elif defined(CGL_RHI_METAL) - Resize_METAL(width, height); + Resize_METAL(width, height); #endif - } + } - void Renderer::SetClearColor(f32 r, f32 g, f32 b, f32 a) - { - m_clearColor = { r, g, b, a }; - } + void Renderer::SetClearColor(f32 r, f32 g, f32 b, f32 a) + { + m_clearColor = { r, g, b, a }; + } - void Renderer::SetPrimitiveTopology(PrimitiveType topology) - { + void Renderer::SetPrimitiveTopology(PrimitiveType topology) + { #if defined(CGL_RHI_DX11) - SetPrimitiveTopology_D3D11(topology); + SetPrimitiveTopology_D3D11(topology); #elif defined(CGL_RHI_OPENGL) - SetPrimitiveTopology_OPENGL(topology); + SetPrimitiveTopology_OPENGL(topology); #elif defined(CGL_RHI_METAL) - SetPrimitiveTopology_METAL(topology); + SetPrimitiveTopology_METAL(topology); #endif - } + } - void Renderer::SetVertexShader(const VertexShader& shader) - { + void Renderer::SetVertexShader(const VertexShader& shader) + { #if defined(CGL_RHI_DX11) - SetVertexShader_D3D11(shader); + SetVertexShader_D3D11(shader); #endif - } + } - void Renderer::SetPixelShader(const PixelShader& shader) - { + void Renderer::SetPixelShader(const PixelShader& shader) + { #if defined(CGL_RHI_DX11) - SetPixelShader_D3D11(shader); + SetPixelShader_D3D11(shader); #endif - } + } - void Renderer::SetMaterial(const Material& material) - { - auto& vs = material.m_vs; - auto& ps = material.m_ps; + void Renderer::SetMaterial(const Material& material) + { + auto& vs = material.m_vs; + auto& ps = material.m_ps; - // Ensure all shaders are compiled before trying to set them - assert(vs->State == ShaderState::Compiled); - assert(ps->State == ShaderState::Compiled); + // Ensure all shaders are compiled before trying to set them + assert(vs->State == ShaderState::Compiled); + assert(ps->State == ShaderState::Compiled); - SetVertexShader(vs->Shader); - SetPixelShader(ps->Shader); - } + SetVertexShader(vs->Shader); + SetPixelShader(ps->Shader); + } - void Renderer::SetVertexBuffer(const VertexBuffer& buffer) - { + void Renderer::SetVertexBuffer(const VertexBuffer& buffer) + { #if defined(CGL_RHI_DX11) - SetVertexBuffer_D3D11(buffer); + SetVertexBuffer_D3D11(buffer); #endif - } + } - void Renderer::SetIndexBuffer(const IndexBuffer& buffer) - { + void Renderer::SetIndexBuffer(const IndexBuffer& buffer) + { #if defined(CGL_RHI_DX11) - SetIndexBuffer_D3D11(buffer); + SetIndexBuffer_D3D11(buffer); #endif - } + } - bool Renderer::CompileVertexShader(const ShaderSource& source, VertexShader* outShader) - { - assert(outShader); + bool Renderer::CompileVertexShader(const ShaderSource& source, VertexShader* outShader) + { + assert(outShader); #if defined(CGL_RHI_DX11) - ShaderCompileResult result = CompileVertexShader_D3D11(source, outShader); + ShaderCompileResult result = CompileVertexShader_D3D11(source, outShader); #endif - ShaderCompiler::ReportResult(result, source.Name.data()); - return result.Status == ShaderCompileStatus::Success || result.Status == ShaderCompileStatus::HasWarnings; - } + ShaderCompiler::ReportResult(result, source.Name.data()); + return result.Status == ShaderCompileStatus::Success || + result.Status == ShaderCompileStatus::HasWarnings; + } - bool Renderer::CompilePixelShader(const ShaderSource& source, PixelShader* outShader) - { - assert(outShader); + bool Renderer::CompilePixelShader(const ShaderSource& source, PixelShader* outShader) + { + assert(outShader); #if defined(CGL_RHI_DX11) - ShaderCompileResult result = CompilePixelShader_D3D11(source, outShader); + ShaderCompileResult result = CompilePixelShader_D3D11(source, outShader); #endif - ShaderCompiler::ReportResult(result, source.Name.data()); - return result.Status == ShaderCompileStatus::Success || result.Status == ShaderCompileStatus::HasWarnings; - } + ShaderCompiler::ReportResult(result, source.Name.data()); + return result.Status == ShaderCompileStatus::Success || + result.Status == ShaderCompileStatus::HasWarnings; + } - VertexBuffer Renderer::CreateVertexBuffer(const BufferSource& source) - { + VertexBuffer Renderer::CreateVertexBuffer(const BufferSource& source) + { #if defined(CGL_RHI_DX11) - return CreateVertexBuffer_D3D11(source); + return CreateVertexBuffer_D3D11(source); #endif - } + } - IndexBuffer Renderer::CreateIndexBuffer(const BufferSource& source) - { + IndexBuffer Renderer::CreateIndexBuffer(const BufferSource& source) + { #if defined(CGL_RHI_DX11) - return CreateIndexBuffer_D3D11(source); + return CreateIndexBuffer_D3D11(source); #endif - } + } - bool Renderer::CompileMaterial(Material* material) - { - assert(material); - bool result = true; + bool Renderer::CompileMaterial(Material* material) + { + assert(material); + bool result = true; - // Compile vertex shader - assert(material->m_vs->State == ShaderState::CompilePending); - if (bool vsResult = CompileVertexShader(material->m_vs->Source, &material->m_vs->Shader)) - { - result &= vsResult; - material->m_vs->State = ShaderState::Compiled; - } + // Compile vertex shader + assert(material->m_vs->State == ShaderState::CompilePending); + if (bool vsResult = CompileVertexShader(material->m_vs->Source, &material->m_vs->Shader)) + { + result &= vsResult; + material->m_vs->State = ShaderState::Compiled; + } - // Compile pixel shader - assert(material->m_ps->State == ShaderState::CompilePending); - if (bool psResult = CompilePixelShader(material->m_ps->Source, &material->m_ps->Shader)) - { - result &= psResult; - material->m_ps->State = ShaderState::Compiled; - } + // Compile pixel shader + assert(material->m_ps->State == ShaderState::CompilePending); + if (bool psResult = CompilePixelShader(material->m_ps->Source, &material->m_ps->Shader)) + { + result &= psResult; + material->m_ps->State = ShaderState::Compiled; + } - // TODO: Add other shader types - return result; - } - - void Renderer::Draw(u32 vertexCount, u32 startVertex) - { + // TODO: Add other shader types + return result; + } + + void Renderer::Draw(u32 vertexCount, u32 startVertex) + { #if defined(CGL_RHI_DX11) - Draw_D3D11(vertexCount, startVertex); + Draw_D3D11(vertexCount, startVertex); #endif - } + } - void Renderer::DrawIndexed(u32 indexCount, u32 startIndex, u32 baseVertex) - { + void Renderer::DrawIndexed(u32 indexCount, u32 startIndex, u32 baseVertex) + { #if defined(CGL_RHI_DX11) - DrawIndexed_D3D11(indexCount, startIndex, baseVertex); + DrawIndexed_D3D11(indexCount, startIndex, baseVertex); #endif - } -} // namespace CGL::Graphics + } +} diff --git a/Core/Graphics/Renderer.h b/Core/Graphics/Renderer.h index 12843e6..ef278e4 100644 --- a/Core/Graphics/Renderer.h +++ b/Core/Graphics/Renderer.h @@ -1,112 +1,109 @@ #pragma once #include +#include +#include #include -#include #include #include -#include -#include +#include struct SDL_Window; namespace CGL::Graphics { - CGL_DECLARE_LOG_CATEGORY(Renderer); + CGL_DECLARE_LOG_CATEGORY(Renderer); #if defined(CGL_RHI_DX11) - class D3D11RendererImpl; + class D3D11RendererImpl; #elif defined(CGL_RHI_DX12) - class D3D12RendererImpl; + class D3D12RendererImpl; #elif defined(CGL_RHI_OPENGL) - class OPENGLRendererImpl; + class OPENGLRendererImpl; #elif defined(CGL_RHI_METAL) - class METALRendererImpl; + class METALRendererImpl; #elif defined(CGL_RHI_VULKAN) - class VULKANRendererImpl; + class VULKANRendererImpl; #endif - class Renderer - { - public: - explicit Renderer(SDL_Window* window); - ~Renderer(); + class Renderer + { + public: + explicit Renderer(SDL_Window* window); + ~Renderer(); - inline u32 GetWidth() const noexcept { return m_width; } - inline u32 GetHeight() const noexcept { return m_height; } + inline u32 GetWidth() const noexcept { return m_width; } + inline u32 GetHeight() const noexcept { return m_height; } - void BeginFrame(); - void EndFrame(); - void Resize(u32 width, u32 height); + void BeginFrame(); + void EndFrame(); + void Resize(u32 width, u32 height); - void SetClearColor(f32 r, f32 g, f32 b, f32 a = 1.0f); - void SetPrimitiveTopology(PrimitiveType topology); - void SetVertexShader(const VertexShader& shader); - void SetPixelShader(const PixelShader& shader); - void SetMaterial(const Material& material); - void SetVertexBuffer(const VertexBuffer& buffer); - void SetIndexBuffer(const IndexBuffer& buffer); + void SetClearColor(f32 r, f32 g, f32 b, f32 a = 1.0f); + void SetPrimitiveTopology(PrimitiveType topology); + void SetVertexShader(const VertexShader& shader); + void SetPixelShader(const PixelShader& shader); + void SetMaterial(const Material& material); + void SetVertexBuffer(const VertexBuffer& buffer); + void SetIndexBuffer(const IndexBuffer& buffer); - VertexBuffer CreateVertexBuffer(const BufferSource& source); - IndexBuffer CreateIndexBuffer(const BufferSource& source); - bool CompilePixelShader(const ShaderSource& source, PixelShader* outShader); - bool CompileVertexShader(const ShaderSource& source, VertexShader* outShader); - bool CompileMaterial(Material* material); + VertexBuffer CreateVertexBuffer(const BufferSource& source); + IndexBuffer CreateIndexBuffer(const BufferSource& source); + bool CompilePixelShader(const ShaderSource& source, PixelShader* outShader); + bool CompileVertexShader(const ShaderSource& source, VertexShader* outShader); + bool CompileMaterial(Material* material); - template - void CreateContantBuffer(const BufferSource& source, ConstantBuffer& outBuffer); - template - void SetConstantBufferData(const ConstantBuffer& buffer, const T& data); - template - void SetContantBuffer(ShaderType shaderType, u32 startSlot, const ConstantBuffer& buffer); + template void CreateContantBuffer(const BufferSource& source, ConstantBuffer& outBuffer); + template void SetConstantBufferData(const ConstantBuffer& buffer, const T& data); + template void SetContantBuffer(ShaderType shaderType, u32 startSlot, const ConstantBuffer& buffer); - void Draw(u32 vertexCount, u32 startVertex = 0); - void DrawIndexed(u32 indexCount, u32 startIndex = 0, u32 baseVertex = 0); + void Draw(u32 vertexCount, u32 startVertex = 0); + void DrawIndexed(u32 indexCount, u32 startIndex = 0, u32 baseVertex = 0); - private: + private: #if defined(CGL_RHI_DX11) - void Constructor_D3D11(SDL_Window* window); - void Destructor_D3D11(); - void BeginFrame_D3D11(); - void EndFrame_D3D11(); - void Resize_D3D11(u32 width, u32 height); - void SetPrimitiveTopology_D3D11(PrimitiveType topology); - void SetVertexShader_D3D11(const VertexShader& shader); - void SetPixelShader_D3D11(const PixelShader& shader); - void SetVertexBuffer_D3D11(const VertexBuffer& buffer); - void SetIndexBuffer_D3D11(const IndexBuffer& buffer); - ShaderCompileResult CompileVertexShader_D3D11(const ShaderSource& source, VertexShader* outShader); - ShaderCompileResult CompilePixelShader_D3D11(const ShaderSource& source, PixelShader* outShader); - void CreateContantBuffer_D3D11(const BufferSource& source, ComPtr& outBuffer); - void SetConstantBufferData_D3D11(ID3D11Buffer* buffer, const void* data, size_t size); - void SetContantBuffer_D3D11(ShaderType type, u32 startSlot, const ComPtr& buffer); - VertexBuffer CreateVertexBuffer_D3D11(const BufferSource& source); - IndexBuffer CreateIndexBuffer_D3D11(const BufferSource& source); - void Draw_D3D11(u32 vertexCount, u32 startVertex = 0); - void DrawIndexed_D3D11(u32 indexCount, u32 startIndex = 0, u32 baseVertex = 0); - D3D11RendererImpl* GetImpl() const; + void Constructor_D3D11(SDL_Window* window); + void Destructor_D3D11(); + void BeginFrame_D3D11(); + void EndFrame_D3D11(); + void Resize_D3D11(u32 width, u32 height); + void SetPrimitiveTopology_D3D11(PrimitiveType topology); + void SetVertexShader_D3D11(const VertexShader& shader); + void SetPixelShader_D3D11(const PixelShader& shader); + void SetVertexBuffer_D3D11(const VertexBuffer& buffer); + void SetIndexBuffer_D3D11(const IndexBuffer& buffer); + ShaderCompileResult CompileVertexShader_D3D11(const ShaderSource& source, VertexShader* outShader); + ShaderCompileResult CompilePixelShader_D3D11(const ShaderSource& source, PixelShader* outShader); + void CreateContantBuffer_D3D11(const BufferSource& source, ComPtr& outBuffer); + void SetConstantBufferData_D3D11(ID3D11Buffer* buffer, const void* data, size_t size); + void SetContantBuffer_D3D11(ShaderType type, u32 startSlot, const ComPtr& buffer); + VertexBuffer CreateVertexBuffer_D3D11(const BufferSource& source); + IndexBuffer CreateIndexBuffer_D3D11(const BufferSource& source); + void Draw_D3D11(u32 vertexCount, u32 startVertex = 0); + void DrawIndexed_D3D11(u32 indexCount, u32 startIndex = 0, u32 baseVertex = 0); + D3D11RendererImpl* GetImpl() const; #elif defined(CGL_RHI_OPENGL) - void Constructor_OPENGL(SDL_Window* window); - void Destructor_OPENGL(); - void BeginFrame_OPENGL(); - void EndFrame_OPENGL(); - void Resize_OPENGL(u32 width, u32 height); - OPENGLRendererImpl* GetImpl() const; + void Constructor_OPENGL(SDL_Window* window); + void Destructor_OPENGL(); + void BeginFrame_OPENGL(); + void EndFrame_OPENGL(); + void Resize_OPENGL(u32 width, u32 height); + OPENGLRendererImpl* GetImpl() const; #elif defined(CGL_RHI_METAL) - void Constructor_METAL(SDL_Window* window); - void Destructor_METAL(); - void BeginFrame_METAL(); - void EndFrame_METAL(); - void Resize_METAL(u32 width, u32 height); - METALRendererImpl* GetImpl() const; + void Constructor_METAL(SDL_Window* window); + void Destructor_METAL(); + void BeginFrame_METAL(); + void EndFrame_METAL(); + void Resize_METAL(u32 width, u32 height); + METALRendererImpl* GetImpl() const; #endif - private: - void* m_impl; - std::array m_clearColor; - u32 m_width; - u32 m_height; - }; -} // namespace CGL::Graphics + private: + void* m_impl; + std::array m_clearColor; + u32 m_width; + u32 m_height; + }; +} // Contains template bodies #include "Renderer.inl" diff --git a/Core/Graphics/Renderer.inl b/Core/Graphics/Renderer.inl index 851f080..99c0b9c 100644 --- a/Core/Graphics/Renderer.inl +++ b/Core/Graphics/Renderer.inl @@ -2,26 +2,26 @@ namespace CGL::Graphics { - template - void Renderer::CreateContantBuffer(const BufferSource& source, ConstantBuffer& outBuffer) - { + template + void Renderer::CreateContantBuffer(const BufferSource& source, ConstantBuffer& outBuffer) + { #if defined(CGL_RHI_DX11) - CreateContantBuffer_D3D11(source, outBuffer.Buffer); + CreateContantBuffer_D3D11(source, outBuffer.Buffer); #endif - } + } - template - void Renderer::SetConstantBufferData(const ConstantBuffer& buffer, const T& data) - { + template + void Renderer::SetConstantBufferData(const ConstantBuffer& buffer, const T& data) + { #if defined(CGL_RHI_DX11) - SetConstantBufferData_D3D11(buffer.Buffer.Get(), static_cast(&data), sizeof(T)); -#endif - } - template - void Renderer::SetContantBuffer(ShaderType shaderType, u32 startSlot, const ConstantBuffer& buffer) - { + SetConstantBufferData_D3D11(buffer.Buffer.Get(), static_cast(&data), sizeof(T)); +#endif + } + template + void Renderer::SetContantBuffer(ShaderType shaderType, u32 startSlot, const ConstantBuffer& buffer) + { #if defined(CGL_RHI_DX11) - SetContantBuffer_D3D11(shaderType, startSlot, buffer.Buffer); -#endif - } -} // namespace CGL::Graphics + SetContantBuffer_D3D11(shaderType, startSlot, buffer.Buffer); +#endif + } +} \ No newline at end of file diff --git a/Core/Graphics/RendererImpl.h b/Core/Graphics/RendererImpl.h index cdcff12..bbf5347 100644 --- a/Core/Graphics/RendererImpl.h +++ b/Core/Graphics/RendererImpl.h @@ -1,20 +1,18 @@ #pragma once -#if defined(CGL_RHI_DX11) + defined(CGL_RHI_DX12) + defined(CGL_RHI_OPENGL) + defined(CGL_RHI_VULKAN) + \ - defined(CGL_RHI_METAL) != \ - 1 - #error \ - "Illegal to build for multiple API's. Exactly one of CGL_RHI_DX11, CGL_RHI_DX12, CGL_RHI_OPENGL, CGL_RHI_VULKAN or CGL_RHI_METAL must be defined" +#if defined(CGL_RHI_DX11) + defined(CGL_RHI_DX12) + defined(CGL_RHI_OPENGL) + defined(CGL_RHI_VULKAN) + defined(CGL_RHI_METAL) != 1 +#error "Illegal to build for multiple API's. Exactly one of CGL_RHI_DX11, CGL_RHI_DX12, CGL_RHI_OPENGL, CGL_RHI_VULKAN or CGL_RHI_METAL must be defined" #endif + #if defined(CGL_RHI_DX11) - #include +#include #elif defined(CGL_RHI_DX12) - #include +#include #elif defined(CGL_RHI_OPENGL) - #include +#include #elif defined(CGL_RHI_VULKAN) - #include +#include #elif defined(CGL_RHI_METAL) - #include +#include #endif diff --git a/Core/Graphics/Shader/Shader.h b/Core/Graphics/Shader/Shader.h index 93ab27b..78c3e07 100644 --- a/Core/Graphics/Shader/Shader.h +++ b/Core/Graphics/Shader/Shader.h @@ -1,43 +1,43 @@ #pragma once #if defined(CGL_RHI_DX11) - #include - #include +#include +#include #endif #if defined(CGL_RHI_DX12) - #include +#include #endif #if defined(CGL_RHI_OPENGL) - #include +#include #endif #if defined(CGL_RHI_METAL) - #include +#include #endif #if defined(CGL_RHI_VULKAN) - #include +#include #endif namespace CGL::Graphics { #if defined(CGL_RHI_DX11) - using VertexShader = D3D11VertexShader; - using PixelShader = D3D11PixelShader; + using VertexShader = D3D11VertexShader; + using PixelShader = D3D11PixelShader; #elif defined(CGL_RHI_DX12) - using VertexShader = D3D12VertexShader; - using PixelShader = D3D12PixelShader; + using VertexShader = D3D12VertexShader; + using PixelShader = D3D12PixelShader; #elif defined(CGL_RHI_OPENGL) - using VertexShader = OPENGLVertexShader; - using PixelShader = OPENGLPixelShader; + using VertexShader = OPENGLVertexShader; + using PixelShader = OPENGLPixelShader; #elif defined(CGL_RHI_METAL) - using VertexShader = METALVertexShader; - using PixelShader = METALPixelShader; + using VertexShader = METALVertexShader; + using PixelShader = METALPixelShader; #elif defined(CGL_RHI_VULKAN) - using VertexShader = VULKANVertexShader; - using PixelShader = VULKANPixelShader; + using VertexShader = VULKANVertexShader; + using PixelShader = VULKANPixelShader; #else - #error Unsupported shader RHI + #error Unsupported shader RHI #endif -} // namespace CGL::Graphics +} diff --git a/Core/Graphics/Shader/ShaderCompileResult.h b/Core/Graphics/Shader/ShaderCompileResult.h index dfe7d36..8534f92 100644 --- a/Core/Graphics/Shader/ShaderCompileResult.h +++ b/Core/Graphics/Shader/ShaderCompileResult.h @@ -3,16 +3,16 @@ namespace CGL::Graphics { - enum class ShaderCompileStatus - { - Success, - Failure, - HasWarnings - }; + enum class ShaderCompileStatus + { + Success, + Failure, + HasWarnings + }; - struct ShaderCompileResult - { - ShaderCompileStatus Status; - std::string Message; - }; -} // namespace CGL::Graphics + struct ShaderCompileResult + { + ShaderCompileStatus Status; + std::string Message; + }; +} diff --git a/Core/Graphics/Shader/ShaderCompiler.cpp b/Core/Graphics/Shader/ShaderCompiler.cpp index 30f40f1..f28f59d 100644 --- a/Core/Graphics/Shader/ShaderCompiler.cpp +++ b/Core/Graphics/Shader/ShaderCompiler.cpp @@ -1,96 +1,105 @@ #include "ShaderCompiler.h" #ifdef CGL_PLATFORM_WINDOWS - #include +#include #endif namespace CGL::Graphics { - CGL_DEFINE_LOG_CATEGORY(ShaderCompiler); + CGL_DEFINE_LOG_CATEGORY(ShaderCompiler); - void ShaderCompiler::ReportResult(const ShaderCompileResult& result, const std::string& source) - { - if (result.Status == ShaderCompileStatus::Success) - { - CGL_LOG(ShaderCompiler, Info, "Successfully compiled shader: {}", source); - } - else if (result.Status == ShaderCompileStatus::Failure) - { - CGL_LOG(ShaderCompiler, Error, "Failed to compile shader: {} Error: {}", source, result.Message); - } - else if (result.Status == ShaderCompileStatus::HasWarnings) - { - CGL_LOG(ShaderCompiler, Warn, "Shader compiled with warnings: {} Warning: {}", source, result.Message); - } - else - { - CGL_LOG(ShaderCompiler, Error, "Failed to compile shader: {} Error: {}", source, result.Message); - } - } + void ShaderCompiler::ReportResult(const ShaderCompileResult& result, const std::string& source) + { + if (result.Status == ShaderCompileStatus::Success) + { + CGL_LOG(ShaderCompiler, Info, "Successfully compiled shader: {}", source); + } + else if (result.Status == ShaderCompileStatus::Failure) + { + CGL_LOG(ShaderCompiler, Error, "Failed to compile shader: {} Error: {}", source, result.Message); + } + else if (result.Status == ShaderCompileStatus::HasWarnings) + { + CGL_LOG(ShaderCompiler, Warn, "Shader compiled with warnings: {} Warning: {}", source, result.Message); + } + else + { + CGL_LOG(ShaderCompiler, Error, "Failed to compile shader: {} Error: {}", source, result.Message); + } + } #if defined(CGL_RHI_D3D) - ShaderCompileResult ShaderCompiler::Compile(const ShaderSource& shader, const CompileConfig& config, - ComPtr& outBlob) - { - ShaderCompileResult result{}; + ShaderCompileResult ShaderCompiler::Compile(const ShaderSource& shader, const CompileConfig& config, ComPtr& outBlob) + { + ShaderCompileResult result{}; - if (shader.SourceData.empty()) - { - result.Status = ShaderCompileStatus::Failure; - result.Message = "Shader file path is empty"; - return result; - } + if (shader.SourceData.empty()) + { + result.Status = ShaderCompileStatus::Failure; + result.Message = "Shader file path is empty"; + return result; + } - DWORD compileFlags = D3DCOMPILE_ENABLE_STRICTNESS; + DWORD compileFlags = D3DCOMPILE_ENABLE_STRICTNESS; - if (config.Debug) - { - compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_DEBUG_NAME_FOR_SOURCE; - } - else if (config.Optimize) - { - compileFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3; - } - else if (config.SkipValidate) - { - compileFlags |= D3DCOMPILE_SKIP_VALIDATION; - } + if (config.Debug) + { + compileFlags |= D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_DEBUG_NAME_FOR_SOURCE; + } + else if (config.Optimize) + { + compileFlags |= D3DCOMPILE_OPTIMIZATION_LEVEL3; + } + else if (config.SkipValidate) + { + compileFlags |= D3DCOMPILE_SKIP_VALIDATION; + } - ID3DBlob* errorBlob = nullptr; - ID3DBlob* shaderBlob = nullptr; + ID3DBlob* errorBlob = nullptr; + ID3DBlob* shaderBlob = nullptr; - HRESULT hr = D3DCompile(shader.SourceData.c_str(), shader.SourceData.length(), shader.Name.c_str(), - config.Defines.data(), D3D_COMPILE_STANDARD_FILE_INCLUDE, config.EntryPoint.data(), - config.Target.data(), compileFlags, 0, &shaderBlob, &errorBlob); + HRESULT hr = D3DCompile( + shader.SourceData.c_str(), + shader.SourceData.length(), + shader.Name.c_str(), + config.Defines.data(), + D3D_COMPILE_STANDARD_FILE_INCLUDE, + config.EntryPoint.data(), + config.Target.data(), + compileFlags, + 0, + &shaderBlob, + &errorBlob + ); - if (FAILED(hr) || shaderBlob == nullptr) - { - if (errorBlob) // If there was an error - { - const char* errorMsg = reinterpret_cast(errorBlob->GetBufferPointer()); - result.Message = errorMsg; - errorBlob->Release(); - } + if (FAILED(hr) || shaderBlob == nullptr) + { + if (errorBlob) // If there was an error + { + const char* errorMsg = reinterpret_cast(errorBlob->GetBufferPointer()); + result.Message = errorMsg; + errorBlob->Release(); + } - result.Status = ShaderCompileStatus::Failure; - return result; - } - else - { - if (errorBlob) // If there was a warning - { - const char* errorMsg = reinterpret_cast(errorBlob->GetBufferPointer()); - result.Message = errorMsg; - result.Status = ShaderCompileStatus::HasWarnings; - errorBlob->Release(); - } + result.Status = ShaderCompileStatus::Failure; + return result; + } + else + { + if (errorBlob) // If there was a warning + { + const char* errorMsg = reinterpret_cast(errorBlob->GetBufferPointer()); + result.Message = errorMsg; + result.Status = ShaderCompileStatus::HasWarnings; + errorBlob->Release(); + } - result.Status = ShaderCompileStatus::Success; - outBlob.Attach(shaderBlob); + result.Status = ShaderCompileStatus::Success; + outBlob.Attach(shaderBlob); - return result; - } - } + return result; + } + } #endif -} // namespace CGL::Graphics +} diff --git a/Core/Graphics/Shader/ShaderCompiler.h b/Core/Graphics/Shader/ShaderCompiler.h index bdb9b8d..a5845dd 100644 --- a/Core/Graphics/Shader/ShaderCompiler.h +++ b/Core/Graphics/Shader/ShaderCompiler.h @@ -4,34 +4,33 @@ #include #if defined(CGL_RHI_D3D) - #include - #include +#include +#include #endif namespace CGL::Graphics { - CGL_DECLARE_LOG_CATEGORY(ShaderCompiler); + CGL_DECLARE_LOG_CATEGORY(ShaderCompiler); - struct CompileConfig - { - std::string_view EntryPoint; + struct CompileConfig + { + std::string_view EntryPoint; #if defined(CGL_RHI_D3D) - std::string_view Target; - std::vector Defines; + std::string_view Target; + std::vector Defines; #endif - bool Optimize = true; - bool Debug = false; - bool SkipValidate = false; - }; + bool Optimize = true; + bool Debug = false; + bool SkipValidate = false; + }; - class ShaderCompiler - { - public: - static void ReportResult(const ShaderCompileResult& result, const std::string& source); + class ShaderCompiler + { + public: + static void ReportResult(const ShaderCompileResult& result, const std::string& source); #if defined(CGL_RHI_D3D) - static ShaderCompileResult Compile(const ShaderSource& shader, const CompileConfig& config, - ComPtr& outBlob); + static ShaderCompileResult Compile(const ShaderSource& shader, const CompileConfig& config, ComPtr& outBlob); #endif - }; -} // namespace CGL::Graphics + }; +} diff --git a/Core/Graphics/Shader/ShaderSource.h b/Core/Graphics/Shader/ShaderSource.h index bc9f5b4..4ec39a0 100644 --- a/Core/Graphics/Shader/ShaderSource.h +++ b/Core/Graphics/Shader/ShaderSource.h @@ -5,9 +5,9 @@ namespace CGL::Graphics { struct ShaderSource - { - ShaderType Type; - std::string SourceData; - std::string Name; - }; -} // namespace CGL::Graphics + { + ShaderType Type; + std::string SourceData; + std::string Name; + }; +} \ No newline at end of file diff --git a/Core/Graphics/Types.h b/Core/Graphics/Types.h index 6fe12cb..e3751a2 100644 --- a/Core/Graphics/Types.h +++ b/Core/Graphics/Types.h @@ -3,164 +3,164 @@ namespace CGL::Graphics { - enum class RHIType - { - None, - OpenGL, - DirectX11, - DirectX12, - Vulkan, - Metal - }; - - enum class PrimitiveType - { - TriangleList, - LineList, - PointList, - TriangleStrip, - LineStrip, - COUNT - }; - - enum class BlendMode - { - Replace, - Add, - Multiply, - Alpha, - AddAlpha, - PreMulAlpha, - InvDestAlpha, - Subtract, - SubtractAlpha, - COUNT - }; - - enum class CompareMode - { - Always, - Equal, - NotEqual, - Less, - LessEqual, - Greater, - GreaterEqual, - COUNT - }; - - enum class CullMode - { - None, - CCW, - CW, - COUNT - }; - - enum class FillMode - { - Solid, - Wireframe, - COUNT - }; - - enum class StencilOp - { - Keep, - Zero, - Ref, - Increment, - Decrement - }; - - enum class TextureFilterMode - { - Nearest, - Bilinear, - Trilinear, - Anisotropic, - NearestAnisotropic, - Default, - COUNT - }; - - enum class TextureAddressMode - { - Wrap, - Mirror, - Clamp, - Border, - COUNT - }; - - enum class TextureCoordinates - { - U, - V, - W, - COUNT - }; - - enum class TextureUsage - { - Static, - Dynamic, - RenderTarget, - DepthStencil - }; - - enum class ShaderType - { - Vertex, - Hull, - Domain, - Geometry, - Pixel, - Compute, - Library - }; - - enum class BufferUsage - { - Default, - Immutable, - Dynamic, - Staging, - COUNT - }; - - enum class BufferType - { - None, - Vertex, - Index, - Constant - }; - - namespace VertexTypes - { - struct Position - { - SM::Vector3 Position; - }; - - struct PositionColor - { - SM::Vector3 Position; - SM::Vector4 Color; - }; - - struct PositionTexture - { - SM::Vector3 Position; - SM::Vector2 Texture; - }; - - struct PositionColorTexture - { - SM::Vector3 Position; - SM::Vector4 Color; - SM::Vector2 Texture; - }; - } // namespace VertexTypes -} // namespace CGL::Graphics + enum class RHIType + { + None, + OpenGL, + DirectX11, + DirectX12, + Vulkan, + Metal + }; + + enum class PrimitiveType + { + TriangleList, + LineList, + PointList, + TriangleStrip, + LineStrip, + COUNT + }; + + enum class BlendMode + { + Replace, + Add, + Multiply, + Alpha, + AddAlpha, + PreMulAlpha, + InvDestAlpha, + Subtract, + SubtractAlpha, + COUNT + }; + + enum class CompareMode + { + Always, + Equal, + NotEqual, + Less, + LessEqual, + Greater, + GreaterEqual, + COUNT + }; + + enum class CullMode + { + None, + CCW, + CW, + COUNT + }; + + enum class FillMode + { + Solid, + Wireframe, + COUNT + }; + + enum class StencilOp + { + Keep, + Zero, + Ref, + Increment, + Decrement + }; + + enum class TextureFilterMode + { + Nearest, + Bilinear, + Trilinear, + Anisotropic, + NearestAnisotropic, + Default, + COUNT + }; + + enum class TextureAddressMode + { + Wrap, + Mirror, + Clamp, + Border, + COUNT + }; + + enum class TextureCoordinates + { + U, + V, + W, + COUNT + }; + + enum class TextureUsage + { + Static, + Dynamic, + RenderTarget, + DepthStencil + }; + + enum class ShaderType + { + Vertex, + Hull, + Domain, + Geometry, + Pixel, + Compute, + Library + }; + + enum class BufferUsage + { + Default, + Immutable, + Dynamic, + Staging, + COUNT + }; + + enum class BufferType + { + None, + Vertex, + Index, + Constant + }; + + namespace VertexTypes + { + struct Position + { + SM::Vector3 Position; + }; + + struct PositionColor + { + SM::Vector3 Position; + SM::Vector4 Color; + }; + + struct PositionTexture + { + SM::Vector3 Position; + SM::Vector2 Texture; + }; + + struct PositionColorTexture + { + SM::Vector3 Position; + SM::Vector4 Color; + SM::Vector2 Texture; + }; + } +} \ No newline at end of file diff --git a/Core/Logging/ILogOutput.h b/Core/Logging/ILogOutput.h index 59bccc6..8659c92 100644 --- a/Core/Logging/ILogOutput.h +++ b/Core/Logging/ILogOutput.h @@ -3,11 +3,11 @@ namespace CGL::Core { - // Abstract class for log outputs - class ILogOutput - { - public: - virtual ~ILogOutput() = default; - virtual void Write([[maybe_unused]] LogLevel level, const std::string& message) = 0; - }; -} // namespace CGL::Core + // Abstract class for log outputs + class ILogOutput + { + public: + virtual ~ILogOutput() = default; + virtual void Write([[maybe_unused]] LogLevel level, const std::string& message) = 0; + }; +} diff --git a/Core/Logging/Log.cpp b/Core/Logging/Log.cpp index c431b58..9501303 100644 --- a/Core/Logging/Log.cpp +++ b/Core/Logging/Log.cpp @@ -1,19 +1,20 @@ #include "Log.h" -#include #include +#include #include + namespace CGL::Core { - void Log::Write(LogLevel level, const LogMessage& message) - { - constexpr std::string_view levelString[] = { "[FATAL]", "[ERROR]", "[WARN]", "[INFO]", "[DEBUG]", "[TRACE]" }; - i8 levelValue = i8(level); + void Log::Write(LogLevel level, const LogMessage& message) + { + constexpr std::string_view levelString[] = { "[FATAL]", "[ERROR]", "[WARN]", "[INFO]", "[DEBUG]", "[TRACE]" }; + i8 levelValue = i8(level); - std::string outMsg = std::format("{} [{}] {}\n", levelString[levelValue], m_name, message.Payload); + std::string outMsg = std::format("{} [{}] {}\n", levelString[levelValue], m_name, message.Payload); - std::scoped_lock lock{ m_mutex }; + std::scoped_lock lock{ m_mutex }; - Utils::Singleton::Get().Write(level, outMsg); - } -} // namespace CGL::Core + Utils::Singleton::Get().Write(level, outMsg); + } +} diff --git a/Core/Logging/Log.h b/Core/Logging/Log.h index a87ae42..17ad807 100644 --- a/Core/Logging/Log.h +++ b/Core/Logging/Log.h @@ -6,102 +6,97 @@ namespace CGL::Core { - struct LogMessage - { - std::string_view Payload; - }; - - class Log - { - public: - explicit Log(std::string_view name) - : m_name(name) - { - } - - template - void Trace(const T& message, Args&&... args) - { - DispatchLog(LogLevel::Trace, message, std::forward(args)...); - } - - template - void Debug(const T& message, Args&&... args) - { - DispatchLog(LogLevel::Debug, message, std::forward(args)...); - } - - template - void Info(const T& message, Args&&... args) - { - DispatchLog(LogLevel::Info, message, std::forward(args)...); - } - - template - void Warn(const T& message, Args&&... args) - { - DispatchLog(LogLevel::Warn, message, std::forward(args)...); - } - - template - void Error(const T& message, Args&&... args) - { - DispatchLog(LogLevel::Error, message, std::forward(args)...); - } - - template - void Fatal(const T& message, Args&&... args) - { - DispatchLog(LogLevel::Fatal, message, std::forward(args)...); - } - - private: - template - void DispatchLog(LogLevel level, std::string_view message, Args&&... args) - { - std::string msg = std::vformat(std::string(message), std::make_format_args(std::forward(args)...)); - Write(level, LogMessage{ .Payload = std::string_view(msg.data(), msg.size()) }); - } - - void Write(LogLevel level, const LogMessage& message); - - private: - std::string_view m_name; - std::mutex m_mutex; - }; - -} // namespace CGL::Core + struct LogMessage + { + std::string_view Payload; + }; + + class Log + { + public: + explicit Log(std::string_view name) : m_name(name) {} + + template + void Trace(const T& message, Args&&... args) + { + DispatchLog(LogLevel::Trace, message, std::forward(args)...); + } + + template + void Debug(const T& message, Args&&... args) + { + DispatchLog(LogLevel::Debug, message, std::forward(args)...); + } + + template + void Info(const T& message, Args&&... args) + { + DispatchLog(LogLevel::Info, message, std::forward(args)...); + } + + template + void Warn(const T& message, Args&&... args) + { + DispatchLog(LogLevel::Warn, message, std::forward(args)...); + } + + template + void Error(const T& message, Args&&... args) + { + DispatchLog(LogLevel::Error, message, std::forward(args)...); + } + + template + void Fatal(const T& message, Args&&... args) + { + DispatchLog(LogLevel::Fatal, message, std::forward(args)...); + } + + private: + template + void DispatchLog(LogLevel level, std::string_view message, Args&&... args) + { + std::string msg = std::vformat(std::string(message), std::make_format_args(std::forward(args)...)); + Write(level, LogMessage{ .Payload = std::string_view(msg.data(), msg.size()) }); + } + + void Write(LogLevel level, const LogMessage& message); + + private: + std::string_view m_name; + std::mutex m_mutex; + }; + +} #define LOG_CONCATENATE(a, b) a##b -#define CGL_DECLARE_LOG_CATEGORY(Name) \ - extern struct Log##Name : public CGL::Core::Log \ - { \ - Log##Name() \ - : Log(#Name) \ - { \ - } \ - } LOG_CONCATENATE(g_Log, Name) +#define CGL_DECLARE_LOG_CATEGORY(Name) \ + extern struct Log##Name : public CGL::Core::Log \ + { \ + Log##Name() : Log(#Name) \ + { \ + } \ + } LOG_CONCATENATE(g_Log, Name) #define CGL_DECLARE_LOG_CATEGORY_INLINE(Name) \ - struct Log##Name : public CGL::Core::Log \ - { \ - Log##Name() \ - : Log(#Name) \ - { \ - } \ - } LOG_CONCATENATE(g_Log, Name) + struct Log##Name : public CGL::Core::Log \ + { \ + Log##Name() : Log(#Name) \ + { \ + } \ + } LOG_CONCATENATE(g_Log, Name) -#define CGL_DEFINE_LOG_CATEGORY(Name) Log##Name LOG_CONCATENATE(g_Log, Name) +#define CGL_DEFINE_LOG_CATEGORY(Name) Log##Name LOG_CONCATENATE(g_Log, Name) #if CGL_LOGGING_ENABLED - #define CGL_LOG(Name, Level, ...) LOG_CONCATENATE(g_Log, Name).Level(__VA_ARGS__) +#define CGL_LOG(Name, Level, ...) LOG_CONCATENATE(g_Log, Name).Level(__VA_ARGS__) #else - #define CGL_LOG(Name, Level, ...) (void)0 +#define CGL_LOG(Name, Level, ...) (void)0 #endif #if CGL_BUILD_DEBUG - #define CGL_LOG_DEBUG(Name, Level, ...) CGL_LOG(Name, Level, __VA_ARGS__) +#define CGL_LOG_DEBUG(Name, Level, ...) CGL_LOG(Name, Level, __VA_ARGS__) #else - #define CGL_LOG_DEBUG(Name, ...) (void)0 +#define CGL_LOG_DEBUG(Name, ...) (void)0 #endif diff --git a/Core/Logging/LogLevel.h b/Core/Logging/LogLevel.h index 221378e..b8078de 100644 --- a/Core/Logging/LogLevel.h +++ b/Core/Logging/LogLevel.h @@ -3,15 +3,15 @@ namespace CGL::Core { - enum class LogLevel : i8 - { - Fatal = 0, - Error = 1, - Warn = 2, - Info = 3, - Debug = 4, - Trace = 5, + enum class LogLevel : i8 + { + Fatal = 0, + Error = 1, + Warn = 2, + Info = 3, + Debug = 4, + Trace = 5, - NUM_COUNT - }; + NUM_COUNT + }; } diff --git a/Core/Logging/LogManager.cpp b/Core/Logging/LogManager.cpp index 7cbaff4..7547597 100644 --- a/Core/Logging/LogManager.cpp +++ b/Core/Logging/LogManager.cpp @@ -2,21 +2,21 @@ namespace CGL::Core { - LogManager::~LogManager() - { - m_outputs.clear(); - } + LogManager::~LogManager() + { + m_outputs.clear(); + } - void LogManager::Write(LogLevel level, const std::string& message) - { - for (auto& [name, output] : m_outputs) - { - output->Write(level, message); - } - } + void LogManager::Write(LogLevel level, const std::string& message) + { + for (auto& [name, output] : m_outputs) + { + output->Write(level, message); + } + } - const std::unordered_map>& LogManager::GetOutputs() const noexcept - { - return m_outputs; - } -} // namespace CGL::Core + const std::unordered_map>& LogManager::GetOutputs() const noexcept + { + return m_outputs; + } +} diff --git a/Core/Logging/LogManager.h b/Core/Logging/LogManager.h index b1cabb5..9cb0fa0 100644 --- a/Core/Logging/LogManager.h +++ b/Core/Logging/LogManager.h @@ -5,31 +5,31 @@ namespace CGL::Core { - class LogManager - { - public: - LogManager() = default; - ~LogManager(); + class LogManager + { + public: + LogManager() = default; + ~LogManager(); - template - void AttachOutput(std::string_view name, Args&&... args) - { - m_outputs[std::string(name)] = std::make_unique(std::forward(args)...); - } + template + void AttachOutput(std::string_view name, Args&&... args) + { + m_outputs[std::string(name)] = std::make_unique(std::forward(args)...); + } - void DetachOutput(std::string_view name) - { - auto it = m_outputs.find(std::string(name)); - if (it != m_outputs.end()) - { - m_outputs.erase(it); - } - } + void DetachOutput(std::string_view name) + { + auto it = m_outputs.find(std::string(name)); + if (it != m_outputs.end()) + { + m_outputs.erase(it); + } + } - void Write(LogLevel level, const std::string& message); - const std::unordered_map>& GetOutputs() const noexcept; + void Write(LogLevel level, const std::string& message); + const std::unordered_map>& GetOutputs() const noexcept; - private: - std::unordered_map> m_outputs; - }; -} // namespace CGL::Core + private: + std::unordered_map> m_outputs; + }; +} diff --git a/Core/Math/Math.h b/Core/Math/Math.h index 4496d82..8771f4a 100644 --- a/Core/Math/Math.h +++ b/Core/Math/Math.h @@ -2,13 +2,13 @@ // Including these to enable API conversion functions #if defined(CGL_RHI_DX11) - #include +#include #elif defined(CGL_RHI_DX12) - #include +#include #endif #include #include using namespace DirectX; -namespace SM = DirectX::SimpleMath; +namespace SM = DirectX::SimpleMath; \ No newline at end of file diff --git a/Core/Platform/Linux/Logging/LinuxLogOutput.cpp b/Core/Platform/Linux/Logging/LinuxLogOutput.cpp index 9fbc349..2b9ce18 100644 --- a/Core/Platform/Linux/Logging/LinuxLogOutput.cpp +++ b/Core/Platform/Linux/Logging/LinuxLogOutput.cpp @@ -1,84 +1,82 @@ #include "LinuxLogOutput.h" + #include "curses.h" namespace CGL::Core::Platform::Linux { - ConsoleLogOutput::ConsoleLogOutput(std::string_view name) - { - initscr(); - if (has_colors() == FALSE) - { - endwin(); - printf("Your terminal does not support color\n"); - exit(1); - } - start_color(); + ConsoleLogOutput::ConsoleLogOutput(std::string_view name) + { + initscr(); + if (has_colors() == FALSE) + { + endwin(); + printf("Your terminal does not support color\n"); + exit(1); + } + start_color(); - init_pair(0, COLOR_RED, COLOR_BLACK); // Fatal - init_pair(1, COLOR_RED | COLOR_BLUE, COLOR_BLACK); // Error - init_pair(2, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Warn - init_pair(3, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Info - init_pair(4, COLOR_GREEN | COLOR_BLUE, COLOR_BLACK); // Debug - init_pair(5, COLOR_WHITE, COLOR_BLACK); // Trace + init_pair(0, COLOR_RED, COLOR_BLACK); // Fatal + init_pair(1, COLOR_RED | COLOR_BLUE, COLOR_BLACK); // Error + init_pair(2, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Warn + init_pair(3, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Info + init_pair(4, COLOR_GREEN | COLOR_BLUE, COLOR_BLACK); // Debug + init_pair(5, COLOR_WHITE, COLOR_BLACK); // Trace - attron(COLOR_PAIR(4)); - printw("%s\n", name.data()); - attron(COLOR_PAIR(4)); - } + attron(COLOR_PAIR(4)); + printw("%s\n", name.data()); + attron(COLOR_PAIR(4)); + } - ConsoleLogOutput::~ConsoleLogOutput() - { - endwin(); - } + ConsoleLogOutput::~ConsoleLogOutput() + { + endwin(); + } - void ConsoleLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) - { - attron(COLOR_PAIR(level)); - printw(message.c_str()); - attroff(COLOR_PAIR(level)); - refresh(); - } + void ConsoleLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) + { + attron(COLOR_PAIR(level)); + printw(message.c_str()); + attroff(COLOR_PAIR(level)); + refresh(); + } - FileLogOutput::FileLogOutput(std::string_view name) - : m_name{ name } - { - file.open(std::string(m_name), std::ios::out | std::ios::trunc); + FileLogOutput::FileLogOutput(std::string_view name) + : m_name{ name } + { + file.open(std::string(m_name), std::ios::out | std::ios::trunc); - if (file.is_open()) - { - attron(COLOR_PAIR(5)); - printw("Starting Log File - %s\n", name.data()); - attroff(COLOR_PAIR(5)); - } - else - { - attron(COLOR_PAIR(1)); - printw("Failed to Open File\n"); - attroff(COLOR_PAIR(1)); - } - } + if (file.is_open()) { + attron(COLOR_PAIR(5)); + printw("Starting Log File - %s\n", name.data()); + attroff(COLOR_PAIR(5)); + } + else { + attron(COLOR_PAIR(1)); + printw("Failed to Open File\n"); + attroff(COLOR_PAIR(1)); + } + } - FileLogOutput::~FileLogOutput() - { - file.close(); - } + FileLogOutput::~FileLogOutput() + { + file.close(); + } - void FileLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) - { - if (file.is_open()) - { - file << message; - file.flush(); - } - } + void FileLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) + { + if (file.is_open()) { + file << message; + file.flush(); + } + } - CallbackLogOutput::CallbackLogOutput(std::function callback) - : m_callback(std::move(callback)) - { - } + CallbackLogOutput::CallbackLogOutput(std::function callback) + : m_callback(std::move(callback)) + { + } - void CallbackLogOutput::Write(LogLevel level, const std::string& message) - { - m_callback(level, message); - } -} // namespace CGL::Core::Platform::Linux + void CallbackLogOutput::Write(LogLevel level, const std::string& message) + { + m_callback(level, message); + } +} \ No newline at end of file diff --git a/Core/Platform/Linux/Logging/LinuxLogOutput.h b/Core/Platform/Linux/Logging/LinuxLogOutput.h index b9c11e6..009a5fe 100644 --- a/Core/Platform/Linux/Logging/LinuxLogOutput.h +++ b/Core/Platform/Linux/Logging/LinuxLogOutput.h @@ -4,40 +4,40 @@ namespace CGL::Core::Platform::Linux { - class ConsoleLogOutput : public ILogOutput - { - public: - explicit ConsoleLogOutput(std::string_view name); - ~ConsoleLogOutput(); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - }; + class ConsoleLogOutput : public ILogOutput + { + public: + explicit ConsoleLogOutput(std::string_view name); + ~ConsoleLogOutput(); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + }; - class DebugLogOutput : public ILogOutput - { - public: - DebugLogOutput() = default; - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - }; + class DebugLogOutput : public ILogOutput + { + public: + DebugLogOutput() = default; + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + }; - class FileLogOutput : public ILogOutput - { - public: - explicit FileLogOutput(std::string_view name); - ~FileLogOutput(); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + class FileLogOutput : public ILogOutput + { + public: + explicit FileLogOutput(std::string_view name); + ~FileLogOutput(); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + private: + std::string m_name; + std::ofstream file; - private: - std::string m_name; - std::ofstream file; - }; + }; - class CallbackLogOutput : public ILogOutput - { - public: - explicit CallbackLogOutput(std::function callback); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + class CallbackLogOutput : public ILogOutput + { + public: + explicit CallbackLogOutput(std::function callback); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - private: - std::function m_callback; - }; -} // namespace CGL::Core::Platform::Linux + private: + std::function m_callback; + }; +} diff --git a/Core/Platform/LogOutput.h b/Core/Platform/LogOutput.h index d2069ec..c29a9b7 100644 --- a/Core/Platform/LogOutput.h +++ b/Core/Platform/LogOutput.h @@ -1,32 +1,32 @@ #pragma once #ifdef CGL_PLATFORM_WINDOWS - #include +#include #elif CGL_PLATFORM_LINUX - #include +#include #elif CGL_PLATFORM_MACOSX - #include +#include #else - #error "LogOutput not supported on this platform" +#error "LogOutput not supported on this platform" #endif namespace CGL::Core { #ifdef CGL_PLATFORM_WINDOWS - using ConsoleLogOutput = Platform::Win32::ConsoleLogOutput; - using DebugLogOutput = Platform::Win32::DebugLogOutput; - using FileLogOutput = Platform::Win32::FileLogOutput; - using CallbackLogOutput = Platform::Win32::CallbackLogOutput; + using ConsoleLogOutput = Platform::Win32::ConsoleLogOutput; + using DebugLogOutput = Platform::Win32::DebugLogOutput; + using FileLogOutput = Platform::Win32::FileLogOutput; + using CallbackLogOutput = Platform::Win32::CallbackLogOutput; #elif CGL_PLATFORM_LINUX - using ConsoleLogOutput = Platform::Linux::ConsoleLogOutput; - using DebugLogOutput = Platform::Linux::DebugLogOutput; - using FileLogOutput = Platform::Linux::FileLogOutput; - using CallbackLogOutput = Platform::Linux::CallbackLogOutput; + using ConsoleLogOutput = Platform::Linux::ConsoleLogOutput; + using DebugLogOutput = Platform::Linux::DebugLogOutput; + using FileLogOutput = Platform::Linux::FileLogOutput; + using CallbackLogOutput = Platform::Linux::CallbackLogOutput; #elif CGL_PLATFORM_MACOSX - using ConsoleLogOutput = Platform::MacOSX::ConsoleLogOutput; - using DebugLogOutput = Platform::MacOSX::DebugLogOutput; - using FileLogOutput = Platform::MacOSX::FileLogOutput; - using CallbackLogOutput = Platform::MacOSX::CallbackLogOutput; + using ConsoleLogOutput = Platform::MacOSX::ConsoleLogOutput; + using DebugLogOutput = Platform::MacOSX::DebugLogOutput; + using FileLogOutput = Platform::MacOSX::FileLogOutput; + using CallbackLogOutput = Platform::MacOSX::CallbackLogOutput; #else - #error "No log output implementation for this platform" +#error "No log output implementation for this platform" #endif -} // namespace CGL::Core +} diff --git a/Core/Platform/MacOSX/Logging/MacOSXLogOutput.cpp b/Core/Platform/MacOSX/Logging/MacOSXLogOutput.cpp index 6a4e5c7..2ab6ae7 100644 --- a/Core/Platform/MacOSX/Logging/MacOSXLogOutput.cpp +++ b/Core/Platform/MacOSX/Logging/MacOSXLogOutput.cpp @@ -1,84 +1,82 @@ #include "MacOSXLogOutput.h" + #include "curses.h" namespace CGL::Core::Platform::MacOSX { - ConsoleLogOutput::ConsoleLogOutput(std::string_view name) - { - initscr(); - if (has_colors() == FALSE) - { - endwin(); - printf("Your terminal does not support color\n"); - exit(1); - } - start_color(); + ConsoleLogOutput::ConsoleLogOutput(std::string_view name) + { + initscr(); + if (has_colors() == FALSE) + { + endwin(); + printf("Your terminal does not support color\n"); + exit(1); + } + start_color(); - init_pair(0, COLOR_RED, COLOR_BLACK); // Fatal - init_pair(1, COLOR_RED | COLOR_BLUE, COLOR_BLACK); // Error - init_pair(2, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Warn - init_pair(3, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Info - init_pair(4, COLOR_GREEN | COLOR_BLUE, COLOR_BLACK); // Debug - init_pair(5, COLOR_WHITE, COLOR_BLACK); // Trace + init_pair(0, COLOR_RED, COLOR_BLACK); // Fatal + init_pair(1, COLOR_RED | COLOR_BLUE, COLOR_BLACK); // Error + init_pair(2, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Warn + init_pair(3, COLOR_GREEN | COLOR_BLACK, COLOR_BLACK); // Info + init_pair(4, COLOR_GREEN | COLOR_BLUE, COLOR_BLACK); // Debug + init_pair(5, COLOR_WHITE, COLOR_BLACK); // Trace - attron(COLOR_PAIR(4)); - printw("%s\n", name.data()); - attron(COLOR_PAIR(4)); - } + attron(COLOR_PAIR(4)); + printw("%s\n", name.data()); + attron(COLOR_PAIR(4)); + } - ConsoleLogOutput::~ConsoleLogOutput() - { - endwin(); - } + ConsoleLogOutput::~ConsoleLogOutput() + { + endwin(); + } - void ConsoleLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) - { - attron(COLOR_PAIR(level)); - printw(message.c_str()); - attroff(COLOR_PAIR(level)); - refresh(); - } + void ConsoleLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) + { + attron(COLOR_PAIR(level)); + printw(message.c_str()); + attroff(COLOR_PAIR(level)); + refresh(); + } - FileLogOutput::FileLogOutput(std::string_view name) - : m_name{ name } - { - file.open(std::string(m_name), std::ios::out | std::ios::trunc); + FileLogOutput::FileLogOutput(std::string_view name) + : m_name{ name } + { + file.open(std::string(m_name), std::ios::out | std::ios::trunc); - if (file.is_open()) - { - attron(COLOR_PAIR(5)); - printw("Starting Log File - %s\n", name.data()); - attroff(COLOR_PAIR(5)); - } - else - { - attron(COLOR_PAIR(1)); - printw("Failed to Open File\n"); - attroff(COLOR_PAIR(1)); - } - } + if (file.is_open()) { + attron(COLOR_PAIR(5)); + printw("Starting Log File - %s\n", name.data()); + attroff(COLOR_PAIR(5)); + } + else { + attron(COLOR_PAIR(1)); + printw("Failed to Open File\n"); + attroff(COLOR_PAIR(1)); + } + } - FileLogOutput::~FileLogOutput() - { - file.close(); - } + FileLogOutput::~FileLogOutput() + { + file.close(); + } - void FileLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) - { - if (file.is_open()) - { - file << message; - file.flush(); - } - } + void FileLogOutput::Write([[maybe_unused]] LogLevel level, const std::string& message) + { + if (file.is_open()) { + file << message; + file.flush(); + } + } - CallbackLogOutput::CallbackLogOutput(std::function callback) - : m_callback(std::move(callback)) - { - } + CallbackLogOutput::CallbackLogOutput(std::function callback) + : m_callback(std::move(callback)) + { + } - void CallbackLogOutput::Write(LogLevel level, const std::string& message) - { - m_callback(level, message); - } -} // namespace CGL::Core::Platform::MacOSX + void CallbackLogOutput::Write(LogLevel level, const std::string& message) + { + m_callback(level, message); + } +} diff --git a/Core/Platform/MacOSX/Logging/MacOSXLogOutput.h b/Core/Platform/MacOSX/Logging/MacOSXLogOutput.h index 70d9456..3465779 100644 --- a/Core/Platform/MacOSX/Logging/MacOSXLogOutput.h +++ b/Core/Platform/MacOSX/Logging/MacOSXLogOutput.h @@ -4,40 +4,40 @@ namespace CGL::Core::Platform::MacOSX { - class ConsoleLogOutput : public ILogOutput - { - public: - explicit ConsoleLogOutput(std::string_view name); - ~ConsoleLogOutput(); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - }; + class ConsoleLogOutput : public ILogOutput + { + public: + explicit ConsoleLogOutput(std::string_view name); + ~ConsoleLogOutput(); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + }; - class DebugLogOutput : public ILogOutput - { - public: - DebugLogOutput() = default; - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - }; + class DebugLogOutput : public ILogOutput + { + public: + DebugLogOutput() = default; + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + }; - class FileLogOutput : public ILogOutput - { - public: - explicit FileLogOutput(std::string_view name); - ~FileLogOutput(); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + class FileLogOutput : public ILogOutput + { + public: + explicit FileLogOutput(std::string_view name); + ~FileLogOutput(); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + private: + std::string m_name; + std::ofstream file; - private: - std::string m_name; - std::ofstream file; - }; + }; - class CallbackLogOutput : public ILogOutput - { - public: - explicit CallbackLogOutput(std::function callback); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + class CallbackLogOutput : public ILogOutput + { + public: + explicit CallbackLogOutput(std::function callback); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - private: - std::function m_callback; - }; -} // namespace CGL::Core::Platform::MacOSX + private: + std::function m_callback; + }; +} diff --git a/Core/Platform/Win32/Error/HResultError.cpp b/Core/Platform/Win32/Error/HResultError.cpp index e79d347..644fa61 100644 --- a/Core/Platform/Win32/Error/HResultError.cpp +++ b/Core/Platform/Win32/Error/HResultError.cpp @@ -4,16 +4,21 @@ namespace CGL::Platform::Win32 { - std::string GetErrorString(int errorCode) - { - char errorString[MAX_PATH]; - ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, 0, errorCode, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - errorString, MAX_PATH, NULL); + std::string GetErrorString(int errorCode) + { + char errorString[MAX_PATH]; + ::FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, + 0, + errorCode, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + errorString, + MAX_PATH, + NULL); - std::string message = "Win32 Error: "; - message += errorString; - message.erase(std::remove(message.begin(), message.end(), '\n'), message.cend()); - message.erase(std::remove(message.begin(), message.end(), '\r'), message.cend()); - return message; - } -} // namespace CGL::Platform::Win32 + std::string message = "Win32 Error: "; + message += errorString; + message.erase(std::remove(message.begin(), message.end(), '\n'), message.cend()); + message.erase(std::remove(message.begin(), message.end(), '\r'), message.cend()); + return message; + } +} diff --git a/Core/Platform/Win32/Error/HResultError.h b/Core/Platform/Win32/Error/HResultError.h index bc57db8..f0b5a70 100644 --- a/Core/Platform/Win32/Error/HResultError.h +++ b/Core/Platform/Win32/Error/HResultError.h @@ -3,5 +3,5 @@ namespace CGL::Platform::Win32 { - std::string GetErrorString(int errorCode); + std::string GetErrorString(int errorCode); } diff --git a/Core/Platform/Win32/Logging/Win32LogOutput.cpp b/Core/Platform/Win32/Logging/Win32LogOutput.cpp index 89c8984..451e650 100644 --- a/Core/Platform/Win32/Logging/Win32LogOutput.cpp +++ b/Core/Platform/Win32/Logging/Win32LogOutput.cpp @@ -3,117 +3,118 @@ namespace CGL::Core::Platform::Win32 { - namespace - { - void SetConsoleForegroundColor(HANDLE console, u16 color) - { - CONSOLE_SCREEN_BUFFER_INFO info = {}; - if (GetConsoleScreenBufferInfo(console, &info)) - { - SetConsoleTextAttribute(console, (info.wAttributes & 0xF0) | color); - } - } - - u16 GetConsoleTextAttribute(HANDLE console) - { - CONSOLE_SCREEN_BUFFER_INFO info = {}; - if (GetConsoleScreenBufferInfo(console, &info)) - { - return info.wAttributes; - } - return 0; - } - } // namespace - - ConsoleLogOutput::ConsoleLogOutput(std::string_view name) - { - // Try getting the attached console if it already exists - m_console = ::GetStdHandle(STD_OUTPUT_HANDLE); - if (m_console == INVALID_HANDLE_VALUE) - { - // No attached console found, attach - ::AllocConsole(); - } - - ::SetConsoleTitleA(name.data()); - m_console = ::GetStdHandle(STD_OUTPUT_HANDLE); - COORD co = { 80, 25 }; - ::SetConsoleScreenBufferSize(m_console, co); - } - - ConsoleLogOutput::~ConsoleLogOutput() - { - ::FreeConsole(); - } - - void ConsoleLogOutput::Write(LogLevel level, const std::string& message) - { - static constexpr std::array colors = { - FOREGROUND_RED | FOREGROUND_INTENSITY, // Fatal - FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE, // Error - FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY, // Warn - FOREGROUND_GREEN, // Info - FOREGROUND_GREEN | FOREGROUND_BLUE, // Debug - FOREGROUND_INTENSITY, // Trace - }; - - // Sanity check - if (m_console == INVALID_HANDLE_VALUE) - { - return; - } - - u16 originalColor = GetConsoleTextAttribute(m_console); - SetConsoleForegroundColor(m_console, colors[size_t(level)]); - - std::ignore = ::WriteConsoleA(m_console, message.data(), static_cast(message.size()), nullptr, nullptr); - // Restore color - SetConsoleForegroundColor(m_console, originalColor); - } - - void DebugLogOutput::Write(LogLevel level, const std::string& message) - { - UNREFERENCED_PARAMETER(level); - ::OutputDebugStringA(message.c_str()); - } - - FileLogOutput::FileLogOutput(std::string_view name) - : m_name(name), m_file(nullptr) - { - m_file = - ::CreateFileA(m_name.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - - Write(LogLevel::Info, "Starting log file: " + m_name + "\n"); - } - - FileLogOutput::~FileLogOutput() - { - if (m_file != nullptr) - { - ::FlushFileBuffers(m_file); - ::CloseHandle(m_file); - } - } - - void FileLogOutput::Write(LogLevel level, const std::string& message) - { - // Sanity check - if (m_file == nullptr) - { - return; - } - - UNREFERENCED_PARAMETER(level); - std::ignore = ::WriteFile(m_file, message.data(), static_cast(message.size()), nullptr, nullptr); - } - - CallbackLogOutput::CallbackLogOutput(std::function callback) - : m_callback(std::move(callback)) - { - } - - void CallbackLogOutput::Write(LogLevel level, const std::string& message) - { - m_callback(level, message); - } -} // namespace CGL::Core::Platform::Win32 + namespace + { + void SetConsoleForegroundColor(HANDLE console, u16 color) + { + CONSOLE_SCREEN_BUFFER_INFO info = {}; + if (GetConsoleScreenBufferInfo(console, &info)) + { + SetConsoleTextAttribute(console, (info.wAttributes & 0xF0) | color); + } + } + + u16 GetConsoleTextAttribute(HANDLE console) + { + CONSOLE_SCREEN_BUFFER_INFO info = {}; + if (GetConsoleScreenBufferInfo(console, &info)) + { + return info.wAttributes; + } + return 0; + } + } + + ConsoleLogOutput::ConsoleLogOutput(std::string_view name) + { + // Try getting the attached console if it already exists + m_console = ::GetStdHandle(STD_OUTPUT_HANDLE); + if (m_console == INVALID_HANDLE_VALUE) + { + // No attached console found, attach + ::AllocConsole(); + } + + ::SetConsoleTitleA(name.data()); + m_console = ::GetStdHandle(STD_OUTPUT_HANDLE); + COORD co = { 80,25 }; + ::SetConsoleScreenBufferSize(m_console, co); + } + + ConsoleLogOutput::~ConsoleLogOutput() + { + ::FreeConsole(); + } + + void ConsoleLogOutput::Write(LogLevel level, const std::string& message) + { + static constexpr std::array colors = + { + FOREGROUND_RED | FOREGROUND_INTENSITY, // Fatal + FOREGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE, // Error + FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY, // Warn + FOREGROUND_GREEN, // Info + FOREGROUND_GREEN | FOREGROUND_BLUE, // Debug + FOREGROUND_INTENSITY, // Trace + }; + + // Sanity check + if (m_console == INVALID_HANDLE_VALUE) + { + return; + } + + u16 originalColor = GetConsoleTextAttribute(m_console); + SetConsoleForegroundColor(m_console, colors[size_t(level)]); + + std::ignore = ::WriteConsoleA(m_console, message.data(), static_cast(message.size()), nullptr, nullptr); + // Restore color + SetConsoleForegroundColor(m_console, originalColor); + } + + void DebugLogOutput::Write(LogLevel level, const std::string& message) + { + UNREFERENCED_PARAMETER(level); + ::OutputDebugStringA(message.c_str()); + } + + FileLogOutput::FileLogOutput(std::string_view name) + : m_name(name) + , m_file(nullptr) + { + m_file = ::CreateFileA(m_name.c_str(), GENERIC_WRITE, 0, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + + Write(LogLevel::Info, "Starting log file: " + m_name + "\n"); + } + + FileLogOutput::~FileLogOutput() + { + if (m_file != nullptr) + { + ::FlushFileBuffers(m_file); + ::CloseHandle(m_file); + } + } + + void FileLogOutput::Write(LogLevel level, const std::string& message) + { + // Sanity check + if (m_file == nullptr) + { + return; + } + + UNREFERENCED_PARAMETER(level); + std::ignore = ::WriteFile(m_file, message.data(), static_cast(message.size()), nullptr, nullptr); + } + + CallbackLogOutput::CallbackLogOutput(std::function callback) + : m_callback(std::move(callback)) + { + } + + void CallbackLogOutput::Write(LogLevel level, const std::string& message) + { + m_callback(level, message); + } +} diff --git a/Core/Platform/Win32/Logging/Win32LogOutput.h b/Core/Platform/Win32/Logging/Win32LogOutput.h index 3e616c6..ddd8a01 100644 --- a/Core/Platform/Win32/Logging/Win32LogOutput.h +++ b/Core/Platform/Win32/Logging/Win32LogOutput.h @@ -5,43 +5,43 @@ namespace CGL::Core::Platform::Win32 { - class ConsoleLogOutput : public ILogOutput - { - public: - explicit ConsoleLogOutput(std::string_view name); - ~ConsoleLogOutput(); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + class ConsoleLogOutput : public ILogOutput + { + public: + explicit ConsoleLogOutput(std::string_view name); + ~ConsoleLogOutput(); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - private: - HANDLE m_console; - }; + private: + HANDLE m_console; + }; - class DebugLogOutput : public ILogOutput - { - public: - DebugLogOutput() = default; - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - }; + class DebugLogOutput : public ILogOutput + { + public: + DebugLogOutput() = default; + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + }; - class FileLogOutput : public ILogOutput - { - public: - explicit FileLogOutput(std::string_view name); - ~FileLogOutput(); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + class FileLogOutput : public ILogOutput + { + public: + explicit FileLogOutput(std::string_view name); + ~FileLogOutput(); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - private: - std::string m_name; - HANDLE m_file; - }; + private: + std::string m_name; + HANDLE m_file; + }; - class CallbackLogOutput : public ILogOutput - { - public: - explicit CallbackLogOutput(std::function callback); - void Write([[maybe_unused]] LogLevel level, const std::string& message) override; + class CallbackLogOutput : public ILogOutput + { + public: + explicit CallbackLogOutput(std::function callback); + void Write([[maybe_unused]] LogLevel level, const std::string& message) override; - private: - std::function m_callback; - }; -} // namespace CGL::Core::Platform::Win32 + private: + std::function m_callback; + }; +} diff --git a/Core/Platform/Win32/StringUtils.h b/Core/Platform/Win32/StringUtils.h index 29e58b8..24abc2b 100644 --- a/Core/Platform/Win32/StringUtils.h +++ b/Core/Platform/Win32/StringUtils.h @@ -1,30 +1,28 @@ #pragma once -#include #include +#include namespace CGL::Core::Platform::Win32 { - inline std::wstring ToWideStr(const std::string& str) noexcept - { - int cch = MultiByteToWideChar(CP_ACP, 0, str.data(), (int)str.size(), nullptr, 0); + inline std::wstring ToWideStr(const std::string& str) noexcept + { + int cch = MultiByteToWideChar(CP_ACP, 0, str.data(), (int)str.size(), nullptr, 0); - std::wstring wideStr; - wideStr.resize(cch); - ::MultiByteToWideChar(CP_ACP, 0, str.data(), (int)str.size(), wideStr.data(), cch); + std::wstring wideStr; + wideStr.resize(cch); + ::MultiByteToWideChar(CP_ACP, 0, str.data(), (int)str.size(), wideStr.data(), cch); - return wideStr; - } + return wideStr; + } - inline std::string ToNarrowStr(const std::wstring& wstr) noexcept - { - int cch = - WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), static_cast(wstr.size()), nullptr, 0, nullptr, nullptr); + inline std::string ToNarrowStr(const std::wstring& wstr) noexcept + { + int cch = WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), static_cast(wstr.size()), nullptr, 0, nullptr, nullptr); - std::string narrowStr; - narrowStr.resize(cch); - WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), static_cast(wstr.size()), &narrowStr[0], cch, nullptr, - nullptr); + std::string narrowStr; + narrowStr.resize(cch); + WideCharToMultiByte(CP_ACP, 0, wstr.c_str(), static_cast(wstr.size()), &narrowStr[0], cch, nullptr, nullptr); - return narrowStr; - } -} // namespace CGL::Core::Platform::Win32 + return narrowStr; + } +} diff --git a/Core/Types.h b/Core/Types.h index 9fd9048..1564e75 100644 --- a/Core/Types.h +++ b/Core/Types.h @@ -15,12 +15,12 @@ using u64 = uint64_t; inline constexpr u64 u64max = std::numeric_limits::max(); inline constexpr u32 u32max = std::numeric_limits::max(); inline constexpr u16 u16max = std::numeric_limits::max(); -inline constexpr u8 u8max = std::numeric_limits::max(); +inline constexpr u8 u8max = std::numeric_limits::max(); inline constexpr i64 i64max = std::numeric_limits::max(); inline constexpr i32 i32max = std::numeric_limits::max(); inline constexpr i16 i16max = std::numeric_limits::max(); -inline constexpr i8 i8max = std::numeric_limits::max(); +inline constexpr i8 i8max = std::numeric_limits::max(); using f32 = float; using f64 = double; diff --git a/Core/Utils/Singleton.h b/Core/Utils/Singleton.h index 9a0a465..a45bdb5 100644 --- a/Core/Utils/Singleton.h +++ b/Core/Utils/Singleton.h @@ -2,44 +2,51 @@ namespace CGL::Core::Utils { - template - class Singleton final - { - public: - static T& Get() noexcept { return *GetPtr(); } - - static void Destroy() noexcept - { - T* ptr = GetPtr(); - if (ptr) - { - delete ptr; - ptr = nullptr; - } - } - - static bool Exists() noexcept { return s_instanceCreated; } - - Singleton(Singleton&&) = delete; - Singleton(const Singleton&) = delete; - Singleton& operator=(Singleton&&) = delete; - Singleton& operator=(Singleton&) = delete; - - private: - static T* GetPtr() noexcept - { - static Singleton s_instance; - if (!s_instanceCreated) - { - s_instanceCreated = true; - } - return s_instance.m_obj; - } - - private: - Singleton() = default; - - T* m_obj = new T(); - static inline bool s_instanceCreated = false; - }; -} // namespace CGL::Core::Utils + template + class Singleton final + { + public: + static T& Get() noexcept + { + return *GetPtr(); + } + + static void Destroy() noexcept + { + T* ptr = GetPtr(); + if (ptr) + { + delete ptr; + ptr = nullptr; + } + } + + static bool Exists() noexcept + { + return s_instanceCreated; + } + + Singleton(Singleton&&) = delete; + Singleton(const Singleton&) = delete; + Singleton& operator=(Singleton&&) = delete; + Singleton& operator=(Singleton&) = delete; + + private: + + static T* GetPtr() noexcept + { + static Singleton s_instance; + if (!s_instanceCreated) + { + s_instanceCreated = true; + } + return s_instance.m_obj; + } + + private: + Singleton() = default; + + T* m_obj = new T(); + static inline bool s_instanceCreated = false; + }; +} diff --git a/LoadMacros.bat b/LoadMacros.bat index daea864..2569418 100644 --- a/LoadMacros.bat +++ b/LoadMacros.bat @@ -5,6 +5,7 @@ echo Loading xmake macros xmake macro --import=Scripts/Macros/BuildAllConfigs.lua BuildAllConfigs xmake macro --import=Scripts/Macros/Clean.lua Clean xmake macro --import=Scripts/Macros/DeepClean.lua DeepClean +xmake macro --import=Scripts/Macros/WatchDir.lua WatchDir xmake macro --import=Scripts/Macros/GenerateSolutionVS2022.lua GenVS xmake macro --import=Scripts/Macros/GenerateSolutionXCode.lua GenXC diff --git a/LoadMacros.sh b/LoadMacros.sh index 4f09fe8..9bf5d46 100755 --- a/LoadMacros.sh +++ b/LoadMacros.sh @@ -1,6 +1,7 @@ xmake macro --import=./Scripts/Macros/BuildAllConfigs.lua BuildAllConfigs xmake macro --import=./Scripts/Macros/Clean.lua Clean xmake macro --import=./Scripts/Macros/DeepClean.lua DeepClean +xmake macro --import=./Scripts/Macros/WatchDir.lua WatchDir if [[ "$OSTYPE" == "darwin"* ]]; then xmake macro --import=./Scripts/Macros/GenerateSolutionXCode.lua GenXCode xmake macro --import=./Scripts/Macros/macOS.lua MetalBuild diff --git a/Samples/BlankApp/BlankApp.cpp b/Samples/BlankApp/BlankApp.cpp index c989711..af96aad 100644 --- a/Samples/BlankApp/BlankApp.cpp +++ b/Samples/BlankApp/BlankApp.cpp @@ -2,46 +2,46 @@ namespace CGL { - CGL_DEFINE_LOG_CATEGORY(BlankApp); - - BlankApp::BlankApp(i32 argc, char** argv) - : Super("[CGL] Blank App", argc, argv) - { - CGL_LOG(BlankApp, Trace, "Created Blank App"); - } - - BlankApp::~BlankApp() - { - CGL_LOG(BlankApp, Trace, "Destroyed Blank App"); - } - - bool BlankApp::OnInit() - { - if (!Super::OnInit()) - return false; - - CGL_LOG(BlankApp, Info, "Initialized Blank App"); - - return true; - } - - void BlankApp::OnUpdate([[maybe_unused]] const SDL_Event& e) - { - // Update app here - } - - void BlankApp::OnRender() - { - } - - void BlankApp::OnResize(u32 width, u32 height) - { - Super::OnResize(width, height); - } - - void BlankApp::OnShutdown() - { - CGL_LOG(BlankApp, Info, "Shutting down Blank App"); - Super::OnShutdown(); - } -} // namespace CGL + CGL_DEFINE_LOG_CATEGORY(BlankApp); + + BlankApp::BlankApp(i32 argc, char** argv) + : Super("[CGL] Blank App", argc, argv) + { + CGL_LOG(BlankApp, Trace, "Created Blank App"); + } + + BlankApp::~BlankApp() + { + CGL_LOG(BlankApp, Trace, "Destroyed Blank App"); + } + + bool BlankApp::OnInit() + { + if (!Super::OnInit()) + return false; + + CGL_LOG(BlankApp, Info, "Initialized Blank App"); + + return true; + } + + void BlankApp::OnUpdate([[maybe_unused]] const SDL_Event& e) + { + // Update app here + } + + void BlankApp::OnRender() + { + } + + void BlankApp::OnResize(u32 width, u32 height) + { + Super::OnResize(width, height); + } + + void BlankApp::OnShutdown() + { + CGL_LOG(BlankApp, Info, "Shutting down Blank App"); + Super::OnShutdown(); + } +} diff --git a/Samples/BlankApp/BlankApp.h b/Samples/BlankApp/BlankApp.h index 24b344b..d88f046 100644 --- a/Samples/BlankApp/BlankApp.h +++ b/Samples/BlankApp/BlankApp.h @@ -1,25 +1,25 @@ #pragma once -#include #include +#include namespace CGL { - CGL_DECLARE_LOG_CATEGORY(BlankApp); + CGL_DECLARE_LOG_CATEGORY(BlankApp); - class BlankApp : public Core::Application - { - protected: - using Super = Core::Application; + class BlankApp : public Core::Application + { + protected: + using Super = Core::Application; - public: - BlankApp(i32 argc, char** argv); - ~BlankApp(); + public: + BlankApp(i32 argc, char** argv); + ~BlankApp(); - private: - bool OnInit() override final; - void OnUpdate(const SDL_Event& e) override final; - void OnRender() override final; - void OnResize(u32 width, u32 height) override final; - void OnShutdown() override final; - }; -} // namespace CGL + private: + bool OnInit() override final; + void OnUpdate(const SDL_Event& e) override final; + void OnRender() override final; + void OnResize(u32 width, u32 height) override final; + void OnShutdown() override final; + }; +} diff --git a/Samples/BlankApp/Main.cpp b/Samples/BlankApp/Main.cpp index 509453f..b9e3865 100644 --- a/Samples/BlankApp/Main.cpp +++ b/Samples/BlankApp/Main.cpp @@ -1,22 +1,22 @@ #include "BlankApp/BlankApp.h" -#include -#include #include +#include +#include int main(int argc, char** argv) { - using namespace CGL::Core; + using namespace CGL::Core; - auto& logManager = Utils::Singleton::Get(); - logManager.AttachOutput("ConsoleLogOutput", "CGL Log"); - logManager.AttachOutput("FileLogOutput", "BlankAppSampleLog.txt"); + auto& logManager = Utils::Singleton::Get(); + logManager.AttachOutput("ConsoleLogOutput", "CGL Log"); + logManager.AttachOutput("FileLogOutput", "BlankAppSampleLog.txt"); - { - CGL::BlankApp app(argc, argv); - app.Run(); - } + { + CGL::BlankApp app(argc, argv); + app.Run(); + } - Utils::Singleton::Destroy(); + Utils::Singleton::Destroy(); - return 0; + return 0; } diff --git a/Samples/HelloTriangle/HelloTriangle.cpp b/Samples/HelloTriangle/HelloTriangle.cpp index fce949e..6c56e63 100644 --- a/Samples/HelloTriangle/HelloTriangle.cpp +++ b/Samples/HelloTriangle/HelloTriangle.cpp @@ -3,101 +3,107 @@ namespace CGL { - CGL_DEFINE_LOG_CATEGORY(HelloTriangle); - - static constexpr byte s_vertexShader[] = { -#include "HelloTriangleVS.hlsl.h" - }; - - static constexpr byte s_pixelShader[] = { -#include "HelloTrianglePS.hlsl.h" - }; - - HelloTriangle::HelloTriangle(i32 argc, char** argv) - : Super("[CGL] Hello Triangle Sample", argc, argv) - { - CGL_LOG(HelloTriangle, Trace, "Created HelloTriangle App"); - } - HelloTriangle::~HelloTriangle() - { - CGL_LOG(HelloTriangle, Trace, "Destroyed HelloTriangle App"); - } - - bool HelloTriangle::OnInit() - { - if (!Super::OnInit()) - return false; - - GetRenderer()->SetClearColor(0.0f, 1.0f, 1.0f); - - // Define vertex shader source - Graphics::ShaderSource vsSrc; - vsSrc.SourceData = Core::DataToString(s_vertexShader, sizeof(s_vertexShader)); - vsSrc.Type = Graphics::ShaderType::Vertex; - vsSrc.Name = "HelloTriangleVS"; - - // Define pixel shader source - Graphics::ShaderSource psSrc; - psSrc.SourceData = Core::DataToString(s_pixelShader, sizeof(s_pixelShader)); - psSrc.Type = Graphics::ShaderType::Pixel; - psSrc.Name = "HelloTrianglePS"; - - // Compile material - m_material.AddSource(vsSrc); - m_material.AddSource(psSrc); - if (!GetRenderer()->CompileMaterial(&m_material)) - { - CGL_LOG(HelloTriangle, Error, "Failed to compile material for triangle"); - } - - // Define triangle vertices - constexpr std::array vertices = { - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(0.0f, 0.5f, 0.0f), - .Color = SM::Vector4(1.0f, 0.0f, 0.0f, 1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(0.5f, -0.5f, 0.0f), - .Color = SM::Vector4(0.0f, 1.0f, 0.0f, 1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(-0.5f, -0.5f, 0.0f), - .Color = SM::Vector4(0.0f, 0.0f, 1.0f, 1.0f), - }, - }; - - Graphics::BufferSource vbs; - vbs.Data = (void*)vertices.data(); - vbs.Type = Graphics::BufferType::Vertex; - vbs.TypeSize = sizeof(decltype(vertices)::value_type); - vbs.Count = u32(vertices.size()); - m_vertexBuffer = GetRenderer()->CreateVertexBuffer(vbs); - - CGL_LOG(HelloTriangle, Info, "Initialized HelloTriangle App"); - return true; - } - - void HelloTriangle::OnUpdate([[maybe_unused]] const SDL_Event& e) - { - } - - void HelloTriangle::OnRender() - { - GetRenderer()->SetPrimitiveTopology(Graphics::PrimitiveType::TriangleList); - GetRenderer()->SetMaterial(m_material); - GetRenderer()->SetVertexBuffer(m_vertexBuffer); - GetRenderer()->Draw(3, 0); - } - - void HelloTriangle::OnResize(u32 width, u32 height) - { - Super::OnResize(width, height); - } - - void HelloTriangle::OnShutdown() - { - CGL_LOG(HelloTriangle, Info, "Shutting down HelloTriangle App"); - - Super::OnShutdown(); - } -} // namespace CGL + CGL_DEFINE_LOG_CATEGORY(HelloTriangle); + + static constexpr byte s_vertexShader[] = + { + #include "HelloTriangleVS.hlsl.h" + }; + + static constexpr byte s_pixelShader[] = + { + #include "HelloTrianglePS.hlsl.h" + }; + + HelloTriangle::HelloTriangle(i32 argc, char** argv) + : Super("[CGL] Hello Triangle Sample", argc, argv) + { + CGL_LOG(HelloTriangle, Trace, "Created HelloTriangle App"); + } + HelloTriangle::~HelloTriangle() + { + CGL_LOG(HelloTriangle, Trace, "Destroyed HelloTriangle App"); + } + + bool HelloTriangle::OnInit() + { + if (!Super::OnInit()) + return false; + + GetRenderer()->SetClearColor(0.0f, 1.0f, 1.0f); + + // Define vertex shader source + Graphics::ShaderSource vsSrc; + vsSrc.SourceData = Core::DataToString(s_vertexShader, sizeof(s_vertexShader)); + vsSrc.Type = Graphics::ShaderType::Vertex; + vsSrc.Name = "HelloTriangleVS"; + + // Define pixel shader source + Graphics::ShaderSource psSrc; + psSrc.SourceData = Core::DataToString(s_pixelShader, sizeof(s_pixelShader)); + psSrc.Type = Graphics::ShaderType::Pixel; + psSrc.Name = "HelloTrianglePS"; + + // Compile material + m_material.AddSource(vsSrc); + m_material.AddSource(psSrc); + if (!GetRenderer()->CompileMaterial(&m_material)) + { + CGL_LOG(HelloTriangle, Error, "Failed to compile material for triangle"); + } + + // Define triangle vertices + constexpr std::array< Graphics::VertexTypes::PositionColor, 3> vertices = + { + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3( 0.0f, 0.5f, 0.0f ), + .Color = SM::Vector4( 1.0f, 0.0f, 0.0f, 1.0f ), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3( 0.5f, -0.5f, 0.0f ), + .Color = SM::Vector4( 0.0f, 1.0f, 0.0f, 1.0f ), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3( -0.5f, -0.5f, 0.0f ), + .Color = SM::Vector4( 0.0f, 0.0f, 1.0f, 1.0f ), + }, + }; + + Graphics::BufferSource vbs; + vbs.Data = (void*)vertices.data(); + vbs.Type = Graphics::BufferType::Vertex; + vbs.TypeSize = sizeof(decltype(vertices)::value_type); + vbs.Count = u32(vertices.size()); + m_vertexBuffer = GetRenderer()->CreateVertexBuffer(vbs); + + CGL_LOG(HelloTriangle, Info, "Initialized HelloTriangle App"); + return true; + } + + void HelloTriangle::OnUpdate([[maybe_unused]] const SDL_Event& e) + { + } + + void HelloTriangle::OnRender() + { + GetRenderer()->SetPrimitiveTopology(Graphics::PrimitiveType::TriangleList); + GetRenderer()->SetMaterial(m_material); + GetRenderer()->SetVertexBuffer(m_vertexBuffer); + GetRenderer()->Draw(3, 0); + } + + void HelloTriangle::OnResize(u32 width, u32 height) + { + Super::OnResize(width, height); + } + + void HelloTriangle::OnShutdown() + { + CGL_LOG(HelloTriangle, Info, "Shutting down HelloTriangle App"); + + Super::OnShutdown(); + } +} diff --git a/Samples/HelloTriangle/HelloTriangle.h b/Samples/HelloTriangle/HelloTriangle.h index 025e1d5..9c70e76 100644 --- a/Samples/HelloTriangle/HelloTriangle.h +++ b/Samples/HelloTriangle/HelloTriangle.h @@ -1,29 +1,29 @@ #pragma once -#include #include +#include namespace CGL { - CGL_DECLARE_LOG_CATEGORY(HelloTriangle); + CGL_DECLARE_LOG_CATEGORY(HelloTriangle); - class HelloTriangle : public Core::Application - { - protected: - using Super = Core::Application; + class HelloTriangle : public Core::Application + { + protected: + using Super = Core::Application; - public: - HelloTriangle(i32 argc, char** argv); - ~HelloTriangle(); + public: + HelloTriangle(i32 argc, char** argv); + ~HelloTriangle(); - private: - bool OnInit() override final; - void OnUpdate(const SDL_Event& e) override final; - void OnRender() override final; - void OnResize(u32 width, u32 height) override final; - void OnShutdown() override final; + private: + bool OnInit() override final; + void OnUpdate(const SDL_Event& e) override final; + void OnRender() override final; + void OnResize(u32 width, u32 height) override final; + void OnShutdown() override final; - private: - Graphics::VertexBuffer m_vertexBuffer; - Graphics::Material m_material; - }; -} // namespace CGL + private: + Graphics::VertexBuffer m_vertexBuffer; + Graphics::Material m_material; + }; +} diff --git a/Samples/HelloTriangle/Main.cpp b/Samples/HelloTriangle/Main.cpp index 0deb326..2933b75 100644 --- a/Samples/HelloTriangle/Main.cpp +++ b/Samples/HelloTriangle/Main.cpp @@ -1,22 +1,22 @@ #include "HelloTriangle/HelloTriangle.h" -#include -#include #include +#include +#include int main(int argc, char** argv) { - using namespace CGL::Core; + using namespace CGL::Core; - auto& logManager = Utils::Singleton::Get(); - logManager.AttachOutput("ConsoleLogOutput", "CGL Log"); - logManager.AttachOutput("FileLogOutput", "HelloTriangleSampleLog.txt"); + auto& logManager = Utils::Singleton::Get(); + logManager.AttachOutput("ConsoleLogOutput", "CGL Log"); + logManager.AttachOutput("FileLogOutput", "HelloTriangleSampleLog.txt"); - { - CGL::HelloTriangle app(argc, argv); - app.Run(); - } + { + CGL::HelloTriangle app(argc, argv); + app.Run(); + } - Utils::Singleton::Destroy(); + Utils::Singleton::Destroy(); - return 0; + return 0; } diff --git a/Samples/SpinningCube/Main.cpp b/Samples/SpinningCube/Main.cpp index fb1a56c..57f265a 100644 --- a/Samples/SpinningCube/Main.cpp +++ b/Samples/SpinningCube/Main.cpp @@ -1,22 +1,22 @@ #include "SpinningCube/SpinningCube.h" -#include -#include #include +#include +#include int main(int argc, char** argv) { - using namespace CGL::Core; + using namespace CGL::Core; - auto& logManager = Utils::Singleton::Get(); - logManager.AttachOutput("ConsoleLogOutput", "CGL Log"); - logManager.AttachOutput("FileLogOutput", "SpinningCubeLog.txt"); + auto& logManager = Utils::Singleton::Get(); + logManager.AttachOutput("ConsoleLogOutput", "CGL Log"); + logManager.AttachOutput("FileLogOutput", "SpinningCubeLog.txt"); - { - CGL::SpinningCube app(argc, argv); - app.Run(); - } + { + CGL::SpinningCube app(argc, argv); + app.Run(); + } - Utils::Singleton::Destroy(); + Utils::Singleton::Destroy(); - return 0; + return 0; } diff --git a/Samples/SpinningCube/SpinningCube.cpp b/Samples/SpinningCube/SpinningCube.cpp index edc0c68..ea56ee7 100644 --- a/Samples/SpinningCube/SpinningCube.cpp +++ b/Samples/SpinningCube/SpinningCube.cpp @@ -2,165 +2,186 @@ #include namespace CGL { - CGL_DEFINE_LOG_CATEGORY(SpinningCube); - - static constexpr byte s_vertexShader[] = { -#include "SpinningCubeVS.hlsl.h" - }; - - static constexpr byte s_pixelShader[] = { -#include "SpinningCubePS.hlsl.h" - }; - - SpinningCube::SpinningCube(i32 argc, char** argv) - : Super("[CGL] Spinning Cube Sample", argc, argv) - { - CGL_LOG(SpinningCube, Trace, "Created SpinningCube"); - } - - SpinningCube::~SpinningCube() - { - CGL_LOG(SpinningCube, Trace, "Destroyed SpinningCube"); - } - - bool SpinningCube::OnInit() - { - if (!Super::OnInit()) - return false; - - SM::Color color = Colors::BlanchedAlmond.v; - GetRenderer()->SetClearColor(color.R(), color.G(), color.B(), color.A()); - - // Define vertex shader source - Graphics::ShaderSource vsSrc; - vsSrc.SourceData = Core::DataToString(s_vertexShader, sizeof(s_vertexShader)); - vsSrc.Type = Graphics::ShaderType::Vertex; - vsSrc.Name = "SpinningCubeVS"; - - // Define pixel shader source - Graphics::ShaderSource psSrc; - psSrc.SourceData = Core::DataToString(s_pixelShader, sizeof(s_pixelShader)); - psSrc.Type = Graphics::ShaderType::Pixel; - psSrc.Name = "SpinningCubePS"; - - // Compile material - m_material.AddSource(vsSrc); - m_material.AddSource(psSrc); - if (!GetRenderer()->CompileMaterial(&m_material)) - { - CGL_LOG(SpinningCube, Error, "Failed to compile material for triangle"); - } - - // Define cube vertices - constexpr std::array vertices = { - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(-1.0f, 1.0f, -1.0f), - .Color = SM::Vector4(1.0f, 0.0f,0.0f, 1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(1.0f, 1.0f, -1.0f), - .Color = SM::Vector4(0.0f, 1.0f,0.0f,1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(1.0f, 1.0f, 1.0f), - .Color = SM::Vector4(0.0f, 0.0f,1.0f,1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(-1.0f, 1.0f, 1.0f), - .Color = SM::Vector4(1.0f,1.0f,0.0f,1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(-1.0f, -1.0f, -1.0f), - .Color = SM::Vector4(1.0f, 0.0f, 1.0f, 1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(1.0f, -1.0f, -1.0f), - .Color = SM::Vector4(0.0f, 1.0f,1.0f,1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(1.0f, -1.0f, 1.0f), - .Color = SM::Vector4(1.0f, 0.5f,0.0f,1.0f), - }, - Graphics::VertexTypes::PositionColor{ - .Position = SM::Vector3(-1.0f, -1.0f, 1.0f), - .Color = SM::Vector4(0.5f, 0.0f,0.5f,1.0f), - }, - }; - - Graphics::BufferSource vbs; - vbs.Data = (void*)vertices.data(); - vbs.Type = Graphics::BufferType::Vertex; - vbs.TypeSize = sizeof(decltype(vertices)::value_type); - vbs.Count = u32(vertices.size()); - m_vertexBuffer = GetRenderer()->CreateVertexBuffer(vbs); - - // Define cube indices - constexpr std::array indices = { - 3, 1, 0, 2, 1, 3, - - 0, 5, 4, 1, 5, 0, - - 3, 4, 7, 0, 4, 3, - - 1, 6, 5, 2, 6, 1, - - 2, 7, 6, 3, 7, 2, - - 6, 4, 5, 7, 4, 6, - }; - - Graphics::BufferSource ibs; - ibs.Data = (void*)indices.data(); - ibs.Type = Graphics::BufferType::Index; - ibs.TypeSize = sizeof(decltype(indices)::value_type); - ibs.Count = u32(indices.size()); - m_indexBuffer = GetRenderer()->CreateIndexBuffer(ibs); - - // Create constant buffer - Graphics::BufferSource cbs; - cbs.Type = Graphics::BufferType::Constant; - cbs.Usage = Graphics::BufferUsage::Dynamic; - cbs.TypeSize = sizeof(decltype(m_constantBuffer)::value_type); - GetRenderer()->CreateContantBuffer(cbs, m_constantBuffer); - - // Create camera - m_camera.InitAsPerspective(90, f32(GetRenderer()->GetWidth()), f32(GetRenderer()->GetHeight())); - m_camera.SetPosition({ 0.0f, 1.5f, -2.5f }); - CGL_LOG(SpinningCube, Info, "Initialized SpinningCube"); - return true; - } - - f32 time = 0.0f; - void SpinningCube::OnUpdate([[maybe_unused]] const SDL_Event& e) - { - time += 0.0001f; - FrameData data{ .World = SM::Matrix::CreateRotationY(time), - .View = m_camera.GetViewMatrix().Transpose(), - .Projection = m_camera.GetProjectionMatrix().Transpose() }; - - GetRenderer()->SetConstantBufferData(m_constantBuffer, data); - } - - void SpinningCube::OnRender() - { - GetRenderer()->SetPrimitiveTopology(Graphics::PrimitiveType::TriangleList); - GetRenderer()->SetMaterial(m_material); - GetRenderer()->SetContantBuffer(Graphics::ShaderType::Vertex, 0, m_constantBuffer); - GetRenderer()->SetVertexBuffer(m_vertexBuffer); - GetRenderer()->SetIndexBuffer(m_indexBuffer); - - GetRenderer()->DrawIndexed(m_indexBuffer.IndicesCount); - } - - void SpinningCube::OnResize(u32 width, u32 height) - { - m_camera.OnResize(width, height); - Super::OnResize(width, height); - } - - void SpinningCube::OnShutdown() - { - CGL_LOG(SpinningCube, Info, "Shutting down SpinningCube"); - Super::OnShutdown(); - } -} // namespace CGL + CGL_DEFINE_LOG_CATEGORY(SpinningCube); + + static constexpr byte s_vertexShader[] = + { + #include "SpinningCubeVS.hlsl.h" + }; + + static constexpr byte s_pixelShader[] = + { + #include "SpinningCubePS.hlsl.h" + }; + + SpinningCube::SpinningCube(i32 argc, char** argv) + : Super("[CGL] Spinning Cube Sample", argc, argv) + { + CGL_LOG(SpinningCube, Trace, "Created SpinningCube"); + } + + SpinningCube::~SpinningCube() + { + CGL_LOG(SpinningCube, Trace, "Destroyed SpinningCube"); + } + + bool SpinningCube::OnInit() + { + if (!Super::OnInit()) + return false; + + SM::Color color = Colors::BlanchedAlmond.v; + GetRenderer()->SetClearColor(color.R(), color.G(), color.B(), color.A()); + + // Define vertex shader source + Graphics::ShaderSource vsSrc; + vsSrc.SourceData = Core::DataToString(s_vertexShader, sizeof(s_vertexShader)); + vsSrc.Type = Graphics::ShaderType::Vertex; + vsSrc.Name = "SpinningCubeVS"; + + // Define pixel shader source + Graphics::ShaderSource psSrc; + psSrc.SourceData = Core::DataToString(s_pixelShader, sizeof(s_pixelShader)); + psSrc.Type = Graphics::ShaderType::Pixel; + psSrc.Name = "SpinningCubePS"; + + // Compile material + m_material.AddSource(vsSrc); + m_material.AddSource(psSrc); + if (!GetRenderer()->CompileMaterial(&m_material)) + { + CGL_LOG(SpinningCube, Error, "Failed to compile material for triangle"); + } + + // Define cube vertices + constexpr std::array< Graphics::VertexTypes::PositionColor, 8> vertices = + { + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(-1.0f, 1.0f, -1.0f), + .Color = SM::Vector4(1.0f, 0.0f, 0.0f, 1.0f), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(1.0f, 1.0f, -1.0f), + .Color = SM::Vector4(0.0f, 1.0f, 0.0f, 1.0f), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(1.0f, 1.0f, 1.0f), + .Color = SM::Vector4(0.0f, 0.0f, 1.0f, 1.0f), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(-1.0f, 1.0f, 1.0f), + .Color = SM::Vector4(1.0f, 1.0f, 0.0f, 1.0f), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(-1.0f, -1.0f, -1.0f), + .Color = SM::Vector4(1.0f, 0.0f, 1.0f, 1.0f), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(1.0f, -1.0f, -1.0f), + .Color = SM::Vector4(0.0f, 1.0f, 1.0f, 1.0f), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(1.0f, -1.0f, 1.0f), + .Color = SM::Vector4(1.0f, 0.5f, 0.0f, 1.0f), + }, + Graphics::VertexTypes::PositionColor + { + .Position = SM::Vector3(-1.0f, -1.0f, 1.0f), + .Color = SM::Vector4(0.5f, 0.0f, 0.5f, 1.0f), + }, + }; + + Graphics::BufferSource vbs; + vbs.Data = (void*)vertices.data(); + vbs.Type = Graphics::BufferType::Vertex; + vbs.TypeSize = sizeof(decltype(vertices)::value_type); + vbs.Count = u32(vertices.size()); + m_vertexBuffer = GetRenderer()->CreateVertexBuffer(vbs); + + // Define cube indices + constexpr std::array indices = + { + 3,1,0, + 2,1,3, + + 0,5,4, + 1,5,0, + + 3,4,7, + 0,4,3, + + 1,6,5, + 2,6,1, + + 2,7,6, + 3,7,2, + + 6,4,5, + 7,4,6, + }; + + Graphics::BufferSource ibs; + ibs.Data = (void*)indices.data(); + ibs.Type = Graphics::BufferType::Index; + ibs.TypeSize = sizeof(decltype(indices)::value_type); + ibs.Count = u32(indices.size()); + m_indexBuffer = GetRenderer()->CreateIndexBuffer(ibs); + + // Create constant buffer + Graphics::BufferSource cbs; + cbs.Type = Graphics::BufferType::Constant; + cbs.Usage = Graphics::BufferUsage::Dynamic; + cbs.TypeSize = sizeof(decltype(m_constantBuffer)::value_type); + GetRenderer()->CreateContantBuffer(cbs, m_constantBuffer); + + // Create camera + m_camera.InitAsPerspective(90, f32(GetRenderer()->GetWidth()), f32(GetRenderer()->GetHeight())); + m_camera.SetPosition({0.0f, 1.5f, -2.5f}); + CGL_LOG(SpinningCube, Info, "Initialized SpinningCube"); + return true; + } + + f32 time = 0.0f; + void SpinningCube::OnUpdate([[maybe_unused]] const SDL_Event& e) + { + time += 0.0001f; + FrameData data + { + .World = SM::Matrix::CreateRotationY(time), + .View = m_camera.GetViewMatrix().Transpose(), + .Projection = m_camera.GetProjectionMatrix().Transpose() + }; + + GetRenderer()->SetConstantBufferData(m_constantBuffer, data); + } + + void SpinningCube::OnRender() + { + GetRenderer()->SetPrimitiveTopology(Graphics::PrimitiveType::TriangleList); + GetRenderer()->SetMaterial(m_material); + GetRenderer()->SetContantBuffer(Graphics::ShaderType::Vertex, 0, m_constantBuffer); + GetRenderer()->SetVertexBuffer(m_vertexBuffer); + GetRenderer()->SetIndexBuffer(m_indexBuffer); + + GetRenderer()->DrawIndexed(m_indexBuffer.IndicesCount); + } + + void SpinningCube::OnResize(u32 width, u32 height) + { + m_camera.OnResize(width, height); + Super::OnResize(width, height); + } + + void SpinningCube::OnShutdown() + { + CGL_LOG(SpinningCube, Info, "Shutting down SpinningCube"); + Super::OnShutdown(); + } +} diff --git a/Samples/SpinningCube/SpinningCube.h b/Samples/SpinningCube/SpinningCube.h index 2b536b5..2e8c860 100644 --- a/Samples/SpinningCube/SpinningCube.h +++ b/Samples/SpinningCube/SpinningCube.h @@ -1,40 +1,40 @@ #pragma once -#include #include +#include #include namespace CGL { - CGL_DECLARE_LOG_CATEGORY(SpinningCube); + CGL_DECLARE_LOG_CATEGORY(SpinningCube); - struct FrameData - { - SM::Matrix World; - SM::Matrix View; - SM::Matrix Projection; - }; + struct FrameData + { + SM::Matrix World; + SM::Matrix View; + SM::Matrix Projection; + }; - class SpinningCube : public Core::Application - { - protected: - using Super = Core::Application; + class SpinningCube : public Core::Application + { + protected: + using Super = Core::Application; - public: - SpinningCube(i32 argc, char** argv); - ~SpinningCube(); + public: + SpinningCube(i32 argc, char** argv); + ~SpinningCube(); - private: - bool OnInit() override final; - void OnUpdate(const SDL_Event& e) override final; - void OnRender() override final; - void OnResize(u32 width, u32 height) override final; - void OnShutdown() override final; + private: + bool OnInit() override final; + void OnUpdate(const SDL_Event& e) override final; + void OnRender() override final; + void OnResize(u32 width, u32 height) override final; + void OnShutdown() override final; - private: - Graphics::ConstantBuffer m_constantBuffer; - Graphics::VertexBuffer m_vertexBuffer; - Graphics::IndexBuffer m_indexBuffer; - Graphics::Material m_material; - Graphics::Camera m_camera; - }; -} // namespace CGL + private: + Graphics::ConstantBuffer m_constantBuffer; + Graphics::VertexBuffer m_vertexBuffer; + Graphics::IndexBuffer m_indexBuffer; + Graphics::Material m_material; + Graphics::Camera m_camera; + }; +} diff --git a/Scripts/Macros/WatchDir.lua b/Scripts/Macros/WatchDir.lua new file mode 100644 index 0000000..87e0f51 --- /dev/null +++ b/Scripts/Macros/WatchDir.lua @@ -0,0 +1,4 @@ +function main(argv) + print("Enabling xmake watch...") + os.exec("xmake watch -d \"Core/*;Samples/*;Scripts/*\"") +end