12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import e from"../../core/Logger.js";import{BufferObject as r}from"./BufferObject.js";import{TargetType as t,DepthStencilTargetType as o,TextureType as i,TextureWrapMode as n,PixelFormat as a,PixelType as s,TextureSamplingMode as p,Usage as m,DataType as c,PrimitiveType as d}from"./enums.js";import{FramebufferObject as l}from"./FramebufferObject.js";import{Texture as g}from"./Texture.js";import{VertexArrayObject as u}from"./VertexArrayObject.js";import{VertexElementDescriptor as f}from"./VertexElementDescriptor.js";function w(w){const h=new l(w,{colorTarget:t.TEXTURE,depthStencilTarget:o.NONE},{target:i.TEXTURE_2D,wrapMode:n.CLAMP_TO_EDGE,pixelFormat:a.RGBA,dataType:s.UNSIGNED_BYTE,samplingMode:p.NEAREST,width:1,height:1}),_="\nprecision highp float;\nattribute vec2 a_pos;\nuniform highp sampler2D u_texture;\nvarying vec4 v_color;\n\nfloat getBit(in float bitset, in int bitIndex) {\n float offset = pow(2.0, float(bitIndex));\n return mod(floor(bitset / offset), 2.0);\n}\n\nvoid main() {\n vec4 value = texture2D(u_texture, vec2(0.0));\n float bit = getBit(value.x * 255.0, 1);\n\n v_color = bit * vec4(1.0);\n gl_Position = vec4(a_pos * 2.0 - 1.0, 0.0, 1.0);\n}\n",T="\nprecision highp float;\nvarying vec4 v_color;\n\nvoid main() {\n gl_FragColor = v_color;\n}\n",b=new Uint8Array(4),v=r.createVertex(w,m.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),E=new u(w,new Map([["a_position",0]]),{geometry:[new f("a_position",2,c.SHORT,0,4)]},{geometry:v}),A=w.programCache.acquire(_,T,new Map([["a_pos",0]]));w.useProgram(A);const x=new g(w,{target:i.TEXTURE_2D,wrapMode:n.CLAMP_TO_EDGE,pixelFormat:a.RGBA,dataType:s.UNSIGNED_BYTE,samplingMode:p.NEAREST,width:1,height:1},new Uint8Array([2,255,0,0]));A.setUniform1i("u_texture",0),w.bindTexture(x,0);const y=w.getBoundFramebufferObject();w.bindFramebuffer(h),w.useProgram(A);const{x:R,y:j,width:D,height:N}=w.getViewport();w.setViewport(0,0,1,1),w.bindVAO(E),w.drawArrays(d.TRIANGLE_STRIP,0,4),w.setViewport(R,j,D,N),h.readPixels(0,0,1,1,a.RGBA,s.UNSIGNED_BYTE,b),A.dispose(),E.dispose(!1),v.dispose(),h.dispose();const B=255!==b[0]||255!==b[1]||255!==b[2]||255!==b[3];return B&&e.getLogger("esri.views.webgl.testSamplerPrecision").warn(`A problem was detected with your graphics driver. Your driver does not appear to honor sampler precision specifiers, which may result in rendering issues due to numerical instability. We recommend ensuring that your drivers have been updated to the latest version. Applying lowp sampler workaround. [${b[0]}.${b[1]}.${b[2]}.${b[3]}]`),w.bindFramebuffer(y),B}export{w as testSamplerPrecision};
|