Generalised Draw functions in SHDebugDrawSystem for potentially any number of draw queues
This commit is contained in:
parent
8c666ef236
commit
1371302a40
|
@ -117,54 +117,75 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
void SHDebugDrawSystem::DrawLine(const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
|
||||
{
|
||||
if (points.size() > MAX_POINTS)
|
||||
drawLine(points, color, startPt, endPt);
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3)
|
||||
{
|
||||
drawPoly(points, color, { pt1, pt2, pt3 });
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4)
|
||||
{
|
||||
drawPoly(points, color, { pt1, pt2, pt3, pt4 });
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList)
|
||||
{
|
||||
drawPoly(points, color, pointList.begin(), pointList.end());
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size)
|
||||
{
|
||||
drawCube(points, color, pos, size);
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawSphere(const SHVec4& color, const SHVec3& pos, double radius)
|
||||
{
|
||||
drawSphere(points, color, pos, radius);
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::drawLine(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt)
|
||||
{
|
||||
if (storage.size() > MAX_POINTS)
|
||||
{
|
||||
SHLOG_WARNING("[DebugDraw] Exceeded maximum size of drawable debug elements.");
|
||||
return;
|
||||
}
|
||||
|
||||
points.emplace_back(PointVertex{ startPt, color });
|
||||
points.emplace_back(PointVertex{ endPt, color });
|
||||
storage.emplace_back(PointVertex{ startPt, color });
|
||||
storage.emplace_back(PointVertex{ endPt, color });
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawTri(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3)
|
||||
void SHDebugDrawSystem::drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, std::initializer_list<SHVec3> pointList)
|
||||
{
|
||||
DrawPoly(color, { pt1, pt2, pt3 });
|
||||
drawPoly(storage, color, pointList.begin(), pointList.end());
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawQuad(const SHVec4& color, const SHVec3& pt1, const SHVec3& pt2, const SHVec3& pt3, const SHVec3& pt4)
|
||||
void SHDebugDrawSystem::drawCube(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, const SHVec3& size)
|
||||
{
|
||||
DrawPoly(color, { pt1, pt2, pt3, pt4 });
|
||||
}
|
||||
static const SHVec3 EXTENTS = SHVec3{ 0.5f, 0.5f, 0.5f };
|
||||
static const SHVec3 UNIT_BOT_LEFT_FRONT = SHVec3{ pos - EXTENTS };
|
||||
static const SHVec3 UNIT_BOT_RIGHT_FRONT = SHVec3{ pos + SHVec3 { EXTENTS.x, -EXTENTS.y, -EXTENTS.z } };
|
||||
static const SHVec3 UNIT_BOT_RIGHT_BACK = SHVec3{ pos + SHVec3 { EXTENTS.x, -EXTENTS.y, EXTENTS.z } };
|
||||
static const SHVec3 UNIT_BOT_LEFT_BACK = SHVec3{ pos + SHVec3 { -EXTENTS.x, -EXTENTS.y, EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_LEFT_BACK = SHVec3{ pos + SHVec3 { -EXTENTS.x, EXTENTS.y, EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_RIGHT_FRONT = SHVec3{ pos + SHVec3 { EXTENTS.x, EXTENTS.y, -EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_LEFT_FRONT = SHVec3{ pos + SHVec3 { -EXTENTS.x, EXTENTS.y, -EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_RIGHT_BACK = SHVec3{ pos + EXTENTS };
|
||||
|
||||
void SHDebugDrawSystem::DrawPoly(const SHVec4& color, std::initializer_list<SHVec3> pointList)
|
||||
{
|
||||
DrawPoly(color, pointList.begin(), pointList.end());
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawCube(const SHVec4& color, const SHVec3& pos, const SHVec3& size)
|
||||
{
|
||||
static const SHVec3 EXTENTS = SHVec3 { 0.5f, 0.5f, 0.5f };
|
||||
static const SHVec3 UNIT_BOT_LEFT_FRONT = SHVec3 { pos - EXTENTS };
|
||||
static const SHVec3 UNIT_BOT_RIGHT_FRONT = SHVec3 { pos + SHVec3 { EXTENTS.x, -EXTENTS.y, -EXTENTS.z } };
|
||||
static const SHVec3 UNIT_BOT_RIGHT_BACK = SHVec3 { pos + SHVec3 { EXTENTS.x, -EXTENTS.y, EXTENTS.z } };
|
||||
static const SHVec3 UNIT_BOT_LEFT_BACK = SHVec3 { pos + SHVec3 { -EXTENTS.x, -EXTENTS.y, EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_LEFT_BACK = SHVec3 { pos + SHVec3 { -EXTENTS.x, EXTENTS.y, EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_RIGHT_FRONT = SHVec3 { pos + SHVec3 { EXTENTS.x, EXTENTS.y, -EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_LEFT_FRONT = SHVec3 { pos + SHVec3 { -EXTENTS.x, EXTENTS.y, -EXTENTS.z } };
|
||||
static const SHVec3 UNIT_TOP_RIGHT_BACK = SHVec3 { pos + EXTENTS };
|
||||
|
||||
const SHVec3 BOT_LEFT_BACK = UNIT_BOT_LEFT_BACK * size;
|
||||
const SHVec3 BOT_RIGHT_BACK = UNIT_BOT_RIGHT_BACK * size;
|
||||
const SHVec3 BOT_LEFT_FRONT = UNIT_BOT_LEFT_FRONT * size;
|
||||
const SHVec3 BOT_LEFT_BACK = UNIT_BOT_LEFT_BACK * size;
|
||||
const SHVec3 BOT_RIGHT_BACK = UNIT_BOT_RIGHT_BACK * size;
|
||||
const SHVec3 BOT_LEFT_FRONT = UNIT_BOT_LEFT_FRONT * size;
|
||||
const SHVec3 BOT_RIGHT_FRONT = UNIT_BOT_RIGHT_FRONT * size;
|
||||
const SHVec3 TOP_LEFT_BACK = UNIT_TOP_LEFT_BACK * size;
|
||||
const SHVec3 TOP_RIGHT_BACK = UNIT_TOP_RIGHT_BACK * size;
|
||||
const SHVec3 TOP_LEFT_FRONT = UNIT_TOP_LEFT_FRONT * size;
|
||||
const SHVec3 TOP_LEFT_BACK = UNIT_TOP_LEFT_BACK * size;
|
||||
const SHVec3 TOP_RIGHT_BACK = UNIT_TOP_RIGHT_BACK * size;
|
||||
const SHVec3 TOP_LEFT_FRONT = UNIT_TOP_LEFT_FRONT * size;
|
||||
const SHVec3 TOP_RIGHT_FRONT = UNIT_TOP_RIGHT_FRONT * size;
|
||||
|
||||
DrawPoly
|
||||
drawPoly
|
||||
(
|
||||
storage,
|
||||
color,
|
||||
{
|
||||
// Bottom Square
|
||||
|
@ -186,7 +207,7 @@ namespace SHADE
|
|||
);
|
||||
}
|
||||
|
||||
void SHDebugDrawSystem::DrawSphere(const SHVec4& color, const SHVec3& pos, double radius)
|
||||
void SHDebugDrawSystem::drawSphere(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, double radius)
|
||||
{
|
||||
if (spherePoints.empty())
|
||||
{
|
||||
|
@ -197,6 +218,6 @@ namespace SHADE
|
|||
spherePoints.emplace_back(SPHERE.VertexPositions[idx]);
|
||||
}
|
||||
}
|
||||
DrawPoly(color, spherePoints.begin(), spherePoints.end());
|
||||
drawPoly(storage, color, spherePoints.begin(), spherePoints.end());
|
||||
}
|
||||
}
|
|
@ -148,11 +148,22 @@ namespace SHADE
|
|||
/*---------------------------------------------------------------------------------*/
|
||||
// CPU Buffers
|
||||
std::vector<PointVertex> points;
|
||||
std::vector<PointVertex> persistentPoints;
|
||||
// GPU Buffers
|
||||
TripleBuffer vertexBuffers;
|
||||
TripleUInt numPoints;
|
||||
// Cached Points for polygon drawing
|
||||
std::vector<SHVec3> spherePoints;
|
||||
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
/* Helper Draw Functions */
|
||||
/*---------------------------------------------------------------------------------*/
|
||||
void drawLine(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& startPt, const SHVec3& endPt);
|
||||
void drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, std::initializer_list<SHVec3> pointList);
|
||||
template<typename IterType>
|
||||
void drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, IterType pointListBegin, IterType pointListEnd);
|
||||
void drawCube(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, const SHVec3& size);
|
||||
void drawSphere(std::vector<PointVertex>& storage, const SHVec4& color, const SHVec3& pos, double radius);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -20,12 +20,21 @@ namespace SHADE
|
|||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename IterType>
|
||||
void SHDebugDrawSystem::DrawPoly(const SHVec4& color, IterType pointListBegin, IterType pointListEnd)
|
||||
{
|
||||
drawPoly(points, color, pointListBegin, pointListEnd);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
/* Helper Draw Functions */
|
||||
/*-----------------------------------------------------------------------------------*/
|
||||
template<typename IterType>
|
||||
void SHDebugDrawSystem::drawPoly(std::vector<PointVertex>& storage, const SHVec4& color, IterType pointListBegin, IterType pointListEnd)
|
||||
{
|
||||
// Ensure dereferenced type is SHVec3
|
||||
static_assert(std::is_same_v<SHVec3, std::remove_cvref_t<decltype(*pointListBegin)>>, "Parameters to DrawPoly must be SHVec3.");
|
||||
|
||||
// Check if points exceeded max
|
||||
if (points.size() > MAX_POINTS)
|
||||
if (storage.size() > MAX_POINTS)
|
||||
{
|
||||
SHLOG_WARNING("[DebugDraw] Exceeded maximum size of drawable debug elements.");
|
||||
return;
|
||||
|
@ -42,7 +51,7 @@ namespace SHADE
|
|||
const size_t POINTS_ROUNDED_COUNT = POINTS_COUNT / 2 * 2;
|
||||
for (auto pointIter = pointListBegin; pointIter != (pointListBegin + POINTS_ROUNDED_COUNT); ++pointIter)
|
||||
{
|
||||
points.emplace_back(PointVertex{ *pointIter, color });
|
||||
storage.emplace_back(PointVertex{ *pointIter, color });
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue