Browse Source

Prepare the visibility tests for the octree

Panagiotis Christopoulos Charitos 7 years ago
parent
commit
eac3974ab8

+ 2 - 0
src/anki/scene/Octree.h

@@ -208,6 +208,8 @@ class OctreePlaceable : public NonCopyable
 	friend class Octree;
 
 public:
+	void* m_userData = nullptr;
+
 	void reset()
 	{
 		m_visitedMask.set(0);

+ 39 - 0
src/anki/scene/VisibilityInternal.h

@@ -9,6 +9,8 @@
 #include <anki/scene/SectorNode.h>
 #include <anki/scene/SceneGraph.h>
 #include <anki/scene/SoftwareRasterizer.h>
+#include <anki/scene/components/FrustumComponent.h>
+#include <anki/scene/Octree.h>
 #include <anki/util/Thread.h>
 #include <anki/core/Trace.h>
 
@@ -176,6 +178,43 @@ private:
 	void rasterize();
 };
 
+/// ThreadHive task to get visible nodes from the octree.
+class GatherVisiblesFromOctreeTask
+{
+public:
+	VisibilityContext* m_visCtx ANKI_DBG_NULLIFY;
+	FrustumComponent* m_frc ANKI_DBG_NULLIFY; ///< What to test against.
+	WeakArray<OctreePlaceable*> m_octreePlaceables; ///< The results of the task.
+
+	/// Thread hive task.
+	static void callback(void* ud, U32 threadId, ThreadHive& hive)
+	{
+		GatherVisiblesFromOctreeTask& self = *static_cast<GatherVisiblesFromOctreeTask*>(ud);
+		self.gather();
+	}
+
+private:
+	void gather()
+	{
+		ANKI_TRACE_SCOPED_EVENT(SCENE_VISIBILITY_OCTREE);
+		U testIdx = m_visCtx->m_testsCount.fetchAdd(1);
+
+		DynamicArrayAuto<OctreePlaceable*> arr(m_visCtx->m_scene->getFrameAllocator());
+		m_visCtx->m_scene->getOctree().gatherVisible(m_frc->getFrustum(), testIdx, arr);
+
+		if(arr.getSize() > 0)
+		{
+			OctreePlaceable** data;
+			PtrSize size;
+			PtrSize storage;
+			arr.moveAndReset(data, size, storage);
+
+			ANKI_ASSERT(data && size);
+			m_octreePlaceables = WeakArray<OctreePlaceable*>(data, size);
+		}
+	}
+};
+
 /// ThreadHive task to get visible nodes from sectors.
 class GatherVisiblesFromSectorsTask
 {

+ 1 - 0
src/anki/scene/components/SpatialComponent.cpp

@@ -17,6 +17,7 @@ SpatialComponent::SpatialComponent(SceneNode* node, const CollisionShape* shape)
 {
 	ANKI_ASSERT(shape);
 	markForUpdate();
+	m_octreeInfo.m_userData = this;
 }
 
 SpatialComponent::~SpatialComponent()