From 26f73456930ea13fffb643a8017f1edabca6e6df Mon Sep 17 00:00:00 2001 From: yangxiao Date: Wed, 27 Aug 2014 12:09:23 +0800 Subject: [PATCH] 2d cull only for default camera --- cocos/2d/CCScene.cpp | 4 ++-- cocos/2d/CCScene.h | 1 + cocos/renderer/CCRenderer.cpp | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/cocos/2d/CCScene.cpp b/cocos/2d/CCScene.cpp index 9d5fa4cfdc..996f1b5e46 100644 --- a/cocos/2d/CCScene.cpp +++ b/cocos/2d/CCScene.cpp @@ -193,6 +193,8 @@ void Scene::addChildToPhysicsWorld(Node* child) } } +#endif + void Scene::onProjectionChanged(EventCustom* event) { if (_defaultCamera) @@ -201,6 +203,4 @@ void Scene::onProjectionChanged(EventCustom* event) } } -#endif - NS_CC_END diff --git a/cocos/2d/CCScene.h b/cocos/2d/CCScene.h index 7630111cc9..a5dce16a14 100644 --- a/cocos/2d/CCScene.h +++ b/cocos/2d/CCScene.h @@ -83,6 +83,7 @@ protected: friend class SpriteBatchNode; friend class Camera; friend class Director; + friend class Renderer; std::vector _cameras; //weak ref to Camera Camera* _defaultCamera; //weak ref, default camera created by scene, _cameras[0], Caution that the default camera can not be added to _cameras before onEnter is called diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index 2eca2d9ead..54d15f40bd 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -39,6 +39,8 @@ #include "base/CCEventDispatcher.h" #include "base/CCEventListenerCustom.h" #include "base/CCEventType.h" +#include "base/CCCamera.h" +#include "2d/CCScene.h" NS_CC_BEGIN @@ -549,6 +551,11 @@ void Renderer::flush3D() bool Renderer::checkVisibility(const Mat4 &transform, const Size &size) { + auto scene = Director::getInstance()->getRunningScene(); + // only cull the default camera. The culling algorithm is valid for default camera. + if (scene->_defaultCamera != Camera::getVisitingCamera()) + return true; + // half size of the screen Size screen_half = Director::getInstance()->getWinSize(); screen_half.width /= 2;