@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 30 kB
JavaScript
import{cA as e,C as t,w as r,y as i,aN as n,cD as a,cE as s,cB as _,cn as u,p as T,cF as l,cG as h}from"./index-BPURObVq.esm.min.js";import{R as E}from"./renderTargetWrapper-BsxrLXvO.esm.min.js";import{a as f}from"./sphericalPolynomial.pure-CsRKkAN3.esm.min.js";import"./textureLoaderManager-CGf6Ha4H.esm.min.js";let o=!1;o||(o=!0,e.prototype.setAlphaMode=function(e,r=!1,i=0){if(this._alphaMode[i]===e){if(!r){const r=e===t.ALPHA_DISABLE;this.depthCullingState.depthMask!==r&&(this.depthCullingState.depthMask=r)}return}const n=e===t.ALPHA_DISABLE;this._alphaState.setAlphaBlend(!n,i),this._alphaState.setAlphaMode(e,i),r||(this.depthCullingState.depthMask=n),this._alphaMode[i]=e});let d=!1;!function(){if(d)return;d=!0;const t=new WeakMap,r=new WeakMap,i=new WeakMap,n=new WeakMap;e.prototype.getAlphaToCoverage=function(){return t.get(this)??!1},e.prototype.setAlphaToCoverage=function(e){(t.get(this)!==e||this._gl&&r.get(this)!==this._gl)&&(t.set(this,e),this._gl&&(e?this._gl.enable(this._gl.SAMPLE_ALPHA_TO_COVERAGE):this._gl.disable(this._gl.SAMPLE_ALPHA_TO_COVERAGE),r.set(this,this._gl)))},Object.defineProperty(e.prototype,"currentSampleCount",{get:function(){return this._currentRenderTarget?this._currentRenderTarget.samples:this._gl?(n.get(this)!==this._gl&&(i.set(this,this._gl.getContextAttributes()?.antialias?Math.max(1,this._gl.getParameter(this._gl.SAMPLES)):1),n.set(this,this._gl)),i.get(this)):1},enumerable:!1,configurable:!0})}();let p=!1;!function(){function a(e,r,i,n){let a,s=1;n===t.TEXTURETYPE_FLOAT?a=new Float32Array(r*i*4):n===t.TEXTURETYPE_HALF_FLOAT?(a=new Uint16Array(r*i*4),s=15360):a=n===t.TEXTURETYPE_UNSIGNED_INTEGER?new Uint32Array(r*i*4):new Uint8Array(r*i*4);for(let t=0;t<r;t++)for(let n=0;n<i;n++){const i=3*(n*r+t),_=4*(n*r+t);a[_+0]=e[i+0],a[_+1]=e[i+1],a[_+2]=e[i+2],a[_+3]=s}return a}function s(e){return function(i,n,a,s,_,u,T,l,h=null,E=t.TEXTURETYPE_UNSIGNED_BYTE){const f=e?this._gl.TEXTURE_3D:this._gl.TEXTURE_2D_ARRAY,o=new r(this,e?10:11);o.baseWidth=n,o.baseHeight=a,o.baseDepth=s,o.width=n,o.height=a,o.depth=s,o.format=_,o.type=E,o.generateMipMaps=u,o.samplingMode=l,e?o.is3D=!0:o.is2DArray=!0,this._doNotHandleContextLost||(o._bufferView=i),e?this.updateRawTexture3D(o,i,_,T,h,E):this.updateRawTexture2DArray(o,i,_,T,h,E),this._bindTextureDirectly(f,o,!0);const d=this._getSamplingParameters(l,u);return this._gl.texParameteri(f,this._gl.TEXTURE_MAG_FILTER,d.mag),this._gl.texParameteri(f,this._gl.TEXTURE_MIN_FILTER,d.min),u&&this._gl.generateMipmap(f),this._bindTextureDirectly(f,null),this._internalTexturesCache.push(o),o}}function _(e){return function(r,i,n,a,s=null,_=t.TEXTURETYPE_UNSIGNED_BYTE){const u=e?this._gl.TEXTURE_3D:this._gl.TEXTURE_2D_ARRAY,T=this._getWebGLTextureType(_),l=this._getInternalFormat(n),h=this._getRGBABufferInternalSizedFormat(_,n);this._bindTextureDirectly(u,r,!0),this._unpackFlipY(void 0===a||!!a),this._doNotHandleContextLost||(r._bufferView=i,r.format=n,r.invertY=a,r._compression=s),r.width%4!=0&&this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT,1),s&&i?this._gl.compressedTexImage3D(u,0,this.getCaps().s3tc[s],r.width,r.height,r.depth,0,i):this._gl.texImage3D(u,0,h,r.width,r.height,r.depth,0,l,T,i),r.generateMipMaps&&this._gl.generateMipmap(u),this._bindTextureDirectly(u,null),r.isReady=!0}}p||(p=!0,e.prototype.updateRawTexture=function(e,r,i,n,a=null,s=t.TEXTURETYPE_UNSIGNED_BYTE,_=!1){if(!e)return;const u=this._getRGBABufferInternalSizedFormat(s,i,_),T=this._getInternalFormat(i),l=this._getWebGLTextureType(s);this._bindTextureDirectly(this._gl.TEXTURE_2D,e,!0),this._unpackFlipY(void 0===n||!!n),this._doNotHandleContextLost||(e._bufferView=r,e.format=i,e.type=s,e.invertY=n,e._compression=a),e.width%4!=0&&this._gl.pixelStorei(this._gl.UNPACK_ALIGNMENT,1),a&&r?this._gl.compressedTexImage2D(this._gl.TEXTURE_2D,0,this.getCaps().s3tc[a],e.width,e.height,0,r):this._gl.texImage2D(this._gl.TEXTURE_2D,0,u,e.width,e.height,0,T,l,r),e.generateMipMaps&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),e.isReady=!0},e.prototype.createRawTexture=function(e,i,n,a,s,_,u,T=null,l=t.TEXTURETYPE_UNSIGNED_BYTE,h=0,E=!1){const f=new r(this,3);f.baseWidth=i,f.baseHeight=n,f.width=i,f.height=n,f.format=a,f.generateMipMaps=s,f.samplingMode=u,f.invertY=_,f._compression=T,f.type=l,f._useSRGBBuffer=this._getUseSRGBBuffer(E,!s),this._doNotHandleContextLost||(f._bufferView=e),this.updateRawTexture(f,e,a,_,T,l,f._useSRGBBuffer),this._bindTextureDirectly(this._gl.TEXTURE_2D,f,!0);const o=this._getSamplingParameters(u,s);return this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MAG_FILTER,o.mag),this._gl.texParameteri(this._gl.TEXTURE_2D,this._gl.TEXTURE_MIN_FILTER,o.min),s&&this._gl.generateMipmap(this._gl.TEXTURE_2D),this._bindTextureDirectly(this._gl.TEXTURE_2D,null),this._internalTexturesCache.push(f),f},e.prototype.createRawCubeTexture=function(e,a,s,_,u,T,l,h=null){const E=this._gl,f=new r(this,8);f.isCube=!0,f.format=s,f.type=_,this._doNotHandleContextLost||(f._bufferViewArray=e);const o=this._getWebGLTextureType(_);let d=this._getInternalFormat(s);d===E.RGB&&(d=E.RGBA),o!==E.FLOAT||this._caps.textureFloatLinearFiltering?o!==this._gl.HALF_FLOAT_OES||this._caps.textureHalfFloatLinearFiltering?o!==E.FLOAT||this._caps.textureFloatRender?o!==E.HALF_FLOAT||this._caps.colorBufferFloat||(u=!1,i.Warn("Render to half float textures is not supported. Mipmap generation forced to false.")):(u=!1,i.Warn("Render to float textures is not supported. Mipmap generation forced to false.")):(u=!1,l=t.TEXTURE_NEAREST_SAMPLINGMODE,i.Warn("Half float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.")):(u=!1,l=t.TEXTURE_NEAREST_SAMPLINGMODE,i.Warn("Float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively."));const p=a,c=p;f.width=p,f.height=c,f.invertY=T,f._compression=h;if(!this.needPOTTextures||n(f.width)&&n(f.height)||(u=!1),e)this.updateRawCubeTexture(f,e,s,_,T,h);else{const e=this._getRGBABufferInternalSizedFormat(_),t=0;this._bindTextureDirectly(E.TEXTURE_CUBE_MAP,f,!0);for(let r=0;r<6;r++)h?E.compressedTexImage2D(E.TEXTURE_CUBE_MAP_POSITIVE_X+r,t,this.getCaps().s3tc[h],f.width,f.height,0,void 0):E.texImage2D(E.TEXTURE_CUBE_MAP_POSITIVE_X+r,t,e,f.width,f.height,0,d,o,null);this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null)}this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,f,!0),e&&u&&this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP);const R=this._getSamplingParameters(l,u);return E.texParameteri(E.TEXTURE_CUBE_MAP,E.TEXTURE_MAG_FILTER,R.mag),E.texParameteri(E.TEXTURE_CUBE_MAP,E.TEXTURE_MIN_FILTER,R.min),E.texParameteri(E.TEXTURE_CUBE_MAP,E.TEXTURE_WRAP_S,E.CLAMP_TO_EDGE),E.texParameteri(E.TEXTURE_CUBE_MAP,E.TEXTURE_WRAP_T,E.CLAMP_TO_EDGE),this._bindTextureDirectly(E.TEXTURE_CUBE_MAP,null),f.generateMipMaps=u,f.samplingMode=l,f.isReady=!0,f},e.prototype.updateRawCubeTexture=function(e,t,r,i,s,_=null,u=0){e._bufferViewArray=t,e.format=r,e.type=i,e.invertY=s,e._compression=_;const T=this._gl,l=this._getWebGLTextureType(i);let h=this._getInternalFormat(r);const E=this._getRGBABufferInternalSizedFormat(i);let f=!1;h===T.RGB&&(h=T.RGBA,f=!0),this._bindTextureDirectly(T.TEXTURE_CUBE_MAP,e,!0),this._unpackFlipY(void 0===s||!!s),e.width%4!=0&&T.pixelStorei(T.UNPACK_ALIGNMENT,1);for(let r=0;r<6;r++){let n=t[r];_?T.compressedTexImage2D(T.TEXTURE_CUBE_MAP_POSITIVE_X+r,u,this.getCaps().s3tc[_],e.width,e.height,0,n):(f&&(n=a(n,e.width,e.height,i)),T.texImage2D(T.TEXTURE_CUBE_MAP_POSITIVE_X+r,u,E,e.width,e.height,0,h,l,n))}(!this.needPOTTextures||n(e.width)&&n(e.height))&&e.generateMipMaps&&0===u&&this._gl.generateMipmap(this._gl.TEXTURE_CUBE_MAP),this._bindTextureDirectly(this._gl.TEXTURE_CUBE_MAP,null),e.isReady=!0},e.prototype.createRawCubeTextureFromUrl=function(e,r,i,n,s,_,u,T,l=null,h=null,E=t.TEXTURE_TRILINEAR_SAMPLINGMODE,f=!1){const o=this._gl,d=this.createRawCubeTexture(null,i,n,s,!_,f,E,null);r?.addPendingData(d),d.url=e,d.isReady=!1,this._internalTexturesCache.push(d);const p=(e,t)=>{r?.removePendingData(d),h&&h(e?e.status+" "+e.statusText:"Failed to parse texture data",t)},c=async e=>{if(!d._hardwareTexture)return;const t=u(e);if(!t)return;const i=t instanceof Promise?await t:t,_=d.width;if(T){const e=this._getWebGLTextureType(s);let t=this._getInternalFormat(n);const r=this._getRGBABufferInternalSizedFormat(s);let u=!1;t===o.RGB&&(t=o.RGBA,u=!0),this._bindTextureDirectly(o.TEXTURE_CUBE_MAP,d,!0),this._unpackFlipY(!1);const l=T(i);for(let i=0;i<l.length;i++){const n=_>>i;for(let _=0;_<6;_++){let T=l[i][_];u&&(T=a(T,n,n,s)),o.texImage2D(_,i,r,n,n,0,t,e,T)}}this._bindTextureDirectly(o.TEXTURE_CUBE_MAP,null)}else this.updateRawCubeTexture(d,i,n,s,f);d.isReady=!0,r?.removePendingData(d),d.onLoadedObservable.notifyObservers(d),d.onLoadedObservable.clear(),l&&l()};return this._loadFile(e,e=>{c(e).catch(e=>{p(void 0,e)})},void 0,r?.offlineProvider,!0,p),d},e.prototype.createRawTexture2DArray=s(!1),e.prototype.createRawTexture3D=s(!0),e.prototype.updateRawTexture2DArray=_(!1),e.prototype.updateRawTexture3D=_(!0))}();let c=!1;c||(c=!0,e.prototype._readTexturePixelsSync=function(e,t,r,i=-1,n=0,s=null,_=!0,u=!1,T=0,l=0){const h=this._gl;if(!h)throw new Error("Engine does not have gl rendering context.");if(!this._dummyFramebuffer){const e=h.createFramebuffer();if(!e)throw new Error("Unable to create dummy framebuffer");this._dummyFramebuffer=e}h.bindFramebuffer(h.FRAMEBUFFER,this._dummyFramebuffer),i>-1&&(e.is2DArray||e.is3D)?h.framebufferTextureLayer(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0,e._hardwareTexture?.underlyingResource,n,i):i>-1?h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0,h.TEXTURE_CUBE_MAP_POSITIVE_X+i,e._hardwareTexture?.underlyingResource,n):h.framebufferTexture2D(h.FRAMEBUFFER,h.COLOR_ATTACHMENT0,h.TEXTURE_2D,e._hardwareTexture?.underlyingResource,n);let E=void 0!==e.type?this._getWebGLTextureType(e.type):h.UNSIGNED_BYTE;return u?s||(s=a(e.type,4*t*r)):E===h.UNSIGNED_BYTE?(s||(s=new Uint8Array(4*t*r)),E=h.UNSIGNED_BYTE):(s||(s=new Float32Array(4*t*r)),E=h.FLOAT),_&&this.flushFramebuffer(),h.readPixels(T,l,t,r,h.RGBA,E,s),h.bindFramebuffer(h.FRAMEBUFFER,this._currentFramebuffer),s},e.prototype._readTexturePixels=function(e,t,r,i=-1,n=0,a=null,s=!0,_=!1,u=0,T=0){return Promise.resolve(this._readTexturePixelsSync(e,t,r,i,n,a,s,_,u,T))}),s();let R=!1;R||(R=!0,e.prototype._createDepthStencilCubeTexture=function(e,t){const n=new r(this,12);if(n.isCube=!0,1===this.webGLVersion)return i.Error("Depth cube texture is not supported by WebGL 1."),n;const a={bilinearFiltering:!1,comparisonFunction:0,generateStencil:!1,...t},s=this._gl;this._bindTextureDirectly(s.TEXTURE_CUBE_MAP,n,!0),this._setupDepthStencilTexture(n,e,a.bilinearFiltering,a.comparisonFunction);for(let t=0;t<6;t++)a.generateStencil?s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,s.DEPTH24_STENCIL8,e,e,0,s.DEPTH_STENCIL,s.UNSIGNED_INT_24_8,null):s.texImage2D(s.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,s.DEPTH_COMPONENT24,e,e,0,s.DEPTH_COMPONENT,s.UNSIGNED_INT,null);return this._bindTextureDirectly(s.TEXTURE_CUBE_MAP,null),this._internalTexturesCache.push(n),n},e.prototype._setCubeMapTextureParams=function(e,r,i){const n=this._gl;n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MIN_FILTER,r?n.LINEAR_MIPMAP_LINEAR:n.LINEAR),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),e.samplingMode=r?t.TEXTURE_TRILINEAR_SAMPLINGMODE:t.TEXTURE_LINEAR_LINEAR,r&&this.getCaps().textureMaxLevel&&void 0!==i&&i>0&&(n.texParameteri(n.TEXTURE_CUBE_MAP,n.TEXTURE_MAX_LEVEL,i),e._maxLodLevel=i),this._bindTextureDirectly(n.TEXTURE_CUBE_MAP,null)},e.prototype.createCubeTexture=function(e,t,r,n,a=null,s=null,u,T=null,l=!1,h=0,E=0,f=null,o,d=!1,p=null){const c=this._gl;return this.createCubeTextureBase(e,t,r,!!n,a,s,u,T,l,h,E,f,e=>this._bindTextureDirectly(c.TEXTURE_CUBE_MAP,e,!0),(e,t)=>{const r=this.needPOTTextures?_(t[0].width,this._caps.maxCubemapTextureSize):t[0].width,s=r,T=[c.TEXTURE_CUBE_MAP_POSITIVE_X,c.TEXTURE_CUBE_MAP_POSITIVE_Y,c.TEXTURE_CUBE_MAP_POSITIVE_Z,c.TEXTURE_CUBE_MAP_NEGATIVE_X,c.TEXTURE_CUBE_MAP_NEGATIVE_Y,c.TEXTURE_CUBE_MAP_NEGATIVE_Z];this._bindTextureDirectly(c.TEXTURE_CUBE_MAP,e,!0),this._unpackFlipY(!1);const l=u?this._getInternalFormat(u,e._useSRGBBuffer):e._useSRGBBuffer?this._glSRGBExtensionValues.SRGB8_ALPHA8:c.RGBA;let h=u?this._getInternalFormat(u):c.RGBA;e._useSRGBBuffer&&1===this.webGLVersion&&(h=l);for(let e=0;e<T.length;e++)if(t[e].width!==r||t[e].height!==s){if(this._prepareWorkingCanvas(),!this._workingCanvas||!this._workingContext)return void i.Warn("Cannot create canvas to resize texture.");this._workingCanvas.width=r,this._workingCanvas.height=s,this._workingContext.drawImage(t[e],0,0,t[e].width,t[e].height,0,0,r,s),c.texImage2D(T[e],0,l,h,c.UNSIGNED_BYTE,this._workingCanvas)}else c.texImage2D(T[e],0,l,h,c.UNSIGNED_BYTE,t[e]);n||c.generateMipmap(c.TEXTURE_CUBE_MAP),this._setCubeMapTextureParams(e,!n),e.width=r,e.height=s,e.isReady=!0,u&&(e.format=u),e.onLoadedObservable.notifyObservers(e),e.onLoadedObservable.clear(),a&&a()},!!d,p)},e.prototype.generateMipMapsForCubemap=function(e,t=!0){if(e.generateMipMaps){const r=this._gl;this._bindTextureDirectly(r.TEXTURE_CUBE_MAP,e,!0),r.generateMipmap(r.TEXTURE_CUBE_MAP),t&&this._bindTextureDirectly(r.TEXTURE_CUBE_MAP,null)}});class A extends E{setDepthStencilTexture(e,t=!0){if(super.setDepthStencilTexture(e,t),!e)return;const r=this._engine,i=this._context,n=e._hardwareTexture;if(n&&e._autoMSAAManagement&&this._MSAAFramebuffer){const t=r._currentFramebuffer;r._bindUnboundFramebuffer(this._MSAAFramebuffer),i.framebufferRenderbuffer(i.FRAMEBUFFER,u(e.format)?i.DEPTH_STENCIL_ATTACHMENT:i.DEPTH_ATTACHMENT,i.RENDERBUFFER,n.getMSAARenderBuffer()),r._bindUnboundFramebuffer(t)}}constructor(e,t,r,i,n){super(e,t,r,i),this._framebuffer=null,this._depthStencilBuffer=null,this._MSAAFramebuffer=null,this._colorTextureArray=null,this._depthStencilTextureArray=null,this._disposeOnlyFramebuffers=!1,this._currentLOD=0,this._context=n}_cloneRenderTargetWrapper(){let e;return this._colorTextureArray&&this._depthStencilTextureArray?(e=this._engine.createMultiviewRenderTargetTexture(this.width,this.height),e.texture.isReady=!0):e=super._cloneRenderTargetWrapper(),e}_swapRenderTargetWrapper(e){super._swapRenderTargetWrapper(e),e._framebuffer=this._framebuffer,e._depthStencilBuffer=this._depthStencilBuffer,e._MSAAFramebuffer=this._MSAAFramebuffer,e._colorTextureArray=this._colorTextureArray,e._depthStencilTextureArray=this._depthStencilTextureArray,this._framebuffer=this._depthStencilBuffer=this._MSAAFramebuffer=this._colorTextureArray=this._depthStencilTextureArray=null}createDepthStencilTexture(e=0,r=!0,i=!1,n=1,a=t.TEXTUREFORMAT_DEPTH32_FLOAT,s){if(this._depthStencilBuffer){const e=this._engine,t=e._currentFramebuffer,r=this._context;e._bindUnboundFramebuffer(this._framebuffer),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_STENCIL_ATTACHMENT,r.RENDERBUFFER,null),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.DEPTH_ATTACHMENT,r.RENDERBUFFER,null),r.framebufferRenderbuffer(r.FRAMEBUFFER,r.STENCIL_ATTACHMENT,r.RENDERBUFFER,null),e._bindUnboundFramebuffer(t),r.deleteRenderbuffer(this._depthStencilBuffer),this._depthStencilBuffer=null}return super.createDepthStencilTexture(e,r,i,n,a,s)}shareDepth(e){super.shareDepth(e);const t=this._context,r=this._depthStencilBuffer,i=e._MSAAFramebuffer||e._framebuffer,n=this._engine;e._depthStencilBuffer&&e._depthStencilBuffer!==r&&t.deleteRenderbuffer(e._depthStencilBuffer),e._depthStencilBuffer=r;const a=e._generateStencilBuffer?t.DEPTH_STENCIL_ATTACHMENT:t.DEPTH_ATTACHMENT;n._bindUnboundFramebuffer(i),t.framebufferRenderbuffer(t.FRAMEBUFFER,a,t.RENDERBUFFER,r),n._bindUnboundFramebuffer(null)}_bindTextureRenderTarget(e,t=0,r,i=0){const n=e._hardwareTexture;if(!n)return;const a=this._framebuffer,s=this._engine,_=s._currentFramebuffer;let u;if(s._bindUnboundFramebuffer(a),s.webGLVersion>1){const a=this._context;u=a["COLOR_ATTACHMENT"+t],e.is2DArray||e.is3D?(r=r??this.layerIndices?.[t]??0,a.framebufferTextureLayer(a.FRAMEBUFFER,u,n.underlyingResource,i,r)):e.isCube?(r=r??this.faceIndices?.[t]??0,a.framebufferTexture2D(a.FRAMEBUFFER,u,a.TEXTURE_CUBE_MAP_POSITIVE_X+r,n.underlyingResource,i)):a.framebufferTexture2D(a.FRAMEBUFFER,u,a.TEXTURE_2D,n.underlyingResource,i)}else{const e=this._context;u=e["COLOR_ATTACHMENT"+t+"_WEBGL"];const a=void 0!==r?e.TEXTURE_CUBE_MAP_POSITIVE_X+r:e.TEXTURE_2D;e.framebufferTexture2D(e.FRAMEBUFFER,u,a,n.underlyingResource,i)}if(e._autoMSAAManagement&&this._MSAAFramebuffer){const e=this._context;s._bindUnboundFramebuffer(this._MSAAFramebuffer),e.framebufferRenderbuffer(e.FRAMEBUFFER,u,e.RENDERBUFFER,n.getMSAARenderBuffer())}s._bindUnboundFramebuffer(_)}setTexture(e,t=0,r=!0){super.setTexture(e,t,r),this._bindTextureRenderTarget(e,t)}setLayerAndFaceIndices(e,t){if(super.setLayerAndFaceIndices(e,t),!this.textures||!this.layerIndices||!this.faceIndices)return;const r=this._attachments?.length??this.textures.length;for(let e=0;e<r;e++){const t=this.textures[e];t&&(t.is2DArray||t.is3D?this._bindTextureRenderTarget(t,e,this.layerIndices[e]):t.isCube?this._bindTextureRenderTarget(t,e,this.faceIndices[e]):this._bindTextureRenderTarget(t,e))}}setLayerAndFaceIndex(e=0,t,r){if(super.setLayerAndFaceIndex(e,t,r),!this.textures||!this.layerIndices||!this.faceIndices)return;const i=this.textures[e];i.is2DArray||i.is3D?this._bindTextureRenderTarget(this.textures[e],e,this.layerIndices[e]):i.isCube&&this._bindTextureRenderTarget(this.textures[e],e,this.faceIndices[e])}resolveMSAATextures(){const e=this._engine,t=e._currentFramebuffer;e._bindUnboundFramebuffer(this._MSAAFramebuffer),super.resolveMSAATextures(),e._bindUnboundFramebuffer(t)}dispose(e=this._disposeOnlyFramebuffers){const t=this._context;e||(this._colorTextureArray&&(this._context.deleteTexture(this._colorTextureArray),this._colorTextureArray=null),this._depthStencilTextureArray&&(this._context.deleteTexture(this._depthStencilTextureArray),this._depthStencilTextureArray=null)),this._framebuffer&&(t.deleteFramebuffer(this._framebuffer),this._framebuffer=null),this._depthStencilBuffer&&(t.deleteRenderbuffer(this._depthStencilBuffer),this._depthStencilBuffer=null),this._MSAAFramebuffer&&(t.deleteFramebuffer(this._MSAAFramebuffer),this._MSAAFramebuffer=null),super.dispose(e)}}let m=!1;m||(m=!0,e.prototype._createHardwareRenderTargetWrapper=function(e,t,r){const i=new A(e,t,r,this,this._gl);return this._renderTargetWrapperCache.push(i),i},e.prototype.createRenderTargetTexture=function(e,t){const r=this._createHardwareRenderTargetWrapper(!1,!1,e);let i,n,a=!0,s=!1,_=!1,u=1;void 0!==t&&"object"==typeof t&&(a=t.generateDepthBuffer??!0,s=!!t.generateStencilBuffer,_=!!t.noColorAttachment,i=t.colorAttachment,u=t.samples??1,n=t.label);const T=i||(_?null:this._createInternalTexture(e,t,!0,5)),l=e.width||e,h=e.height||e,E=this._currentFramebuffer,f=this._gl,o=f.createFramebuffer();if(this._bindUnboundFramebuffer(o),r._depthStencilBuffer=this._setupFramebufferDepthAttachments(s,a,l,h),!T||T.is2DArray||T.is3D||f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,f.TEXTURE_2D,T._hardwareTexture.underlyingResource,0),this._bindUnboundFramebuffer(E),r.label=n??"RenderTargetWrapper",r._framebuffer=o,r._generateDepthBuffer=a,r._generateStencilBuffer=s,r.setTextures(T),i){if(r._samples=i.samples,i.samples>1){const e=i._hardwareTexture.getMSAARenderBuffer(0);r._MSAAFramebuffer=f.createFramebuffer(),this._bindUnboundFramebuffer(r._MSAAFramebuffer),f.framebufferRenderbuffer(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,f.RENDERBUFFER,e),this._bindUnboundFramebuffer(null)}}else this.updateRenderTargetTextureSampleCount(r,u);return r},e.prototype._createDepthStencilTexture=function(e,n,a){const s=this._gl,_=e.layers||0,T=e.depth||0;let l=s.TEXTURE_2D;0!==_?l=s.TEXTURE_2D_ARRAY:0!==T&&(l=s.TEXTURE_3D);const h=new r(this,12);if(h.label=n.label,!this._caps.depthTextureExtension)return i.Error("Depth texture is not supported by your browser or hardware."),h;const E={bilinearFiltering:!1,comparisonFunction:0,generateStencil:!1,...n};if(this._bindTextureDirectly(l,h,!0),this._setupDepthStencilTexture(h,e,0!==E.comparisonFunction&&E.bilinearFiltering,E.comparisonFunction,E.samples),void 0!==E.depthTextureFormat){if(E.depthTextureFormat!==t.TEXTUREFORMAT_DEPTH16&&E.depthTextureFormat!==t.TEXTUREFORMAT_DEPTH24&&E.depthTextureFormat!==t.TEXTUREFORMAT_DEPTH24UNORM_STENCIL8&&E.depthTextureFormat!==t.TEXTUREFORMAT_DEPTH24_STENCIL8&&E.depthTextureFormat!==t.TEXTUREFORMAT_DEPTH32_FLOAT&&E.depthTextureFormat!==t.TEXTUREFORMAT_DEPTH32FLOAT_STENCIL8)return i.Error(`Depth texture ${E.depthTextureFormat} format is not supported.`),h;h.format=E.depthTextureFormat}else h.format=E.generateStencil?t.TEXTUREFORMAT_DEPTH24_STENCIL8:t.TEXTUREFORMAT_DEPTH24;const f=u(h.format),o=this._getWebGLTextureTypeFromDepthTextureFormat(h.format),d=f?s.DEPTH_STENCIL:s.DEPTH_COMPONENT,p=this._getInternalFormatFromDepthTextureFormat(h.format,!0,f);return h.is2DArray?s.texImage3D(l,0,p,h.width,h.height,_,0,d,o,null):h.is3D?s.texImage3D(l,0,p,h.width,h.height,T,0,d,o,null):s.texImage2D(l,0,p,h.width,h.height,0,d,o,null),this._bindTextureDirectly(l,null),this._internalTexturesCache.push(h),a._depthStencilBuffer&&(s.deleteRenderbuffer(a._depthStencilBuffer),a._depthStencilBuffer=null),this._bindUnboundFramebuffer(a._MSAAFramebuffer??a._framebuffer),a._generateStencilBuffer=f,a._depthStencilTextureWithStencil=f,a._depthStencilBuffer=this._setupFramebufferDepthAttachments(a._generateStencilBuffer,a._generateDepthBuffer,a.width,a.height,a.samples,h.format),this._bindUnboundFramebuffer(null),h},e.prototype.updateRenderTargetTextureSampleCount=function(e,t){if(this.webGLVersion<2||!e)return 1;if(e.samples===t)return t;const r=this._gl;t=Math.min(t,this.getCaps().maxMSAASamples),e._depthStencilBuffer&&(r.deleteRenderbuffer(e._depthStencilBuffer),e._depthStencilBuffer=null),e._MSAAFramebuffer&&(r.deleteFramebuffer(e._MSAAFramebuffer),e._MSAAFramebuffer=null);const i=e.texture?._hardwareTexture;if(i?.releaseMSAARenderBuffers(),e.texture&&t>1&&"function"==typeof r.renderbufferStorageMultisample){const n=r.createFramebuffer();if(!n)throw new Error("Unable to create multi sampled framebuffer");e._MSAAFramebuffer=n,this._bindUnboundFramebuffer(e._MSAAFramebuffer);const a=this._createRenderBuffer(e.texture.width,e.texture.height,t,-1,this._getRGBABufferInternalSizedFormat(e.texture.type,e.texture.format,e.texture._useSRGBBuffer),r.COLOR_ATTACHMENT0,!1);if(!a)throw new Error("Unable to create multi sampled framebuffer");i?.addMSAARenderBuffer(a)}this._bindUnboundFramebuffer(e._MSAAFramebuffer??e._framebuffer),e.texture&&(e.texture.samples=t),e._samples=t;const n=e._depthStencilTexture?e._depthStencilTexture.format:void 0;return e._depthStencilBuffer=this._setupFramebufferDepthAttachments(e._generateStencilBuffer,e._generateDepthBuffer,e.width,e.height,t,n),this._bindUnboundFramebuffer(null),t},e.prototype._setupDepthStencilTexture=function(e,r,i,n,a=1){const s=r.width??r,_=r.height??r,u=r.layers||0,T=r.depth||0;e.baseWidth=s,e.baseHeight=_,e.width=s,e.height=_,e.is2DArray=u>0,e.depth=u||T,e.isReady=!0,e.samples=a,e.generateMipMaps=!1,e.samplingMode=i?t.TEXTURE_BILINEAR_SAMPLINGMODE:t.TEXTURE_NEAREST_SAMPLINGMODE,e.type=t.TEXTURETYPE_UNSIGNED_BYTE,e._comparisonFunction=n;const l=this._gl,h=this._getTextureTarget(e),E=this._getSamplingParameters(e.samplingMode,!1);l.texParameteri(h,l.TEXTURE_MAG_FILTER,E.mag),l.texParameteri(h,l.TEXTURE_MIN_FILTER,E.min),l.texParameteri(h,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(h,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),this.webGLVersion>1&&(0===n?(l.texParameteri(h,l.TEXTURE_COMPARE_FUNC,t.LEQUAL),l.texParameteri(h,l.TEXTURE_COMPARE_MODE,l.NONE)):(l.texParameteri(h,l.TEXTURE_COMPARE_FUNC,n),l.texParameteri(h,l.TEXTURE_COMPARE_MODE,l.COMPARE_REF_TO_TEXTURE)))});let g=!1;g||(g=!0,e.prototype.setDepthStencilTexture=function(e,t,r,i){void 0!==e&&(t&&(this._boundUniforms[e]=t),r&&r.depthStencilTexture?this._setTexture(e,r,!1,!0,i):this._setTexture(e,null,void 0,void 0,i))});let U=!1;U||(U=!0,e.prototype.createRenderTargetCubeTexture=function(e,n){const a=this._createHardwareRenderTargetWrapper(!1,!0,e),s={generateMipMaps:!0,generateDepthBuffer:!0,generateStencilBuffer:!1,type:t.TEXTURETYPE_UNSIGNED_BYTE,samplingMode:t.TEXTURE_TRILINEAR_SAMPLINGMODE,format:t.TEXTUREFORMAT_RGBA,...n};s.generateStencilBuffer=s.generateDepthBuffer&&s.generateStencilBuffer,(s.type!==t.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering)&&(s.type!==t.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering)||(s.samplingMode=t.TEXTURE_NEAREST_SAMPLINGMODE);const _=this._gl,u=new r(this,5);this._bindTextureDirectly(_.TEXTURE_CUBE_MAP,u,!0);const T=this._getSamplingParameters(s.samplingMode,s.generateMipMaps);s.type!==t.TEXTURETYPE_FLOAT||this._caps.textureFloat||(s.type=t.TEXTURETYPE_UNSIGNED_BYTE,i.Warn("Float textures are not supported. Cube render target forced to TEXTURETYPE_UNESIGNED_BYTE type")),_.texParameteri(_.TEXTURE_CUBE_MAP,_.TEXTURE_MAG_FILTER,T.mag),_.texParameteri(_.TEXTURE_CUBE_MAP,_.TEXTURE_MIN_FILTER,T.min),_.texParameteri(_.TEXTURE_CUBE_MAP,_.TEXTURE_WRAP_S,_.CLAMP_TO_EDGE),_.texParameteri(_.TEXTURE_CUBE_MAP,_.TEXTURE_WRAP_T,_.CLAMP_TO_EDGE);for(let t=0;t<6;t++)_.texImage2D(_.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,this._getRGBABufferInternalSizedFormat(s.type,s.format),e,e,0,this._getInternalFormat(s.format),this._getWebGLTextureType(s.type),null);const l=_.createFramebuffer();return this._bindUnboundFramebuffer(l),a._depthStencilBuffer=this._setupFramebufferDepthAttachments(s.generateStencilBuffer,s.generateDepthBuffer,e,e),s.generateMipMaps&&_.generateMipmap(_.TEXTURE_CUBE_MAP),this._bindTextureDirectly(_.TEXTURE_CUBE_MAP,null),this._bindUnboundFramebuffer(null),a._framebuffer=l,a._generateDepthBuffer=s.generateDepthBuffer,a._generateStencilBuffer=s.generateStencilBuffer,u.width=e,u.height=e,u.isReady=!0,u.isCube=!0,u.samples=1,u.generateMipMaps=s.generateMipMaps,u.samplingMode=s.samplingMode,u.type=s.type,u.format=s.format,this._internalTexturesCache.push(u),a.setTextures(u),a});let b=!1;b||(b=!0,e.prototype.createPrefilteredCubeTexture=function(e,n,a,s,_=null,u=null,l,h=null,E=!0){return this.createCubeTexture(e,n,null,!1,async e=>{if(!e)return void(_&&_(null));const u=e.texture;if(E?e.info.sphericalPolynomial&&(u._sphericalPolynomial=e.info.sphericalPolynomial):u._sphericalPolynomial=u._sphericalPolynomial??new f,u._source=9,this.getCaps().textureLOD)return void(_&&_(u));const l=this._gl,h=e.width;if(!h)return;const{DDSTools:o}=await import("./dds-DrEz0Z7d.esm.min.js"),d=[];for(let _=0;_<3;_++){const E=1-_/2,f=s,p=Math.log2(h)*a+s,c=f+(p-f)*E,R=Math.round(Math.min(Math.max(c,0),p)),A=new r(this,2);if(A.type=u.type,A.format=u.format,A.width=Math.pow(2,Math.max(Math.log2(h)-R,0)),A.height=A.width,A.isCube=!0,A._cachedWrapU=t.TEXTURE_CLAMP_ADDRESSMODE,A._cachedWrapV=t.TEXTURE_CLAMP_ADDRESSMODE,this._bindTextureDirectly(l.TEXTURE_CUBE_MAP,A,!0),A.samplingMode=t.TEXTURE_LINEAR_LINEAR,l.texParameteri(l.TEXTURE_CUBE_MAP,l.TEXTURE_MAG_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_CUBE_MAP,l.TEXTURE_MIN_FILTER,l.LINEAR),l.texParameteri(l.TEXTURE_CUBE_MAP,l.TEXTURE_WRAP_S,l.CLAMP_TO_EDGE),l.texParameteri(l.TEXTURE_CUBE_MAP,l.TEXTURE_WRAP_T,l.CLAMP_TO_EDGE),e.isDDS){const t=e.info,r=e.data;this._unpackFlipY(t.isCompressed),o.UploadDDSLevels(this,A,r,t,!0,6,R)}else i.Warn("DDS is the only prefiltered cube map supported so far.");this._bindTextureDirectly(l.TEXTURE_CUBE_MAP,null);const m=new T(n);m._isCube=!0,m._texture=A,A.isReady=!0,d.push(m)}u._lodTextureHigh=d[2],u._lodTextureMid=d[1],u._lodTextureLow=d[0],_&&_(u)},u,l,h,E,a,s)});let M=!1;M||(M=!0,e.prototype.createUniformBuffer=function(e,t){const r=this._gl.createBuffer();if(!r)throw new Error("Unable to create uniform buffer");const i=new l(r);return this.bindUniformBuffer(i),e instanceof Float32Array?this._gl.bufferData(this._gl.UNIFORM_BUFFER,e,this._gl.STATIC_DRAW):this._gl.bufferData(this._gl.UNIFORM_BUFFER,new Float32Array(e),this._gl.STATIC_DRAW),this.bindUniformBuffer(null),i.references=1,i},e.prototype.createDynamicUniformBuffer=function(e,t){const r=this._gl.createBuffer();if(!r)throw new Error("Unable to create dynamic uniform buffer");const i=new l(r);return this.bindUniformBuffer(i),e instanceof Float32Array?this._gl.bufferData(this._gl.UNIFORM_BUFFER,e,this._gl.DYNAMIC_DRAW):this._gl.bufferData(this._gl.UNIFORM_BUFFER,new Float32Array(e),this._gl.DYNAMIC_DRAW),this.bindUniformBuffer(null),i.references=1,i},e.prototype.updateUniformBuffer=function(e,t,r,i){this.bindUniformBuffer(e),void 0===r&&(r=0),void 0===i?t instanceof Float32Array?this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,r,t):this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,r,new Float32Array(t)):t instanceof Float32Array?this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,0,t.subarray(r,r+i)):this._gl.bufferSubData(this._gl.UNIFORM_BUFFER,0,new Float32Array(t).subarray(r,r+i)),this.bindUniformBuffer(null)},e.prototype.bindUniformBuffer=function(e){this._gl.bindBuffer(this._gl.UNIFORM_BUFFER,e?e.underlyingResource:null)},e.prototype.bindUniformBufferBase=function(e,t,r){this._gl.bindBufferBase(this._gl.UNIFORM_BUFFER,t,e?e.underlyingResource:null)},e.prototype.bindUniformBlock=function(e,t,r){const i=e.program,n=this._gl.getUniformBlockIndex(i,t);4294967295!==n&&this._gl.uniformBlockBinding(i,n,r)});let F=!1;F||(F=!0,e.prototype.enableScissor=function(e,t,r,i){const n=this._gl;n.enable(n.SCISSOR_TEST),n.scissor(e,t,r,i)},e.prototype.disableScissor=function(){const e=this._gl;e.disable(e.SCISSOR_TEST)});export{h as Engine};
//# sourceMappingURL=engine-DI6BzGxb.esm.min.js.map