Browse Source

Fixing Dgb stage

Panagiotis Christopoulos Charitos 13 years ago
parent
commit
6edb6bc245

+ 13 - 34
include/anki/renderer/Drawer.h

@@ -7,6 +7,7 @@
 #include "anki/resource/Resource.h"
 #include "anki/collision/CollisionShape.h"
 #include "anki/scene/SceneNode.h"
+#include "anki/util/Flags.h"
 #include <array>
 #include <map>
 #include <LinearMath/btIDebugDraw.h>
@@ -40,8 +41,8 @@ public:
 	{
 		crntCol = Vec3(col);
 	}
-	void setModelMat(const Mat4& modelMat);
-	void setViewProjectionMat(const Mat4& m)
+	void setModelMatrix(const Mat4& modelMat);
+	void setViewProjectionMatrix(const Mat4& m)
 	{
 		vpMat = m;
 	}
@@ -148,58 +149,36 @@ class Renderer;
 class Camera;
 
 /// This is a drawer for some scene nodes that need debug
-class SceneDebugDrawer
+class SceneDebugDrawer: public Flags<uint32_t>
 {
 public:
 	enum DebugFlag
 	{
 		DF_NONE = 0,
-		DF_SPATIAL = 1,
-		DF_MOVABLE = 2,
-		DF_FRUSTUMABLE = 4
+		DF_SPATIAL = 1 << 0,
+		DF_FRUSTUMABLE = 1 << 1
 	};
 
 	SceneDebugDrawer(DebugDrawer* d)
-		: dbg(d), flags(DF_NONE)
+		: Flags<uint32_t>(DF_SPATIAL | DF_FRUSTUMABLE), dbg(d)
 	{}
 
 	virtual ~SceneDebugDrawer()
 	{}
 
-	/// @name Flag manipulation
-	/// @{
-	void enableFlag(DebugFlag flag, bool enable = true)
-	{
-		flags = enable ? flags | flag : flags & ~flag;
-	}
-	void disableFlag(DebugFlag flag)
-	{
-		enableFlag(flag, false);
-	}
-	bool isFlagEnabled(DebugFlag flag) const
-	{
-		return flags & flag;
-	}
-	uint getFlagsBitmask() const
-	{
-		return flags;
-	}
-	/// @}
-
-	void draw(const SceneNode& node);
+	void draw(SceneNode& node);
 
-	virtual void draw(const Octree& octree) const;
+	virtual void draw(Octree& octree) const;
 
 private:
 	DebugDrawer* dbg;
-	uint flags;
 
-	virtual void draw(const Frustumable& fr) const;
+	virtual void draw(Frustumable& fr) const;
 
-	virtual void draw(const Spatial& sp) const;
+	virtual void draw(Spatial& sp) const;
 
-	virtual void draw(const OctreeNode& octnode,
-		uint depth, const Octree& octree) const;
+	virtual void draw(OctreeNode& octnode,
+		uint depth, Octree& octree) const;
 };
 
 class PassLevelKey;

+ 1 - 1
include/anki/renderer/Renderer.h

@@ -166,7 +166,7 @@ public:
 		return framesNum;
 	}
 
-	const Mat4& getViewProjectionMat() const
+	const Mat4& getViewProjectionMatrix() const
 	{
 		return viewProjectionMat;
 	}

+ 0 - 28
include/anki/scene/SceneNode.h

@@ -74,34 +74,6 @@ public:
 	}
 	/// @}
 
-	/// @name Accessors of components (const version)
-	/// @{
-	const Movable* getMovable() const
-	{
-		return const_cast<const Movable*>(getMovable());
-	}
-
-	const Renderable* getRenderable() const
-	{
-		return const_cast<const Renderable*>(getRenderable());
-	}
-
-	const Frustumable* getFrustumable() const
-	{
-		return const_cast<const Frustumable*>(getFrustumable());
-	}
-
-	const Spatial* getSpatial() const
-	{
-		return const_cast<const Spatial*>(getSpatial());
-	}
-
-	const Light* getLight() const
-	{
-		return const_cast<const Light*>(getLight());
-	}
-	/// @}
-
 	/// This is called by the scene every frame after logic and before
 	/// rendering. By default it does nothing
 	/// @param[in] prevUpdateTime Timestamp of the previous update

+ 12 - 5
include/anki/util/Flags.h

@@ -10,28 +10,35 @@ class Flags
 public:
 	typedef T Value;
 
+	Flags()
+	{}
+
+	Flags(T mask_)
+		: mask(mask_)
+	{}
+
 	/// @name Flag manipulation
 	/// @{
 	void enableFlag(Value flag)
 	{
-		flags |= flag;
+		mask |= flag;
 	}
 	void disableFlag(Value flag)
 	{
-		flags &= ~flag;
+		mask &= ~flag;
 	}
 	bool isFlagEnabled(Value flag) const
 	{
-		return flags & flag;
+		return mask & flag;
 	}
 	Value getFlagsBitmask() const
 	{
-		return flags;
+		return mask;
 	}
 	/// @}
 
 protected:
-	Value flags = 0;
+	Value mask = 0;
 };
 
 } // end namespace anki

+ 3 - 0
src/renderer/Dbg.cpp

@@ -2,6 +2,7 @@
 #include "anki/renderer/Renderer.h"
 #include "anki/resource/ShaderProgramResource.h"
 #include "anki/scene/Scene.h"
+#include "anki/core/Logger.h"
 
 namespace anki {
 
@@ -43,6 +44,8 @@ void Dbg::run()
 
 	fbo.bind();
 
+	drawer->setViewProjectionMatrix(r->getViewProjectionMatrix());
+	drawer->setModelMatrix(Mat4::getIdentity());
 	drawer->drawGrid();
 
 	for(auto it = scene.getAllNodesBegin(); it != scene.getAllNodesEnd(); it++)

+ 15 - 20
src/renderer/Drawer.cpp

@@ -190,7 +190,7 @@ void DebugDrawer::drawCube(float size)
 }
 
 //==============================================================================
-void DebugDrawer::setModelMat(const Mat4& modelMat_)
+void DebugDrawer::setModelMatrix(const Mat4& modelMat_)
 {
 	ANKI_ASSERT(pointIndex == 0
 		&& "The func called after begin and before end");
@@ -238,7 +238,7 @@ void DebugDrawer::pushBackVertex(const Vec3& pos)
 //==============================================================================
 void CollisionDebugDrawer::visit(const Sphere& sphere)
 {
-	dbg->setModelMat(Mat4(sphere.getCenter(), Mat3::getIdentity(), 1.0));
+	dbg->setModelMatrix(Mat4(sphere.getCenter(), Mat3::getIdentity(), 1.0));
 	dbg->drawSphere(sphere.getRadius());
 }
 
@@ -258,7 +258,7 @@ void CollisionDebugDrawer::visit(const Obb& obb)
 	tsl = Mat4::combineTransformations(rot, scale);
 	tsl = Mat4::combineTransformations(trs, tsl);
 
-	dbg->setModelMat(tsl);
+	dbg->setModelMatrix(tsl);
 	dbg->setColor(Vec3(1.0, 1.0, 0.0));
 	dbg->drawCube(2.0);
 }
@@ -274,7 +274,7 @@ void CollisionDebugDrawer::visit(const Plane& plane)
 	rot.rotateXAxis(Math::PI / 2);
 	Mat4 trf(n * o, rot);
 
-	dbg->setModelMat(trf);
+	dbg->setModelMatrix(trf);
 	dbg->drawGrid();
 }
 
@@ -294,7 +294,7 @@ void CollisionDebugDrawer::visit(const Aabb& aabb)
 	// Translation
 	trf.setTranslationPart((max + min) / 2.0);
 
-	dbg->setModelMat(trf);
+	dbg->setModelMatrix(trf);
 	dbg->drawCube();
 }
 
@@ -308,7 +308,7 @@ void CollisionDebugDrawer::visit(const Frustum& f)
 			break;
 		case Frustum::FT_PERSPECTIVE:
 		{
-			dbg->setColor(Vec4(1.0, 0.0, 1.0, 1.0));
+			dbg->setColor(Vec4(0.5, 0.0, 0.5, 1.0));
 			const PerspectiveFrustum& pf =
 				static_cast<const PerspectiveFrustum&>(f);
 
@@ -355,7 +355,7 @@ void PhysicsDebugDrawer::drawSphere(btScalar radius,
 	const btVector3& color)
 {
 	dbg->setColor(toAnki(color));
-	dbg->setModelMat(Mat4(toAnki(transform)));
+	dbg->setModelMatrix(Mat4(toAnki(transform)));
 	dbg->drawSphere(radius);
 }
 
@@ -370,7 +370,7 @@ void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 	trf(0, 3) = (max.getX() + min.getX()) / 2.0;
 	trf(1, 3) = (max.getY() + min.getY()) / 2.0;
 	trf(2, 3) = (max.getZ() + min.getZ()) / 2.0;
-	dbg->setModelMat(trf);
+	dbg->setModelMatrix(trf);
 	dbg->setColor(toAnki(color));
 	dbg->drawCube(1.0);
 }
@@ -387,7 +387,7 @@ void PhysicsDebugDrawer::drawBox(const btVector3& min, const btVector3& max,
 	trf(1, 3) = (max.getY() + min.getY()) / 2.0;
 	trf(2, 3) = (max.getZ() + min.getZ()) / 2.0;
 	trf = Mat4::combineTransformations(Mat4(toAnki(trans)), trf);
-	dbg->setModelMat(trf);
+	dbg->setModelMatrix(trf);
 	dbg->setColor(toAnki(color));
 	dbg->drawCube(1.0);
 }
@@ -418,7 +418,7 @@ void PhysicsDebugDrawer::draw3dText(const btVector3& /*location*/,
 //==============================================================================
 
 //==============================================================================
-void SceneDebugDrawer::draw(const SceneNode& node)
+void SceneDebugDrawer::draw(SceneNode& node)
 {
 	if(isFlagEnabled(DF_FRUSTUMABLE) && node.getFrustumable())
 	{
@@ -431,9 +431,8 @@ void SceneDebugDrawer::draw(const SceneNode& node)
 	}
 }
 
-
 //==============================================================================
-void SceneDebugDrawer::draw(const Frustumable& fr) const
+void SceneDebugDrawer::draw(Frustumable& fr) const
 {
 	const Frustum& fs = fr.getFrustum();
 
@@ -441,9 +440,8 @@ void SceneDebugDrawer::draw(const Frustumable& fr) const
 	fs.accept(coldraw);
 }
 
-
 //==============================================================================
-void SceneDebugDrawer::draw(const Spatial& x) const
+void SceneDebugDrawer::draw(Spatial& x) const
 {
 	const CollisionShape& cs = x.getSpatialCollisionShape();
 
@@ -451,18 +449,16 @@ void SceneDebugDrawer::draw(const Spatial& x) const
 	cs.accept(coldraw);
 }
 
-
 //==============================================================================
-void SceneDebugDrawer::draw(const Octree& octree) const
+void SceneDebugDrawer::draw(Octree& octree) const
 {
 	dbg->setColor(Vec3(1.0));
 	draw(octree.getRoot(), 0, octree);
 }
 
-
 //==============================================================================
-void SceneDebugDrawer::draw(const OctreeNode& octnode, uint depth,
-	const Octree& octree) const
+void SceneDebugDrawer::draw(OctreeNode& octnode, uint depth,
+	Octree& octree) const
 {
 	Vec3 color = Vec3(1.0 - float(depth) / float(octree.getMaxDepth()));
 	dbg->setColor(color);
@@ -578,5 +574,4 @@ void RenderableDrawer::render(const Camera& cam, uint pass,
 	vao.unbind();
 }
 
-
 }  // namespace anki