/*
All material copyright ESRI, All Rights Reserved, unless otherwise specified.
See https://js.arcgis.com/4.24/esri/copyright.txt for details.
*/
define(["../BufferObject","../enums","../RenderingContext","../Texture","../VertexArrayObject","../VertexElementDescriptor"],(function(t,e,i,r,s,a){"use strict";return function(){function o(t,e,r,s,a){this._vertexAttributeLocations=new Map([["position",0],["uv0",1]]),this._context=void 0,this._glslProgram=void 0,this._vertexAttributes=void 0,this._vertexArrayObject=void 0,this._texture=void 0,this._geometryData=void 0,this._initialized=!1,t||console.error("WebGL rendering context is not initialized!"),this._context=new i.RenderingContext(t,{}),this._posX=e,this._posY=r,this._dx=.05*Math.random()*s*(Math.random()<.5?-1:1),this._dy=.05*Math.random()*a*(Math.random()<.5?-1:1),this._canvasWidth=s,this._canvasHieght=a}var n=o.prototype;return n.draw=function(){if(!this._initialize())return;this._updatePos();const t=this._context;t.setBlendingEnabled(!0),t.setBlendFunction(e.BlendFactor.SRC_ALPHA,e.BlendFactor.ONE_MINUS_SRC_ALPHA),t.setClearColor(1,1,1,1),t.clear(t.gl.COLOR_BUFFER_BIT),t.bindVAO(this._vertexArrayObject),t.useProgram(this._glslProgram),t.bindTexture(this._texture,0),t.drawArrays(e.PrimitiveType.TRIANGLE_STRIP,0,4)},n._updatePos=function(){this._posX+=this._dx,this._posY+=this._dy,(this._posX<0||this._posX>this._canvasWidth)&&(this._dx=-this._dx),(this._posY<0||this._posY>this._canvasHieght)&&(this._dy=-this._dy);const t=this._vertexArrayObject.vertexBuffers.geometry;t&&(this._populateBuffer(256),t.setData(this._geometryData))},n._initialize=function(){if(this._initialized)return!0;const i="\n      precision highp float;\n\n      // geometry attributes\n      attribute vec2 pos;\n      attribute vec2 tex;\n\n      varying vec2 v_tex;\n\n      void main(void)\n      {\n        gl_Position = vec4(pos, 0.0, 1.0);\n        v_tex = tex;\n      }",o="\n      precision highp float;\n      uniform sampler2D u_texture;\n\n      varying vec2 v_tex;\n      void main(void)\n      {\n        vec4 color = texture2D(u_texture, v_tex);\n        gl_FragColor = color;\n      }";this._glslProgram=this._context.programCache.acquire(i,o,this._vertexAttributeLocations),this._vertexAttributes={geometry:[new a.VertexElementDescriptor("pos",2,e.DataType.FLOAT,0,16),new a.VertexElementDescriptor("tex",2,e.DataType.FLOAT,8,16)]};const n=document.createElement("canvas"),h=256;n.width=h,n.height=h;const _=n.getContext("2d");_.clearRect(0,0,0,0);const c=n.width/2,g=n.height/2,d=n.height/2-15;_.beginPath(),_.arc(c,g,d,0,2*Math.PI,!1),_.fillStyle="green",_.fill(),_.lineWidth=5,_.strokeStyle="#003300",_.stroke(),this._populateBuffer(256);const u=t.BufferObject.createVertex(this._context,e.Usage.DYNAMIC_DRAW,this._geometryData);return this._vertexArrayObject=new s.VertexArrayObject(this._context,this._vertexAttributeLocations,this._vertexAttributes,{geometry:u}),this._texture=new r.Texture(this._context,{target:e.TextureType.TEXTURE_2D,pixelFormat:e.PixelFormat.RGBA,dataType:e.PixelType.UNSIGNED_BYTE,flipped:!0},n),this._initialized=!0,!1},n._populateBuffer=function(t){const e=2*(this._posX/this._canvasWidth-.5),i=2*((this._canvasHieght-this._posY)/this._canvasHieght-.5),r=1*t/this._canvasWidth,s=1*t/this._canvasHieght;this._geometryData||(this._geometryData=new Float32Array(16)),this._geometryData[0]=e+r,this._geometryData[1]=i+s,this._geometryData[2]=1,this._geometryData[3]=1,this._geometryData[4]=e+r,this._geometryData[5]=i-s,this._geometryData[6]=1,this._geometryData[7]=0,this._geometryData[8]=e-r,this._geometryData[9]=i+s,this._geometryData[10]=0,this._geometryData[11]=1,this._geometryData[12]=e-r,this._geometryData[13]=i-s,this._geometryData[14]=0,this._geometryData[15]=0},o}()}));
