12345 |
- /*
- All material copyright ESRI, All Rights Reserved, unless otherwise specified.
- See https://js.arcgis.com/4.25/esri/copyright.txt for details.
- */
- import{blendingAlpha as e}from"../3d/webgl-engine/lib/OrderIndependentTransparency.js";import{BufferObject as t}from"./BufferObject.js";import{ContextType as r}from"./context-util.js";import{TargetType as n,DepthStencilTargetType as o,TextureType as a,TextureWrapMode as i,PixelFormat as f,PixelType as u,SizedPixelFormat as l,TextureSamplingMode as c,Usage as s,DataType as d,PrimitiveType as g}from"./enums.js";import{FramebufferObject as b}from"./FramebufferObject.js";import{makePipelineState as E}from"./renderState.js";import{VertexArrayObject as p}from"./VertexArrayObject.js";import{VertexElementDescriptor as m}from"./VertexElementDescriptor.js";var T,_,F,x={exports:{}};function A(T){if(!T.gl)return!1;if(T.type===r.WEBGL1)return!(!T.capabilities.textureFloat?.textureFloat||!T.capabilities.colorBufferFloat?.textureFloat);if(!(T.capabilities.textureFloat?.textureFloat&&T.capabilities.colorBufferFloat?.textureFloat&&T.capabilities.colorBufferFloat?.floatBlend))return!1;const _=new b(T,{colorTarget:n.TEXTURE,depthStencilTarget:o.NONE},{target:a.TEXTURE_2D,wrapMode:i.CLAMP_TO_EDGE,pixelFormat:f.RGBA,dataType:u.FLOAT,internalFormat:l.RGBA32F,samplingMode:c.NEAREST,width:1,height:1}),F=t.createVertex(T,s.STATIC_DRAW,new Uint16Array([0,0,1,0,0,1,1,1])),A=new p(T,new Map([["a_pos",0]]),{geometry:[new m("a_pos",2,d.UNSIGNED_SHORT,0,4)]},{geometry:F}),R="\n precision highp float;\n attribute vec2 a_pos;\n\n void main() {\n gl_Position = vec4(a_pos * 2.0 - 1.0, 0.0, 1.0);\n }\n ",v="\n precision highp float;\n\n void main() {\n gl_FragColor = vec4(0.5, 0.5, 0.5, 0.5);\n }\n ",S=T.programCache.acquire(R,v,new Map([["a_pos",0]]));T.useProgram(S);const h=T.getBoundFramebufferObject(),{x:P,y:L,width:B,height:C}=T.getViewport();T.bindFramebuffer(_),T.setViewport(0,0,1,1),T.bindVAO(A),T.drawArrays(g.TRIANGLE_STRIP,0,4);const w=E({blending:e});T.setPipelineState(w),T.drawArrays(g.TRIANGLE_STRIP,0,4),x.exports.init(T);const O=T.gl.getError();return T.setViewport(P,L,B,C),T.bindFramebuffer(h),S.dispose(),A.dispose(!1),F.dispose(),_.dispose(),1282!==O||(console.warn("Device claims support for WebGL extension EXT_float_blend but does not support it. Using fall back."),!1)}T=x,_=function(){var e=function(e){window.console&&window.console.log&&window.console.log(e)},t=function(t){window.console&&window.console.error?window.console.error(t):e(t)},r={enable:{1:{0:!0}},disable:{1:{0:!0}},getParameter:{1:{0:!0}},drawArrays:{3:{0:!0}},drawElements:{4:{0:!0,2:!0}},createShader:{1:{0:!0}},getShaderParameter:{2:{1:!0}},getProgramParameter:{2:{1:!0}},getShaderPrecisionFormat:{2:{0:!0,1:!0}},getVertexAttrib:{2:{1:!0}},vertexAttribPointer:{6:{2:!0}},bindTexture:{2:{0:!0}},activeTexture:{1:{0:!0}},getTexParameter:{2:{0:!0,1:!0}},texParameterf:{3:{0:!0,1:!0}},texParameteri:{3:{0:!0,1:!0,2:!0}},texImage2D:{9:{0:!0,2:!0,6:!0,7:!0},6:{0:!0,2:!0,3:!0,4:!0}},texSubImage2D:{9:{0:!0,6:!0,7:!0},7:{0:!0,4:!0,5:!0}},copyTexImage2D:{8:{0:!0,2:!0}},copyTexSubImage2D:{8:{0:!0}},generateMipmap:{1:{0:!0}},compressedTexImage2D:{7:{0:!0,2:!0}},compressedTexSubImage2D:{8:{0:!0,6:!0}},bindBuffer:{2:{0:!0}},bufferData:{3:{0:!0,2:!0}},bufferSubData:{3:{0:!0}},getBufferParameter:{2:{0:!0,1:!0}},pixelStorei:{2:{0:!0,1:!0}},readPixels:{7:{4:!0,5:!0}},bindRenderbuffer:{2:{0:!0}},bindFramebuffer:{2:{0:!0}},checkFramebufferStatus:{1:{0:!0}},framebufferRenderbuffer:{4:{0:!0,1:!0,2:!0}},framebufferTexture2D:{5:{0:!0,1:!0,2:!0}},getFramebufferAttachmentParameter:{3:{0:!0,1:!0,2:!0}},getRenderbufferParameter:{2:{0:!0,1:!0}},renderbufferStorage:{4:{0:!0,1:!0}},clear:{1:{0:{enumBitwiseOr:["COLOR_BUFFER_BIT","DEPTH_BUFFER_BIT","STENCIL_BUFFER_BIT"]}}},depthFunc:{1:{0:!0}},blendFunc:{2:{0:!0,1:!0}},blendFuncSeparate:{4:{0:!0,1:!0,2:!0,3:!0}},blendEquation:{1:{0:!0}},blendEquationSeparate:{2:{0:!0,1:!0}},stencilFunc:{3:{0:!0}},stencilFuncSeparate:{4:{0:!0,1:!0}},stencilMaskSeparate:{2:{0:!0}},stencilOp:{3:{0:!0,1:!0,2:!0}},stencilOpSeparate:{4:{0:!0,1:!0,2:!0,3:!0}},cullFace:{1:{0:!0}},frontFace:{1:{0:!0}},drawArraysInstancedANGLE:{4:{0:!0}},drawElementsInstancedANGLE:{5:{0:!0,2:!0}},blendEquationEXT:{1:{0:!0}}},n=null,o=null;function a(e){if(null==n)for(var t in n={},o={},e)"number"==typeof e[t]&&(n[e[t]]=t,o[t]=e[t])}function i(){if(null==n)throw"WebGLDebugUtils.init(ctx) not called"}function f(e){return i(),void 0!==n[e]}function u(e){i();var t=n[e];return void 0!==t?"gl."+t:"/*UNKNOWN WebGL ENUM*/ 0x"+e.toString(16)}function l(e,t,n,a){var i;if(void 0!==(i=r[e])&&void 0!==(i=i[t])&&i[n]){if("object"==typeof i[n]&&void 0!==i[n].enumBitwiseOr){for(var f=i[n].enumBitwiseOr,l=0,c=[],s=0;s<f.length;++s){var d=o[f[s]];0!=(a&d)&&(l|=d,c.push(u(d)))}return l===a?c.join(" | "):u(a)}return u(a)}return null===a?"null":void 0===a?"undefined":a.toString()}function c(e,t){for(var r="",n=t.length,o=0;o<n;++o)r+=(0==o?"":", ")+l(e,n,o,t[o]);return r}function s(e,t,r){e.__defineGetter__(r,(function(){return t[r]})),e.__defineSetter__(r,(function(e){t[r]=e}))}function d(e,r,n,o){o=o||e,a(e),r=r||function(e,r,n){for(var o="",a=n.length,i=0;i<a;++i)o+=(0==i?"":", ")+l(r,a,i,n[i]);t("WebGL error "+u(e)+" in "+r+"("+o+")")};var i={};function f(e,t){return function(){n&&n(t,arguments);var a=e[t].apply(e,arguments),f=o.getError();return 0!=f&&(i[f]=!0,r(f,t,arguments)),a}}var c={};for(var g in e)if("function"==typeof e[g])if("getExtension"!=g)c[g]=f(e,g);else{var b=f(e,g);c[g]=function(){return d(b.apply(e,arguments),r,n,o)}}else s(c,e,g);return c.getError=function(){for(var t in i)if(i.hasOwnProperty(t)&&i[t])return i[t]=!1,t;return e.NO_ERROR},c}function g(e){var t=e.getParameter(e.MAX_VERTEX_ATTRIBS),r=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,r);for(var n=0;n<t;++n)e.disableVertexAttribArray(n),e.vertexAttribPointer(n,4,e.FLOAT,!1,0,0),e.vertexAttrib1f(n,0);e.deleteBuffer(r);var o=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(n=0;n<o;++n)e.activeTexture(e.TEXTURE0+n),e.bindTexture(e.TEXTURE_CUBE_MAP,null),e.bindTexture(e.TEXTURE_2D,null);for(e.activeTexture(e.TEXTURE0),e.useProgram(null),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.DITHER),e.disable(e.SCISSOR_TEST),e.blendColor(0,0,0,0),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.clearColor(0,0,0,0),e.clearDepth(1),e.clearStencil(-1),e.colorMask(!0,!0,!0,!0),e.cullFace(e.BACK),e.depthFunc(e.LESS),e.depthMask(!0),e.depthRange(0,1),e.frontFace(e.CCW),e.hint(e.GENERATE_MIPMAP_HINT,e.DONT_CARE),e.lineWidth(1),e.pixelStorei(e.PACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_ALIGNMENT,4),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),e.UNPACK_COLORSPACE_CONVERSION_WEBGL&&e.pixelStorei(e.UNPACK_COLORSPACE_CONVERSION_WEBGL,e.BROWSER_DEFAULT_WEBGL),e.polygonOffset(0,0),e.sampleCoverage(1,!1),e.scissor(0,0,e.canvas.width,e.canvas.height),e.stencilFunc(e.ALWAYS,0,4294967295),e.stencilMask(4294967295),e.stencilOp(e.KEEP,e.KEEP,e.KEEP),e.viewport(0,0,e.canvas.width,e.canvas.height),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT|e.STENCIL_BUFFER_BIT);e.getError(););}function b(e){var t,r,n=[],o=[],a={},i=1,f=!1,u=[],l=0,c=0,d=!1,b=0,E={};function p(e){return"function"==typeof e?e:function(t){e.handleEvent(t)}}e.getContext=(r=e.getContext,function(){var n=r.apply(e,arguments);if(n instanceof WebGLRenderingContext){if(n!=t){if(t)throw"got different context";a=S(t=n)}return a}return n});var m=function(e){n.push(p(e))},T=function(e){o.push(p(e))};function _(e){var t=e.addEventListener;e.addEventListener=function(r,n,o){switch(r){case"webglcontextlost":m(n);break;case"webglcontextrestored":T(n);break;default:t.apply(e,arguments)}}}function F(){for(var e=Object.keys(E),t=0;t<e.length;++t)delete E[e]}function x(){++c,f||l==c&&e.loseContext()}function A(e,t){var r=e[t];return function(){if(x(),!f)return r.apply(e,arguments)}}function R(){for(var e=0;e<u.length;++e){var r=u[e];r instanceof WebGLBuffer?t.deleteBuffer(r):r instanceof WebGLFramebuffer?t.deleteFramebuffer(r):r instanceof WebGLProgram?t.deleteProgram(r):r instanceof WebGLRenderbuffer?t.deleteRenderbuffer(r):r instanceof WebGLShader?t.deleteShader(r):r instanceof WebGLTexture&&t.deleteTexture(r)}}function v(e){return{statusMessage:e,preventDefault:function(){d=!0}}}return _(e),e.loseContext=function(){if(!f){for(f=!0,l=0,++i;t.getError(););F(),E[t.CONTEXT_LOST_WEBGL]=!0;var r=v("context lost"),o=n.slice();setTimeout((function(){for(var t=0;t<o.length;++t)o[t](r);b>=0&&setTimeout((function(){e.restoreContext()}),b)}),0)}},e.restoreContext=function(){f&&o.length&&setTimeout((function(){if(!d)throw"can not restore. webglcontestlost listener did not call event.preventDefault";R(),g(t),f=!1,c=0,d=!1;for(var e=o.slice(),r=v("context restored"),n=0;n<e.length;++n)e[n](r)}),0)},e.loseContextInNCalls=function(e){if(f)throw"You can not ask a lost contet to be lost";l=c+e},e.getNumCalls=function(){return c},e.setRestoreTimeout=function(e){b=e},e;function S(e){for(var r in e)"function"==typeof e[r]?a[r]=A(e,r):s(a,e,r);a.getError=function(){if(x(),!f)for(;e=t.getError();)E[e]=!0;for(var e in E)if(E[e])return delete E[e],e;return a.NO_ERROR};for(var n=["createBuffer","createFramebuffer","createProgram","createRenderbuffer","createShader","createTexture"],o=0;o<n.length;++o){var l=n[o];a[l]=function(t){return function(){if(x(),f)return null;var r=t.apply(e,arguments);return r.__webglDebugContextLostId__=i,u.push(r),r}}(e[l])}var c=["getActiveAttrib","getActiveUniform","getBufferParameter","getContextAttributes","getAttachedShaders","getFramebufferAttachmentParameter","getParameter","getProgramParameter","getProgramInfoLog","getRenderbufferParameter","getShaderParameter","getShaderInfoLog","getShaderSource","getTexParameter","getUniform","getUniformLocation","getVertexAttrib"];for(o=0;o<c.length;++o)l=c[o],a[l]=function(t){return function(){return x(),f?null:t.apply(e,arguments)}}(a[l]);var d=["isBuffer","isEnabled","isFramebuffer","isProgram","isRenderbuffer","isShader","isTexture"];for(o=0;o<d.length;++o)l=d[o],a[l]=function(t){return function(){return x(),!f&&t.apply(e,arguments)}}(a[l]);return a.checkFramebufferStatus=function(t){return function(){return x(),f?a.FRAMEBUFFER_UNSUPPORTED:t.apply(e,arguments)}}(a.checkFramebufferStatus),a.getAttribLocation=function(t){return function(){return x(),f?-1:t.apply(e,arguments)}}(a.getAttribLocation),a.getVertexAttribOffset=function(t){return function(){return x(),f?0:t.apply(e,arguments)}}(a.getVertexAttribOffset),a.isContextLost=function(){return f},a}}return{init:a,mightBeEnum:f,glEnumToString:u,glFunctionArgToString:l,glFunctionArgsToString:c,makeDebugContext:d,makeLostContextSimulatingCanvas:b,resetToInitialState:g}},void 0!==(F=_())&&(T.exports=F);export{A as testFloatBufferBlend};
|