@doegis/core
Version:
DOE GIS API
3 lines (1 loc) • 2.86 kB
JavaScript
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 s,PixelType as a,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 u}from"./Texture.js";import{VertexArrayObject as g}from"./VertexArrayObject.js";import{VertexElementDescriptor as f}from"./VertexElementDescriptor.js";import{WebGLDriverTestModule as _}from"./WebGLDriverTestModule.js";class h extends _{constructor(e){super(),this._rctx=e;const r="\n precision highp float;\n attribute vec2 a_pos;\n uniform highp sampler2D u_texture;\n varying vec4 v_color;\n\n float 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\n void 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="\n precision highp float;\n varying vec4 v_color;\n\n void main() {\n gl_FragColor = v_color;\n }\n ";this._program=e.programCache.acquire(r,t,new Map([["a_pos",0]]))}_test(_){const h=this._rctx,w=new l(h,{colorTarget:t.TEXTURE,depthStencilTarget:o.NONE},{target:i.TEXTURE_2D,wrapMode:n.CLAMP_TO_EDGE,pixelFormat:s.RGBA,dataType:a.UNSIGNED_BYTE,samplingMode:p.NEAREST,width:1,height:1}),T=new Uint8Array(4),b=r.createVertex(h,m.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),v=new g(h,new Map([["a_position",0]]),{geometry:[new f("a_position",2,c.SHORT,0,4)]},{geometry:b});h.useProgram(_);const E=new u(h,{target:i.TEXTURE_2D,wrapMode:n.CLAMP_TO_EDGE,pixelFormat:s.RGBA,dataType:a.UNSIGNED_BYTE,samplingMode:p.NEAREST,width:1,height:1},new Uint8Array([2,255,0,0]));_.setUniform1i("u_texture",0),h.bindTexture(E,0);const x=h.getBoundFramebufferObject();h.bindFramebuffer(w),h.useProgram(_);const{x:A,y,width:j,height:D}=h.getViewport();h.setViewport(0,0,1,1),h.bindVAO(v),h.drawArrays(d.TRIANGLE_STRIP,0,4),h.setViewport(A,y,j,D),w.readPixels(0,0,1,1,s.RGBA,a.UNSIGNED_BYTE,T),v.dispose(!1),b.dispose(),w.dispose();const R=255!==T[0]||255!==T[1]||255!==T[2]||255!==T[3];return R&&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. [${T[0]}.${T[1]}.${T[2]}.${T[3]}]`),h.bindFramebuffer(x),R}}export{h as IgnoresSamplerPrecision};