/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
import e from"../../../../core/Error.js";import t from"../../../../core/Logger.js";import{watch as r}from"../../../../core/reactiveUtils.js";import{create as s}from"../../../../core/libs/gl-matrix-2/factories/mat3f32.js";import{DisplayObject as i}from"../DisplayObject.js";import o from"./Mesh2D.js";import{createScreenExtent as a}from"../../support/clippingUtils.js";import{VertexArrayObject as h}from"../../../webgl/VertexArrayObject.js";class c extends i{constructor(e,t){super(),this._clip=t,this._cache={},this.stage=e,this._handle=r(()=>t.version,()=>this._invalidate()),this.ready()}static fromClipArea(e,t){return new c(e,t)}_destroyGL(){null!=this._cache.mesh&&(this._cache.mesh.destroy(),this._cache.mesh=null),null!=this._cache.vao&&(this._cache.vao.dispose(),this._cache.vao=null)}destroy(){super.destroy(),this._destroyGL(),this._handle.remove()}getVAO(e,t,r){const[s,i]=t.size;if("geometry"!==this._clip.type&&this._lastWidth===s&&this._lastHeight===i||(this._lastWidth=s,this._lastHeight=i,this._destroyGL()),null==this._cache.vao){const s=this._createMesh(t,this._clip),i=s.getIndexBuffer(e),o=s.getVertexBuffers(e,r);this._cache.mesh=s,this._cache.vao=new h(e,o,i)}return this._cache.vao}_createTransforms(){return{displayViewScreenMat3:s()}}_invalidate(){this._destroyGL(),this.requestRender()}_createMesh(r,s){switch(s.type){case"rect":return o.fromScreenExtent(a(s,r.size[0],r.size[1]));case"path":return o.fromPath(s);case"geometry":return o.fromGeometry(r,s);default:return t.getLogger("esri.views.2d.engine.webgl.ClippingInfo").error(new e("mapview-bad-type","Unable to create ClippingInfo mesh from clip of type: ${clip.type}")),o.fromScreenExtent({xmin:0,ymin:0,xmax:1,ymax:1})}}}export{c as default};
