Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
DebugRendererRecorder.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 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
12#include <Jolt/Core/StreamOut.h>
13#include <Jolt/Core/Mutex.h>
15
17
20{
21public:
23
25 DebugRendererRecorder(StreamOut &inStream) : mStream(inStream) { Initialize(); }
26
28 virtual void DrawLine(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor) override;
29 virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor) override;
30 virtual Batch CreateTriangleBatch(const Triangle *inTriangles, int inTriangleCount) override;
31 virtual Batch CreateTriangleBatch(const Vertex *inVertices, int inVertexCount, const uint32 *inIndices, int inIndexCount) override;
32 virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode, ECastShadow inCastShadow, EDrawMode inDrawMode) override;
33 virtual void DrawText3D(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight) override;
34
36 void EndFrame();
37
39 enum class ECommand : uint8
40 {
45 };
46
48 struct LineBlob
49 {
53 };
54
57 {
62 };
63
65 struct TextBlob
66 {
67 TextBlob() = default;
68 TextBlob(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight) : mPosition(inPosition), mString(inString), mColor(inColor), mHeight(inHeight) { }
69
73 float mHeight;
74 };
75
78 {
85 };
86
88 struct Frame
89 {
94 };
95
96private:
98 class BatchImpl : public RefTargetVirtual
99 {
100 public:
102
103 BatchImpl(uint32 inID) : mID(inID) { }
104
105 virtual void AddRef() override { ++mRefCount; }
106 virtual void Release() override { if (--mRefCount == 0) delete this; }
107
108 atomic<uint32> mRefCount = 0;
109 uint32 mID;
110 };
111
113 Mutex mMutex;
114
116 StreamOut & mStream;
117
119 uint32 mNextBatchID = 1;
120 uint32 mNextGeometryID = 1;
121
124
126 Frame mCurrentFrame;
127};
128
uint32_t uint32
Definition: Core.h:312
#define JPH_NAMESPACE_END
Definition: Core.h:240
uint8_t uint8
Definition: Core.h:310
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
std::basic_string< char, std::char_traits< char >, STLAllocator< char > > String
Definition: STLAllocator.h:82
std::vector< T, STLAllocator< T > > Array
Definition: STLAllocator.h:81
std::unordered_map< Key, T, Hash, KeyEqual, STLAllocator< pair< const Key, T > > > UnorderedMap
Definition: UnorderedMap.h:13
Axis aligned box.
Definition: AABox.h:16
Class that holds an RGBA color with 8-bits per component.
Definition: Color.h:16
Simple triangle renderer for debugging purposes.
Definition: DebugRenderer.h:25
Ref< RefTargetVirtual > Batch
Handle for a batch of triangles.
Definition: DebugRenderer.h:155
Ref< Geometry > GeometryRef
Handle for a lodded triangle batch.
Definition: DebugRenderer.h:183
void Initialize()
Initialize the system, must be called from the constructor of the DebugRenderer implementation.
Definition: DebugRenderer.cpp:396
ECullMode
Determines which polygons are culled.
Definition: DebugRenderer.h:202
ECastShadow
Enum that determines if a shadow should be cast or not.
Definition: DebugRenderer.h:66
EDrawMode
Determines how triangles are drawn.
Definition: DebugRenderer.h:73
Implementation of DebugRenderer that records the API invocations to be played back later.
Definition: DebugRendererRecorder.h:20
void EndFrame()
Mark the end of a frame.
Definition: DebugRendererRecorder.cpp:103
virtual void DrawText3D(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight) override
Draw text.
Definition: DebugRendererRecorder.cpp:96
virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor) override
Draw a single back face culled triangle without any shadows.
Definition: DebugRendererRecorder.cpp:20
ECommand
Control commands written into the stream.
Definition: DebugRendererRecorder.h:40
virtual Batch CreateTriangleBatch(const Triangle *inTriangles, int inTriangleCount) override
Create a batch of triangles that can be drawn efficiently.
Definition: DebugRendererRecorder.cpp:27
virtual void DrawLine(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor) override
Implementation of DebugRenderer interface.
Definition: DebugRendererRecorder.cpp:13
JPH_OVERRIDE_NEW_DELETE DebugRendererRecorder(StreamOut &inStream)
Constructor.
Definition: DebugRendererRecorder.h:25
virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode, ECastShadow inCastShadow, EDrawMode inDrawMode) override
Definition: DebugRendererRecorder.cpp:65
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition: Mat44.h:13
Definition: Mutex.h:122
Pure virtual version of RefTarget.
Definition: Reference.h:82
Simple binary output stream.
Definition: StreamOut.h:11
A simple triangle and its material.
Definition: Triangle.h:11
Definition: Vec3.h:16
All information for a single frame.
Definition: DebugRendererRecorder.h:89
Array< LineBlob > mLines
Definition: DebugRendererRecorder.h:90
Array< TextBlob > mTexts
Definition: DebugRendererRecorder.h:92
Array< GeometryBlob > mGeometries
Definition: DebugRendererRecorder.h:93
Array< TriangleBlob > mTriangles
Definition: DebugRendererRecorder.h:91
Holds a single geometry draw call.
Definition: DebugRendererRecorder.h:78
EDrawMode mDrawMode
Definition: DebugRendererRecorder.h:84
uint32 mGeometryID
Definition: DebugRendererRecorder.h:81
ECullMode mCullMode
Definition: DebugRendererRecorder.h:82
ECastShadow mCastShadow
Definition: DebugRendererRecorder.h:83
Color mModelColor
Definition: DebugRendererRecorder.h:80
RMat44 mModelMatrix
Definition: DebugRendererRecorder.h:79
Holds a single line segment.
Definition: DebugRendererRecorder.h:49
RVec3 mTo
Definition: DebugRendererRecorder.h:51
RVec3 mFrom
Definition: DebugRendererRecorder.h:50
Color mColor
Definition: DebugRendererRecorder.h:52
Holds a single text entry.
Definition: DebugRendererRecorder.h:66
String mString
Definition: DebugRendererRecorder.h:71
float mHeight
Definition: DebugRendererRecorder.h:73
TextBlob(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight)
Definition: DebugRendererRecorder.h:68
Color mColor
Definition: DebugRendererRecorder.h:72
RVec3 mPosition
Definition: DebugRendererRecorder.h:70
Holds a single triangle.
Definition: DebugRendererRecorder.h:57
RVec3 mV1
Definition: DebugRendererRecorder.h:58
Color mColor
Definition: DebugRendererRecorder.h:61
RVec3 mV3
Definition: DebugRendererRecorder.h:60
RVec3 mV2
Definition: DebugRendererRecorder.h:59