/* COPYRIGHT Esri - https://js.arcgis.com/5.0.18/LICENSE.txt */
import has from"../../core/has.js";import{glsl as e}from"../3d/webgl-engine/core/shaderModules/glsl.js";import{AppleAmdDriverHelper as r}from"./AppleAmdDriverHelper.js";import{BufferObject as t}from"./BufferObject.js";import{PrimitiveType as o,DataType as n,PixelType as i}from"./enums.js";import{FramebufferObject as s}from"./FramebufferObject.js";import{TextureDescriptor as a}from"./TextureDescriptor.js";import{WebGLDriverTestModule as p}from"./WebGLDriverTestModule.js";class l extends p{constructor(e){super(),this._rctx=e,this._helperProgram=null,has("mac")&&has("chrome")&&(this._program=this._prepareProgram(),this._helperProgram=this._prepareHelperProgram())}dispose(){super.dispose(),this._helperProgram?.dispose(),this._helperProgram=null}_test(e){const r=this._rctx,p=r.getBoundFramebufferObject(),{x:l,y:c,width:m,height:g}=r.getViewport();r.resetState();const f=new a(1);f.wrapMode=33071,f.samplingMode=9728;const d=new s(r,f),h=t.createIndex(this._rctx,35044,new Uint8Array([0]));r.bindFramebuffer(d),r.setViewport(0,0,1,1),r.useProgram(this._helperProgram),r.bindBuffer(h,34963),r.drawElements(o.POINTS,1,n.UNSIGNED_BYTE,0),r.useProgram(e),r.bindVAO(null),r.drawArrays(o.TRIANGLES,0,258);const u=new Uint8Array(4);return d.readPixels(0,0,1,1,6408,i.UNSIGNED_BYTE,u),r.setViewport(l,c,m,g),r.bindFramebuffer(p),d.dispose(),h.dispose(),255===u[0]}_prepareProgram(){const r=85,t=`#version 300 es\n    precision highp float;\n\n    out float triangleId;\n\n    const vec3 triangleVertices[3] = vec3[3](vec3(-0.5, -0.5, 0.0), vec3(0.5, -0.5, 0.0), vec3(0.0, 0.5, 0.0));\n\n    void main(void) {\n      triangleId = floor(float(gl_VertexID)/3.0);\n\n      vec3 position = triangleVertices[gl_VertexID % 3];\n      float offset = triangleId / ${e.float(r)};\n      position.z = 0.5 - offset;\n\n      gl_Position = vec4(position, 1.0);\n    }\n    `,o=`#version 300 es\n    precision highp float;\n\n    in float triangleId;\n\n    out vec4 fragColor;\n\n    void main(void) {\n      fragColor = triangleId == ${e.float(r)} ? vec4(0.0, 1.0, 0.0, 1.0) : vec4(1.0, 0.0, 0.0, 1.0);\n    }\n    `;return this._rctx.programCache.acquire(t,o,new Map([]))}_prepareHelperProgram(){const e=r.getShaderSources();return this._rctx.programCache.acquire(e.vertex,e.fragment,new Map([]))}}export{l as DrawArraysRequiresIndicesTypeReset};
