Exemplo n.º 1
0
void CCBatchNode::draw()
{
    CC_NODE_DRAW_SETUP();
    CCObject *object = NULL;
    CCARRAY_FOREACH(m_pChildren, object)
    {
        CCArmature *armature = dynamic_cast<CCArmature *>(object);
        if (armature)
        {
            armature->visit();
            m_pAtlas = armature->getTextureAtlas();
        }
        else
        {
            ((CCNode *)object)->visit();
        }
    }
Exemplo n.º 2
0
void CBArmature::draw()
{
    if(m_preDrawFunction)
        m_preDrawFunction->execute();
    
    if (m_pParentBone == NULL && m_pBatchNode == NULL)
    {
        CC_NODE_DRAW_SETUP();
        ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
    }
    
    CCObject *object = NULL;
    CCARRAY_FOREACH(m_pChildren, object)
    {
        if (CCBone *bone = dynamic_cast<CCBone *>(object))
        {
            CCNode *node = bone->getDisplayRenderNode();
            
            if (NULL == node)
                continue;
            
            switch (bone->getDisplayRenderNodeType())
            {
                case CS_DISPLAY_SPRITE:
                {
                    CCSkin *skin = (CCSkin *)node;
                    
                    CCTextureAtlas *textureAtlas = skin->getTextureAtlas();
                    bool blendDirty = bone->isBlendDirty();
                    if(m_pAtlas != textureAtlas || blendDirty)
                    {
                        if (m_pAtlas)
                        {
                            if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                                pAtlas->drawQuadsEx();
                            } else {
                                m_pAtlas->drawQuads();
                            }
                            m_pAtlas->removeAllQuads();
                        }
                    }
                    
                    m_pAtlas = textureAtlas;
                    if (m_pAtlas->getCapacity() == m_pAtlas->getTotalQuads() && !m_pAtlas->resizeCapacity(m_pAtlas->getCapacity() * 2))
                        return;
                    
                    skin->updateTransform();
                    
                    if (blendDirty)
                    {
                        ccBlendFunc func = bone->getBlendFunc();
                        ccGLBlendFunc(func.src, func.dst);
                        
                        if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                            pAtlas->drawQuadsEx();
                        } else {
                            m_pAtlas->drawQuads();
                        }
                        m_pAtlas->removeAllQuads();
                        
                        ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
                        bone->setBlendDirty(false);
                    }
                }
                    break;
                case CS_DISPLAY_ARMATURE:
                {
                    CCArmature *armature = (CCArmature *)(node);
                    
                    CCTextureAtlas *textureAtlas = armature->getTextureAtlas();
                    if(m_pAtlas != textureAtlas)
                    {
                        if (m_pAtlas)
                        {
                            if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                                pAtlas->drawQuadsEx();
                            } else {
                                m_pAtlas->drawQuads();
                            }
                            m_pAtlas->removeAllQuads();
                        }
                    }
                    armature->draw();
                    
                    m_pAtlas = armature->getTextureAtlas();
                }
                    break;
                default:
                {
                    if (m_pAtlas)
                    {
                        if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                            pAtlas->drawQuadsEx();
                        } else {
                            m_pAtlas->drawQuads();
                        }
                        m_pAtlas->removeAllQuads();
                    }
                    node->visit();
                    
                    CC_NODE_DRAW_SETUP();
                    ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
                }
                    break;
            }
        }
        else if(CCNode *node = dynamic_cast<CCNode *>(object))
        {
            if (m_pAtlas)
            {
                if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
                    pAtlas->drawQuadsEx();
                } else {
                    m_pAtlas->drawQuads();
                }
                m_pAtlas->removeAllQuads();
            }
            node->visit();
            
            CC_NODE_DRAW_SETUP();
            ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
        }
    }
    
    if(m_pAtlas && !m_pBatchNode && m_pParentBone == NULL)
    {
        if(CBTextureAtlas* pAtlas = dynamic_cast<CBTextureAtlas *>(m_pAtlas)) {
            pAtlas->drawQuadsEx();
        } else {
            m_pAtlas->drawQuads();
        }
        m_pAtlas->removeAllQuads();
    }
}