Simplify culling.

This commit is contained in:
vlj 2014-09-04 03:07:00 +02:00
parent 4482ed6fc8
commit 0a6735a6ec
3 changed files with 16 additions and 20 deletions

View File

@ -410,7 +410,7 @@ private:
void renderLights(unsigned pointlightCount); void renderLights(unsigned pointlightCount);
void renderShadowsDebug(); void renderShadowsDebug();
void doScreenShot(); void doScreenShot();
void PrepareDrawCalls(); void PrepareDrawCalls(scene::ICameraSceneNode *camnode);
public: public:
IrrDriver(); IrrDriver();
~IrrDriver(); ~IrrDriver();

View File

@ -275,7 +275,7 @@ void IrrDriver::renderScene(scene::ICameraSceneNode * const camnode, unsigned po
m_scene_manager->setActiveCamera(camnode); m_scene_manager->setActiveCamera(camnode);
PROFILER_PUSH_CPU_MARKER("- Draw Call Generation", 0xFF, 0xFF, 0xFF); PROFILER_PUSH_CPU_MARKER("- Draw Call Generation", 0xFF, 0xFF, 0xFF);
PrepareDrawCalls(); PrepareDrawCalls(camnode);
PROFILER_POP_CPU_MARKER(); PROFILER_POP_CPU_MARKER();
// Shadows // Shadows
{ {

View File

@ -340,7 +340,7 @@ handleSTKCommon(scene::ISceneNode *Node, std::vector<scene::ISceneNode *> *Immed
static void static void
parseSceneManager(core::list<scene::ISceneNode*> List, std::vector<scene::ISceneNode *> *ImmediateDraw, parseSceneManager(core::list<scene::ISceneNode*> List, std::vector<scene::ISceneNode *> *ImmediateDraw,
scene::ICameraSceneNode *shadowCams[4], scene::ICameraSceneNode *RSM_cam) scene::ICameraSceneNode* cam, scene::ICameraSceneNode *shadowCams[4], scene::ICameraSceneNode *RSM_cam)
{ {
core::list<scene::ISceneNode*>::Iterator I = List.begin(), E = List.end(); core::list<scene::ISceneNode*>::Iterator I = List.begin(), E = List.end();
for (; I != E; ++I) for (; I != E; ++I)
@ -351,20 +351,16 @@ parseSceneManager(core::list<scene::ISceneNode*> List, std::vector<scene::IScene
continue; continue;
(*I)->updateAbsolutePosition(); (*I)->updateAbsolutePosition();
scene::ICameraSceneNode* cam = irr_driver->getSceneManager()->getActiveCamera(); core::aabbox3d<f32> tbox = (*I)->getBoundingBox();
bool IsCulledForSolid = irr_driver->getSceneManager()->isCulled(*I); (*I)->getAbsoluteTransformation().transformBoxEx(tbox);
bool IsCulledForSolid = !(tbox.intersectsWithBox(cam->getViewFrustum()->getBoundingBox()));
bool IsCulledForShadow[4]; bool IsCulledForShadow[4];
for (unsigned i = 0; i < 4; ++i) for (unsigned i = 0; i < 4; ++i)
{ IsCulledForShadow[i] = !(tbox.intersectsWithBox(shadowCams[i]->getViewFrustum()->getBoundingBox()));
scene::ICameraSceneNode* cam = shadowCams[i];
irr_driver->getSceneManager()->setActiveCamera(cam);
IsCulledForShadow[i] = irr_driver->getSceneManager()->isCulled(*I);
}
irr_driver->getSceneManager()->setActiveCamera(RSM_cam); bool IsCulledForRSM = !(tbox.intersectsWithBox(RSM_cam->getViewFrustum()->getBoundingBox()));
bool IsCulledForRSM = irr_driver->getSceneManager()->isCulled(*I);
irr_driver->getSceneManager()->setActiveCamera(cam);
if (!IsCulledForSolid) if (!IsCulledForSolid)
{ {
@ -378,7 +374,7 @@ parseSceneManager(core::list<scene::ISceneNode*> List, std::vector<scene::IScene
handleSTKCommon(*I, ImmediateDraw, IsCulledForSolid, IsCulledForShadow, IsCulledForRSM); handleSTKCommon(*I, ImmediateDraw, IsCulledForSolid, IsCulledForShadow, IsCulledForRSM);
parseSceneManager((*I)->getChildren(), 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]; ShadowPassCmd::getInstance()->Size[cascade][Mat] = CommandBufferOffset - ShadowPassCmd::getInstance()->Offset[cascade][Mat];
} }
void IrrDriver::PrepareDrawCalls() void IrrDriver::PrepareDrawCalls(scene::ICameraSceneNode *camnode)
{ {
windDir = getWindDir(); windDir = getWindDir();
ListBlendTransparent::getInstance()->clear(); ListBlendTransparent::getInstance()->clear();
@ -437,14 +433,11 @@ void IrrDriver::PrepareDrawCalls()
core::list<scene::ISceneNode*> List = m_scene_manager->getRootSceneNode()->getChildren(); core::list<scene::ISceneNode*> List = m_scene_manager->getRootSceneNode()->getChildren();
bool isCulled[4] = {}; bool isCulled[4] = {};
parseSceneManager(List, ImmediateDrawList::getInstance(), m_shadow_camnodes, m_suncam);
if (!irr_driver->hasARB_draw_indirect())
return;
// Add a 20 ms timeout // Add a 20 ms timeout
if (!m_sync) if (!m_sync)
m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0); 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) /* switch (reason)
{ {
case GL_ALREADY_SIGNALED: case GL_ALREADY_SIGNALED:
@ -460,6 +453,9 @@ void IrrDriver::PrepareDrawCalls()
printf("Wait Failed\n"); printf("Wait Failed\n");
break; break;
}*/ }*/
parseSceneManager(List, ImmediateDrawList::getInstance(), camnode, m_shadow_camnodes, m_suncam);
if (!irr_driver->hasARB_draw_indirect())
return;
InstanceData *InstanceBuffer; InstanceData *InstanceBuffer;
InstanceData *ShadowInstanceBuffer; InstanceData *ShadowInstanceBuffer;