From a3aa708b3402b0ab86c15f89ccc6df2c88a94b74 Mon Sep 17 00:00:00 2001 From: Kah Wei Date: Sun, 18 Sep 2022 00:49:27 +0800 Subject: [PATCH] Fixed numerous template errors and warnings --- .../Graphics/MiddleEnd/Batching/SHBatch.cpp | 1 + .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 20 ++-- .../MiddleEnd/Interface/SHMeshLibrary.h | 2 +- .../MiddleEnd/Interface/SHRenderer.cpp | 8 +- .../Graphics/MiddleEnd/Interface/SHRenderer.h | 100 +++++++++--------- .../Graphics/MiddleEnd/Interface/SHViewport.h | 2 +- .../MiddleEnd/Pipeline/SHPipelineLibrary.cpp | 2 + .../MiddleEnd/Pipeline/SHPipelineLibrary.h | 11 +- SHADE_Engine/src/Resource/Handle.h | 27 +++++ SHADE_Engine/src/Resource/Handle.hpp | 20 ++++ 10 files changed, 116 insertions(+), 77 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp index 0a38e40b..a4d3cb50 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Batching/SHBatch.cpp @@ -14,6 +14,7 @@ of DigiPen Institute of Technology is prohibited. #include "SHBatch.h" #include "Graphics/Commands/SHVkCommandBuffer.h" +#include "Graphics/Buffers/SHVkBuffer.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" #include "Graphics/Devices/SHVkLogicalDevice.h" diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 893ea182..0e44ac8e 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -100,13 +100,13 @@ namespace SHADE // Set Up Cameras screenCamera = resourceManager.Create(); screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); - screenCamera->SetOrthographic(windowDims.first, windowDims.second, 0.01f, 100.0f); + screenCamera->SetOrthographic(static_cast(windowDims.first), static_cast(windowDims.second), 0.01f, 100.0f); worldCamera = resourceManager.Create(); worldCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); - worldCamera->SetPerspective(90.0f, windowDims.first, windowDims.second, 0.0f, 100.0f); + worldCamera->SetPerspective(90.0f, static_cast(windowDims.first), static_cast(windowDims.second), 0.0f, 100.0f); // Create Default Viewport - defaultViewport = AddViewport(vk::Viewport(0, 0, window->GetWindowSize().first, window->GetWindowSize().second, 0.0f, 1.0f)); + defaultViewport = AddViewport(vk::Viewport(0.0f, 0.0f, window->GetWindowSize().first, window->GetWindowSize().second, 0.0f, 1.0f)); // Create Debug Renderers debugScreenRenderer = defaultViewport->AddRenderer(resourceManager); @@ -171,7 +171,7 @@ namespace SHADE */ /***************************************************************************/ - void SHGraphicsSystem::Run(double dt) noexcept + void SHGraphicsSystem::Run(double) noexcept { // Frame data for the current frame auto const& frameData = renderContext.GetCurrentFrameData(); @@ -182,13 +182,13 @@ namespace SHADE // For every viewport for (int vpIndex = 0; vpIndex < static_cast(viewports.size()); ++vpIndex) { - auto const& renderers = viewports[vpIndex]->GetRenderers(); + auto& renderers = viewports[vpIndex]->GetRenderers(); // For every renderer for (int renIndex = 0; renIndex < static_cast(renderers.size()); ++renIndex) { // Draw first - renderers[renIndex]->Draw(renderContext.GetCurrentFrame()); + renderers[renIndex]->Draw(renderContext.GetCurrentFrame()); // get render graph auto rg = renderers[renIndex]->GetRenderGraph(); @@ -328,11 +328,11 @@ namespace SHADE Handle pipeline = pipelineLibrary.GetDrawPipline(shaderPair); if (!pipeline) { - pipeline = pipelineLibrary.CreateDrawPipeline - ( - shaderPair, + /*pipeline = pipelineLibrary.CreateDrawPipeline + ( + shaderPair, - ); + );*/ } // Create material diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h index ffebb74d..e9923385 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMeshLibrary.h @@ -104,7 +104,7 @@ namespace SHADE */ /*******************************************************************************/ - Handle AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices); + Handle AddMesh(uint32_t vertexCount, const SHMesh::VertexPosition* const positions, const SHMesh::VertexTexCoord* const texCoords, const SHMesh::VertexTangent* const tangents, const SHMesh::VertexNormal* const normals, uint32_t indexCount, const SHMesh::Index* const indices); /*******************************************************************************/ /*! diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp index 6a5b86e3..ab6a97d2 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.cpp @@ -25,12 +25,10 @@ namespace SHADE /* Constructor/Destructors */ /*---------------------------------------------------------------------------------*/ SHRenderer::SHRenderer(Handle viewport, ResourceManager& resourceManager) - : renderGraph{resourceManager.Create ()} + : viewport { viewport } + , renderGraph { resourceManager.Create ()} { - } - SHRenderer::~SHRenderer() - { } /*-----------------------------------------------------------------------------*/ @@ -44,7 +42,7 @@ namespace SHADE /*---------------------------------------------------------------------------------*/ /* Drawing Functions */ /*---------------------------------------------------------------------------------*/ - void SHRenderer::Draw(uint32_t frameIndex) const noexcept + void SHRenderer::Draw(uint32_t frameIndex) noexcept { renderGraph->Execute(frameIndex); } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h index 7bc143e6..ed0c6ec3 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHRenderer.h @@ -22,59 +22,59 @@ of DigiPen Institute of Technology is prohibited. namespace SHADE { - /*---------------------------------------------------------------------------------*/ - /* Forward Declarations */ - /*---------------------------------------------------------------------------------*/ - class SHVkBuffer; - class SHVkRenderpass; - class SHVkFramebuffer; - class SHMaterial; - class SHVkLogicalDevice; - class SHViewport; - class SHVkImageView; - class SHVkCommandBuffer; - class SHCamera; + /*---------------------------------------------------------------------------------*/ + /* Forward Declarations */ + /*---------------------------------------------------------------------------------*/ + class SHVkBuffer; + class SHVkRenderpass; + class SHVkFramebuffer; + class SHMaterial; + class SHVkLogicalDevice; + class SHViewport; + class SHVkImageView; + class SHVkCommandBuffer; + class SHCamera; - /*---------------------------------------------------------------------------------*/ - /* Type Definitions */ - /*---------------------------------------------------------------------------------*/ - /***********************************************************************************/ - /*! - \brief - Brings together a set of Cameras and objects with various Pipelines to render - them as part of a set. Multiple Renderers can exist to render objects differently - in a separate step. - */ - /***********************************************************************************/ - class SHRenderer - { - public: - /*-----------------------------------------------------------------------------*/ - /* Constructor/Destructors */ - /*-----------------------------------------------------------------------------*/ - SHRenderer(Handle viewport, ResourceManager& resourceManager); - ~SHRenderer(); + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + /***********************************************************************************/ + /*! + \brief + Brings together a set of Cameras and objects with various Pipelines to render + them as part of a set. Multiple Renderers can exist to render objects differently + in a separate step. + */ + /***********************************************************************************/ + class SHRenderer + { + public: + /*-----------------------------------------------------------------------------*/ + /* Constructor/Destructors */ + /*-----------------------------------------------------------------------------*/ + SHRenderer(Handle viewport, ResourceManager& resourceManager); - /*-----------------------------------------------------------------------------*/ - /* Camera Registration */ - /*-----------------------------------------------------------------------------*/ - void SetCamera(Handle _camera); + /*-----------------------------------------------------------------------------*/ + /* Camera Registration */ + /*-----------------------------------------------------------------------------*/ + void SetCamera(Handle _camera); - /*-----------------------------------------------------------------------------*/ - /* Drawing Functions */ - /*-----------------------------------------------------------------------------*/ - void Draw(uint32_t frameIndex) const noexcept; + /*-----------------------------------------------------------------------------*/ + /* Drawing Functions */ + /*-----------------------------------------------------------------------------*/ + void Draw(uint32_t frameIndex) noexcept; - /*-----------------------------------------------------------------------------*/ - /* Setters and Getters */ - /*-----------------------------------------------------------------------------*/ - Handle GetRenderGraph (void) const noexcept; + /*-----------------------------------------------------------------------------*/ + /* Setters and Getters */ + /*-----------------------------------------------------------------------------*/ + Handle GetRenderGraph (void) const noexcept; - private: - /*-----------------------------------------------------------------------------*/ - /* Data Members */ - /*-----------------------------------------------------------------------------*/ - Handle camera; - Handle renderGraph; - }; + private: + /*-----------------------------------------------------------------------------*/ + /* Data Members */ + /*-----------------------------------------------------------------------------*/ + Handle viewport; + Handle camera; + Handle renderGraph; + }; } diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h index e970e32c..33179477 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHViewport.h @@ -67,7 +67,7 @@ namespace SHADE float GetHeight() const { return viewport.height; } float GetMinDepth() const { return viewport.minDepth; } float GetMaxDepth() const { return viewport.maxDepth; } - const std::vector>& GetRenderers() const { return renderers; } + std::vector>& GetRenderers() { return renderers; } private: diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp index ed3900d5..7e9c2cbd 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.cpp @@ -25,6 +25,8 @@ namespace SHADE // Emplace the new pipeline pipelines.emplace (vsFsPair, newPipeline); + + return newPipeline; } void SHPipelineLibrary::Init(Handle device, SHVertexInputState const* viState, std::vector> const* globalLayouts) noexcept diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h index 52cb8e9c..c2a5a916 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Pipeline/SHPipelineLibrary.h @@ -4,7 +4,6 @@ #include "Graphics/Shaders/SHVkShaderModule.h" #include "Graphics/Pipeline/SHVkPipeline.h" - namespace SHADE { class SHVRenderpass; @@ -18,20 +17,12 @@ namespace SHADE { private: // TOOD: Move this somewhere eventually. Can use for other things - struct SHHandlePairHash - { - template - std::size_t operator() (std::pair const& pair) const - { - return std::hash(pair.first.GetId()) ^ std::hash(pair.second.GetId()); - } - }; //! Logical Device required for creation of pipelines Handle logicalDevice; //! a map of pipelines that are hashed using a pair of shader module handles - std::unordered_map, Handle>, Handle, SHHandlePairHash> pipelines; + std::unordered_map, Handle>, Handle> pipelines; //! Default vertex input state for pipeline creation SHVertexInputState const* vertexInputState; diff --git a/SHADE_Engine/src/Resource/Handle.h b/SHADE_Engine/src/Resource/Handle.h index c56e29bd..a0272290 100644 --- a/SHADE_Engine/src/Resource/Handle.h +++ b/SHADE_Engine/src/Resource/Handle.h @@ -190,6 +190,33 @@ namespace SHADE /*-----------------------------------------------------------------------------*/ Handle handle; }; + +} + +namespace std +{ + /*---------------------------------------------------------------------------------*/ + /* Type Definitions */ + /*---------------------------------------------------------------------------------*/ + /// + /// std::hash template specialization for Handle + /// + /// Type for the Handle. + template + struct hash> + { + std::size_t operator() (const SHADE::Handle& hdl) const; + }; + /// + /// std::hash template specialization for std::pair, Handle> + /// + /// Type for the first Handle. + /// Type for the second Handle. + template + struct hash, SHADE::Handle>> + { + std::size_t operator() (std::pair, SHADE::Handle> const& pair) const; + }; } #include "Handle.hpp" \ No newline at end of file diff --git a/SHADE_Engine/src/Resource/Handle.hpp b/SHADE_Engine/src/Resource/Handle.hpp index 64918e0f..27cdd1cd 100644 --- a/SHADE_Engine/src/Resource/Handle.hpp +++ b/SHADE_Engine/src/Resource/Handle.hpp @@ -95,3 +95,23 @@ namespace SHADE handle = hdl; } } + +namespace std +{ + /*---------------------------------------------------------------------------------*/ + /* std::hash Template Specializations */ + /*---------------------------------------------------------------------------------*/ + template + std::size_t hash>::operator()(const SHADE::Handle& hdl) const + { + return std::hash{}(hdl.GetId().Raw); + } + + template + std::size_t hash, SHADE::Handle>>::operator()( + std::pair, SHADE::Handle> const& pair) const + { + + return std::hash{}(pair.first.GetId().Raw) ^ std::hash{}(pair.second.GetId().Raw); + } +}