Path: blob/master/thirdparty/jolt_physics/Jolt/Renderer/DebugRendererRecorder.h
9906 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2021 Jorrit Rouwe2// SPDX-License-Identifier: MIT34#pragma once56#ifndef JPH_DEBUG_RENDERER7#error This file should only be included when JPH_DEBUG_RENDERER is defined8#endif // !JPH_DEBUG_RENDERER910#include <Jolt/Renderer/DebugRenderer.h>11#include <Jolt/Core/StreamOut.h>12#include <Jolt/Core/Mutex.h>13#include <Jolt/Core/UnorderedMap.h>1415JPH_NAMESPACE_BEGIN1617/// Implementation of DebugRenderer that records the API invocations to be played back later18class JPH_DEBUG_RENDERER_EXPORT DebugRendererRecorder final : public DebugRenderer19{20public:21JPH_OVERRIDE_NEW_DELETE2223/// Constructor24DebugRendererRecorder(StreamOut &inStream) : mStream(inStream) { Initialize(); }2526/// Implementation of DebugRenderer interface27virtual void DrawLine(RVec3Arg inFrom, RVec3Arg inTo, ColorArg inColor) override;28virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow) override;29virtual Batch CreateTriangleBatch(const Triangle *inTriangles, int inTriangleCount) override;30virtual Batch CreateTriangleBatch(const Vertex *inVertices, int inVertexCount, const uint32 *inIndices, int inIndexCount) override;31virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode, ECastShadow inCastShadow, EDrawMode inDrawMode) override;32virtual void DrawText3D(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight) override;3334/// Mark the end of a frame35void EndFrame();3637/// Control commands written into the stream38enum class ECommand : uint839{40CreateBatch,41CreateBatchIndexed,42CreateGeometry,43EndFrame44};4546/// Holds a single line segment47struct LineBlob48{49RVec3 mFrom;50RVec3 mTo;51Color mColor;52};5354/// Holds a single triangle55struct TriangleBlob56{57RVec3 mV1;58RVec3 mV2;59RVec3 mV3;60Color mColor;61ECastShadow mCastShadow;62};6364/// Holds a single text entry65struct TextBlob66{67TextBlob() = default;68TextBlob(RVec3Arg inPosition, const string_view &inString, ColorArg inColor, float inHeight) : mPosition(inPosition), mString(inString), mColor(inColor), mHeight(inHeight) { }6970RVec3 mPosition;71String mString;72Color mColor;73float mHeight;74};7576/// Holds a single geometry draw call77struct GeometryBlob78{79RMat44 mModelMatrix;80Color mModelColor;81uint32 mGeometryID;82ECullMode mCullMode;83ECastShadow mCastShadow;84EDrawMode mDrawMode;85};8687/// All information for a single frame88struct Frame89{90Array<LineBlob> mLines;91Array<TriangleBlob> mTriangles;92Array<TextBlob> mTexts;93Array<GeometryBlob> mGeometries;94};9596private:97/// Implementation specific batch object98class BatchImpl : public RefTargetVirtual99{100public:101JPH_OVERRIDE_NEW_DELETE102103BatchImpl(uint32 inID) : mID(inID) { }104105virtual void AddRef() override { ++mRefCount; }106virtual void Release() override { if (--mRefCount == 0) delete this; }107108atomic<uint32> mRefCount = 0;109uint32 mID;110};111112/// Lock that prevents concurrent access to the internal structures113Mutex mMutex;114115/// Stream that recorded data will be sent to116StreamOut & mStream;117118/// Next available ID119uint32 mNextBatchID = 1;120uint32 mNextGeometryID = 1;121122/// Cached geometries and their IDs123UnorderedMap<GeometryRef, uint32> mGeometries;124125/// Data that is being accumulated for the current frame126Frame mCurrentFrame;127};128129JPH_NAMESPACE_END130131132