From ebb13d3bf2114d3b1302f86b97494cbc26abe12a Mon Sep 17 00:00:00 2001 From: Lynix Date: Thu, 10 Jul 2014 10:12:25 +0200 Subject: [PATCH] Added DebugDrawer::DrawLine and DebugDrawer::DrawPoints Former-commit-id: e1b2278a7c11ebfc8050bad23aef7a9a4cbf3c25 --- include/Nazara/Renderer/DebugDrawer.hpp | 2 ++ src/Nazara/Renderer/DebugDrawer.cpp | 45 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/include/Nazara/Renderer/DebugDrawer.hpp b/include/Nazara/Renderer/DebugDrawer.hpp index b8e272d5d..fc632765a 100644 --- a/include/Nazara/Renderer/DebugDrawer.hpp +++ b/include/Nazara/Renderer/DebugDrawer.hpp @@ -29,6 +29,8 @@ class NAZARA_API NzDebugDrawer static void Draw(const NzSkeleton* skeleton); static void DrawBinormals(const NzStaticMesh* subMesh); static void DrawCone(const NzVector3f& origin, const NzQuaternionf& rotation, float angle, float length); + static void DrawLine(const NzVector3f& p1, const NzVector3f& p2); + static void DrawPoints(const NzVector3f* ptr, unsigned int pointCount); static void DrawNormals(const NzStaticMesh* subMesh); static void DrawTangents(const NzStaticMesh* subMesh); diff --git a/src/Nazara/Renderer/DebugDrawer.cpp b/src/Nazara/Renderer/DebugDrawer.cpp index 3e3f1490b..1a2e96ee7 100644 --- a/src/Nazara/Renderer/DebugDrawer.cpp +++ b/src/Nazara/Renderer/DebugDrawer.cpp @@ -486,6 +486,51 @@ void NzDebugDrawer::DrawCone(const NzVector3f& origin, const NzQuaternionf& rota NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 16); } +void NzDebugDrawer::DrawLine(const NzVector3f& p1, const NzVector3f& p2) +{ + if (!s_initialized && !Initialize()) + { + NazaraError("Failed to initialize Debug Drawer"); + return; + } + + NzVertexStruct_XYZ buffer[2]; + buffer[0].position = p1; + buffer[1].position = p2; + + s_vertexBuffer.Fill(&buffer[0], 0, 2); + + NzRenderer::SetRenderStates(s_renderStates); + NzRenderer::SetShader(s_shader); + NzRenderer::SetVertexBuffer(&s_vertexBuffer); + + s_shader->SendColor(s_colorLocation, s_primaryColor); + NzRenderer::DrawPrimitives(nzPrimitiveMode_LineList, 0, 2); +} + +void NzDebugDrawer::DrawPoints(const NzVector3f* ptr, unsigned int pointCount) +{ + static_assert(sizeof(NzVertexStruct_XYZ) == sizeof(NzVector3f), "NzVertexStruct_XYZ is no longer equal to NzVector3f, please rewrite this"); + + if (!s_initialized && !Initialize()) + { + NazaraError("Failed to initialize Debug Drawer"); + return; + } + + if (pointCount > 0) + { + s_vertexBuffer.Fill(ptr, 0, pointCount); + + NzRenderer::SetRenderStates(s_renderStates); + NzRenderer::SetShader(s_shader); + NzRenderer::SetVertexBuffer(&s_vertexBuffer); + + s_shader->SendColor(s_colorLocation, s_primaryColor); + NzRenderer::DrawPrimitives(nzPrimitiveMode_PointList, 0, pointCount); + } +} + void NzDebugDrawer::DrawNormals(const NzStaticMesh* subMesh) { if (!s_initialized && !Initialize())