Merge remote-tracking branch 'origin/SP3-1-Rendering' into SP3-1-Rendering

This commit is contained in:
Brandon Mak 2022-09-19 00:04:42 +08:00
commit 23fe51b483
4 changed files with 140 additions and 30 deletions

View File

@ -369,6 +369,27 @@ namespace SHADE
{
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
{

View File

@ -27,6 +27,7 @@ of DigiPen Institute of Technology is prohibited.
#include "Graphics/RenderGraph/SHRenderGraph.h"
#include "Graphics/MiddleEnd/Shaders/SHShaderSourceLibrary.h"
#include "Graphics/MiddleEnd/Shaders/SHShaderModuleLibrary.h"
#include "SHMeshLibrary.h"
namespace SHADE
{
@ -122,6 +123,67 @@ namespace SHADE
Handle<SHMaterialInstance> AddMaterialInstance(Handle<SHMaterial> material);
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 */
@ -156,17 +218,15 @@ namespace SHADE
Handle<SHVkCommandPool> transferCmdPool;
Handle<SHVkCommandBuffer> transferCmdBuffer;
SHRenderContext renderContext;
std::array<Handle<SHVkSemaphore>, 2> graphSemaphores;
std::array<Handle<SHVkSemaphore>, 2> graphSemaphores;
// Not Owned Resources
SHWindow* window;
// Global descriptor set layouts
std::vector<Handle<SHVkDescriptorSetLayout>> globalDescSetLayouts;
// Middle End Resources
ResourceManager resourceManager;
ResourceManager resourceManager;
SHMeshLibrary meshLibrary;
// Viewports
Handle<SHViewport> defaultViewport; // Whole screen
std::vector<Handle<SHViewport>> viewports; // Additional viewports

View File

@ -13,6 +13,8 @@ of DigiPen Institute of Technology is prohibited.
#include "SHpch.h"
#include "SHPrimitiveGenerator.h"
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
namespace SHADE
{
SHMeshData SHPrimitiveGenerator::Cube() noexcept
@ -34,10 +36,10 @@ namespace SHADE
SHVec3( 0.5f, -0.5f, -0.5f),
// 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
SHVec3(-0.5f, -0.5f, -0.5f),
@ -66,10 +68,10 @@ namespace SHADE
SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.0f),
SHVec2(0.0f, 1.0f),
SHVec2(1.0f, 1.0f),
SHVec2(1.0f, 0.0f),
SHVec2(0.0f, 0.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),
// top
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),
// 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),
// left
SHVec3(-1.0f, 0.0f, 0.0f),
@ -192,15 +194,29 @@ namespace SHADE
{
SHMeshData meshData = Cube();
return meshLibrary.AddMesh
(
meshData.VertexPositions.size(),
meshData.VertexPositions.data(),
meshData.VertexTexCoords.data(),
meshData.VertexTangents.data(),
meshData.VertexNormals.data(),
meshData.Indices.size(),
meshData.Indices.data()
(
meshData.VertexPositions.size(),
meshData.VertexPositions.data(),
meshData.VertexTexCoords.data(),
meshData.VertexTangents.data(),
meshData.VertexNormals.data(),
meshData.Indices.size(),
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
{
/*************************************************************************************/
/*!
\brief
Static class that contains functions for generating 3D primitives.
*/
/*************************************************************************************/
/*************************************************************************************/
/*!
\brief
Static class that contains functions for generating 3D primitives.
*/
/*************************************************************************************/
class SHPrimitiveGenerator
{
/*---------------------------------------------------------------------------------*/
@ -56,5 +56,18 @@ namespace SHADE
*/
/***********************************************************************************/
[[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;
};
}