Branimir Karadžić 9 years ago
parent
commit
016d403644
2 changed files with 47 additions and 10 deletions
  1. 43 9
      examples/common/debugdraw/debugdraw.cpp
  2. 4 1
      examples/common/debugdraw/debugdraw.h

+ 43 - 9
examples/common/debugdraw/debugdraw.cpp

@@ -484,6 +484,12 @@ struct DebugDraw
 		m_stack   = 0;
 		m_stack   = 0;
 
 
 		Attrib& attrib = m_attrib[0];
 		Attrib& attrib = m_attrib[0];
+		attrib.m_state = 0
+			| BGFX_STATE_RGB_WRITE
+			| BGFX_STATE_DEPTH_TEST_LESS
+			| BGFX_STATE_DEPTH_WRITE
+			| BGFX_STATE_CULL_CW
+			;
 		attrib.m_scale     = 1.0f;
 		attrib.m_scale     = 1.0f;
 		attrib.m_offset    = 0.0f;
 		attrib.m_offset    = 0.0f;
 		attrib.m_abgr      = UINT32_MAX;
 		attrib.m_abgr      = UINT32_MAX;
@@ -546,6 +552,31 @@ struct DebugDraw
 		setTranslate(_pos[0], _pos[1], _pos[2]);
 		setTranslate(_pos[0], _pos[1], _pos[2]);
 	}
 	}
 
 
+	void setState(bool _depthTest, bool _depthWrite, bool _clockwise)
+	{
+		m_attrib[m_stack].m_state &= ~(0
+			| BGFX_STATE_DEPTH_TEST_LESS
+			| BGFX_STATE_DEPTH_WRITE
+			| BGFX_STATE_CULL_CW
+			| BGFX_STATE_CULL_CCW
+			);
+
+		m_attrib[m_stack].m_state |= _depthTest
+			? BGFX_STATE_DEPTH_TEST_LESS
+			: 0
+			;
+
+		m_attrib[m_stack].m_state |= _depthWrite
+			? BGFX_STATE_DEPTH_WRITE
+			: 0
+			;
+
+		m_attrib[m_stack].m_state |= _clockwise
+			? BGFX_STATE_CULL_CW
+			: BGFX_STATE_CULL_CCW
+			;
+	}
+
 	void setColor(uint32_t _abgr)
 	void setColor(uint32_t _abgr)
 	{
 	{
 		BX_CHECK(State::Count != m_state);
 		BX_CHECK(State::Count != m_state);
@@ -792,7 +823,7 @@ struct DebugDraw
 		draw(Mesh::Enum(Mesh::Sphere0 + lod), mtx, attrib.m_wireframe);
 		draw(Mesh::Enum(Mesh::Sphere0 + lod), mtx, attrib.m_wireframe);
 	}
 	}
 
 
-	void draw(const float* _viewProj)
+	void drawFrustum(const float* _viewProj)
 	{
 	{
 		Plane planes[6];
 		Plane planes[6];
 		buildFrustumPlanes(planes, _viewProj);
 		buildFrustumPlanes(planes, _viewProj);
@@ -832,9 +863,9 @@ struct DebugDraw
 		lineTo(&points[21]);
 		lineTo(&points[21]);
 	}
 	}
 
 
-	void draw(const void* _viewProj)
+	void drawFrustum(const void* _viewProj)
 	{
 	{
-		draw( (const float*)_viewProj);
+		drawFrustum( (const float*)_viewProj);
 	}
 	}
 
 
 	void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
 	void drawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
@@ -1160,10 +1191,7 @@ private:
 		bgfx::setTransform(_mtx);
 		bgfx::setTransform(_mtx);
 		bgfx::setVertexBuffer(m_vbh, mesh.m_startVertex, mesh.m_numVertices);
 		bgfx::setVertexBuffer(m_vbh, mesh.m_startVertex, mesh.m_numVertices);
 		bgfx::setState(0
 		bgfx::setState(0
-				| BGFX_STATE_RGB_WRITE
-				| BGFX_STATE_DEPTH_TEST_LESS
-				| BGFX_STATE_DEPTH_WRITE
-				| BGFX_STATE_CULL_CW
+				| attrib.m_state
 				| (_wireframe ? BGFX_STATE_PT_LINES : 0)
 				| (_wireframe ? BGFX_STATE_PT_LINES : 0)
 				);
 				);
 		bgfx::submit(m_viewId, m_program[_wireframe ? Program::Fill : Program::FillLit]);
 		bgfx::submit(m_viewId, m_program[_wireframe ? Program::Fill : Program::FillLit]);
@@ -1238,6 +1266,7 @@ private:
 
 
 	struct Attrib
 	struct Attrib
 	{
 	{
+		uint64_t m_state;
 		float    m_offset;
 		float    m_offset;
 		float    m_scale;
 		float    m_scale;
 		uint32_t m_abgr;
 		uint32_t m_abgr;
@@ -1293,6 +1322,11 @@ void ddPop()
 	s_dd.pop();
 	s_dd.pop();
 }
 }
 
 
+void ddSetState(bool _depthTest, bool _depthWrite, bool _clockwise)
+{
+	s_dd.setState(_depthTest, _depthWrite, _clockwise);
+}
+
 void ddSetColor(uint32_t _abgr)
 void ddSetColor(uint32_t _abgr)
 {
 {
 	s_dd.setColor(_abgr);
 	s_dd.setColor(_abgr);
@@ -1373,9 +1407,9 @@ void ddDraw(const Sphere& _sphere)
 	s_dd.draw(_sphere);
 	s_dd.draw(_sphere);
 }
 }
 
 
-void ddDraw(const void* _viewProj)
+void ddDrawFrustum(const void* _viewProj)
 {
 {
-	s_dd.draw(_viewProj);
+	s_dd.drawFrustum(_viewProj);
 }
 }
 
 
 void ddDrawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)
 void ddDrawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees)

+ 4 - 1
examples/common/debugdraw/debugdraw.h

@@ -39,6 +39,9 @@ void ddPush();
 ///
 ///
 void ddPop();
 void ddPop();
 
 
+///
+void ddSetState(bool _depthTest, bool _depthWrite, bool _clockwise);
+
 ///
 ///
 void ddSetColor(uint32_t _abgr);
 void ddSetColor(uint32_t _abgr);
 
 
@@ -88,7 +91,7 @@ void ddDraw(const Obb& _obb);
 void ddDraw(const Sphere& _sphere);
 void ddDraw(const Sphere& _sphere);
 
 
 ///
 ///
-void ddDraw(const void* _viewProj);
+void ddDrawFrustum(const void* _viewProj);
 
 
 ///
 ///
 void ddDrawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees);
 void ddDrawArc(Axis::Enum _axis, float _x, float _y, float _z, float _radius, float _degrees);