Reworked DebugDraw System #294

Merged
Pycorax merged 9 commits from SP3-1-DebugDraw into main 2022-12-16 02:21:32 +08:00
8 changed files with 134 additions and 4 deletions
Showing only changes of commit eb06eebc32 - Show all commits

View File

@ -182,6 +182,11 @@ namespace SHADE
DrawLineLoop({ p1, p2, p3, p4 }, color, depthTested); DrawLineLoop({ p1, p2, p3, p4 }, color, depthTested);
} }
void SHDebugDrawSystem::DrawCircle(const SHMatrix& matrix, const SHColour& color /*= SHColour::WHITE*/, bool depthTested /*= false*/)
{
drawCircle(getMeshBatch(false, depthTested), matrix, color);
}
void SHDebugDrawSystem::DrawWireCube(const SHMatrix& matrix, const SHColour& color, bool depthTested) void SHDebugDrawSystem::DrawWireCube(const SHMatrix& matrix, const SHColour& color, bool depthTested)
{ {
drawWireCube(getMeshBatch(false, depthTested), matrix, color); drawWireCube(getMeshBatch(false, depthTested), matrix, color);
@ -229,6 +234,12 @@ namespace SHADE
markPersistentDrawsDirty(); markPersistentDrawsDirty();
} }
void SHDebugDrawSystem::DrawPersistentCircle(const SHMatrix& matrix, const SHColour& color, bool depthTested)
{
drawCircle(getPersistentMeshBatch(false, depthTested), matrix, color);
markPersistentDrawsDirty();
}
void SHDebugDrawSystem::DrawPersistentWireCube(const SHMatrix& matrix, const SHColour& color, bool depthTested) void SHDebugDrawSystem::DrawPersistentWireCube(const SHMatrix& matrix, const SHColour& color, bool depthTested)
{ {
drawWireCube(getPersistentMeshBatch(false, depthTested), matrix, color); drawWireCube(getPersistentMeshBatch(false, depthTested), matrix, color);
@ -328,6 +339,15 @@ namespace SHADE
); );
} }
void SHDebugDrawSystem::drawCircle(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color)
{
drawMesh
(
gfxSystem->GetMeshPrimitive(PrimitiveType::LineCircle),
batch, transformMatrix, color
);
}
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Helper Batch Functions - Lines */ /* Helper Batch Functions - Lines */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -101,6 +101,7 @@ namespace SHADE
void DrawLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawQuad(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHVec3& p4, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawQuad(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHVec3& p4, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawCircle(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawWireCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawWireCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawWireSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawWireSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
@ -115,6 +116,7 @@ namespace SHADE
void DrawPersistentLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawPersistentLineLoop(IterType pointListBegin, IterType pointListEnd, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawPersistentTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawPersistentTri(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawPersistentQuad(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHVec3& p4, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawPersistentQuad(const SHVec3& p1, const SHVec3& p2, const SHVec3& p3, const SHVec3& p4, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawPersistentCircle(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawPersistentWireCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawPersistentWireCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawPersistentWireSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawPersistentWireSphere(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
void DrawPersistentCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false); void DrawPersistentCube(const SHMatrix& matrix, const SHColour& color = SHColour::WHITE, bool depthTested = false);
@ -216,6 +218,7 @@ namespace SHADE
void drawWireSphere(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color); void drawWireSphere(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color);
void drawCube(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color); void drawCube(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color);
void drawSphere(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color); void drawSphere(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color);
void drawCircle(MeshBatch& batch, const SHMatrix& transformMatrix, const SHColour& color);
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
/* Helper Batch Functions - Lines */ /* Helper Batch Functions - Lines */

View File

@ -413,8 +413,9 @@ namespace SHADE
// Create default meshes // Create default meshes
primitiveMeshes[static_cast<int>(PrimitiveType::Cube)] = SHPrimitiveGenerator::Cube(meshLibrary); primitiveMeshes[static_cast<int>(PrimitiveType::Cube)] = SHPrimitiveGenerator::Cube(meshLibrary);
primitiveMeshes[static_cast<int>(PrimitiveType::LineCube)] = SHPrimitiveGenerator::LineCube(meshLibrary);
primitiveMeshes[static_cast<int>(PrimitiveType::Sphere)] = SHPrimitiveGenerator::Sphere(meshLibrary); primitiveMeshes[static_cast<int>(PrimitiveType::Sphere)] = SHPrimitiveGenerator::Sphere(meshLibrary);
primitiveMeshes[static_cast<int>(PrimitiveType::LineCube)] = SHPrimitiveGenerator::LineCube(meshLibrary);
primitiveMeshes[static_cast<int>(PrimitiveType::LineCircle)] = SHPrimitiveGenerator::LineCircle(meshLibrary);
BuildMeshBuffers(); BuildMeshBuffers();
// Create default materials // Create default materials
@ -840,6 +841,7 @@ namespace SHADE
case PrimitiveType::Cube: case PrimitiveType::Cube:
case PrimitiveType::Sphere: case PrimitiveType::Sphere:
case PrimitiveType::LineCube: case PrimitiveType::LineCube:
case PrimitiveType::LineCircle:
return primitiveMeshes[static_cast<int>(type)]; return primitiveMeshes[static_cast<int>(type)];
default: default:
return {}; return {};

View File

@ -71,9 +71,10 @@ namespace SHADE
{ {
Cube, Cube,
Sphere, Sphere,
LineCube LineCube,
LineCircle
}; };
static constexpr int MAX_PRIMITIVE_TYPES = 3; static constexpr int MAX_PRIMITIVE_TYPES = 4;
enum class DebugDrawPipelineType enum class DebugDrawPipelineType
{ {
LineNoDepthTest, LineNoDepthTest,

View File

@ -10,9 +10,13 @@ Copyright (C) 2022 DigiPen Institute of Technology.
Reproduction or disclosure of this file or its contents without the prior written consent Reproduction or disclosure of this file or its contents without the prior written consent
of DigiPen Institute of Technology is prohibited. of DigiPen Institute of Technology is prohibited.
*//*************************************************************************************/ *//*************************************************************************************/
// Precompiled Header
#include "SHpch.h" #include "SHpch.h"
// Primary Includes
#include "SHPrimitiveGenerator.h" #include "SHPrimitiveGenerator.h"
// STL Includes
#include <numbers>
// Project Includes
#include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h" #include "Graphics/MiddleEnd/Interface/SHGraphicsSystem.h"
#include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h" #include "Graphics/MiddleEnd/Interface/SHMeshLibrary.h"
@ -24,6 +28,7 @@ namespace SHADE
SHMeshData SHPrimitiveGenerator::cubeMesh; SHMeshData SHPrimitiveGenerator::cubeMesh;
SHMeshData SHPrimitiveGenerator::sphereMesh; SHMeshData SHPrimitiveGenerator::sphereMesh;
SHMeshData SHPrimitiveGenerator::lineCubeMesh; SHMeshData SHPrimitiveGenerator::lineCubeMesh;
SHMeshData SHPrimitiveGenerator::lineCircleMesh;
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Primitive Generation Functions */ /* Primitive Generation Functions */
@ -341,6 +346,52 @@ namespace SHADE
return addMeshDataTo(lineCubeMesh, gfxSystem); return addMeshDataTo(lineCubeMesh, gfxSystem);
} }
SHMeshData SHPrimitiveGenerator::LineCircle() noexcept
{
SHMeshData mesh;
// Generate points of the circle
static constexpr int SPLITS = 36;
static constexpr float ANGLE_INCREMENTS = (std::numbers::pi_v<float> * 2.0f) / static_cast<float>(SPLITS);
for (int i = 0; i < SPLITS; ++i)
{
const float ANGLE = ANGLE_INCREMENTS * i;
mesh.VertexPositions.emplace_back(cos(ANGLE) * 0.5f, sin(ANGLE) * 0.5f, 0.0f);
}
// Generate lines of the circle
for (int i = 1; i < SPLITS; ++i)
{
mesh.Indices.emplace_back(static_cast<uint32_t>(i - 1));
mesh.Indices.emplace_back(static_cast<uint32_t>(i));
}
// Last line to complete the circle
mesh.Indices.emplace_back(static_cast<uint32_t>(SPLITS - 1));
mesh.Indices.emplace_back(static_cast<uint32_t>(0));
mesh.VertexNormals.resize(mesh.VertexPositions.size());
mesh.VertexTangents.resize(mesh.VertexPositions.size());
mesh.VertexTexCoords.resize(mesh.VertexPositions.size());
return mesh;
}
Handle<SHMesh> SHPrimitiveGenerator::LineCircle(SHMeshLibrary& meshLibrary) noexcept
{
if (lineCircleMesh.VertexPositions.empty())
lineCircleMesh = LineCircle();
return addMeshDataTo(lineCircleMesh, meshLibrary);
}
Handle<SHMesh> SHPrimitiveGenerator::LineCircle(SHGraphicsSystem& gfxSystem) noexcept
{
if (lineCircleMesh.VertexPositions.empty())
lineCircleMesh = LineCircle();
return addMeshDataTo(lineCircleMesh, gfxSystem);
}
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/
/* Helper Functions */ /* Helper Functions */
/*-----------------------------------------------------------------------------------*/ /*-----------------------------------------------------------------------------------*/

View File

@ -154,6 +154,46 @@ namespace SHADE
*/ */
/***********************************************************************************/ /***********************************************************************************/
[[nodiscard]] static Handle<SHMesh> LineCube(SHGraphicsSystem& gfxSystem) noexcept; [[nodiscard]] static Handle<SHMesh> LineCube(SHGraphicsSystem& gfxSystem) noexcept;
/***********************************************************************************/
/*!
\brief
Produces a circle that is comprised only of lines with no diagonal lines and
store the data in a SHMeshData object.
\return
SHMeshData object containing vertex data for the line circle.
*/
/***********************************************************************************/
[[nodiscard]] static SHMeshData LineCircle() noexcept;
/***********************************************************************************/
/*!
\brief
Produces a line circle and constructs a SHMesh using the SHGraphicsSystem
provided.
\param meshLibrary
Reference to the SHMeshLibrary to produce and store a line circle mesh in.
\return
SHMesh object that points to the generated line circle mesh in the SHMeshLibrary.
*/
/***********************************************************************************/
[[nodiscard]] static Handle<SHMesh> LineCircle(SHMeshLibrary& meshLibrary) noexcept;
/***********************************************************************************/
/*!
\brief
Produces a line circle and constructs a SHMesh using the SHGraphicsSystem
provided.
\param gfxSystem
Reference to the SHGraphicsSystem to produce and store a line circle mesh in.
\return
SHMesh object that points to the generated line circle mesh in the
SHGraphicsSystem.
*/
/***********************************************************************************/
[[nodiscard]] static Handle<SHMesh> LineCircle(SHGraphicsSystem& gfxSystem) noexcept;
private: private:
/*---------------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------------*/
@ -168,5 +208,6 @@ namespace SHADE
static SHMeshData cubeMesh; static SHMeshData cubeMesh;
static SHMeshData sphereMesh; static SHMeshData sphereMesh;
static SHMeshData lineCubeMesh; static SHMeshData lineCubeMesh;
static SHMeshData lineCircleMesh;
}; };
} }

View File

@ -57,6 +57,11 @@ namespace SHADE
dbgDrawSys->DrawQuad(pt1, pt2, pt3, pt4, color); dbgDrawSys->DrawQuad(pt1, pt2, pt3, pt4, color);
} }
void SHDebugDraw::Circle(const SHMatrix& mat, const SHVec4& color)
{
dbgDrawSys->DrawCircle(mat, color);
}
void SHDebugDraw::LineLoop(const SHVec4& color, std::initializer_list<SHVec3> pointList) void SHDebugDraw::LineLoop(const SHVec4& color, std::initializer_list<SHVec3> pointList)
{ {
dbgDrawSys->DrawLineLoop(pointList, color); dbgDrawSys->DrawLineLoop(pointList, color);
@ -110,6 +115,11 @@ namespace SHADE
dbgDrawSys->DrawPersistentQuad(pt1, pt2, pt3, pt4, color); dbgDrawSys->DrawPersistentQuad(pt1, pt2, pt3, pt4, color);
} }
void SHDebugDraw::PersistentCircle(const SHMatrix& mat, const SHVec4& color)
{
dbgDrawSys->DrawPersistentCircle(mat, color);
}
void SHDebugDraw::PersistentLineLoop(const SHVec4& color, std::initializer_list<SHVec3> pointList) void SHDebugDraw::PersistentLineLoop(const SHVec4& color, std::initializer_list<SHVec3> pointList)
{ {
dbgDrawSys->DrawPersistentLineLoop(pointList, color); dbgDrawSys->DrawPersistentLineLoop(pointList, color);

View File

@ -72,6 +72,7 @@ namespace SHADE
/// <param name="pt3">Third point of the quadrilateral.</param> /// <param name="pt3">Third point of the quadrilateral.</param>
/// <param name="pt4">Third point of the quadrilateral.</param> /// <param name="pt4">Third point of the quadrilateral.</param>
static void Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4); static void Quad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4);
static void Circle(const SHMatrix& mat,const SHVec4& color);
/// <summary> /// <summary>
/// Renders a polygon indicated by the specified set of points in world space. /// Renders a polygon indicated by the specified set of points in world space.
/// </summary> /// </summary>
@ -115,6 +116,7 @@ namespace SHADE
/// <param name="pt3">Third point of the quadrilateral.</param> /// <param name="pt3">Third point of the quadrilateral.</param>
/// <param name="pt4">Third point of the quadrilateral.</param> /// <param name="pt4">Third point of the quadrilateral.</param>
static void PersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4); static void PersistentQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4);
static void PersistentCircle(const SHMatrix& mat,const SHVec4& color);
/// <summary> /// <summary>
/// Renders a polygon indicated by the specified set of points in world space that /// Renders a polygon indicated by the specified set of points in world space that
/// will persist until ClearPersistentDraws() is called. /// will persist until ClearPersistentDraws() is called.