diff --git a/cocos/2d/CCCamera.cpp b/cocos/2d/CCCamera.cpp index 5d8ad80396..886da6267d 100644 --- a/cocos/2d/CCCamera.cpp +++ b/cocos/2d/CCCamera.cpp @@ -483,7 +483,7 @@ void Camera::clearBackground(float depth) } } -void Camera::setFrameBufferObject(FrameBufferObject *fbo) +void Camera::setFrameBufferObject(experimental::FrameBuffer *fbo) { CC_SAFE_RETAIN(fbo); CC_SAFE_RELEASE_NULL(_fbo); @@ -498,7 +498,7 @@ void Camera::applyFrameBufferObject() { if(nullptr == _fbo) { - FrameBufferObject::applyDefaultFBO(); + experimental::FrameBuffer::applyDefaultFBO(); } else { diff --git a/cocos/2d/CCCamera.h b/cocos/2d/CCCamera.h index 309db0b392..ff20ac768c 100644 --- a/cocos/2d/CCCamera.h +++ b/cocos/2d/CCCamera.h @@ -32,7 +32,10 @@ THE SOFTWARE. NS_CC_BEGIN class Scene; -class FrameBufferObject; +namespace experimental +{ + class FrameBuffer; +} /** Viewport is a normalized to FrameBufferObject But for default FBO, the size is absolute. @@ -256,7 +259,7 @@ public: /** Set FBO, which will attacha several render target for the rendered result. */ - void setFrameBufferObject(FrameBufferObject* fbo); + void setFrameBufferObject(experimental::FrameBuffer* fbo); /** Set Viewport for camera. */ @@ -303,7 +306,7 @@ protected: friend class Director; Viewport _viewport; - FrameBufferObject* _fbo; + experimental::FrameBuffer* _fbo; protected: static Viewport _defaultViewport; public: diff --git a/cocos/2d/CCScene.cpp b/cocos/2d/CCScene.cpp index 448a94d8c7..66d2ce3fa3 100644 --- a/cocos/2d/CCScene.cpp +++ b/cocos/2d/CCScene.cpp @@ -187,7 +187,7 @@ void Scene::render(Renderer* renderer) #endif Camera::_visitingCamera = nullptr; - FrameBufferObject::applyDefaultFBO(); + experimental::FrameBuffer::applyDefaultFBO(); } void Scene::removeAllChildren() diff --git a/cocos/base/CCDirector.cpp b/cocos/base/CCDirector.cpp index 07c0addd0b..899f88d293 100644 --- a/cocos/base/CCDirector.cpp +++ b/cocos/base/CCDirector.cpp @@ -279,7 +279,7 @@ void Director::drawScene() } _renderer->clear(); - FrameBufferObject::clearAllFBOs(); + experimental::FrameBuffer::clearAllFBOs(); /* to avoid flickr, nextScene MUST be here: after tick and before draw. * FIXME: Which bug is this one. It seems that it can't be reproduced with v0.9 */ @@ -417,7 +417,7 @@ void Director::setOpenGLView(GLView *openGLView) _eventDispatcher->setEnabled(true); } - _defaultFBO = FrameBufferObject::getOrCreateDefaultFBO(_openGLView); + _defaultFBO = experimental::FrameBuffer::getOrCreateDefaultFBO(_openGLView); _defaultFBO->retain(); } } diff --git a/cocos/base/CCDirector.h b/cocos/base/CCDirector.h index 53ead69108..28cbdcfbf8 100644 --- a/cocos/base/CCDirector.h +++ b/cocos/base/CCDirector.h @@ -60,8 +60,10 @@ class Renderer; class Camera; class Console; - -class FrameBufferObject; +namespace experimental +{ + class FrameBuffer; +} /** * @brief Matrix stack type. @@ -597,7 +599,7 @@ protected: Renderer *_renderer; /* Default FrameBufferObject*/ - FrameBufferObject* _defaultFBO; + experimental::FrameBuffer* _defaultFBO; /* Console for the director */ Console *_console; diff --git a/cocos/renderer/CCFrameBufferObject.cpp b/cocos/renderer/CCFrameBufferObject.cpp index dba3efcd85..022e1b8604 100644 --- a/cocos/renderer/CCFrameBufferObject.cpp +++ b/cocos/renderer/CCFrameBufferObject.cpp @@ -30,9 +30,9 @@ #include "base/CCEventType.h" NS_CC_BEGIN - -FrameBufferObject* FrameBufferObject::_defaultFBO = nullptr; -std::set FrameBufferObject::_frameBufferObjects; +namespace experimental{ +FrameBuffer* FrameBuffer::_defaultFBO = nullptr; +std::set FrameBuffer::_frameBuffers; RenderTargetBase::RenderTargetBase() { @@ -266,7 +266,7 @@ RenderTargetDepthStencil* RenderTargetDepthStencil::create(unsigned int width, u } } -bool FrameBufferObject::initWithGLView(GLView* view) +bool FrameBuffer::initWithGLView(GLView* view) { if(view == nullptr) { @@ -278,11 +278,11 @@ bool FrameBufferObject::initWithGLView(GLView* view) return true; } -FrameBufferObject* FrameBufferObject::getOrCreateDefaultFBO(GLView* view) +FrameBuffer* FrameBuffer::getOrCreateDefaultFBO(GLView* view) { if(nullptr == _defaultFBO) { - auto result = new (std::nothrow) FrameBufferObject(); + auto result = new (std::nothrow) FrameBuffer(); if(result && result->initWithGLView(view)) { @@ -300,7 +300,7 @@ FrameBufferObject* FrameBufferObject::getOrCreateDefaultFBO(GLView* view) return _defaultFBO; } -void FrameBufferObject::applyDefaultFBO() +void FrameBuffer::applyDefaultFBO() { if(_defaultFBO) { @@ -308,17 +308,17 @@ void FrameBufferObject::applyDefaultFBO() } } -void FrameBufferObject::clearAllFBOs() +void FrameBuffer::clearAllFBOs() { - for (auto fbo : _frameBufferObjects) + for (auto fbo : _frameBuffers) { fbo->clearFBO(); } } -FrameBufferObject* FrameBufferObject::create(uint8_t fid, unsigned int width, unsigned int height) +FrameBuffer* FrameBuffer::create(uint8_t fid, unsigned int width, unsigned int height) { - auto result = new (std::nothrow) FrameBufferObject(); + auto result = new (std::nothrow) FrameBuffer(); if(result && result->init(fid, width, height)) { result->autorelease(); @@ -331,7 +331,7 @@ FrameBufferObject* FrameBufferObject::create(uint8_t fid, unsigned int width, un } } -bool FrameBufferObject::init(uint8_t fid, unsigned int width, unsigned int height) +bool FrameBuffer::init(uint8_t fid, unsigned int width, unsigned int height) { _fid = fid; _width = width; @@ -365,7 +365,7 @@ bool FrameBufferObject::init(uint8_t fid, unsigned int width, unsigned int heigh return true; } -FrameBufferObject::FrameBufferObject() +FrameBuffer::FrameBuffer() : _clearColor(Color4F(0, 0, 0, 1)) , _clearDepth(1.0) , _clearStencil(0) @@ -378,10 +378,10 @@ FrameBufferObject::FrameBufferObject() , _dirtyFBOListener(nullptr) #endif { - _frameBufferObjects.insert(this); + _frameBuffers.insert(this); } -FrameBufferObject::~FrameBufferObject() +FrameBuffer::~FrameBuffer() { if(!isDefaultFBO()) { @@ -389,14 +389,14 @@ FrameBufferObject::~FrameBufferObject() CC_SAFE_RELEASE_NULL(_rtDepthStencil); glDeleteFramebuffers(1, &_fbo); _fbo = 0; - _frameBufferObjects.erase(this); + _frameBuffers.erase(this); #if CC_ENABLE_CACHE_TEXTURE_DATA Director::getInstance()->getEventDispatcher()->removeEventListener(_dirtyFBOListener); #endif } } -void FrameBufferObject::clearFBO() +void FrameBuffer::clearFBO() { applyFBO(); glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a); @@ -406,7 +406,7 @@ void FrameBufferObject::clearFBO() applyDefaultFBO(); } -void FrameBufferObject::AttachRenderTarget(RenderTargetBase* rt) +void FrameBuffer::attachRenderTarget(RenderTargetBase* rt) { if(isDefaultFBO()) { @@ -425,7 +425,7 @@ void FrameBufferObject::AttachRenderTarget(RenderTargetBase* rt) _fboBindingDirty = true; } -void FrameBufferObject::applyFBO() +void FrameBuffer::applyFBO() { CHECK_GL_ERROR_DEBUG(); glBindFramebuffer(GL_FRAMEBUFFER, _fbo); @@ -452,7 +452,7 @@ void FrameBufferObject::applyFBO() CHECK_GL_ERROR_DEBUG(); } -void FrameBufferObject::AttachDepthStencilTarget(RenderTargetDepthStencil* rt) +void FrameBuffer::attachDepthStencilTarget(RenderTargetDepthStencil* rt) { if(isDefaultFBO()) { @@ -470,4 +470,5 @@ void FrameBufferObject::AttachDepthStencilTarget(RenderTargetDepthStencil* rt) _rtDepthStencil = rt; _fboBindingDirty = true; } -NS_CC_END \ No newline at end of file +} //end of namespace experimental +NS_CC_END diff --git a/cocos/renderer/CCFrameBufferObject.h b/cocos/renderer/CCFrameBufferObject.h index a1171ec35c..3663d80d90 100644 --- a/cocos/renderer/CCFrameBufferObject.h +++ b/cocos/renderer/CCFrameBufferObject.h @@ -31,8 +31,12 @@ #include NS_CC_BEGIN + +class GLView; class EventListenerCustom; +namespace experimental { + class RenderTargetBase : public Ref { public: @@ -126,12 +130,10 @@ protected: #endif }; -class GLView; - -class CC_DLL FrameBufferObject : public Ref +class CC_DLL FrameBuffer : public Ref { public: - static FrameBufferObject* create(uint8_t fid, unsigned int width, unsigned int height); + static FrameBuffer* create(uint8_t fid, unsigned int width, unsigned int height); bool init(uint8_t fid, unsigned int width, unsigned int height); public: @@ -149,16 +151,16 @@ public: RenderTargetBase* getRenderTarget() const { return _rt; } RenderTargetDepthStencil* getDepthStencilTarget() const { return _rtDepthStencil; } - void AttachRenderTarget(RenderTargetBase* rt); - void AttachDepthStencilTarget(RenderTargetDepthStencil* rt); + void attachRenderTarget(RenderTargetBase* rt); + void attachDepthStencilTarget(RenderTargetDepthStencil* rt); bool isDefaultFBO() const { return _isDefault; } unsigned int getWidth() const { return _width; } unsigned int getHeight() const { return _height; } CC_CONSTRUCTOR_ACCESS: - FrameBufferObject(); - virtual ~FrameBufferObject(); + FrameBuffer(); + virtual ~FrameBuffer(); bool initWithGLView(GLView* view); private: //openGL content for FrameBuffer @@ -177,19 +179,20 @@ private: RenderTargetDepthStencil* _rtDepthStencil; bool _isDefault; public: - static FrameBufferObject* getOrCreateDefaultFBO(GLView* glView); + static FrameBuffer* getOrCreateDefaultFBO(GLView* glView); static void applyDefaultFBO(); static void clearAllFBOs(); private: //static GLuint _defaultFBO; - static FrameBufferObject* _defaultFBO; - static std::set _frameBufferObjects; + static FrameBuffer* _defaultFBO; + static std::set _frameBuffers; private: #if CC_ENABLE_CACHE_TEXTURE_DATA EventListenerCustom* _dirtyFBOListener; #endif }; +} // end of namespace experimental NS_CC_END diff --git a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp index 5d2d2c3fa9..69ea20fe5a 100644 --- a/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp +++ b/tests/cpp-tests/Classes/Camera3DTest/Camera3DTest.cpp @@ -1433,7 +1433,7 @@ void CameraFrameBufferObjectTest::onEnter() auto sizeInpixels = Director::getInstance()->getWinSizeInPixels(); auto size = Director::getInstance()->getWinSize(); auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5); - auto fbo = FrameBufferObject::create(1, fboSize.width, fboSize.height); + auto fbo = experimental::FrameBuffer::create(1, fboSize.width, fboSize.height); CameraBaseTest::onEnter(); //auto sprite = Sprite::createWithTexture(fbo); @@ -1449,10 +1449,10 @@ void CameraFrameBufferObjectTest::onEnter() // sprite->runAction(RepeatForever::create(animate)); //} //sprite->setPosition(Vec2(100,100)); - auto rt = RenderTarget::create(fboSize.width, fboSize.height); - auto rtDS = RenderTargetDepthStencil::create(fboSize.width, fboSize.height); - fbo->AttachRenderTarget(rt); - fbo->AttachDepthStencilTarget(rtDS); + auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height); + auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height); + fbo->attachRenderTarget(rt); + fbo->attachDepthStencilTarget(rtDS); auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture()); sprite->setScale(0.3); sprite->runAction(RepeatForever::create(RotateBy::create(1, 90)));