Fix NewClipNodeTest

This commit is contained in:
Nite Luo 2013-11-15 17:32:29 -08:00
parent c5f9434331
commit f5a8c1d02c
6 changed files with 52 additions and 12 deletions

View File

@ -34,7 +34,7 @@ NewDrawNode::~NewDrawNode()
bool NewDrawNode::init()
{
return false;
return DrawNode::init();
}
void NewDrawNode::draw()

View File

@ -72,20 +72,34 @@ NewClippingNode::NewClippingNode()
currentStencilFail = GL_KEEP;
currentStencilPassDepthFail = GL_KEEP;
currentStencilPassDepthPass = GL_KEEP;
GLboolean currentDepthWriteMask = GL_TRUE;
}
void NewClippingNode::visit()
{
//Add group command
GroupCommand* groupCommand = new GroupCommand(0,0);
Renderer::getInstance()->addCommand(groupCommand, groupCommand->getRenderQueueID());
GroupCommand* groupCommand = new GroupCommand(0,_vertexZ);
Renderer::getInstance()->addCommand(groupCommand);
Renderer::getInstance()->setCurrentRenderQueue(groupCommand->getRenderQueueID());
CustomCommand* beforeVisitCmd = new CustomCommand(0,_vertexZ);
beforeVisitCmd->func = CC_CALLBACK_0(NewClippingNode::beforeVisit, this);
Renderer::getInstance()->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());
Node::visit();
CustomCommand* prepareStencil = new CustomCommand(0,0);
prepareStencil->func = CC_CALLBACK_0(NewClippingNode::beforeVisit, this);
CustomCommand* afterVisitCmd = new CustomCommand(0,_vertexZ);
afterVisitCmd->func = CC_CALLBACK_0(NewClippingNode::afterVisit, this);
Renderer::getInstance()->addCommand(afterVisitCmd, groupCommand->getRenderQueueID());
Renderer::getInstance()->setCurrentRenderQueue(DEFAULT_RENDER_QUEUE);
}
void NewClippingNode::beforeVisit()
@ -106,7 +120,7 @@ void NewClippingNode::beforeVisit()
// mask of all layers less than the current (ie: for layer 3: 00000011)
GLint mask_layer_l = mask_layer - 1;
// mask of all layers less than or equal to the current (ie: for layer 3: 00000111)
GLint mask_layer_le = mask_layer | mask_layer_l;
mask_layer_le = mask_layer | mask_layer_l;
// manually save the stencil state
@ -129,8 +143,7 @@ void NewClippingNode::beforeVisit()
glStencilMask(mask_layer);
// manually save the depth test state
//GLboolean currentDepthTestEnabled = GL_TRUE;
GLboolean currentDepthWriteMask = GL_TRUE;
//currentDepthTestEnabled = glIsEnabled(GL_DEPTH_TEST);
glGetBooleanv(GL_DEPTH_WRITEMASK, &currentDepthWriteMask);
@ -181,7 +194,10 @@ void NewClippingNode::beforeVisit()
setProgram(_stencil, program);
//Draw _stencil
}
void NewClippingNode::afterDrawStencil()
{
// restore the depth test state
glDepthMask(currentDepthWriteMask);
//if (currentDepthTestEnabled) {
@ -203,6 +219,7 @@ void NewClippingNode::beforeVisit()
// draw (according to the stencil test func) this node and its childs
}
void NewClippingNode::afterVisit()
{
///////////////////////////////////

View File

@ -27,6 +27,7 @@ protected:
NewClippingNode();
void beforeVisit();
void afterDrawStencil();
void afterVisit();
protected:
@ -38,6 +39,9 @@ protected:
GLenum currentStencilFail;
GLenum currentStencilPassDepthFail;
GLenum currentStencilPassDepthPass;
GLboolean currentDepthWriteMask;
GLint mask_layer_le;
};
NS_CC_END

View File

@ -42,6 +42,8 @@ Renderer::Renderer()
,_firstCommand(0)
,_lastCommand(0)
{
_currRenderQueueID = DEFAULT_RENDER_QUEUE;
RenderQueue defaultRenderQueue;
_renderGroups.push_back(defaultRenderQueue);
_renderStack.push({DEFAULT_RENDER_QUEUE, 0});
@ -107,6 +109,12 @@ void Renderer::setupVBOAndVAO()
CHECK_GL_ERROR_DEBUG();
}
void Renderer::addCommand(RenderCommand* command)
{
command->generateID();
_renderGroups[_currRenderQueueID].push_back(command);
}
void Renderer::addCommand(RenderCommand* command, int renderQueue)
{
command->generateID();

View File

@ -35,10 +35,13 @@ public:
static void destroyInstance();
//TODO support multiple viewport
void addCommand(RenderCommand *command, int renderQueue = DEFAULT_RENDER_QUEUE);
void addCommand(RenderCommand* command);
void addCommand(RenderCommand* command, int renderQueue);
int createRenderQueue();
void render();
inline void setCurrentRenderQueue(int renderQueueID) { _currRenderQueueID = renderQueueID; }
protected:
Renderer();
~Renderer();
@ -54,6 +57,8 @@ protected:
stack<RenderStackElement> _renderStack;
vector<RenderQueue> _renderGroups;
int _currRenderQueueID;
int _lastMaterialID;
size_t _firstCommand;

View File

@ -7,6 +7,7 @@
#include "CCNewSprite.h"
#include "CCNewSpriteBatchNode.h"
#include "NewClippingNode.h"
#include "CCNewDrawNode.h"
static int sceneIdx = -1;
@ -260,15 +261,17 @@ void NewSpriteBatchTest::addNewSpriteWithCoords(Point p)
NewClippingNodeTest::NewClippingNodeTest()
{
auto s = Director::getInstance()->getWinSize();
auto clipper = NewClippingNode::create();
clipper->setTag( kTagClipperNode );
clipper->setContentSize( Size(200, 200) );
clipper->setAnchorPoint( Point(0.5, 0.5) );
clipper->setPosition( Point(this->getContentSize().width / 2, this->getContentSize().height / 2) );
clipper->setPosition( Point(s.width / 2, s.height / 2) );
clipper->runAction(RepeatForever::create(RotateBy::create(1, 45)));
this->addChild(clipper);
auto stencil = DrawNode::create();
auto stencil = NewDrawNode::create();
Point rectangle[4];
rectangle[0] = Point(0, 0);
rectangle[1] = Point(clipper->getContentSize().width, 0);
@ -279,6 +282,9 @@ NewClippingNodeTest::NewClippingNodeTest()
stencil->drawPolygon(rectangle, 4, white, 1, white);
clipper->setStencil(stencil);
// auto stencil = NewSprite::create("Images/background2.png");
// clipper->setStencil(stencil);
auto content = NewSprite::create("Images/background2.png");
content->setTag( kTagContentNode );
content->setAnchorPoint( Point(0.5, 0.5) );