Fixed numerous template errors and warnings

This commit is contained in:
Kah Wei 2022-09-18 00:49:27 +08:00
parent 6e4d6abd1c
commit a3aa708b34
10 changed files with 116 additions and 77 deletions

View File

@ -14,6 +14,7 @@ of DigiPen Institute of Technology is prohibited.
#include "SHBatch.h" #include "SHBatch.h"
#include "Graphics/Commands/SHVkCommandBuffer.h" #include "Graphics/Commands/SHVkCommandBuffer.h"
#include "Graphics/Buffers/SHVkBuffer.h"
#include "Graphics/MiddleEnd/Interface/SHRenderable.h" #include "Graphics/MiddleEnd/Interface/SHRenderable.h"
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" #include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
#include "Graphics/Devices/SHVkLogicalDevice.h" #include "Graphics/Devices/SHVkLogicalDevice.h"

View File

@ -100,13 +100,13 @@ namespace SHADE
// Set Up Cameras // Set Up Cameras
screenCamera = resourceManager.Create<SHCamera>(); screenCamera = resourceManager.Create<SHCamera>();
screenCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); 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<float>(windowDims.first), static_cast<float>(windowDims.second), 0.01f, 100.0f);
worldCamera = resourceManager.Create<SHCamera>(); worldCamera = resourceManager.Create<SHCamera>();
worldCamera->SetLookAt(SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, 1.0f), SHVec3(0.0f, 1.0f, 0.0f)); 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<float>(windowDims.first), static_cast<float>(windowDims.second), 0.0f, 100.0f);
// Create Default Viewport // 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 // Create Debug Renderers
debugScreenRenderer = defaultViewport->AddRenderer(resourceManager); 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 // Frame data for the current frame
auto const& frameData = renderContext.GetCurrentFrameData(); auto const& frameData = renderContext.GetCurrentFrameData();
@ -182,7 +182,7 @@ namespace SHADE
// For every viewport // For every viewport
for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex) for (int vpIndex = 0; vpIndex < static_cast<int>(viewports.size()); ++vpIndex)
{ {
auto const& renderers = viewports[vpIndex]->GetRenderers(); auto& renderers = viewports[vpIndex]->GetRenderers();
// For every renderer // For every renderer
for (int renIndex = 0; renIndex < static_cast<int>(renderers.size()); ++renIndex) for (int renIndex = 0; renIndex < static_cast<int>(renderers.size()); ++renIndex)
@ -328,11 +328,11 @@ namespace SHADE
Handle<SHVkPipeline> pipeline = pipelineLibrary.GetDrawPipline(shaderPair); Handle<SHVkPipeline> pipeline = pipelineLibrary.GetDrawPipline(shaderPair);
if (!pipeline) if (!pipeline)
{ {
pipeline = pipelineLibrary.CreateDrawPipeline /*pipeline = pipelineLibrary.CreateDrawPipeline
( (
shaderPair, shaderPair,
); );*/
} }
// Create material // Create material

View File

@ -104,7 +104,7 @@ namespace SHADE
*/ */
/*******************************************************************************/ /*******************************************************************************/
Handle<SHMesh> 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<SHMesh> 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);
/*******************************************************************************/ /*******************************************************************************/
/*! /*!

View File

@ -25,12 +25,10 @@ namespace SHADE
/* Constructor/Destructors */ /* Constructor/Destructors */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
SHRenderer::SHRenderer(Handle<SHViewport> viewport, ResourceManager& resourceManager) SHRenderer::SHRenderer(Handle<SHViewport> viewport, ResourceManager& resourceManager)
: renderGraph{resourceManager.Create<SHRenderGraph> ()} : viewport { viewport }
, renderGraph { resourceManager.Create<SHRenderGraph> ()}
{ {
}
SHRenderer::~SHRenderer()
{
} }
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
@ -44,7 +42,7 @@ namespace SHADE
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Drawing Functions */ /* Drawing Functions */
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
void SHRenderer::Draw(uint32_t frameIndex) const noexcept void SHRenderer::Draw(uint32_t frameIndex) noexcept
{ {
renderGraph->Execute(frameIndex); renderGraph->Execute(frameIndex);
} }

View File

@ -53,7 +53,6 @@ namespace SHADE
/* Constructor/Destructors */ /* Constructor/Destructors */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
SHRenderer(Handle<SHViewport> viewport, ResourceManager& resourceManager); SHRenderer(Handle<SHViewport> viewport, ResourceManager& resourceManager);
~SHRenderer();
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Camera Registration */ /* Camera Registration */
@ -63,7 +62,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Drawing Functions */ /* Drawing Functions */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
void Draw(uint32_t frameIndex) const noexcept; void Draw(uint32_t frameIndex) noexcept;
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Setters and Getters */ /* Setters and Getters */
@ -74,6 +73,7 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Data Members */ /* Data Members */
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
Handle<SHViewport> viewport;
Handle<SHCamera> camera; Handle<SHCamera> camera;
Handle<SHRenderGraph> renderGraph; Handle<SHRenderGraph> renderGraph;
}; };

View File

@ -67,7 +67,7 @@ namespace SHADE
float GetHeight() const { return viewport.height; } float GetHeight() const { return viewport.height; }
float GetMinDepth() const { return viewport.minDepth; } float GetMinDepth() const { return viewport.minDepth; }
float GetMaxDepth() const { return viewport.maxDepth; } float GetMaxDepth() const { return viewport.maxDepth; }
const std::vector<Handle<SHRenderer>>& GetRenderers() const { return renderers; } std::vector<Handle<SHRenderer>>& GetRenderers() { return renderers; }
private: private:

View File

@ -25,6 +25,8 @@ namespace SHADE
// Emplace the new pipeline // Emplace the new pipeline
pipelines.emplace (vsFsPair, newPipeline); pipelines.emplace (vsFsPair, newPipeline);
return newPipeline;
} }
void SHPipelineLibrary::Init(Handle<SHVkLogicalDevice> device, SHVertexInputState const* viState, std::vector<Handle<SHVkDescriptorSetLayout>> const* globalLayouts) noexcept void SHPipelineLibrary::Init(Handle<SHVkLogicalDevice> device, SHVertexInputState const* viState, std::vector<Handle<SHVkDescriptorSetLayout>> const* globalLayouts) noexcept

View File

@ -4,7 +4,6 @@
#include "Graphics/Shaders/SHVkShaderModule.h" #include "Graphics/Shaders/SHVkShaderModule.h"
#include "Graphics/Pipeline/SHVkPipeline.h" #include "Graphics/Pipeline/SHVkPipeline.h"
namespace SHADE namespace SHADE
{ {
class SHVRenderpass; class SHVRenderpass;
@ -18,20 +17,12 @@ namespace SHADE
{ {
private: private:
// TOOD: Move this somewhere eventually. Can use for other things // TOOD: Move this somewhere eventually. Can use for other things
struct SHHandlePairHash
{
template <typename T1, typename T2>
std::size_t operator() (std::pair<T1, T2> const& pair) const
{
return std::hash<T1>(pair.first.GetId()) ^ std::hash<T2>(pair.second.GetId());
}
};
//! Logical Device required for creation of pipelines //! Logical Device required for creation of pipelines
Handle<SHVkLogicalDevice> logicalDevice; Handle<SHVkLogicalDevice> logicalDevice;
//! a map of pipelines that are hashed using a pair of shader module handles //! a map of pipelines that are hashed using a pair of shader module handles
std::unordered_map<std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>>, Handle<SHVkPipeline>, SHHandlePairHash> pipelines; std::unordered_map<std::pair<Handle<SHVkShaderModule>, Handle<SHVkShaderModule>>, Handle<SHVkPipeline>> pipelines;
//! Default vertex input state for pipeline creation //! Default vertex input state for pipeline creation
SHVertexInputState const* vertexInputState; SHVertexInputState const* vertexInputState;

View File

@ -190,6 +190,33 @@ namespace SHADE
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
Handle<T> handle; Handle<T> handle;
}; };
}
namespace std
{
/*---------------------------------------------------------------------------------*/
/* Type Definitions */
/*---------------------------------------------------------------------------------*/
/// <summary>
/// std::hash template specialization for Handle<T>
/// </summary>
/// <typeparam name="T">Type for the Handle.</typeparam>
template<typename T>
struct hash<SHADE::Handle<T>>
{
std::size_t operator() (const SHADE::Handle<T>& hdl) const;
};
/// <summary>
/// std::hash template specialization for std::pair<Handle<T1>, Handle<T2>>
/// </summary>
/// <typeparam name="T">Type for the first Handle.</typeparam>
/// <typeparam name="T">Type for the second Handle.</typeparam>
template<typename T1, typename T2>
struct hash<std::pair<SHADE::Handle<T1>, SHADE::Handle<T2>>>
{
std::size_t operator() (std::pair<SHADE::Handle<T1>, SHADE::Handle<T2>> const& pair) const;
};
} }
#include "Handle.hpp" #include "Handle.hpp"

View File

@ -95,3 +95,23 @@ namespace SHADE
handle = hdl; handle = hdl;
} }
} }
namespace std
{
/*---------------------------------------------------------------------------------*/
/* std::hash Template Specializations */
/*---------------------------------------------------------------------------------*/
template <typename T>
std::size_t hash<SHADE::Handle<T>>::operator()(const SHADE::Handle<T>& hdl) const
{
return std::hash<uint64_t>{}(hdl.GetId().Raw);
}
template <typename T1, typename T2>
std::size_t hash<pair<SHADE::Handle<T1>, SHADE::Handle<T2>>>::operator()(
std::pair<SHADE::Handle<T1>, SHADE::Handle<T2>> const& pair) const
{
return std::hash<uint64_t>{}(pair.first.GetId().Raw) ^ std::hash<uint64_t>{}(pair.second.GetId().Raw);
}
}