From f20d487adea7874a3e4c4cb8b67edd916f0e292d Mon Sep 17 00:00:00 2001 From: "Huabing.Xu" Date: Mon, 24 Feb 2014 20:02:48 +0800 Subject: [PATCH] closed #3818: fix CC_SPRITE_DEBUG_DRAW feature --- cocos/2d/CCSprite.cpp | 35 +++++++++++++++++++++++------------ cocos/2d/CCSprite.h | 6 +++++- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/cocos/2d/CCSprite.cpp b/cocos/2d/CCSprite.cpp index 4b5ae03fe2..9a76c6279d 100644 --- a/cocos/2d/CCSprite.cpp +++ b/cocos/2d/CCSprite.cpp @@ -47,7 +47,6 @@ THE SOFTWARE. #include "CCProfiling.h" #include "CCDirector.h" #include "renderer/CCRenderer.h" -#include "renderer/CCQuadCommand.h" #include "renderer/CCFrustum.h" // external @@ -590,17 +589,6 @@ void Sprite::updateTransform(void) arrayMakeObjectsPerformSelector(_children, updateTransform, Sprite*); }*/ Node::updateTransform(); - -#if CC_SPRITE_DEBUG_DRAW - // draw bounding box - Point vertices[4] = { - Point( _quad.bl.vertices.x, _quad.bl.vertices.y ), - Point( _quad.br.vertices.x, _quad.br.vertices.y ), - Point( _quad.tr.vertices.x, _quad.tr.vertices.y ), - Point( _quad.tl.vertices.x, _quad.tl.vertices.y ), - }; - DrawPrimitives::drawPoly(vertices, 4, true); -#endif // CC_SPRITE_DEBUG_DRAW } // draw @@ -611,8 +599,31 @@ void Sprite::draw(void) { _quadCommand.init(_globalZOrder, _texture->getName(), _shaderProgram, _blendFunc, &_quad, 1, _modelViewTransform); Director::getInstance()->getRenderer()->addCommand(&_quadCommand); +#if CC_SPRITE_DEBUG_DRAW + _customDebugDrawCommand.init(_globalZOrder); + _customDebugDrawCommand.func = CC_CALLBACK_0(Sprite::drawDebugData, this); + Director::getInstance()->getRenderer()->addCommand(&_customDebugDrawCommand); +#endif //CC_SPRITE_DEBUG_DRAW } } +#if CC_SPRITE_DEBUG_DRAW +void Sprite::drawDebugData() +{ + kmMat4 oldModelView; + kmGLGetMatrix(KM_GL_MODELVIEW, &oldModelView); + kmGLLoadMatrix(&_modelViewTransform); + // draw bounding box + Point vertices[4] = { + Point( _quad.bl.vertices.x, _quad.bl.vertices.y ), + Point( _quad.br.vertices.x, _quad.br.vertices.y ), + Point( _quad.tr.vertices.x, _quad.tr.vertices.y ), + Point( _quad.tl.vertices.x, _quad.tl.vertices.y ), + }; + DrawPrimitives::drawPoly(vertices, 4, true); + + kmGLLoadMatrix(&oldModelView); +} +#endif //CC_SPRITE_DEBUG_DRAW // Culling function from cocos2d-iphone CCSprite.m file bool Sprite::culling() const diff --git a/cocos/2d/CCSprite.h b/cocos/2d/CCSprite.h index bb77d131dc..a04f851f16 100644 --- a/cocos/2d/CCSprite.h +++ b/cocos/2d/CCSprite.h @@ -39,6 +39,7 @@ THE SOFTWARE. #endif // EMSCRIPTEN #include "CCPhysicsBody.h" #include "renderer/CCQuadCommand.h" +#include "renderer/CCCustomCommand.h" #include "kazmath/kazmath.h" NS_CC_BEGIN @@ -546,7 +547,10 @@ protected: BlendFunc _blendFunc; /// It's required for TextureProtocol inheritance Texture2D* _texture; /// Texture2D object that is used to render the sprite QuadCommand _quadCommand; /// quad command - +#if CC_SPRITE_DEBUG_DRAW + CustomCommand _customDebugDrawCommand; + void drawDebugData(); +#endif //CC_SPRITE_DEBUG_DRAW // // Shared data //