/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import{disposeMaybe as e}from"../../../../core/maybe.js";import{identity as t,translate as r,scale as s}from"../../../../core/libs/gl-matrix-2/math/mat3.js";import{create as a}from"../../../../core/libs/gl-matrix-2/factories/mat3f32.js";import{BufferObject as i}from"../../../webgl/BufferObject.js";import"../../../webgl/FramebufferObject.js";import"../../../webgl/Program.js";import"../../../../core/has.js";import"../../../webgl/Renderbuffer.js";import"../../../webgl/Texture.js";import{VertexArrayObject as o}from"../../../webgl/VertexArrayObject.js";import{DisplayObject as n}from"../../engine/DisplayObject.js";import{DataType as m,PrimitiveType as f}from"../../../webgl/enums.js";import{fromLayout as c}from"../../../webgl/VertexAttributeLocations.js";import{VertexBuffer as l}from"../../../webgl/VertexBuffer.js";import{VertexElementDescriptor as p}from"../../../webgl/VertexElementDescriptor.js";const h=[new p("a_PositionAndFlags",3,m.SHORT,0,6)],u={vsPath:"debug/overlay",fsPath:"debug/overlay",locations:c(h)};class g extends n{constructor(e){super(),this._conf=e}static makeFlags(e,t){return e|t<<2}_createTransforms(){return{displayViewScreenMat3:a()}}doRender(e){if(1!==e.drawPhase)return;this._updateTransforms(e),this._ensureResources(e);const{context:t}=e;t.useProgram(this._program),this._program.setUniformMatrix3fv("u_dvsMat3",this.transforms.displayViewScreenMat3),this._program.setUniform4fv("u_colors",this._conf.getColors(e)),this._program.setUniform1fv("u_opacities",this._conf.getOpacities(e));const{vertexData:r,indexData:s}=this._conf.getMesh(e);this._vertexBuffer.setData(r),this._indexBuffer.setData(s),t.bindVAO(this._vertexArray),t.setBlendingEnabled(!0),t.setBlendFunction(1,771),t.setDepthTestEnabled(!1),t.setStencilTestEnabled(!1),t.setColorMask(!0,!0,!0,!0),t.drawElements(f.TRIANGLES,s.length,m.UNSIGNED_INT,0)}onDetach(){this._vertexArray=e(this._vertexArray)}_updateTransforms(e){t(this.transforms.displayViewScreenMat3),r(this.transforms.displayViewScreenMat3,this.transforms.displayViewScreenMat3,[-1,1]),s(this.transforms.displayViewScreenMat3,this.transforms.displayViewScreenMat3,[2/e.state.size[0],-2/e.state.size[1],1])}_ensureResources(e){const{context:t}=e;this._program??=e.painter.materialManager.getProgram(u),this._vertexBuffer??=new l(t,h,null,35040),this._indexBuffer??=i.createIndex(t,35040),this._vertexArray??=new o(t,this._vertexBuffer,this._indexBuffer)}}export{g as default};
