reduce cleanning clear buffer times (#19131)

This commit is contained in:
minggo 2018-10-24 16:00:33 +08:00 committed by GitHub
parent 5f6c904db2
commit fb53420b54
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 104 deletions

View File

@ -107,17 +107,8 @@ const Camera* Camera::getVisitingCamera()
// end static methods // end static methods
Camera::Camera() Camera::Camera()
: _scene(nullptr)
, _viewProjectionDirty(true)
, _viewProjectionUpdated(false)
, _cameraFlag(1)
, _frustumDirty(true)
, _depth(-1)
, _fbo(nullptr)
{ {
_frustum.setClipZ(true); _frustum.setClipZ(true);
_clearBrush = CameraBackgroundBrush::createDepthBrush(1.f);
_clearBrush->retain();
} }
Camera::~Camera() Camera::~Camera()

View File

@ -121,8 +121,8 @@ public:
Camera::Type getType() const { return _type; } Camera::Type getType() const { return _type; }
/**get & set Camera flag*/ /**get & set Camera flag*/
CameraFlag getCameraFlag() const { return (CameraFlag)_cameraFlag; } CameraFlag getCameraFlag() const { return _cameraFlag; }
void setCameraFlag(CameraFlag flag) { _cameraFlag = (unsigned short)flag; } void setCameraFlag(CameraFlag flag) { _cameraFlag = flag; }
/** /**
* Make Camera looks at target * Make Camera looks at target
@ -309,7 +309,7 @@ protected:
static Camera* _visitingCamera; static Camera* _visitingCamera;
static experimental::Viewport _defaultViewport; static experimental::Viewport _defaultViewport;
Scene* _scene; //Scene camera belongs to Scene* _scene = nullptr; //Scene camera belongs to
Mat4 _projection; Mat4 _projection;
mutable Mat4 _view; mutable Mat4 _view;
mutable Mat4 _viewInv; mutable Mat4 _viewInv;
@ -322,17 +322,17 @@ protected:
float _aspectRatio; float _aspectRatio;
float _nearPlane; float _nearPlane;
float _farPlane; float _farPlane;
mutable bool _viewProjectionDirty; mutable bool _viewProjectionDirty = true;
bool _viewProjectionUpdated; //Whether or not the viewprojection matrix was updated since the last frame. bool _viewProjectionUpdated = false; //Whether or not the viewprojection matrix was updated since the last frame.
unsigned short _cameraFlag; // camera flag CameraFlag _cameraFlag = CameraFlag::DEFAULT; // camera flag
mutable Frustum _frustum; // camera frustum mutable Frustum _frustum; // camera frustum
mutable bool _frustumDirty; mutable bool _frustumDirty = true;
int8_t _depth; //camera depth, the depth of camera with CameraFlag::DEFAULT flag is 0 by default, a camera with larger depth is drawn on top of camera with smaller depth int8_t _depth = -1; //camera depth, the depth of camera with CameraFlag::DEFAULT flag is 0 by default, a camera with larger depth is drawn on top of camera with smaller depth
CameraBackgroundBrush* _clearBrush; //brush used to clear the back ground CameraBackgroundBrush* _clearBrush = nullptr; //brush used to clear the back ground
experimental::Viewport _viewport; experimental::Viewport _viewport;
experimental::FrameBuffer* _fbo; experimental::FrameBuffer* _fbo = nullptr;
GLint _oldViewport[4]; GLint _oldViewport[4];
}; };

View File

@ -115,9 +115,6 @@ Director* Director::getInstance()
} }
Director::Director() Director::Director()
: _deltaTimePassedByCaller(false)
, _isStatusLabelUpdated(true)
, _invalid(true)
{ {
} }
@ -125,43 +122,11 @@ bool Director::init(void)
{ {
setDefaultValues(); setDefaultValues();
// scenes
_runningScene = nullptr;
_nextScene = nullptr;
_notificationNode = nullptr;
_scenesStack.reserve(15); _scenesStack.reserve(15);
// FPS // FPS
_accumDt = 0.0f;
_frameRate = 0.0f;
_FPSLabel = _drawnBatchesLabel = _drawnVerticesLabel = nullptr;
_totalFrames = 0;
_lastUpdate = std::chrono::steady_clock::now(); _lastUpdate = std::chrono::steady_clock::now();
_secondsPerFrame = 1.0f;
_frames = 0;
// paused ?
_paused = false;
// purge ?
_purgeDirectorInNextLoop = false;
// restart ?
_restartDirectorInNextLoop = false;
// invalid ?
_invalid = false;
_winSizeInPoints = Size::ZERO;
_openGLView = nullptr;
_defaultFBO = nullptr;
_contentScaleFactor = 1.0f;
_console = new (std::nothrow) Console; _console = new (std::nothrow) Console;
// scheduler // scheduler
@ -214,7 +179,6 @@ Director::~Director(void)
CC_SAFE_RELEASE(_notificationNode); CC_SAFE_RELEASE(_notificationNode);
CC_SAFE_RELEASE(_scheduler); CC_SAFE_RELEASE(_scheduler);
CC_SAFE_RELEASE(_actionManager); CC_SAFE_RELEASE(_actionManager);
CC_SAFE_DELETE(_defaultFBO);
CC_SAFE_RELEASE(_beforeSetNextScene); CC_SAFE_RELEASE(_beforeSetNextScene);
CC_SAFE_RELEASE(_afterSetNextScene); CC_SAFE_RELEASE(_afterSetNextScene);
@ -437,9 +401,6 @@ void Director::setOpenGLView(GLView *openGLView)
{ {
_eventDispatcher->setEnabled(true); _eventDispatcher->setEnabled(true);
} }
_defaultFBO = experimental::FrameBuffer::getOrCreateDefaultFBO(_openGLView);
_defaultFBO->retain();
} }
} }
@ -770,9 +731,6 @@ void Director::setDepthTest(bool on)
void Director::setClearColor(const Color4F& clearColor) void Director::setClearColor(const Color4F& clearColor)
{ {
_renderer->setClearColor(clearColor); _renderer->setClearColor(clearColor);
auto defaultFBO = experimental::FrameBuffer::getOrCreateDefaultFBO(_openGLView);
if(defaultFBO) defaultFBO->setClearColor(clearColor);
} }
static void GLToClipTransform(Mat4 *transformOut) static void GLToClipTransform(Mat4 *transformOut)

View File

@ -591,10 +591,10 @@ protected:
virtual void setAnimationInterval(float interval, SetIntervalReason reason); virtual void setAnimationInterval(float interval, SetIntervalReason reason);
void purgeDirector(); void purgeDirector();
bool _purgeDirectorInNextLoop; // this flag will be set to true in end() bool _purgeDirectorInNextLoop = false; // this flag will be set to true in end()
void restartDirector(); void restartDirector();
bool _restartDirectorInNextLoop; // this flag will be set to true in restart() bool _restartDirectorInNextLoop = false; // this flag will be set to true in restart()
void setNextScene(); void setNextScene();
@ -625,61 +625,66 @@ protected:
/** Scheduler associated with this director /** Scheduler associated with this director
@since v2.0 @since v2.0
*/ */
Scheduler *_scheduler; Scheduler *_scheduler = nullptr;
/** ActionManager associated with this director /** ActionManager associated with this director
@since v2.0 @since v2.0
*/ */
ActionManager *_actionManager; ActionManager *_actionManager = nullptr;
/** EventDispatcher associated with this director /** EventDispatcher associated with this director
@since v3.0 @since v3.0
*/ */
EventDispatcher* _eventDispatcher; EventDispatcher* _eventDispatcher = nullptr;
EventCustom *_eventProjectionChanged, *_eventBeforeDraw, *_eventAfterDraw, *_eventAfterVisit, *_eventBeforeUpdate, *_eventAfterUpdate, *_eventResetDirector, *_beforeSetNextScene, *_afterSetNextScene; EventCustom* _eventProjectionChanged = nullptr;
EventCustom* _eventBeforeDraw =nullptr;
EventCustom* _eventAfterDraw = nullptr;
EventCustom* _eventAfterVisit = nullptr;
EventCustom* _eventBeforeUpdate = nullptr;
EventCustom* _eventAfterUpdate = nullptr;
EventCustom* _eventResetDirector = nullptr;
EventCustom* _beforeSetNextScene = nullptr;
EventCustom* _afterSetNextScene = nullptr;
/* delta time since last tick to main loop */ /* delta time since last tick to main loop */
float _deltaTime; float _deltaTime = 0.0f;
bool _deltaTimePassedByCaller; bool _deltaTimePassedByCaller = false;
/* The _openGLView, where everything is rendered, GLView is a abstract class,cocos2d-x provide GLViewImpl /* The _openGLView, where everything is rendered, GLView is a abstract class,cocos2d-x provide GLViewImpl
which inherit from it as default renderer context,you can have your own by inherit from it*/ which inherit from it as default renderer context,you can have your own by inherit from it*/
GLView *_openGLView; GLView *_openGLView = nullptr;
//texture cache belongs to this director //texture cache belongs to this director
TextureCache *_textureCache; TextureCache *_textureCache = nullptr;
float _animationInterval; float _animationInterval = 0.0f;
float _oldAnimationInterval; float _oldAnimationInterval = 0.0f;
/* landscape mode ? */ bool _displayStats = false;
bool _landscape; float _accumDt = 0.0f;
float _frameRate = 0.0f;
bool _displayStats; LabelAtlas *_FPSLabel = nullptr;
float _accumDt; LabelAtlas *_drawnBatchesLabel = nullptr;
float _frameRate; LabelAtlas *_drawnVerticesLabel = nullptr;
LabelAtlas *_FPSLabel;
LabelAtlas *_drawnBatchesLabel;
LabelAtlas *_drawnVerticesLabel;
/** Whether or not the Director is paused */ /** Whether or not the Director is paused */
bool _paused; bool _paused = false;
/* How many frames were called since the director started */ /* How many frames were called since the director started */
unsigned int _totalFrames; unsigned int _totalFrames = 0;
unsigned int _frames; unsigned int _frames = 0;
float _secondsPerFrame; float _secondsPerFrame = 1.f;
/* The running scene */ /* The running scene */
Scene *_runningScene; Scene *_runningScene = nullptr;
/* will be the next 'runningScene' in the next frame /* will be the next 'runningScene' in the next frame
nextScene is a weak reference. */ nextScene is a weak reference. */
Scene *_nextScene; Scene *_nextScene = nullptr;
/* If true, then "old" scene will receive the cleanup message */ /* If true, then "old" scene will receive the cleanup message */
bool _sendCleanupToScene; bool _sendCleanupToScene = false;
/* scheduled scenes */ /* scheduled scenes */
Vector<Scene*> _scenesStack; Vector<Scene*> _scenesStack;
@ -688,36 +693,33 @@ protected:
std::chrono::steady_clock::time_point _lastUpdate; std::chrono::steady_clock::time_point _lastUpdate;
/* whether or not the next delta time will be zero */ /* whether or not the next delta time will be zero */
bool _nextDeltaTimeZero; bool _nextDeltaTimeZero = false;
/* projection used */ /* projection used */
Projection _projection; Projection _projection = Projection::DEFAULT;
/* window size in points */ /* window size in points */
Size _winSizeInPoints; Size _winSizeInPoints = Size::ZERO;
/* content scale factor */ /* content scale factor */
float _contentScaleFactor; float _contentScaleFactor = 1.0f;
/* This object will be visited after the scene. Useful to hook a notification node */ /* This object will be visited after the scene. Useful to hook a notification node */
Node *_notificationNode; Node *_notificationNode = nullptr;
/* Renderer for the Director */ /* Renderer for the Director */
Renderer *_renderer; Renderer *_renderer = nullptr;
/* Default FrameBufferObject*/
experimental::FrameBuffer* _defaultFBO;
/* Console for the director */ /* Console for the director */
Console *_console; Console *_console = nullptr;
bool _isStatusLabelUpdated; bool _isStatusLabelUpdated = true;
/* cocos2d thread id */ /* cocos2d thread id */
std::thread::id _cocos2d_thread_id; std::thread::id _cocos2d_thread_id;
/* whether or not the director is in a valid state */ /* whether or not the director is in a valid state */
bool _invalid; bool _invalid = false;
// GLView will recreate stats labels to fit visible rect // GLView will recreate stats labels to fit visible rect
friend class GLView; friend class GLView;

View File

@ -26,7 +26,7 @@
#import "AppController.h" #import "AppController.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "platform/ios/CCEAGLView-ios.h" #import "platform/ios/CCEAGLView-ios.h"
#import "AppDelegate.h" #import "../Classes/AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"
@implementation AppController @implementation AppController

View File

@ -28,7 +28,7 @@
#import "platform/ios/CCEAGLView-ios.h" #import "platform/ios/CCEAGLView-ios.h"
#import "cocos2d.h" #import "cocos2d.h"
#import "AppDelegate.h" #import "../../Classes/AppDelegate.h"
#import "RootViewController.h" #import "RootViewController.h"
@implementation AppController @implementation AppController