cocos2d-html5 icon indicating copy to clipboard operation
cocos2d-html5 copied to clipboard

Save render cache flag from renderer when using RenderTexture

Open 1scaR1 opened this issue 6 years ago • 0 comments

RenderTexture render cmd do not correctly save cache flag of render cmd's of renderer and as result some render command are placed in cache, not in _renderCmds array.

Test case for reproduce: Scene has for example a scroll view (it enables cache flag on visit with cc.renderer_turnToCacheMode) and sprites on background (zOrder < scroll.zOrder) Render texture is created and placed on ScrollView some time after (e.g. data for is loaded from network or clicking some button) adding scroll view to scene (must be passed one loop of cc.director). As a result scene doesn't render background sprites after using render texture (begin() - end() pair).

Test scene code (for js-test from cocos2d-x)

var RenderTextureWithScrollView = RenderTextureBaseLayer.extend({
    _scroll: null,

    ctor:function() {
        this._super();

        var backSprite = new cc.Sprite(s_back1);

        backSprite.x = winSize.width/2;
        backSprite.y = winSize.height/2;

        this.addChild(backSprite, 1);

        this._scroll = new ccui.ListView();
        this._scroll.setDirection(ccui.ScrollView.DIR_HORIZONTAL);
        this._scroll.setContentSize(winSize.width, winSize.height);
        this._scroll.setPosition(winSize.width/4, winSize.height/4);
        this._scroll.setBounceEnabled(true);

        this.addChild(this._scroll, 2);

        var callfunc = cc.callFunc(this._addRenderTextureNode, this);

        this.runAction(cc.sequence(cc.delayTime(0.1), callfunc));
    },

    _addRenderTextureNode: function()
    {
        var sprite = new cc.Sprite(s_grossini);

        // create a render texture
        var rend = new cc.RenderTexture( winSize.width/2, winSize.height/2 );

        sprite.x = winSize.width/2;
        sprite.y = 3*winSize.height/4;

        rend.begin();
        sprite.visit();
        rend.end();

        var texture = rend.getSprite().getTexture();
        var spr = new cc.Sprite(texture);
        spr.setScaleY(-1);
        spr.setAnchorPoint(0, 0);

        var layout = new ccui.Layout();
        layout.addChild(spr);
        layout.setContentSize(spr.getContentSize());

        this._scroll.pushBackCustomItem(layout);
    },

    title:function () {
        return "Render Texture and ScrollView";
    },

    subtitle:function () {
        return "Background and rendered sprites must be visible, not a black screen";
    }
});

1scaR1 avatar Sep 22 '18 16:09 1scaR1