add transparent flag to render command

This commit is contained in:
yangxiao 2014-09-18 12:00:44 +08:00
parent 35acdc2284
commit 25091ca849
6 changed files with 17 additions and 14 deletions

View File

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

View File

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

View File

@ -30,6 +30,7 @@ NS_CC_BEGIN
RenderCommand::RenderCommand()
: _type(RenderCommand::Type::UNKNOWN_COMMAND)
, _globalOrder(0)
, _isTransparent(false)
{
}

View File

@ -59,6 +59,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();
virtual ~RenderCommand();
@ -70,6 +76,8 @@ protected:
// commands are sort by depth
float _globalOrder;
bool _isTransparent;
};
NS_CC_END

View File

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

View File

@ -109,9 +109,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);