// Copyright (C) 2009-2021, Panagiotis Christopoulos Charitos and contributors. // All rights reserved. // Code licensed under the BSD License. // http://www.anki3d.org/LICENSE #pragma once #include #include #include #include #include #include namespace anki { // Forward class RenderQueueDrawContext; class StagingGpuMemoryManager; class StagingGpuMemoryToken; /// @addtogroup renderer /// @{ /// Allocate memory for a line cube and populate it. void allocateAndPopulateDebugBox(StagingGpuMemoryManager& stagingGpuAllocator, StagingGpuMemoryToken& vertsToken, StagingGpuMemoryToken& indicesToken, U32& indexCount); /// Debug drawer. class DebugDrawer2 { public: ANKI_USE_RESULT Error init(ResourceManager* rsrcManager); Bool isInitialized() const { return m_prog.isCreated(); } void drawCubes(ConstWeakArray mvps, const Vec4& color, F32 lineSize, Bool ditherFailedDepth, F32 cubeSideSize, StagingGpuMemoryManager& stagingGpuAllocator, CommandBufferPtr& cmdb) const; void drawCube(const Mat4& mvp, const Vec4& color, F32 lineSize, Bool ditherFailedDepth, F32 cubeSideSize, StagingGpuMemoryManager& stagingGpuAllocator, CommandBufferPtr& cmdb) const { drawCubes(ConstWeakArray(&mvp, 1), color, lineSize, ditherFailedDepth, cubeSideSize, stagingGpuAllocator, cmdb); } void drawLines(ConstWeakArray mvps, const Vec4& color, F32 lineSize, Bool ditherFailedDepth, ConstWeakArray linePositions, StagingGpuMemoryManager& stagingGpuAllocator, CommandBufferPtr& cmdb) const; void drawLine(const Mat4& mvp, const Vec4& color, F32 lineSize, Bool ditherFailedDepth, const Vec3& a, const Vec3& b, StagingGpuMemoryManager& stagingGpuAllocator, CommandBufferPtr& cmdb) const { Array points = {a, b}; drawLines(ConstWeakArray(&mvp, 1), color, lineSize, ditherFailedDepth, points, stagingGpuAllocator, cmdb); } void drawBillboardTextures(const Mat4& projMat, const Mat4& viewMat, ConstWeakArray positions, const Vec4& color, Bool ditherFailedDepth, TextureViewPtr tex, SamplerPtr sampler, Vec2 billboardSize, StagingGpuMemoryManager& stagingGpuAllocator, CommandBufferPtr& cmdb) const; void drawBillboardTexture(const Mat4& projMat, const Mat4& viewMat, Vec3 position, const Vec4& color, Bool ditherFailedDepth, TextureViewPtr tex, SamplerPtr sampler, Vec2 billboardSize, StagingGpuMemoryManager& stagingGpuAllocator, CommandBufferPtr& cmdb) const { drawBillboardTextures(projMat, viewMat, ConstWeakArray(&position, 1), color, ditherFailedDepth, tex, sampler, billboardSize, stagingGpuAllocator, cmdb); } private: ShaderProgramResourcePtr m_prog; BufferPtr m_cubePositionsBuffer; BufferPtr m_cubeIndicesBuffer; }; /// Implement physics debug drawer. class PhysicsDebugDrawer : public PhysicsDrawer { public: PhysicsDebugDrawer(const DebugDrawer2* dbg) : m_dbg(dbg) { } void start(const Mat4& mvp, CommandBufferPtr& cmdb, StagingGpuMemoryManager* stagingGpuAllocator) { ANKI_ASSERT(stagingGpuAllocator); ANKI_ASSERT(m_vertCount == 0); m_mvp = mvp; m_cmdb = cmdb; m_stagingGpuAllocator = stagingGpuAllocator; } void drawLines(const Vec3* lines, const U32 vertCount, const Vec4& color) final; void end() { flush(); m_cmdb.reset(nullptr); // This is essential!!! m_stagingGpuAllocator = nullptr; } private: const DebugDrawer2* m_dbg; ///< The debug drawer Mat4 m_mvp = Mat4::getIdentity(); CommandBufferPtr m_cmdb; StagingGpuMemoryManager* m_stagingGpuAllocator = nullptr; // Use a vertex cache because drawLines() is practically called for every line Array m_vertCache; U32 m_vertCount = 0; Vec4 m_currentColor = Vec4(-1.0f); void flush(); }; /// @} } // end namespace anki