StateBlock() is public

This commit is contained in:
Ricardo Quesada 2015-06-15 17:43:37 -07:00
parent 695c2a7137
commit b167ab3e78
4 changed files with 36 additions and 21 deletions

View File

@ -253,6 +253,26 @@ It should work same as apples CFSwapInt32LittleToHost(..)
} while (false)
#endif
/**
* GL assertion that can be used for any OpenGL function call.
*
* This macro will assert if an error is detected when executing
* the specified GL code. This macro will do nothing in release
* mode and is therefore safe to use for realtime/per-frame GL
* function calls.
*/
#if defined(NDEBUG) || (defined(__APPLE__) && !defined(DEBUG))
#define CC_GL_ASSERT( gl_code ) gl_code
#else
#define CC_GL_ASSERT( gl_code ) do \
{ \
gl_code; \
__gl_error_code = glGetError(); \
CC_ASSERT(__gl_error_code == GL_NO_ERROR, "Error"); \
} while(0)
#endif
/** @def CC_INCREMENT_GL_DRAWS_BY_ONE
Increments the GL Draws counts by one.
The number of calls per frame are displayed on the screen when the Director's stats are enabled.

View File

@ -201,6 +201,13 @@ public:
*/
static StateBlock* create();
/** The recommended way to create StateBlocks is by calling `create`.
* Don't use `new` or `delete` on them.
*
*/
StateBlock();
~StateBlock();
/**
* Binds the state in this StateBlock to the renderer.
*
@ -398,8 +405,6 @@ public:
static StateBlock* _defaultState;
protected:
StateBlock();
~StateBlock();
void bindNoRestore();
static void enableDepthWrite();

View File

@ -480,21 +480,12 @@ void Material_renderState::onEnter()
skeletonNode->setNormalizedPosition(Vec2(0.6,0.3));
this->addChild(skeletonNode);
_stateBlock = RenderState::StateBlock::create();
_stateBlock->retain();
_stateBlock->setDepthTest(false);
_stateBlock->setDepthWrite(false);
_stateBlock->setCullFace(true);
_stateBlock->setCullFaceSide(RenderState::CULL_FACE_SIDE_FRONT);
_stateBlock->setFrontFace(RenderState::FRONT_FACE_CW);
_stateBlock->setBlend(false);
}
void Material_renderState::onExit()
{
MaterialSystemBaseTest::onExit();
_stateBlock->release();
_stateBlock.setDepthTest(false);
_stateBlock.setDepthWrite(false);
_stateBlock.setCullFace(true);
_stateBlock.setCullFaceSide(RenderState::CULL_FACE_SIDE_FRONT);
_stateBlock.setFrontFace(RenderState::FRONT_FACE_CW);
_stateBlock.setBlend(false);
}
std::string Material_renderState::subtitle() const
@ -507,12 +498,12 @@ void Material_renderState::draw(cocos2d::Renderer *renderer, const cocos2d::Mat4
_customCommand.init(_globalZOrder, transform, flags);
_customCommand.func = [this]() {
this->_stateBlock->bind();
this->_stateBlock.bind();
// should do something...
// and after that, restore
this->_stateBlock->restore(0);
this->_stateBlock.restore(0);
};
renderer->addCommand(&_customCommand);

View File

@ -130,12 +130,11 @@ public:
CREATE_FUNC(Material_renderState);
virtual void onEnter() override;
virtual void onExit() override;
virtual std::string subtitle() const override;
virtual void draw(cocos2d::Renderer *renderer, const cocos2d::Mat4 &transform, uint32_t flags) override;
cocos2d::RenderState::StateBlock* _stateBlock;
cocos2d::RenderState::StateBlock _stateBlock;
cocos2d::CustomCommand _customCommand;
};