var gdjs;(function(d){class m{constructor(t,e){this._profilerText=null;this._showCursorAtNextRender=!1;this._threeRenderer=null;this._layerRenderingMetrics={rendered2DLayersCount:0,rendered3DLayersCount:0};this._backgroundColor=null;this._runtimeGameRenderer=e,this._runtimeScene=t,this._pixiContainer=new PIXI.Container,this._pixiContainer.sortableChildren=!0,this._threeRenderer=this._runtimeGameRenderer?this._runtimeGameRenderer.getThreeRenderer():null}onGameResolutionResized(){const t=this._runtimeGameRenderer?this._runtimeGameRenderer.getPIXIRenderer():null;if(!t)return;const e=this._runtimeScene.getGame();this._pixiContainer.scale.x=t.width/e.getGameResolutionWidth(),this._pixiContainer.scale.y=t.height/e.getGameResolutionHeight();for(const r of this._runtimeScene._orderedLayers)r.getRenderer().onGameResolutionResized()}onSceneUnloaded(){}render(){const t=this._runtimeGameRenderer;if(!t)return;const e=t.getPIXIRenderer();if(!e)return;const r=this._threeRenderer;if(!(r&&r.xr.isPresenting)){if(this._layerRenderingMetrics.rendered2DLayersCount=0,this._layerRenderingMetrics.rendered3DLayersCount=0,r){r.info.autoReset=!1,r.info.reset();let n=!0,s=!0;r.resetState();for(let l=0;l<this._runtimeScene._orderedLayers.length;++l){const o=this._runtimeScene._orderedLayers[l];if(!o.isVisible())continue;const i=o.getRenderer(),c=o.getRenderingType();if(this._runtimeScene.getGame().isInGameEdition()||c!==d.RuntimeLayerRenderingType.TWO_D&&i.has3DObjects()){const a=i.getThreeScene(),h=i.getThreeCamera(),R=i.getThreeEffectComposer();if(a&&h&&R){if(c===d.RuntimeLayerRenderingType.TWO_D_PLUS_THREE_D){const g=i.has2DObjects();g&&(s&&(r.resetState(),e.reset()),i.renderOnPixiRenderTexture(e),i.updateThreePlaneTextureFromPixiRenderTexture(r,e),this._layerRenderingMetrics.rendered2DLayersCount++,s=!1),i.show2DRenderingPlane(g)}s||(e.reset(),r.resetState()),n?(r.setClearColor(this._runtimeScene.getBackgroundColor()),r.resetState(),this._runtimeScene.getClearCanvas()&&r.clear(),this._backgroundColor||(this._backgroundColor=new THREE.Color),this._backgroundColor.set(this._runtimeScene.getBackgroundColor()),a.background||(a.background=this._backgroundColor),n=!1):a.background===this._backgroundColor&&(a.background=null),r.clearDepth(),i.hasPostProcessingPass()?R.render():r.render(a,h),this._layerRenderingMetrics.rendered3DLayersCount++,s=!0}}else{s&&(r.resetState(),e.reset()),n&&(e.background.color=this._runtimeScene.getBackgroundColor(),e.background.alpha=1,this._runtimeScene.getClearCanvas()&&e.clear(),n=!1),o.isLightingLayer()&&i.renderOnPixiRenderTexture(e);const a=o.isLightingLayer()&&i.getLightingSprite()||i.getRendererObject();e.render(a,{clear:!1}),this._layerRenderingMetrics.rendered2DLayersCount++,s=!1}}const u=this._runtimeScene.getDebuggerRenderer().getRendererObject();u&&(r.resetState(),e.reset(),e.render(u),s=!1),s||e.reset()}else{for(const n of this._runtimeScene._orderedLayers)n.isLightingLayer()&&n.getRenderer().renderOnPixiRenderTexture(e);e.background.color=this._runtimeScene.getBackgroundColor(),e.render(this._pixiContainer,{clear:this._runtimeScene.getClearCanvas()}),this._layerRenderingMetrics.rendered2DLayersCount++}if(this._showCursorAtNextRender){const n=t.getCanvas();n&&(n.style.cursor=""),this._showCursorAtNextRender=!1}}}renderForVR(){if(!this._runtimeGameRenderer)return;const e=this._threeRenderer;if(!e)throw new Error("Cannot render a scene with no 3D elements in VR!");let r=!0;for(let n=0;n<this._runtimeScene._orderedLayers.length;++n){const s=this._runtimeScene._orderedLayers[n];if(!s.isVisible())continue;const u=s.getRenderer();if(s.getRenderingType()===d.RuntimeLayerRenderingType.TWO_D||!u.has3DObjects())continue;const o=u.getThreeScene(),i=u.getThreeCamera();!o||!i||(r?(e.setClearColor(this._runtimeScene.getBackgroundColor()),this._runtimeScene.getClearCanvas()&&e.clear(),o.background=new THREE.Color(this._runtimeScene.getBackgroundColor()),r=!1):o.background=null,e.clearDepth(),e.render(o,i))}}_renderProfileText(){const t=this._runtimeScene.getProfiler();if(!t)return;this._profilerText||(this._profilerText=new PIXI.Text(" ",{align:"left",stroke:"#FFF",strokeThickness:1}),this._pixiContainer.addChild(this._profilerText));const e=t.getFramesAverageMeasures(),r=[];d.Profiler.getProfilerSectionTexts("All",e,r),this._profilerText.text=r.join(`
`)}hideCursor(){this._showCursorAtNextRender=!1;const t=this._runtimeGameRenderer?this._runtimeGameRenderer.getCanvas():null;t&&(t.style.cursor="none")}showCursor(){this._showCursorAtNextRender=!0}getPIXIContainer(){return this._pixiContainer}getRendererObject(){return this._pixiContainer}get3DRendererObject(){return null}getPIXIRenderer(){return this._runtimeGameRenderer?this._runtimeGameRenderer.getPIXIRenderer():null}setLayerIndex(t,e){const r=t.getRenderer();let n=r.getRendererObject();t.isLightingLayer()&&(n=r.getLightingSprite()),!!n&&this._pixiContainer.children.indexOf(n)!==e&&(this._pixiContainer.removeChild(n),this._pixiContainer.addChildAt(n,e))}}d.RuntimeScenePixiRenderer=m,d.RuntimeSceneRenderer=d.RuntimeScenePixiRenderer})(gdjs||(gdjs={}));
//# sourceMappingURL=runtimescene-pixi-renderer.js.map
