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
Camera::Camera()
: _scene(nullptr)
, _viewProjectionDirty(true)
, _viewProjectionUpdated(false)
, _cameraFlag(1)
, _frustumDirty(true)
, _depth(-1)
, _fbo(nullptr)
{
_frustum.setClipZ(true);
_clearBrush = CameraBackgroundBrush::createDepthBrush(1.f);
_clearBrush->retain();
}
Camera::~Camera()

View File

@ -121,8 +121,8 @@ public:
Camera::Type getType() const { return _type; }
/**get & set Camera flag*/
CameraFlag getCameraFlag() const { return (CameraFlag)_cameraFlag; }
void setCameraFlag(CameraFlag flag) { _cameraFlag = (unsigned short)flag; }
CameraFlag getCameraFlag() const { return _cameraFlag; }
void setCameraFlag(CameraFlag flag) { _cameraFlag = flag; }
/**
* Make Camera looks at target
@ -309,7 +309,7 @@ protected:
static Camera* _visitingCamera;
static experimental::Viewport _defaultViewport;
Scene* _scene; //Scene camera belongs to
Scene* _scene = nullptr; //Scene camera belongs to
Mat4 _projection;
mutable Mat4 _view;
mutable Mat4 _viewInv;
@ -322,20 +322,20 @@ protected:
float _aspectRatio;
float _nearPlane;
float _farPlane;
mutable bool _viewProjectionDirty;
bool _viewProjectionUpdated; //Whether or not the viewprojection matrix was updated since the last frame.
unsigned short _cameraFlag; // camera flag
mutable bool _viewProjectionDirty = true;
bool _viewProjectionUpdated = false; //Whether or not the viewprojection matrix was updated since the last frame.
CameraFlag _cameraFlag = CameraFlag::DEFAULT; // camera flag
mutable Frustum _frustum; // camera frustum
mutable bool _frustumDirty;
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
mutable bool _frustumDirty = true;
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::FrameBuffer* _fbo;
experimental::FrameBuffer* _fbo = nullptr;
GLint _oldViewport[4];
};
NS_CC_END
#endif// __CCCAMERA_H_
#endif// __CCCAMERA_H_

View File

@ -115,9 +115,6 @@ Director* Director::getInstance()
}
Director::Director()
: _deltaTimePassedByCaller(false)
, _isStatusLabelUpdated(true)
, _invalid(true)
{
}
@ -125,43 +122,11 @@ bool Director::init(void)
{
setDefaultValues();
// scenes
_runningScene = nullptr;
_nextScene = nullptr;
_notificationNode = nullptr;
_scenesStack.reserve(15);
// FPS
_accumDt = 0.0f;
_frameRate = 0.0f;
_FPSLabel = _drawnBatchesLabel = _drawnVerticesLabel = nullptr;
_totalFrames = 0;
_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;
// scheduler
@ -214,7 +179,6 @@ Director::~Director(void)
CC_SAFE_RELEASE(_notificationNode);
CC_SAFE_RELEASE(_scheduler);
CC_SAFE_RELEASE(_actionManager);
CC_SAFE_DELETE(_defaultFBO);
CC_SAFE_RELEASE(_beforeSetNextScene);
CC_SAFE_RELEASE(_afterSetNextScene);
@ -437,9 +401,6 @@ void Director::setOpenGLView(GLView *openGLView)
{
_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)
{
_renderer->setClearColor(clearColor);
auto defaultFBO = experimental::FrameBuffer::getOrCreateDefaultFBO(_openGLView);
if(defaultFBO) defaultFBO->setClearColor(clearColor);
}
static void GLToClipTransform(Mat4 *transformOut)

View File

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

View File

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

View File

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