Path: blob/master/thirdparty/jolt_physics/Jolt/Renderer/DebugRendererSimple.h
9912 views
// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)1// SPDX-FileCopyrightText: 2024 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>1112JPH_NAMESPACE_BEGIN1314/// Inherit from this class to simplify implementing a debug renderer, start with this implementation:15///16/// class MyDebugRenderer : public JPH::DebugRendererSimple17/// {18/// public:19/// virtual void DrawLine(JPH::RVec3Arg inFrom, JPH::RVec3Arg inTo, JPH::ColorArg inColor) override20/// {21/// // Implement22/// }23///24/// virtual void DrawTriangle(JPH::RVec3Arg inV1, JPH::RVec3Arg inV2, JPH::RVec3Arg inV3, JPH::ColorArg inColor, ECastShadow inCastShadow) override25/// {26/// // Implement27/// }28///29/// virtual void DrawText3D(JPH::RVec3Arg inPosition, const string_view &inString, JPH::ColorArg inColor, float inHeight) override30/// {31/// // Implement32/// }33/// };34///35/// 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.36class JPH_DEBUG_RENDERER_EXPORT DebugRendererSimple : public DebugRenderer37{38public:39JPH_OVERRIDE_NEW_DELETE4041/// Constructor42DebugRendererSimple();4344/// Should be called every frame by the application to provide the camera position.45/// This is used to determine the correct LOD for rendering.46void SetCameraPos(RVec3Arg inCameraPos)47{48mCameraPos = inCameraPos;49mCameraPosSet = true;50}5152/// Fallback implementation that uses DrawLine to draw a triangle (override this if you have a version that renders solid triangles)53virtual void DrawTriangle(RVec3Arg inV1, RVec3Arg inV2, RVec3Arg inV3, ColorArg inColor, ECastShadow inCastShadow) override54{55DrawLine(inV1, inV2, inColor);56DrawLine(inV2, inV3, inColor);57DrawLine(inV3, inV1, inColor);58}5960protected:61/// Implementation of DebugRenderer interface62virtual Batch CreateTriangleBatch(const Triangle *inTriangles, int inTriangleCount) override;63virtual Batch CreateTriangleBatch(const Vertex *inVertices, int inVertexCount, const uint32 *inIndices, int inIndexCount) override;64virtual void DrawGeometry(RMat44Arg inModelMatrix, const AABox &inWorldSpaceBounds, float inLODScaleSq, ColorArg inModelColor, const GeometryRef &inGeometry, ECullMode inCullMode, ECastShadow inCastShadow, EDrawMode inDrawMode) override;6566private:67/// Implementation specific batch object68class BatchImpl : public RefTargetVirtual69{70public:71JPH_OVERRIDE_NEW_DELETE7273virtual void AddRef() override { ++mRefCount; }74virtual void Release() override { if (--mRefCount == 0) delete this; }7576Array<Triangle> mTriangles;7778private:79atomic<uint32> mRefCount = 0;80};8182/// Last provided camera position83RVec3 mCameraPos;84bool mCameraPosSet = false;85};8687JPH_NAMESPACE_END888990