UNPKG

@animech-public/playcanvas

Version:
2 lines (1 loc) 3.35 kB
import{PIXELFORMAT_DEPTH as e,PIXELFORMAT_DEPTHSTENCIL as t}from"./constants.js";import{GraphicsDevice as i}from"./graphics-device.js";let s=0;class r{constructor(r={}){var h,l,o,f,d,u;this.name=void 0,this._device=void 0,this._colorBuffer=void 0,this._colorBuffers=void 0,this._depthBuffer=void 0,this._depth=void 0,this._stencil=void 0,this._samples=void 0,this.autoResolve=void 0,this._face=void 0,this.flipY=void 0,this.id=s++;const n=arguments[1],c=arguments[2];if(r instanceof i?(this._colorBuffer=n,r=c):this._colorBuffer=r.colorBuffer,this._colorBuffer&&(this._colorBuffers=[this._colorBuffer]),this._depthBuffer=r.depthBuffer,this._face=null!=(h=r.face)?h:0,this._depthBuffer){const i=this._depthBuffer._format;i===e?(this._depth=!0,this._stencil=!1):i===t?(this._depth=!0,this._stencil=!0):(this._depth=!1,this._stencil=!1)}else{var _,a;this._depth=null==(_=r.depth)||_,this._stencil=null!=(a=r.stencil)&&a}r.colorBuffers&&(this._colorBuffers||(this._colorBuffers=[...r.colorBuffers],this._colorBuffer=r.colorBuffers[0]));const v=(null==(l=this._colorBuffer)?void 0:l.device)||(null==(o=this._depthBuffer)?void 0:o.device)||r.graphicsDevice;this._device=v;const{maxSamples:p}=this._device;var B,m;(this._samples=Math.min(null!=(f=r.samples)?f:1,p),v.isWebGPU&&(this._samples=this._samples>1?p:1),this.autoResolve=null==(d=r.autoResolve)||d,this.name=r.name,this.name)||(this.name=null==(B=this._colorBuffer)?void 0:B.name);this.name||(this.name=null==(m=this._depthBuffer)?void 0:m.name);this.name||(this.name="Untitled"),this.flipY=null!=(u=r.flipY)&&u,this.validateMrt(),this.impl=v.createRenderTargetImpl(this)}destroy(){const e=this._device;e&&(e.targets.delete(this),e.renderTarget===this&&e.setRenderTarget(null),this.destroyFrameBuffers())}destroyFrameBuffers(){const e=this._device;e&&this.impl.destroy(e)}destroyTextureBuffers(){var e,t;null==(e=this._depthBuffer)||e.destroy(),this._depthBuffer=null,null==(t=this._colorBuffers)||t.forEach((e=>{e.destroy()})),this._colorBuffers=null,this._colorBuffer=null}resize(e,t){if(this.width!==e||this.height!==t){var i,s;const r=this._device;this.destroyFrameBuffers(),r.renderTarget===this&&r.setRenderTarget(null),null==(i=this._depthBuffer)||i.resize(e,t),null==(s=this._colorBuffers)||s.forEach((i=>{i.resize(e,t)})),this.validateMrt(),this.impl=r.createRenderTargetImpl(this)}}validateMrt(){}init(){this.impl.init(this._device,this)}get initialized(){return this.impl.initialized}get device(){return this._device}loseContext(){this.impl.loseContext()}resolve(e=!0,t=!!this._depthBuffer){this._device&&this._samples>1&&this.impl.resolve(this._device,this,e,t)}copy(e,t,i){if(!this._device){if(!e._device)return!1;this._device=e._device}return this._device.copyRenderTarget(e,this,t,i)}get samples(){return this._samples}get depth(){return this._depth}get stencil(){return this._stencil}get colorBuffer(){return this._colorBuffer}getColorBuffer(e){var t;return null==(t=this._colorBuffers)?void 0:t[e]}get depthBuffer(){return this._depthBuffer}get face(){return this._face}get width(){var e,t;return(null==(e=this._colorBuffer)?void 0:e.width)||(null==(t=this._depthBuffer)?void 0:t.width)||this._device.width}get height(){var e,t;return(null==(e=this._colorBuffer)?void 0:e.height)||(null==(t=this._depthBuffer)?void 0:t.height)||this._device.height}}export{r as RenderTarget};