From 25091ca849c90c8aefc9c0b4da218ae81fca340e Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 18 Sep 2014 12:00:44 +0800 Subject: [PATCH 1/2] add transparent flag to render command --- cocos/3d/CCBillBoard.cpp | 3 ++- cocos/3d/CCSprite3D.cpp | 6 ++---- cocos/renderer/CCRenderCommand.cpp | 1 + cocos/renderer/CCRenderCommand.h | 8 ++++++++ cocos/renderer/CCRenderer.cpp | 10 ++++------ cocos/renderer/CCRenderer.h | 3 --- 6 files changed, 17 insertions(+), 14 deletions(-) diff --git a/cocos/3d/CCBillBoard.cpp b/cocos/3d/CCBillBoard.cpp index 26112ca572..c39bff5364 100644 --- a/cocos/3d/CCBillBoard.cpp +++ b/cocos/3d/CCBillBoard.cpp @@ -148,7 +148,8 @@ void BillBoard::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) //FIXME: frustum culling here { _quadCommand.init(_zDepthInView, _texture->getName(), getGLProgramState(), _blendFunc, &_quad, 1, _billboardTransform); - renderer->addCommandToTransparentQueue(&_quadCommand); + _quadCommand.setTransparent(true); + renderer->addCommand(&_quadCommand); } } diff --git a/cocos/3d/CCSprite3D.cpp b/cocos/3d/CCSprite3D.cpp index dcb3ecc012..faa8516284 100644 --- a/cocos/3d/CCSprite3D.cpp +++ b/cocos/3d/CCSprite3D.cpp @@ -521,10 +521,8 @@ void Sprite3D::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) } //support tint and fade meshCommand.setDisplayColor(Vec4(color.r, color.g, color.b, color.a)); - if (mesh->_isTransparent) - renderer->addCommandToTransparentQueue(&meshCommand); - else - renderer->addCommand(&meshCommand); + meshCommand.setTransparent(mesh->_isTransparent); + renderer->addCommand(&meshCommand); } } diff --git a/cocos/renderer/CCRenderCommand.cpp b/cocos/renderer/CCRenderCommand.cpp index 0996ab2d52..b7f9a35f51 100644 --- a/cocos/renderer/CCRenderCommand.cpp +++ b/cocos/renderer/CCRenderCommand.cpp @@ -30,6 +30,7 @@ NS_CC_BEGIN RenderCommand::RenderCommand() : _type(RenderCommand::Type::UNKNOWN_COMMAND) , _globalOrder(0) +, _isTransparent(false) { } diff --git a/cocos/renderer/CCRenderCommand.h b/cocos/renderer/CCRenderCommand.h index 7c560cda58..997bc41d4f 100644 --- a/cocos/renderer/CCRenderCommand.h +++ b/cocos/renderer/CCRenderCommand.h @@ -58,6 +58,12 @@ public: /** Returns the Command type */ inline Type getType() const { return _type; } + + /** Retruns whether is transparent */ + inline bool isTransparent() const { return _isTransparent; } + + /** set transparent flag */ + inline void setTransparent(bool isTransparent) { _isTransparent = isTransparent; } protected: RenderCommand(); @@ -70,6 +76,8 @@ protected: // commands are sort by depth float _globalOrder; + + bool _isTransparent; }; NS_CC_END diff --git a/cocos/renderer/CCRenderer.cpp b/cocos/renderer/CCRenderer.cpp index e62c812e05..226d26b17b 100644 --- a/cocos/renderer/CCRenderer.cpp +++ b/cocos/renderer/CCRenderer.cpp @@ -268,12 +268,10 @@ void Renderer::addCommand(RenderCommand* command, int renderQueue) CCASSERT(!_isRendering, "Cannot add command while rendering"); CCASSERT(renderQueue >=0, "Invalid render queue"); CCASSERT(command->getType() != RenderCommand::Type::UNKNOWN_COMMAND, "Invalid Command Type"); - _renderGroups[renderQueue].push_back(command); -} - -void Renderer::addCommandToTransparentQueue(RenderCommand* command) -{ - _transparentRenderGroups.push_back(command); + if (command->isTransparent()) + _transparentRenderGroups.push_back(command); + else + _renderGroups[renderQueue].push_back(command); } void Renderer::pushGroup(int renderQueueID) diff --git a/cocos/renderer/CCRenderer.h b/cocos/renderer/CCRenderer.h index a2f21966c2..e9913dd775 100644 --- a/cocos/renderer/CCRenderer.h +++ b/cocos/renderer/CCRenderer.h @@ -108,9 +108,6 @@ public: /** Adds a `RenderComamnd` into the renderer specifying a particular render queue ID */ void addCommand(RenderCommand* command, int renderQueue); - - /** add transprent command */ - void addCommandToTransparentQueue(RenderCommand* command); /** Pushes a group into the render queue */ void pushGroup(int renderQueueID); From 720264fb98da61decb5c0a68c9afcb00d2b47a21 Mon Sep 17 00:00:00 2001 From: yangxiao Date: Thu, 18 Sep 2014 12:04:42 +0800 Subject: [PATCH 2/2] add comment --- cocos/renderer/CCRenderCommand.h | 1 + 1 file changed, 1 insertion(+) diff --git a/cocos/renderer/CCRenderCommand.h b/cocos/renderer/CCRenderCommand.h index 997bc41d4f..b73bfb11bd 100644 --- a/cocos/renderer/CCRenderCommand.h +++ b/cocos/renderer/CCRenderCommand.h @@ -77,6 +77,7 @@ protected: // commands are sort by depth float _globalOrder; + // transparent flag bool _isTransparent; };