[SOLVED] Possibility to pause rendering without removing render loops

Hi,

Was wondering if its possible to fully stop rendering loop if nothing is changing on the screen.
Checked code for the Engine and found this function, that stop rendering if focus is lost.

public _renderLoop(): void {
        if (!this._contextWasLost) {
            var shouldRender = true;
            if (!this.renderEvenInBackground && this._windowIsBackground) {
                shouldRender = false;
            }

            if (shouldRender) {
                // Start new frame
                this.beginFrame();

                for (var index = 0; index < this._activeRenderLoops.length; index++) {
                    var renderFunction = this._activeRenderLoops[index];

                    renderFunction();
                }

                // Present
                this.endFrame();
            }
        }

        if (this._activeRenderLoops.length > 0) {
           this._frameHandler = this._queueNewFrame(this._bindedRenderFunction, this.getHostWindow());
        } else {
            this._renderingQueueLaunched = false;
        }
    }

What about having possibility to manully stop it ? like this

public _renderLoop(): void {
        if (!this._contextWasLost) {
            var shouldRender = true;
            if (!this.renderEvenInBackground && this._windowIsBackground) {
                shouldRender = false;
            }

            if (shouldRender && !this.paused) {
                // Start new frame
                this.beginFrame();

                for (var index = 0; index < this._activeRenderLoops.length; index++) {
                    var renderFunction = this._activeRenderLoops[index];

                    renderFunction();
                }

                // Present
                this.endFrame();
            }
        }

        if (this._activeRenderLoops.length > 0) {
           this._frameHandler = this._queueNewFrame(this._bindedRenderFunction, this.getHostWindow());
        } else {
            this._renderingQueueLaunched = false;
        }
    }

Also should this part still be triggered even if render is blocked ?

 if (this._activeRenderLoops.length > 0) {
           this._frameHandler = this._queueNewFrame(this._bindedRenderFunction, this.getHostWindow());
        } else {
            this._renderingQueueLaunched = false;
        }

:slightly_smiling_face:

The best option is to just call stopRenderLoop and then call runRenderLoop when needed or other idea: inside your render loop, you can have a boolean to decide if you want to call scene.render

If you want to control it manually, you can use:

        engine.runRenderLoop(function () { 
                if(!scene.paused){
                    scene.render();
                }
        });

for you own render loop and set scene.paused when you want.

Or

scene.freezeActiveMeshes();

according to docs

BUT. I think you can’t control it in automatic way

And you have to know by youself that’s nothing changing in your core right now

Thank you for the input, I went for not calling scene.render() if game is pasued, as stopRenderLoop / runRenderLoop is heavy operation, if done too ofen