Debian Codegraph @

thirdparty/jolt_physics/Jolt/Renderer/DebugRendererSimple.h

raw symbols SCIP
1 // Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2 // SPDX-FileCopyrightText: 2024 Jorrit Rouwe
3 // SPDX-License-Identifier: MIT
4
5 #pragma once
6
7 #ifndef JPH_DEBUG_RENDERER
8 #error This file should only be included when JPH_DEBUG_RENDERER is defined
9 #endif // !JPH_DEBUG_RENDERER
10
11 #include <Jolt/Renderer/DebugRenderer.h>
12
13 JPH_NAMESPACE_BEGIN
14
15 /// Inherit from this class to simplify implementing a debug renderer, start with this implementation:
16 ///
17 /// class MyDebugRenderer : public JPH::DebugRendererSimple
18 /// {
19 /// public:
20 /// virtual void DrawLine(JPH::RVec3Arg inFrom, JPH::RVec3Arg inTo, JPH::ColorArg inColor) override
21 /// {
22 /// // Implement
23 /// }
24 ///
25 /// virtual void DrawTriangle(JPH::RVec3Arg inV1, JPH::RVec3Arg inV2, JPH::RVec3Arg inV3, JPH::ColorArg inColor, ECastShadow inCastShadow) override
26 /// {
27 /// // Implement
28 /// }
29 ///
30 /// virtual void DrawText3D(JPH::RVec3Arg inPosition, const string_view &inString, JPH::ColorArg inColor, float inHeight) override
31 /// {
32 /// // Implement
33 /// }
34 /// };
35 ///
36 /// Note that this class is meant to be a quick start for implementing a debug renderer, it is not the most efficient way to implement a debug renderer.
37 class JPH_DEBUG_RENDERER_EXPORT DebugRendererSimple : public DebugRenderer
38 {
39 public:
40 JPH_OVERRIDE_NEW_DELETE
41
42 /// Constructor
43 DebugRendererSimple();
44
45 /// Should be called every frame by the application to provide the camera position.
46 /// This is used to determine the correct LOD for rendering.
47 void SetCameraPos(RVec3Arg inCameraPos)
48 {
49 mCameraPos = inCameraPos;
50 mCameraPosSet = true;
51 }
52
53 /// Fallback implementation that uses DrawLine to draw a triangle (override this if you have a version that renders solid triangles)
54 virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow) override
55 {
56 DrawLine(inV1, inV2, inColor);
57 DrawLine(inV2, inV3, inColor);
58 DrawLine(inV3, inV1, inColor);
59 }
60
61 protected:
62 /// Implementation of DebugRenderer interface
63 virtual Batch CreateTriangleBatch(const Triangle *inTriangles, int inTriangleCount) override;
64 virtual Batch CreateTriangleBatch(const Vertex *inVertices, int inVertexCount, const uint32 *inIndices, int inIndexCount) override;
65 virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode, ECastShadow inCastShadow, EDrawMode inDrawMode) override;
66
67 private:
68 /// Implementation specific batch object
69 class BatchImpl : public RefTargetVirtual
70 {
71 public:
72 JPH_OVERRIDE_NEW_DELETE
73
74 virtual void AddRef() override { ++mRefCount; }
75 virtual void Release() override { if (--mRefCount == 0) delete this; }
76
77 Array<Triangle> mTriangles;
78
79 private:
80 atomic<uint32> mRefCount = 0;
81 };
82
83 /// Last provided camera position
84 RVec3 mCameraPos;
85 bool mCameraPosSet = false;
86 };
87
88 JPH_NAMESPACE_END