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);