17std::vector<Vertex>* DebugLineRenderer::s_vertices =
nullptr;
21bool DebugLineRenderer::s_enabled =
false;
22bool DebugLineRenderer::s_initialized =
false;
25 if (s_initialized)
return;
28 "assets/shaders/debug_line.hlsl"));
29 if (!s_shader.IsValid()) {
30 SLEAK_ERROR(
"DebugLineRenderer: Failed to create debug line shader");
35 std::vector<Vertex> emptyVerts(MAX_VERTICES);
38 MAX_VERTICES *
sizeof(
Vertex),
48 s_constantBuffer->SetSlot(0);
50 s_vertices =
new std::vector<Vertex>();
51 s_vertices->reserve(MAX_VERTICES);
59 s_vertexBuffer.reset();
61 s_constantBuffer.reset();
62 s_initialized =
false;
66 float r,
float g,
float b,
float a) {
67 if (s_vertices->size() + 2 > MAX_VERTICES)
return;
71 v1.
r = r; v1.
g = g; v1.
b = b; v1.
a = a;
75 v2.
r = r; v2.
g = g; v2.
b = b; v2.
a = a;
77 s_vertices->push_back(v1);
78 s_vertices->push_back(v2);
82 float r,
float g,
float b,
float a) {
116 float r,
float g,
float b,
float a,
118 float step = 2.0f * 3.14159265f /
static_cast<float>(segments);
121 for (
int i = 0; i < segments; ++i) {
122 float angle0 = step * i;
123 float angle1 = step * (i + 1);
125 center.
GetY() + radius * std::sin(angle0),
128 center.
GetY() + radius * std::sin(angle1),
134 for (
int i = 0; i < segments; ++i) {
135 float angle0 = step * i;
136 float angle1 = step * (i + 1);
139 center.
GetZ() + radius * std::sin(angle0));
142 center.
GetZ() + radius * std::sin(angle1));
147 for (
int i = 0; i < segments; ++i) {
148 float angle0 = step * i;
149 float angle1 = step * (i + 1);
151 center.
GetY() + radius * std::cos(angle0),
152 center.
GetZ() + radius * std::sin(angle0));
154 center.
GetY() + radius * std::cos(angle1),
155 center.
GetZ() + radius * std::sin(angle1));
161 float r,
float g,
float b,
float a,
165 float radius = capsule.
radius;
168 float step = 2.0f * 3.14159265f /
static_cast<float>(segments);
171 int ax = capsule.
axis;
172 int ax1 = (ax + 1) % 3;
173 int ax2 = (ax + 2) % 3;
175 for (
int i = 0; i < segments; ++i) {
176 float angle = step * i;
177 float c1 = radius * std::cos(angle);
178 float c2 = radius * std::sin(angle);
181 if (ax1 == 0) offset.
SetX(c1);
else if (ax1 == 1) offset.
SetY(c1);
else offset.
SetZ(c1);
182 if (ax2 == 0) offset.
SetX(c2);
else if (ax2 == 1) offset.
SetY(c2);
else offset.
SetZ(c2);
184 DrawLine(pointA + offset, pointB + offset, r, g, b, a);
188 DrawSphere(pointA, radius, r, g, b, a, segments);
189 DrawSphere(pointB, radius, r, g, b, a, segments);
193 if (!s_initialized || !s_vertices || s_vertices->empty()) {
194 if (s_vertices) s_vertices->clear();
203 uint32_t vertexCount =
static_cast<uint32_t
>(s_vertices->size());
204 if (vertexCount > MAX_VERTICES) vertexCount = MAX_VERTICES;
212 s_vertexBuffer->Update(s_vertices->data(), vertexCount *
sizeof(
Vertex));
215 auto shader = s_shader;
216 auto vb = s_vertexBuffer;
217 auto cb = s_constantBuffer;
218 uint32_t count = vertexCount;
static const Math::Matrix4 & GetMainProjectionMatrix()
static const Math::Matrix4 & GetMainViewMatrix()
static void DrawLine(const Math::Vector3D &start, const Math::Vector3D &end, float r, float g, float b, float a=1.0f)
Queues a single line segment for the next Flush.
static void Flush(Camera *camera)
Uploads all queued lines and draws them in one pass, then clears the queue.
static void DrawSphere(const Math::Vector3D ¢er, float radius, float r, float g, float b, float a=1.0f, int segments=16)
Queues a wireframe sphere approximated with segments latitude/longitude rings.
static void DrawAABB(const Physics::AABB &aabb, float r, float g, float b, float a=1.0f)
Queues a wireframe box outline.
static void DrawCapsule(const Physics::BoundingCapsule &capsule, float r, float g, float b, float a=1.0f, int segments=16)
Queues a wireframe capsule outline.
static void Initialize()
Allocates the shared vertex buffer, shader, and constant buffer.
static Matrix< float, Rows, Rows > Identity()
void SubmitCustomCommand(CustomCommand::ExecuteFunction function)
Queues an arbitrary callback to run inline with other render commands.
static RenderCommandQueue * GetInstance()
Lazily creates and returns the process-wide singleton instance.
Abstract interface for high-level graphics command execution and resource management.
virtual void Draw(uint32_t vertexCount)=0
Non-indexed draw from the currently bound vertex buffer.
virtual void BindVertexBuffer(RefPtr< BufferBase > buffer, uint32_t slot=0)=0
virtual void BeginDebugLinePass()
virtual void EndDebugLinePass()
virtual void BindConstantBuffer(RefPtr< BufferBase > buffer, uint32_t slot=0)=0
static Shader * CreateShader(const std::string &ShaderPath)
Compiles a shader via the currently registered backend factory.
static BufferBase * CreateBuffer(BufferType Type, uint32_t Size, void *Data)
Creates a buffer via the currently registered backend factory.
Matrix< float, 4, 4 > Matrix4
Root namespace for everything the engine exposes.
Math::Matrix4 ViewProjection
Vector3D GetPointA() const
World position of the capsule's positive-axis cap center.
Vector3D GetPointB() const
World position of the capsule's negative-axis cap center.