From 0a6735a6ecc6e8c8423010ec13958045996f30bc Mon Sep 17 00:00:00 2001 From: vlj Date: Thu, 4 Sep 2014 03:07:00 +0200 Subject: [PATCH] Simplify culling. --- src/graphics/irr_driver.hpp | 2 +- src/graphics/render.cpp | 2 +- src/graphics/stkscenemanager.cpp | 32 ++++++++++++++------------------ 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/graphics/irr_driver.hpp b/src/graphics/irr_driver.hpp index e91d6a924..8a233227f 100644 --- a/src/graphics/irr_driver.hpp +++ b/src/graphics/irr_driver.hpp @@ -410,7 +410,7 @@ private: void renderLights(unsigned pointlightCount); void renderShadowsDebug(); void doScreenShot(); - void PrepareDrawCalls(); + void PrepareDrawCalls(scene::ICameraSceneNode *camnode); public: IrrDriver(); ~IrrDriver(); diff --git a/src/graphics/render.cpp b/src/graphics/render.cpp index b908eb23b..8a1a561f4 100644 --- a/src/graphics/render.cpp +++ b/src/graphics/render.cpp @@ -275,7 +275,7 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po m_scene_manager->setActiveCamera(camnode); PROFILER_PUSH_CPU_MARKER("- Draw Call Generation", 0xFF, 0xFF, 0xFF); - PrepareDrawCalls(); + PrepareDrawCalls(camnode); PROFILER_POP_CPU_MARKER(); // Shadows { diff --git a/src/graphics/stkscenemanager.cpp b/src/graphics/stkscenemanager.cpp index 56e4f16c5..0fbfe882d 100644 --- a/src/graphics/stkscenemanager.cpp +++ b/src/graphics/stkscenemanager.cpp @@ -340,7 +340,7 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector *Immed static void parseSceneManager(core::list List, std::vector *ImmediateDraw, - scene::ICameraSceneNode *shadowCams[4], scene::ICameraSceneNode *RSM_cam) + scene::ICameraSceneNode* cam, scene::ICameraSceneNode *shadowCams[4], scene::ICameraSceneNode *RSM_cam) { core::list::Iterator I = List.begin(), E = List.end(); for (; I != E; ++I) @@ -351,20 +351,16 @@ parseSceneManager(core::list List, std::vectorupdateAbsolutePosition(); - scene::ICameraSceneNode* cam = irr_driver->getSceneManager()->getActiveCamera(); - bool IsCulledForSolid = irr_driver->getSceneManager()->isCulled(*I); + core::aabbox3d tbox = (*I)->getBoundingBox(); + (*I)->getAbsoluteTransformation().transformBoxEx(tbox); + + bool IsCulledForSolid = !(tbox.intersectsWithBox(cam->getViewFrustum()->getBoundingBox())); + bool IsCulledForShadow[4]; - for (unsigned i = 0; i < 4; ++i) - { - scene::ICameraSceneNode* cam = shadowCams[i]; - irr_driver->getSceneManager()->setActiveCamera(cam); - IsCulledForShadow[i] = irr_driver->getSceneManager()->isCulled(*I); - } + IsCulledForShadow[i] = !(tbox.intersectsWithBox(shadowCams[i]->getViewFrustum()->getBoundingBox())); - irr_driver->getSceneManager()->setActiveCamera(RSM_cam); - bool IsCulledForRSM = irr_driver->getSceneManager()->isCulled(*I); - irr_driver->getSceneManager()->setActiveCamera(cam); + bool IsCulledForRSM = !(tbox.intersectsWithBox(RSM_cam->getViewFrustum()->getBoundingBox())); if (!IsCulledForSolid) { @@ -378,7 +374,7 @@ parseSceneManager(core::list List, std::vectorgetChildren(), ImmediateDraw, shadowCams, RSM_cam); + parseSceneManager((*I)->getChildren(), ImmediateDraw, cam, shadowCams, RSM_cam); } } @@ -404,7 +400,7 @@ InstanceData *InstanceBuffer, DrawElementsIndirectCommand *CommandBuffer, size_t ShadowPassCmd::getInstance()->Size[cascade][Mat] = CommandBufferOffset - ShadowPassCmd::getInstance()->Offset[cascade][Mat]; } -void IrrDriver::PrepareDrawCalls() +void IrrDriver::PrepareDrawCalls(scene::ICameraSceneNode *camnode) { windDir = getWindDir(); ListBlendTransparent::getInstance()->clear(); @@ -437,14 +433,11 @@ void IrrDriver::PrepareDrawCalls() core::list List = m_scene_manager->getRootSceneNode()->getChildren(); bool isCulled[4] = {}; - parseSceneManager(List, ImmediateDrawList::getInstance(), m_shadow_camnodes, m_suncam); - if (!irr_driver->hasARB_draw_indirect()) - return; // Add a 20 ms timeout if (!m_sync) m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); - GLenum reason = glClientWaitSync(m_sync, GL_SYNC_FLUSH_COMMANDS_BIT, 20000000); + GLenum reason = glClientWaitSync(m_sync, GL_SYNC_FLUSH_COMMANDS_BIT, 1000000000); /* switch (reason) { case GL_ALREADY_SIGNALED: @@ -460,6 +453,9 @@ void IrrDriver::PrepareDrawCalls() printf("Wait Failed\n"); break; }*/ + parseSceneManager(List, ImmediateDrawList::getInstance(), camnode, m_shadow_camnodes, m_suncam); + if (!irr_driver->hasARB_draw_indirect()) + return; InstanceData *InstanceBuffer; InstanceData *ShadowInstanceBuffer;