// Copyright (C) 2009-2016, 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 #include namespace anki { // Forward class Renderer; class PortalComponent; class SectorComponent; class ReflectionProxyComponent; /// @addtogroup renderer /// @{ /// Draws simple primitives class DebugDrawer { public: DebugDrawer(); ~DebugDrawer(); ANKI_USE_RESULT Error init(Renderer* r); void drawGrid(); void drawSphere(F32 radius, I complexity = 8); void drawCube(F32 size = 1.0); void drawLine(const Vec3& from, const Vec3& to, const Vec4& color); void prepareFrame(CommandBufferPtr& jobs); void finishFrame(); /// @name Render functions. Imitate the GL 1.1 immediate mode /// @{ void begin(PrimitiveTopology topology); ///< Initiates the draw void end(); ///< Draws void pushBackVertex(const Vec3& pos); ///< Something like glVertex /// Something like glColor void setColor(const Vec3& col) { m_crntCol = col; } /// Something like glColor void setColor(const Vec4& col) { m_crntCol = col.xyz(); } void setModelMatrix(const Mat4& m); void setViewProjectionMatrix(const Mat4& m); /// @} void setDepthTestEnabled(Bool enabled) { m_depthTestEnabled = enabled; } Bool getDepthTestEnabled() const { return m_depthTestEnabled; } private: class Vertex { public: Vec4 m_position; Vec4 m_color; }; static const U MAX_VERTS_PER_FRAME = 1024 * 1024; Renderer* m_r; ShaderResourcePtr m_frag; ShaderResourcePtr m_vert; Array2d m_pplines; Array m_rcGroup; Array m_vertBuff; CommandBufferPtr m_cmdb; WeakArray m_clientVerts; Mat4 m_mMat; Mat4 m_vpMat; Mat4 m_mvpMat; ///< Optimization. Vec3 m_crntCol = Vec3(1.0, 0.0, 0.0); PrimitiveTopology m_primitive = PrimitiveTopology::LINES; U32 m_frameVertCount = 0; U32 m_crntDrawVertCount = 0; DynamicArray m_sphereVerts; Bool8 m_depthTestEnabled = true; PipelinePtr& getPpline(Bool depth, PrimitiveTopology topology) { U i = (depth == false) ? 0 : 1; U j = (topology == PrimitiveTopology::LINES) ? 0 : 1; return m_pplines[i][j]; } void flush(); }; /// Contains methods to render the collision shapes class CollisionDebugDrawer : public CollisionShape::ConstVisitor { public: /// Constructor CollisionDebugDrawer(DebugDrawer* dbg) : m_dbg(dbg) { } void visit(const LineSegment&); void visit(const Obb&); void visit(const Frustum&); void visit(const Plane&); void visit(const Sphere&); void visit(const Aabb&); void visit(const CompoundShape&); void visit(const ConvexHullShape&); private: DebugDrawer* m_dbg; ///< The debug drawer }; /// Implement physics debug drawer. class PhysicsDebugDrawer : public PhysicsDrawer { public: PhysicsDebugDrawer(DebugDrawer* dbg) : m_dbg(dbg) { } void drawLines( const Vec3* lines, const U32 linesCount, const Vec4& color) final; private: DebugDrawer* m_dbg; ///< The debug drawer }; /// This is a drawer for some scene nodes that need debug class SceneDebugDrawer { public: SceneDebugDrawer(DebugDrawer* d) : m_dbg(d) { } void draw(FrustumComponent& fr) const; void draw(SpatialComponent& sp) const; void draw(const PortalComponent& c) const; void draw(const SectorComponent& c) const; void drawPath(const Path& path) const; void draw(const ReflectionProxyComponent& proxy) const; private: DebugDrawer* m_dbg; }; /// @} } // end namespace anki