Browse Source

Feature complete

Panagiotis Christopoulos Charitos 7 years ago
parent
commit
36c4875c99
3 changed files with 17 additions and 10 deletions
  1. 2 0
      src/anki/scene/Octree.cpp
  2. 14 9
      src/anki/scene/Visibility.cpp
  3. 1 1
      src/anki/scene/VisibilityInternal.h

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

@@ -70,6 +70,7 @@ void Octree::placeRecursive(const Aabb& volume, OctreePlaceable* placeable, Leaf
 		// Need to stop and bin the placeable to the leaf
 
 		// Checks
+#if ANKI_ASSERTS_ENABLED
 		for(const LeafNode& node : placeable->m_leafs)
 		{
 			ANKI_ASSERT(node.m_leaf != parent && "Already binned. That's wrong");
@@ -79,6 +80,7 @@ void Octree::placeRecursive(const Aabb& volume, OctreePlaceable* placeable, Leaf
 		{
 			ANKI_ASSERT(node.m_placeable != placeable);
 		}
+#endif
 
 		// Connect placeable and leaf
 		placeable->m_leafs.pushBack(newLeafNode(parent));

+ 14 - 9
src/anki/scene/Visibility.cpp

@@ -105,14 +105,14 @@ void VisibilityContext::submitNewWork(FrustumComponent& frc, RenderQueue& rqueue
 		}
 	}
 
-	// Gather visibles from sector
-	GatherVisiblesFromSectorsTask* gather = alloc.newInstance<GatherVisiblesFromSectorsTask>();
+	// Gather visibles from octree
+	GatherVisiblesFromOctreeTask* gather = alloc.newInstance<GatherVisiblesFromOctreeTask>();
 	gather->m_visCtx = this;
 	gather->m_frc = &frc;
-	gather->m_r = r;
+	gather->m_rasterizer = r;
 
 	ThreadHiveTask gatherTask;
-	gatherTask.m_callback = GatherVisiblesFromSectorsTask::callback;
+	gatherTask.m_callback = GatherVisiblesFromOctreeTask::callback;
 	gatherTask.m_argument = gather;
 	if(r)
 	{
@@ -131,7 +131,7 @@ void VisibilityContext::submitNewWork(FrustumComponent& frc, RenderQueue& rqueue
 		auto& test = tests[i];
 		test.m_visCtx = this;
 		test.m_frc = &frc;
-		test.m_sectorsCtx = &gather->m_sectorsCtx;
+		test.m_octreePlaceables = &gather->m_octreePlaceables;
 		test.m_taskIdx = i;
 		test.m_taskCount = testCount;
 		test.m_r = r;
@@ -227,7 +227,8 @@ void GatherVisiblesFromOctreeTask::gather()
 
 	// Test
 	DynamicArrayAuto<OctreePlaceable*> arr(m_visCtx->m_scene->getFrameAllocator());
-	m_visCtx->m_scene->getOctree().gatherVisible(m_frc->getFrustum(), testIdx, testCallback, m_rasterizer, arr);
+	OctreeNodeVisibilityTestCallback cb = (m_rasterizer) ? testCallback : nullptr;
+	m_visCtx->m_scene->getOctree().gatherVisible(m_frc->getFrustum(), testIdx, cb, m_rasterizer, arr);
 
 	// Store results
 	if(arr.getSize() > 0)
@@ -279,9 +280,13 @@ void VisibilityTestTask::test(ThreadHive& hive)
 
 	// Chose the test range and a few other things
 	PtrSize start, end;
-	ThreadPoolTask::choseStartEnd(m_taskIdx, m_taskCount, m_sectorsCtx->getVisibleSceneNodeCount(), start, end);
+	ThreadPoolTask::choseStartEnd(m_taskIdx, m_taskCount, m_octreePlaceables->getSize(), start, end);
+	for(U i = start; i < end; ++i)
+	{
+		OctreePlaceable* placeable = (*m_octreePlaceables)[i];
+		SpatialComponent* spatialC = static_cast<SpatialComponent*>(placeable->m_userData);
+		SceneNode& node = spatialC->getSceneNode();
 
-	m_sectorsCtx->iterateVisibleSceneNodes(start, end, [&](SceneNode& node) {
 		// Skip if it is the same
 		if(ANKI_UNLIKELY(&testedNode == &node))
 		{
@@ -523,7 +528,7 @@ void VisibilityTestTask::test(ThreadHive& hive)
 
 		// Update timestamp
 		m_timestamp = max(m_timestamp, node.getComponentMaxTimestamp());
-	}); // end for
+	} // end for
 }
 
 void CombineResultsTask::combine()

+ 1 - 1
src/anki/scene/VisibilityInternal.h

@@ -230,7 +230,7 @@ class VisibilityTestTask
 public:
 	WeakPtr<VisibilityContext> m_visCtx;
 	WeakPtr<FrustumComponent> m_frc;
-	WeakPtr<SectorGroupVisibilityTestsContext> m_sectorsCtx;
+	WeakArray<OctreePlaceable*>* m_octreePlaceables ANKI_DBG_NULLIFY;
 	U32 m_taskIdx;
 	U32 m_taskCount;
 	RenderQueueView m_result; ///< Sub result. Will be combined later.