Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save render cache flag from renderer when using RenderTexture #3562

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

1scaR1
Copy link
Contributor

@1scaR1 1scaR1 commented Sep 22, 2018

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 1scaR1 changed the title Save cache render cache flag from renderer when using RenderTexture Save render cache flag from renderer when using RenderTexture Sep 22, 2018
1scaR1 added a commit to 1scaR1/cocos2d-x that referenced this pull request Sep 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant