Use stack to manage current RenderGroup

This commit is contained in:
Nite Luo 2013-11-20 11:05:01 -08:00
parent 8ce16e1e12
commit 0e51504ee6
3 changed files with 28 additions and 16 deletions

View File

@ -82,28 +82,31 @@ NewClippingNode::NewClippingNode()
void NewClippingNode::visit()
{
//Add group command
Renderer* renderer = Renderer::getInstance();
GroupCommand* groupCommand = new GroupCommand(0,_vertexZ);
Renderer::getInstance()->addCommand(groupCommand);
renderer->addCommand(groupCommand);
Renderer::getInstance()->setCurrentRenderQueue(groupCommand->getRenderQueueID());
renderer->pushGroup(groupCommand->getRenderQueueID());
CustomCommand* beforeVisitCmd = new CustomCommand(0,_vertexZ);
beforeVisitCmd->func = CC_CALLBACK_0(NewClippingNode::beforeVisit, this);
Renderer::getInstance()->addCommand(beforeVisitCmd, groupCommand->getRenderQueueID());
renderer->addCommand(beforeVisitCmd, groupCommand->getRenderQueueID());
_stencil->visit();
CustomCommand* afterDrawStencilCmd = new CustomCommand(0,_vertexZ);
afterDrawStencilCmd->func = CC_CALLBACK_0(NewClippingNode::afterDrawStencil, this);
Renderer::getInstance()->addCommand(afterDrawStencilCmd, groupCommand->getRenderQueueID());
renderer->addCommand(afterDrawStencilCmd, groupCommand->getRenderQueueID());
Node::visit();
CustomCommand* afterVisitCmd = new CustomCommand(0,_vertexZ);
afterVisitCmd->func = CC_CALLBACK_0(NewClippingNode::afterVisit, this);
Renderer::getInstance()->addCommand(afterVisitCmd, groupCommand->getRenderQueueID());
renderer->addCommand(afterVisitCmd, groupCommand->getRenderQueueID());
Renderer::getInstance()->setCurrentRenderQueue(DEFAULT_RENDER_QUEUE);
renderer->popGroup();
}
void NewClippingNode::beforeVisit()

View File

@ -3,13 +3,11 @@
//
#include <OpenGL/OpenGL.h>
#include "Renderer.h"
#include "CCShaderCache.h"
#include "ccGLStateCache.h"
#include "CustomCommand.h"
#include "QuadCommand.h"
#include "CCGL.h"
#include "GroupCommand.h"
@ -42,8 +40,8 @@ Renderer::Renderer()
,_firstCommand(0)
,_lastCommand(0)
{
_currRenderQueueID = DEFAULT_RENDER_QUEUE;
_commandGroupStack.push(DEFAULT_RENDER_QUEUE);
RenderQueue defaultRenderQueue;
_renderGroups.push_back(defaultRenderQueue);
_renderStack.push({DEFAULT_RENDER_QUEUE, 0});
@ -112,7 +110,7 @@ void Renderer::setupVBOAndVAO()
void Renderer::addCommand(RenderCommand* command)
{
command->generateID();
_renderGroups[_currRenderQueueID].push_back(command);
_renderGroups[_commandGroupStack.top()].push_back(command);
}
void Renderer::addCommand(RenderCommand* command, int renderQueue)
@ -121,11 +119,21 @@ void Renderer::addCommand(RenderCommand* command, int renderQueue)
_renderGroups[renderQueue].push_back(command);
}
void Renderer::pushGroup(int renderQueueID)
{
_commandGroupStack.push(renderQueueID);
}
void Renderer::popGroup()
{
_commandGroupStack.pop();
}
int Renderer::createRenderQueue()
{
RenderQueue newRenderQueue;
_renderGroups.push_back(newRenderQueue);
return _renderGroups.size() - 1;
return (int)_renderGroups.size() - 1;
}
bool compareRenderCommand(RenderCommand* a, RenderCommand* b)

View File

@ -37,11 +37,12 @@ public:
//TODO support multiple viewport
void addCommand(RenderCommand* command);
void addCommand(RenderCommand* command, int renderQueue);
void pushGroup(int renderQueueID);
void popGroup();
int createRenderQueue();
void render();
inline void setCurrentRenderQueue(int renderQueueID) { _currRenderQueueID = renderQueueID; }
protected:
Renderer();
~Renderer();
@ -54,11 +55,11 @@ protected:
void flush();
protected:
stack<int> _commandGroupStack;
stack<RenderStackElement> _renderStack;
vector<RenderQueue> _renderGroups;
int _currRenderQueueID;
int _lastMaterialID;
size_t _firstCommand;