mirror of https://github.com/axmolengine/axmol.git
rename FrameBufferObject->FrameBuffer
Move FrameBufferObject related class to experimental namespace
This commit is contained in:
parent
133ef90c09
commit
9acab65e4f
|
@ -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_RETAIN(fbo);
|
||||||
CC_SAFE_RELEASE_NULL(_fbo);
|
CC_SAFE_RELEASE_NULL(_fbo);
|
||||||
|
@ -498,7 +498,7 @@ void Camera::applyFrameBufferObject()
|
||||||
{
|
{
|
||||||
if(nullptr == _fbo)
|
if(nullptr == _fbo)
|
||||||
{
|
{
|
||||||
FrameBufferObject::applyDefaultFBO();
|
experimental::FrameBuffer::applyDefaultFBO();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,7 +32,10 @@ THE SOFTWARE.
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
class Scene;
|
class Scene;
|
||||||
class FrameBufferObject;
|
namespace experimental
|
||||||
|
{
|
||||||
|
class FrameBuffer;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
Viewport is a normalized to FrameBufferObject
|
Viewport is a normalized to FrameBufferObject
|
||||||
But for default FBO, the size is absolute.
|
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.
|
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.
|
Set Viewport for camera.
|
||||||
*/
|
*/
|
||||||
|
@ -303,7 +306,7 @@ protected:
|
||||||
friend class Director;
|
friend class Director;
|
||||||
Viewport _viewport;
|
Viewport _viewport;
|
||||||
|
|
||||||
FrameBufferObject* _fbo;
|
experimental::FrameBuffer* _fbo;
|
||||||
protected:
|
protected:
|
||||||
static Viewport _defaultViewport;
|
static Viewport _defaultViewport;
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -187,7 +187,7 @@ void Scene::render(Renderer* renderer)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Camera::_visitingCamera = nullptr;
|
Camera::_visitingCamera = nullptr;
|
||||||
FrameBufferObject::applyDefaultFBO();
|
experimental::FrameBuffer::applyDefaultFBO();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Scene::removeAllChildren()
|
void Scene::removeAllChildren()
|
||||||
|
|
|
@ -279,7 +279,7 @@ void Director::drawScene()
|
||||||
}
|
}
|
||||||
|
|
||||||
_renderer->clear();
|
_renderer->clear();
|
||||||
FrameBufferObject::clearAllFBOs();
|
experimental::FrameBuffer::clearAllFBOs();
|
||||||
/* to avoid flickr, nextScene MUST be here: after tick and before draw.
|
/* 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
|
* 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);
|
_eventDispatcher->setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
_defaultFBO = FrameBufferObject::getOrCreateDefaultFBO(_openGLView);
|
_defaultFBO = experimental::FrameBuffer::getOrCreateDefaultFBO(_openGLView);
|
||||||
_defaultFBO->retain();
|
_defaultFBO->retain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,8 +60,10 @@ class Renderer;
|
||||||
class Camera;
|
class Camera;
|
||||||
|
|
||||||
class Console;
|
class Console;
|
||||||
|
namespace experimental
|
||||||
class FrameBufferObject;
|
{
|
||||||
|
class FrameBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Matrix stack type.
|
* @brief Matrix stack type.
|
||||||
|
@ -597,7 +599,7 @@ protected:
|
||||||
Renderer *_renderer;
|
Renderer *_renderer;
|
||||||
|
|
||||||
/* Default FrameBufferObject*/
|
/* Default FrameBufferObject*/
|
||||||
FrameBufferObject* _defaultFBO;
|
experimental::FrameBuffer* _defaultFBO;
|
||||||
|
|
||||||
/* Console for the director */
|
/* Console for the director */
|
||||||
Console *_console;
|
Console *_console;
|
||||||
|
|
|
@ -30,9 +30,9 @@
|
||||||
#include "base/CCEventType.h"
|
#include "base/CCEventType.h"
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
namespace experimental{
|
||||||
FrameBufferObject* FrameBufferObject::_defaultFBO = nullptr;
|
FrameBuffer* FrameBuffer::_defaultFBO = nullptr;
|
||||||
std::set<FrameBufferObject*> FrameBufferObject::_frameBufferObjects;
|
std::set<FrameBuffer*> FrameBuffer::_frameBuffers;
|
||||||
|
|
||||||
RenderTargetBase::RenderTargetBase()
|
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)
|
if(view == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -278,11 +278,11 @@ bool FrameBufferObject::initWithGLView(GLView* view)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBufferObject* FrameBufferObject::getOrCreateDefaultFBO(GLView* view)
|
FrameBuffer* FrameBuffer::getOrCreateDefaultFBO(GLView* view)
|
||||||
{
|
{
|
||||||
if(nullptr == _defaultFBO)
|
if(nullptr == _defaultFBO)
|
||||||
{
|
{
|
||||||
auto result = new (std::nothrow) FrameBufferObject();
|
auto result = new (std::nothrow) FrameBuffer();
|
||||||
|
|
||||||
if(result && result->initWithGLView(view))
|
if(result && result->initWithGLView(view))
|
||||||
{
|
{
|
||||||
|
@ -300,7 +300,7 @@ FrameBufferObject* FrameBufferObject::getOrCreateDefaultFBO(GLView* view)
|
||||||
return _defaultFBO;
|
return _defaultFBO;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBufferObject::applyDefaultFBO()
|
void FrameBuffer::applyDefaultFBO()
|
||||||
{
|
{
|
||||||
if(_defaultFBO)
|
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();
|
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))
|
if(result && result->init(fid, width, height))
|
||||||
{
|
{
|
||||||
result->autorelease();
|
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;
|
_fid = fid;
|
||||||
_width = width;
|
_width = width;
|
||||||
|
@ -365,7 +365,7 @@ bool FrameBufferObject::init(uint8_t fid, unsigned int width, unsigned int heigh
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBufferObject::FrameBufferObject()
|
FrameBuffer::FrameBuffer()
|
||||||
: _clearColor(Color4F(0, 0, 0, 1))
|
: _clearColor(Color4F(0, 0, 0, 1))
|
||||||
, _clearDepth(1.0)
|
, _clearDepth(1.0)
|
||||||
, _clearStencil(0)
|
, _clearStencil(0)
|
||||||
|
@ -378,10 +378,10 @@ FrameBufferObject::FrameBufferObject()
|
||||||
, _dirtyFBOListener(nullptr)
|
, _dirtyFBOListener(nullptr)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
_frameBufferObjects.insert(this);
|
_frameBuffers.insert(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
FrameBufferObject::~FrameBufferObject()
|
FrameBuffer::~FrameBuffer()
|
||||||
{
|
{
|
||||||
if(!isDefaultFBO())
|
if(!isDefaultFBO())
|
||||||
{
|
{
|
||||||
|
@ -389,14 +389,14 @@ FrameBufferObject::~FrameBufferObject()
|
||||||
CC_SAFE_RELEASE_NULL(_rtDepthStencil);
|
CC_SAFE_RELEASE_NULL(_rtDepthStencil);
|
||||||
glDeleteFramebuffers(1, &_fbo);
|
glDeleteFramebuffers(1, &_fbo);
|
||||||
_fbo = 0;
|
_fbo = 0;
|
||||||
_frameBufferObjects.erase(this);
|
_frameBuffers.erase(this);
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
Director::getInstance()->getEventDispatcher()->removeEventListener(_dirtyFBOListener);
|
Director::getInstance()->getEventDispatcher()->removeEventListener(_dirtyFBOListener);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBufferObject::clearFBO()
|
void FrameBuffer::clearFBO()
|
||||||
{
|
{
|
||||||
applyFBO();
|
applyFBO();
|
||||||
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
glClearColor(_clearColor.r, _clearColor.g, _clearColor.b, _clearColor.a);
|
||||||
|
@ -406,7 +406,7 @@ void FrameBufferObject::clearFBO()
|
||||||
applyDefaultFBO();
|
applyDefaultFBO();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBufferObject::AttachRenderTarget(RenderTargetBase* rt)
|
void FrameBuffer::attachRenderTarget(RenderTargetBase* rt)
|
||||||
{
|
{
|
||||||
if(isDefaultFBO())
|
if(isDefaultFBO())
|
||||||
{
|
{
|
||||||
|
@ -425,7 +425,7 @@ void FrameBufferObject::AttachRenderTarget(RenderTargetBase* rt)
|
||||||
_fboBindingDirty = true;
|
_fboBindingDirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBufferObject::applyFBO()
|
void FrameBuffer::applyFBO()
|
||||||
{
|
{
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, _fbo);
|
||||||
|
@ -452,7 +452,7 @@ void FrameBufferObject::applyFBO()
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameBufferObject::AttachDepthStencilTarget(RenderTargetDepthStencil* rt)
|
void FrameBuffer::attachDepthStencilTarget(RenderTargetDepthStencil* rt)
|
||||||
{
|
{
|
||||||
if(isDefaultFBO())
|
if(isDefaultFBO())
|
||||||
{
|
{
|
||||||
|
@ -470,4 +470,5 @@ void FrameBufferObject::AttachDepthStencilTarget(RenderTargetDepthStencil* rt)
|
||||||
_rtDepthStencil = rt;
|
_rtDepthStencil = rt;
|
||||||
_fboBindingDirty = true;
|
_fboBindingDirty = true;
|
||||||
}
|
}
|
||||||
NS_CC_END
|
} //end of namespace experimental
|
||||||
|
NS_CC_END
|
||||||
|
|
|
@ -31,8 +31,12 @@
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
||||||
NS_CC_BEGIN
|
NS_CC_BEGIN
|
||||||
|
|
||||||
|
class GLView;
|
||||||
class EventListenerCustom;
|
class EventListenerCustom;
|
||||||
|
|
||||||
|
namespace experimental {
|
||||||
|
|
||||||
class RenderTargetBase : public Ref
|
class RenderTargetBase : public Ref
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -126,12 +130,10 @@ protected:
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
class GLView;
|
class CC_DLL FrameBuffer : public Ref
|
||||||
|
|
||||||
class CC_DLL FrameBufferObject : public Ref
|
|
||||||
{
|
{
|
||||||
public:
|
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);
|
bool init(uint8_t fid, unsigned int width, unsigned int height);
|
||||||
public:
|
public:
|
||||||
|
@ -149,16 +151,16 @@ public:
|
||||||
|
|
||||||
RenderTargetBase* getRenderTarget() const { return _rt; }
|
RenderTargetBase* getRenderTarget() const { return _rt; }
|
||||||
RenderTargetDepthStencil* getDepthStencilTarget() const { return _rtDepthStencil; }
|
RenderTargetDepthStencil* getDepthStencilTarget() const { return _rtDepthStencil; }
|
||||||
void AttachRenderTarget(RenderTargetBase* rt);
|
void attachRenderTarget(RenderTargetBase* rt);
|
||||||
void AttachDepthStencilTarget(RenderTargetDepthStencil* rt);
|
void attachDepthStencilTarget(RenderTargetDepthStencil* rt);
|
||||||
|
|
||||||
bool isDefaultFBO() const { return _isDefault; }
|
bool isDefaultFBO() const { return _isDefault; }
|
||||||
unsigned int getWidth() const { return _width; }
|
unsigned int getWidth() const { return _width; }
|
||||||
unsigned int getHeight() const { return _height; }
|
unsigned int getHeight() const { return _height; }
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
FrameBufferObject();
|
FrameBuffer();
|
||||||
virtual ~FrameBufferObject();
|
virtual ~FrameBuffer();
|
||||||
bool initWithGLView(GLView* view);
|
bool initWithGLView(GLView* view);
|
||||||
private:
|
private:
|
||||||
//openGL content for FrameBuffer
|
//openGL content for FrameBuffer
|
||||||
|
@ -177,19 +179,20 @@ private:
|
||||||
RenderTargetDepthStencil* _rtDepthStencil;
|
RenderTargetDepthStencil* _rtDepthStencil;
|
||||||
bool _isDefault;
|
bool _isDefault;
|
||||||
public:
|
public:
|
||||||
static FrameBufferObject* getOrCreateDefaultFBO(GLView* glView);
|
static FrameBuffer* getOrCreateDefaultFBO(GLView* glView);
|
||||||
static void applyDefaultFBO();
|
static void applyDefaultFBO();
|
||||||
static void clearAllFBOs();
|
static void clearAllFBOs();
|
||||||
private:
|
private:
|
||||||
//static GLuint _defaultFBO;
|
//static GLuint _defaultFBO;
|
||||||
static FrameBufferObject* _defaultFBO;
|
static FrameBuffer* _defaultFBO;
|
||||||
static std::set<FrameBufferObject*> _frameBufferObjects;
|
static std::set<FrameBuffer*> _frameBuffers;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
#if CC_ENABLE_CACHE_TEXTURE_DATA
|
||||||
EventListenerCustom* _dirtyFBOListener;
|
EventListenerCustom* _dirtyFBOListener;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
} // end of namespace experimental
|
||||||
|
|
||||||
NS_CC_END
|
NS_CC_END
|
||||||
|
|
||||||
|
|
|
@ -1433,7 +1433,7 @@ void CameraFrameBufferObjectTest::onEnter()
|
||||||
auto sizeInpixels = Director::getInstance()->getWinSizeInPixels();
|
auto sizeInpixels = Director::getInstance()->getWinSizeInPixels();
|
||||||
auto size = Director::getInstance()->getWinSize();
|
auto size = Director::getInstance()->getWinSize();
|
||||||
auto fboSize = Size(sizeInpixels.width * 1, sizeInpixels.height * 1.5);
|
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();
|
CameraBaseTest::onEnter();
|
||||||
//auto sprite = Sprite::createWithTexture(fbo);
|
//auto sprite = Sprite::createWithTexture(fbo);
|
||||||
|
@ -1449,10 +1449,10 @@ void CameraFrameBufferObjectTest::onEnter()
|
||||||
// sprite->runAction(RepeatForever::create(animate));
|
// sprite->runAction(RepeatForever::create(animate));
|
||||||
//}
|
//}
|
||||||
//sprite->setPosition(Vec2(100,100));
|
//sprite->setPosition(Vec2(100,100));
|
||||||
auto rt = RenderTarget::create(fboSize.width, fboSize.height);
|
auto rt = experimental::RenderTarget::create(fboSize.width, fboSize.height);
|
||||||
auto rtDS = RenderTargetDepthStencil::create(fboSize.width, fboSize.height);
|
auto rtDS = experimental::RenderTargetDepthStencil::create(fboSize.width, fboSize.height);
|
||||||
fbo->AttachRenderTarget(rt);
|
fbo->attachRenderTarget(rt);
|
||||||
fbo->AttachDepthStencilTarget(rtDS);
|
fbo->attachDepthStencilTarget(rtDS);
|
||||||
auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture());
|
auto sprite = Sprite::createWithTexture(fbo->getRenderTarget()->getTexture());
|
||||||
sprite->setScale(0.3);
|
sprite->setScale(0.3);
|
||||||
sprite->runAction(RepeatForever::create(RotateBy::create(1, 90)));
|
sprite->runAction(RepeatForever::create(RotateBy::create(1, 90)));
|
||||||
|
|
Loading…
Reference in New Issue