@animech-public/playcanvas
Version:
PlayCanvas WebGL game engine
2 lines (1 loc) • 2.53 kB
JavaScript
import{Color as e}from"../../core/math/color.js";class t{constructor(){this.clearValue=new e(0,0,0,1),this.clear=!1,this.store=!1,this.resolve=!0,this.mipmaps=!1}}class s{constructor(){this.clearDepthValue=1,this.clearStencilValue=0,this.clearDepth=!1,this.clearStencil=!1,this.storeDepth=!1,this.storeStencil=!1}}class i{get colorOps(){return this.colorArrayOps[0]}constructor(e){this._name=void 0,this.device=void 0,this._enabled=!0,this.executeEnabled=!0,this.renderTarget=void 0,this._options=void 0,this.samples=0,this.colorArrayOps=[],this.depthStencilOps=void 0,this.requiresCubemaps=!0,this.fullSizeClearRect=!0,this.beforePasses=[],this.afterPasses=[],this.device=e}set name(e){this._name=e}get name(){return this._name||(this._name=this.constructor.name),this._name}set options(e){var t,s;(this._options=e,e)&&(this._options.scaleX=null!=(t=this._options.scaleX)?t:1,this._options.scaleY=null!=(s=this._options.scaleY)?s:1)}get options(){return this._options}init(e=null,i=null){var r;this.options=i,this.renderTarget=e,this.samples=Math.max(this.renderTarget?this.renderTarget.samples:this.device.samples,1),this.depthStencilOps=new s;const o=e?null==(r=e._colorBuffers)?void 0:r.length:1;this.colorArrayOps.length=0;for(let e=0;e<o;e++){var l;const s=new t;this.colorArrayOps[e]=s,1===this.samples&&(s.store=!0,s.resolve=!1),null!=(l=this.renderTarget)&&null!=(l=l._colorBuffers)&&l[e].mipmaps&&(s.mipmaps=!0)}this.postInit()}destroy(){}postInit(){}frameUpdate(){if(this._options&&this.renderTarget){var e;const t=null!=(e=this._options.resizeSource)?e:this.device.backBuffer,s=Math.floor(t.width*this._options.scaleX),i=Math.floor(t.height*this._options.scaleY);this.renderTarget.resize(s,i)}}before(){}execute(){}after(){}onEnable(){}onDisable(){}set enabled(e){this._enabled!==e&&(this._enabled=e,e?this.onEnable():this.onDisable())}get enabled(){return this._enabled}setClearColor(e){const t=this.colorArrayOps.length;for(let s=0;s<t;s++){const t=this.colorArrayOps[s];e&&t.clearValue.copy(e),t.clear=!!e}}setClearDepth(e){e&&(this.depthStencilOps.clearDepthValue=e),this.depthStencilOps.clearDepth=void 0!==e}setClearStencil(e){e&&(this.depthStencilOps.clearStencilValue=e),this.depthStencilOps.clearStencil=void 0!==e}render(){if(this.enabled){const e=this.device,t=void 0!==this.renderTarget;this.before(),this.executeEnabled&&(t&&e.startRenderPass(this),this.execute(),t&&e.endRenderPass(this)),this.after(),e.renderPassIndex++}}}export{t as ColorAttachmentOps,s as DepthStencilAttachmentOps,i as RenderPass};