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, ECastShadow inCastShadow) 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 {
41 CreateBatch,
42 CreateBatchIndexed,
43 CreateGeometry,
44 EndFrame
45 };
46
48 struct LineBlob
49 {
53 };
54
57 {
63 };
64
66 struct TextBlob
67 {
68 TextBlob() = default;
69 TextBlob(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight) : mPosition(inPosition), mString(inString), mColor(inColor), mHeight(inHeight) { }
70
74 float mHeight;
75 };
76
79 {
86 };
87
89 struct Frame
90 {
95 };
96
97private:
99 class BatchImpl : public RefTargetVirtual
100 {
101 public:
103
104 BatchImpl(uint32 inID) : mID(inID) { }
105
106 virtual void AddRef() override { ++mRefCount; }
107 virtual void Release() override { if (--mRefCount == 0) delete this; }
108
109 atomic<uint32> mRefCount = 0;
110 uint32 mID;
111 };
112
114 Mutex mMutex;
115
117 StreamOut & mStream;
118
120 uint32 mNextBatchID = 1;
121 uint32 mNextGeometryID = 1;
122
125
127 Frame mCurrentFrame;
128};
129
std::uint8_t uint8
Definition: Core.h:453
#define JPH_NAMESPACE_END
Definition: Core.h:378
std::uint32_t uint32
Definition: Core.h:455
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
#define JPH_DEBUG_RENDERER_EXPORT
Definition: DebugRenderer.h:13
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:31
std::basic_string< char, std::char_traits< char >, STLAllocator< char > > String
Definition: STLAllocator.h:107
std::unordered_map< Key, T, Hash, KeyEqual, STLAllocator< pair< const Key, T > > > UnorderedMap
Definition: UnorderedMap.h:13
Axis aligned box.
Definition: AABox.h:16
Definition: Array.h:36
Class that holds an RGBA color with 8-bits per component.
Definition: Color.h:16
Definition: DebugRenderer.h:47
virtual void DrawText3D(RVec3Arg inPosition, const string_view &inString, ColorArg inColor=Color::sWhite, float inHeight=0.5f)=0
Draw text.
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:254
virtual Batch CreateTriangleBatch(const Triangle *inTriangles, int inTriangleCount)=0
Create a batch of triangles that can be drawn efficiently.
virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode=ECullMode::CullBackFace, ECastShadow inCastShadow=ECastShadow::On, EDrawMode inDrawMode=EDrawMode::Solid)=0
ECastShadow
Enum that determines if a shadow should be cast or not.
Definition: DebugRenderer.h:91
EDrawMode
Determines how triangles are drawn.
Definition: DebugRenderer.h:98
virtual void DrawLine(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor)=0
Draw line.
virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow=ECastShadow::Off)=0
Draw a single back face culled triangle.
Implementation of DebugRenderer that records the API invocations to be played back later.
Definition: DebugRendererRecorder.h:20
ECommand
Control commands written into the stream.
Definition: DebugRendererRecorder.h:40
JPH_OVERRIDE_NEW_DELETE DebugRendererRecorder(StreamOut &inStream)
Constructor.
Definition: DebugRendererRecorder.h:25
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:13
A simple triangle and its material.
Definition: Triangle.h:11
Definition: Vec3.h:17
All information for a single frame.
Definition: DebugRendererRecorder.h:90
Array< LineBlob > mLines
Definition: DebugRendererRecorder.h:91
Array< TextBlob > mTexts
Definition: DebugRendererRecorder.h:93
Array< GeometryBlob > mGeometries
Definition: DebugRendererRecorder.h:94
Array< TriangleBlob > mTriangles
Definition: DebugRendererRecorder.h:92
Holds a single geometry draw call.
Definition: DebugRendererRecorder.h:79
EDrawMode mDrawMode
Definition: DebugRendererRecorder.h:85
uint32 mGeometryID
Definition: DebugRendererRecorder.h:82
ECullMode mCullMode
Definition: DebugRendererRecorder.h:83
ECastShadow mCastShadow
Definition: DebugRendererRecorder.h:84
Color mModelColor
Definition: DebugRendererRecorder.h:81
RMat44 mModelMatrix
Definition: DebugRendererRecorder.h:80
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:67
String mString
Definition: DebugRendererRecorder.h:72
float mHeight
Definition: DebugRendererRecorder.h:74
TextBlob(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight)
Definition: DebugRendererRecorder.h:69
Color mColor
Definition: DebugRendererRecorder.h:73
RVec3 mPosition
Definition: DebugRendererRecorder.h:71
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
ECastShadow mCastShadow
Definition: DebugRendererRecorder.h:62
RVec3 mV2
Definition: DebugRendererRecorder.h:59