Пример #1
0
    void Scale9Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
    {
        if (_scale9Image && _scale9Enabled) {
#if CC_USE_CULLING
            // Don't do calculate the culling if the transform was not updated
            auto visitingCamera = Camera::getVisitingCamera();
            auto defaultCamera = Camera::getDefaultCamera();
            if (visitingCamera == defaultCamera) {
                _insideBounds = ((flags & FLAGS_TRANSFORM_DIRTY)|| visitingCamera->isViewProjectionUpdated()) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
            }
            else
            {
                _insideBounds = renderer->checkVisibility(transform, _contentSize);
            }
            
            if(_insideBounds)
#endif
            {
                auto textureName = _scale9Image->getTexture()->getName();
                auto programState = _scale9Image->getGLProgramState();
                auto blendFunc = _scale9Image->getBlendFunc();
                auto& polyInfo = _scale9Image->getPolygonInfo();
                auto globalZOrder = _scale9Image->getGlobalZOrder();
                _trianglesCommand.init(globalZOrder,textureName, programState, blendFunc, polyInfo.triangles, transform, flags);
                renderer->addCommand(&_trianglesCommand);
                
#if CC_SPRITE_DEBUG_DRAW
                _debugDrawNode->clear();
                auto count = polyInfo.triangles.indexCount/3;
                auto indices = polyInfo.triangles.indices;
                auto verts = polyInfo.triangles.verts;
                for(ssize_t i = 0; i < count; i++)
                {
                    //draw 3 lines
                    Vec3 from =verts[indices[i*3]].vertices;
                    Vec3 to = verts[indices[i*3+1]].vertices;
                    _debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::WHITE);
                    
                    from =verts[indices[i*3+1]].vertices;
                    to = verts[indices[i*3+2]].vertices;
                    _debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::WHITE);
                    
                    from =verts[indices[i*3+2]].vertices;
                    to = verts[indices[i*3]].vertices;
                    _debugDrawNode->drawLine(Vec2(from.x, from.y), Vec2(to.x,to.y), Color4F::WHITE);
                }
#endif //CC_SPRITE_DEBUG_DRAW
            }
        }
    }
Пример #2
0
void Label::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
    if (_batchNodes.empty() || _lengthOfString <= 0)
    {
        return;
    }
    // Don't do calculate the culling if the transform was not updated
    bool transformUpdated = flags & FLAGS_TRANSFORM_DIRTY;
#if CC_USE_CULLING
    auto visitingCamera = Camera::getVisitingCamera();
    auto defaultCamera = Camera::getDefaultCamera();
    if (visitingCamera == defaultCamera) {
        _insideBounds = (transformUpdated || visitingCamera->isViewProjectionUpdated()) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
    }
    else
    {
        _insideBounds = renderer->checkVisibility(transform, _contentSize);
    }

    if (_insideBounds)
#endif
    {
        if (!_shadowEnabled && (_currentLabelType == LabelType::BMFONT || _currentLabelType == LabelType::CHARMAP))
        {
            for (auto&& it : _letters)
            {
                it.second->updateTransform();
            }
            auto textureAtlas = _batchNodes.at(0)->getTextureAtlas();
            _quadCommand.init(_globalZOrder, textureAtlas->getTexture()->getName(), getGLProgramState(), 
                _blendFunc, textureAtlas->getQuads(), textureAtlas->getTotalQuads(), transform, flags);
            renderer->addCommand(&_quadCommand);
        }
        else
        {
            _customCommand.init(_globalZOrder, transform, flags);
            _customCommand.func = CC_CALLBACK_0(Label::onDraw, this, transform, transformUpdated);

            renderer->addCommand(&_customCommand);
        }
    }
}
Пример #3
0
void Sprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
#if CC_USE_CULLING
    // Don't do calculate the culling if the transform was not updated
    auto visitingCamera = Camera::getVisitingCamera();
    auto defaultCamera = Camera::getDefaultCamera();
    if (visitingCamera == defaultCamera) {
        _insideBounds = ((flags & FLAGS_TRANSFORM_DIRTY)|| visitingCamera->isViewProjectionUpdated()) ? renderer->checkVisibility(transform, _contentSize) : _insideBounds;
    }
    else
    {
        _insideBounds = renderer->checkVisibility(transform, _contentSize);
    }

    if(_insideBounds)
#endif
    {
        _trianglesCommand.init(_globalZOrder, _texture->getName(), getGLProgramState(), _blendFunc, _polyInfo.triangles, transform, flags);
        renderer->addCommand(&_trianglesCommand);
    }
}