Added Mesh Registration Functions to SHGraphicsSystem and a SHGraphicsSystem compatible version of mesh generation functions for SHPrimitiveGenerator

This commit is contained in:
Kah Wei 2022-09-18 23:23:48 +08:00
parent 41daaaba9c
commit b9185eab18
4 changed files with 140 additions and 31 deletions

View File

@ -355,6 +355,27 @@ namespace SHADE
{ {
resourceManager.Free(materialInstance); resourceManager.Free(materialInstance);
} }
/*---------------------------------------------------------------------------------*/
/* Mesh Registration Functions */
/*---------------------------------------------------------------------------------*/
SHADE::Handle<SHADE::SHMesh> SHGraphicsSystem::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)
{
return meshLibrary.AddMesh(vertexCount, positions, texCoords, tangents, normals, indexCount, indices);
}
void SHGraphicsSystem::RemoveMesh(Handle<SHMesh> mesh)
{
meshLibrary.RemoveMesh(mesh);
}
void SHGraphicsSystem::BuildMeshBuffers()
{
transferCmdBuffer->BeginRecording();
meshLibrary.BuildBuffers(device, transferCmdBuffer);
transferCmdBuffer->EndRecording();
queue->SubmitCommandBuffer({ transferCmdBuffer });
}
void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept void SHGraphicsSystem::SetWindow(SHWindow* wind) noexcept
{ {

View File

@ -25,6 +25,7 @@ of DigiPen Institute of Technology is prohibited.
#include "ECS_Base/System/SHSystemRoutine.h" #include "ECS_Base/System/SHSystemRoutine.h"
#include "Graphics/Descriptors/SHVkDescriptorPool.h" #include "Graphics/Descriptors/SHVkDescriptorPool.h"
#include "Graphics/RenderGraph/SHRenderGraph.h" #include "Graphics/RenderGraph/SHRenderGraph.h"
#include "SHMeshLibrary.h"
namespace SHADE namespace SHADE
{ {
@ -120,6 +121,67 @@ namespace SHADE
Handle<SHMaterialInstance> AddMaterialInstance(Handle<SHMaterial> material); Handle<SHMaterialInstance> AddMaterialInstance(Handle<SHMaterial> material);
void RemoveMaterialInstance(Handle<SHMaterialInstance> materialInstance); void RemoveMaterialInstance(Handle<SHMaterialInstance> materialInstance);
/*-----------------------------------------------------------------------------*/
/* Mesh Registration Functions */
/*-----------------------------------------------------------------------------*/
/*******************************************************************************/
/*!
\brief
Adds a mesh to the Mesh Library. But this does not mean that the meshes have
been added yet. A call to "BuildBuffers()" is required to transfer all
meshes into the GPU.
\param vertexCount
Number of vertices in this Mesh.
\param positions
Pointer to the first in a contiguous array of SHMathVec3s that define vertex
positions.
\param texCoords
Pointer to the first in a contiguous array of SHMathVec2s that define vertex
texture coordinates.
\param tangents
Pointer to the first in a contiguous array of SHMathVec3s that define vertex
tangents.
\param normals
Pointer to the first in a contiguous array of SHMathVec3s that define vertex
normals.
\param indexCount
Number of indices in this mesh.
\param indices
Pointer to the first in a contiguous array of uint32_ts that define mesh
indices.
\return
Handle to the created Mesh. This is not valid to be used until a call to
BuildBuffers().
*/
/*******************************************************************************/
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);
/*******************************************************************************/
/*!
\brief
Removes a mesh from the MeshLibrary. But this does not mean that the meshes
have been removed yet. A call to "BuildBuffers()" is required to finalise all
changes.
\param mesh
Handle to the mesh to remove.
*/
/*******************************************************************************/
void RemoveMesh(Handle<SHMesh> mesh);
/***************************************************************************/
/*!
\brief
Finalises all changes to the MeshLibrary into the GPU buffers.
*/
/***************************************************************************/
void BuildMeshBuffers();
/*-----------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------*/
/* Setters */ /* Setters */
@ -154,16 +216,13 @@ namespace SHADE
Handle<SHVkCommandPool> transferCmdPool; Handle<SHVkCommandPool> transferCmdPool;
Handle<SHVkCommandBuffer> transferCmdBuffer; Handle<SHVkCommandBuffer> transferCmdBuffer;
SHRenderContext renderContext; SHRenderContext renderContext;
std::array<Handle<SHVkSemaphore>, 2> graphSemaphores; std::array<Handle<SHVkSemaphore>, 2> graphSemaphores;
// Not Owned Resources // Not Owned Resources
SHWindow* window; SHWindow* window;
std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts; std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts;
// Middle End Resources // Middle End Resources
ResourceManager resourceManager; ResourceManager resourceManager;
SHMeshLibrary meshLibrary;
// Viewports // Viewports
Handle<SHViewport> defaultViewport; // Whole screen Handle<SHViewport> defaultViewport; // Whole screen
std::vector<Handle<SHViewport>> viewports; // Additional viewports std::vector<Handle<SHViewport>> viewports; // Additional viewports

View File

@ -13,6 +13,8 @@ of DigiPen Institute of Technology is prohibited.
#include "SHpch.h" #include "SHpch.h"
#include "SHPrimitiveGenerator.h" #include "SHPrimitiveGenerator.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
namespace SHADE namespace SHADE
{ {
SHMeshData SHPrimitiveGenerator::Cube() noexcept SHMeshData SHPrimitiveGenerator::Cube() noexcept
@ -34,10 +36,10 @@ namespace SHADE
SHVec3( 0.5f, -0.5f, -0.5f), SHVec3( 0.5f, -0.5f, -0.5f),
// top // top
SHVec3(-0.5f, 0.5f, -0.5f), SHVec3(-0.5f, 0.5f, -0.5f),
SHVec3(-0.5f, 0.5f, 0.5f), SHVec3(-0.5f, 0.5f, 0.5f),
SHVec3( 0.5f, 0.5f, 0.5f), SHVec3( 0.5f, 0.5f, 0.5f),
SHVec3( 0.5f, 0.5f, -0.5f), SHVec3( 0.5f, 0.5f, -0.5f),
// bottom // bottom
SHVec3(-0.5f, -0.5f, -0.5f), SHVec3(-0.5f, -0.5f, -0.5f),
@ -66,10 +68,10 @@ namespace SHADE
SHVec2(0.0f, 0.0f), SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f), SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f), SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f), SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f), SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f), SHVec2(0.0f, 1.0f),
@ -148,7 +150,7 @@ namespace SHADE
SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, -1.0f),
SHVec3(0.0f, 0.0f, -1.0f), SHVec3(0.0f, 0.0f, -1.0f),
// top // top
SHVec3(0.0f, 1.0f, 0.0f), SHVec3(0.0f, 1.0f, 0.0f),
@ -160,13 +162,13 @@ namespace SHADE
SHVec3(0.0f, -1.0f, 0.0f), SHVec3(0.0f, -1.0f, 0.0f),
SHVec3(0.0f, -1.0f, 0.0f), SHVec3(0.0f, -1.0f, 0.0f),
SHVec3(0.0f, -1.0f, 0.0f), SHVec3(0.0f, -1.0f, 0.0f),
SHVec3(0.0f, -1.0f, 0.0f), SHVec3(0.0f, -1.0f, 0.0f),
// right // right
SHVec3(1.0f, 0.0f, 0.0f), SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f), SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f), SHVec3(1.0f, 0.0f, 0.0f),
SHVec3(1.0f, 0.0f, 0.0f), SHVec3(1.0f, 0.0f, 0.0f),
// left // left
SHVec3(-1.0f, 0.0f, 0.0f), SHVec3(-1.0f, 0.0f, 0.0f),
@ -192,15 +194,29 @@ namespace SHADE
{ {
SHMeshData meshData = Cube(); SHMeshData meshData = Cube();
return meshLibrary.AddMesh return meshLibrary.AddMesh
( (
meshData.VertexPositions.size(), meshData.VertexPositions.size(),
meshData.VertexPositions.data(), meshData.VertexPositions.data(),
meshData.VertexTexCoords.data(), meshData.VertexTexCoords.data(),
meshData.VertexTangents.data(), meshData.VertexTangents.data(),
meshData.VertexNormals.data(), meshData.VertexNormals.data(),
meshData.Indices.size(), meshData.Indices.size(),
meshData.Indices.data() meshData.Indices.data()
); );
} }
Handle<SHADE::SHMesh> SHPrimitiveGenerator::Cube(SHGraphicsSystem& gfxSystem) noexcept
{
SHMeshData meshData = Cube();
return gfxSystem.AddMesh
(
meshData.VertexPositions.size(),
meshData.VertexPositions.data(),
meshData.VertexTexCoords.data(),
meshData.VertexTangents.data(),
meshData.VertexNormals.data(),
meshData.Indices.size(),
meshData.Indices.data()
);
}
} }

View File

@ -17,12 +17,12 @@ of DigiPen Institute of Technology is prohibited.
namespace SHADE namespace SHADE
{ {
/*************************************************************************************/ /*************************************************************************************/
/*! /*!
\brief \brief
Static class that contains functions for generating 3D primitives. Static class that contains functions for generating 3D primitives.
*/ */
/*************************************************************************************/ /*************************************************************************************/
class SHPrimitiveGenerator class SHPrimitiveGenerator
{ {
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -56,5 +56,18 @@ namespace SHADE
*/ */
/***********************************************************************************/ /***********************************************************************************/
[[nodiscard]] static Handle<SHMesh> Cube(SHMeshLibrary& meshLibrary) noexcept; [[nodiscard]] static Handle<SHMesh> Cube(SHMeshLibrary& meshLibrary) noexcept;
/***********************************************************************************/
/*!
\brief
Produces a cube and constructs a SHMesh using the SHGraphicsSystem provided.
\param gfxSystem
Reference to the SHGraphicsSystem to produce and store a cube mesh in.
\return
SHMesh object that points to the generated cube mesh in the SHGraphicsSystem.
*/
/***********************************************************************************/
[[nodiscard]] static Handle<SHMesh> Cube(SHGraphicsSystem& gfxSystem) noexcept;
}; };
} }