UNPKG

gfx.js

Version:
2 lines 41.6 kB
var gfx=function(){"use strict";var e=9728;var t=9729;var i=9984;var r=9985;var n=9986;var s=9987;var a=5121;var l=5123;var _=5125;var o=5126;var f=33635;var c=32819;var u=32820;var p=36193;var h=6402;var T=6406;var d=6407;var E=6408;var F=6409;var m=6410;var R=33776;var x=33777;var v=33778;var A=33779;var S=35840;var b=35841;var B=35842;var P=35843;var g=36196;var U=[[e,i,n],[t,r,s]];var L=[{format:d,internalFormat:R,pixelType:null},{format:E,internalFormat:x,pixelType:null},{format:E,internalFormat:v,pixelType:null},{format:E,internalFormat:A,pixelType:null},{format:d,internalFormat:g,pixelType:null},{format:d,internalFormat:b,pixelType:null},{format:E,internalFormat:P,pixelType:null},{format:d,internalFormat:S,pixelType:null},{format:E,internalFormat:B,pixelType:null},{format:T,internalFormat:T,pixelType:a},{format:F,internalFormat:F,pixelType:a},{format:m,internalFormat:m,pixelType:a},{format:d,internalFormat:d,pixelType:f},{format:E,internalFormat:E,pixelType:u},{format:E,internalFormat:E,pixelType:c},{format:d,internalFormat:d,pixelType:a},{format:E,internalFormat:E,pixelType:a},{format:d,internalFormat:d,pixelType:p},{format:E,internalFormat:E,pixelType:p},{format:d,internalFormat:d,pixelType:o},{format:E,internalFormat:E,pixelType:o},{format:null,internalFormat:null,pixelType:null},{format:null,internalFormat:null,pixelType:null},{format:null,internalFormat:null,pixelType:null},{format:null,internalFormat:null,pixelType:null},{format:h,internalFormat:h,pixelType:l},{format:h,internalFormat:h,pixelType:_},{format:null,internalFormat:null,pixelType:null}];var I={USAGE_STATIC:35044,USAGE_DYNAMIC:35048,USAGE_STREAM:35040,INDEX_FMT_UINT8:5121,INDEX_FMT_UINT16:5123,INDEX_FMT_UINT32:5125,ATTR_POSITION:"a_position",ATTR_NORMAL:"a_normal",ATTR_TANGENT:"a_tangent",ATTR_BITANGENT:"a_bitangent",ATTR_WEIGHTS:"a_weights",ATTR_JOINTS:"a_joints",ATTR_COLOR:"a_color",ATTR_COLOR0:"a_color0",ATTR_COLOR1:"a_color1",ATTR_UV:"a_uv",ATTR_UV0:"a_uv0",ATTR_UV1:"a_uv1",ATTR_UV2:"a_uv2",ATTR_UV3:"a_uv3",ATTR_UV4:"a_uv4",ATTR_UV5:"a_uv5",ATTR_UV6:"a_uv6",ATTR_UV7:"a_uv7",ATTR_TYPE_INT8:5120,ATTR_TYPE_UINT8:5121,ATTR_TYPE_INT16:5122,ATTR_TYPE_UINT16:5123,ATTR_TYPE_INT32:5124,ATTR_TYPE_UINT32:5125,ATTR_TYPE_FLOAT32:5126,FILTER_NEAREST:0,FILTER_LINEAR:1,WRAP_REPEAT:10497,WRAP_CLAMP:33071,WRAP_MIRROR:33648,TEXTURE_FMT_RGB_DXT1:0,TEXTURE_FMT_RGBA_DXT1:1,TEXTURE_FMT_RGBA_DXT3:2,TEXTURE_FMT_RGBA_DXT5:3,TEXTURE_FMT_RGB_ETC1:4,TEXTURE_FMT_RGB_PVRTC_2BPPV1:5,TEXTURE_FMT_RGBA_PVRTC_2BPPV1:6,TEXTURE_FMT_RGB_PVRTC_4BPPV1:7,TEXTURE_FMT_RGBA_PVRTC_4BPPV1:8,TEXTURE_FMT_A8:9,TEXTURE_FMT_L8:10,TEXTURE_FMT_L8_A8:11,TEXTURE_FMT_R5_G6_B5:12,TEXTURE_FMT_R5_G5_B5_A1:13,TEXTURE_FMT_R4_G4_B4_A4:14,TEXTURE_FMT_RGB8:15,TEXTURE_FMT_RGBA8:16,TEXTURE_FMT_RGB16F:17,TEXTURE_FMT_RGBA16F:18,TEXTURE_FMT_RGB32F:19,TEXTURE_FMT_RGBA32F:20,TEXTURE_FMT_R32F:21,TEXTURE_FMT_111110F:22,TEXTURE_FMT_SRGB:23,TEXTURE_FMT_SRGBA:24,TEXTURE_FMT_D16:25,TEXTURE_FMT_D32:26,TEXTURE_FMT_D24S8:27,DS_FUNC_NEVER:512,DS_FUNC_LESS:513,DS_FUNC_EQUAL:514,DS_FUNC_LEQUAL:515,DS_FUNC_GREATER:516,DS_FUNC_NOTEQUAL:517,DS_FUNC_GEQUAL:518,DS_FUNC_ALWAYS:519,RB_FMT_RGBA4:32854,RB_FMT_RGB5_A1:32855,RB_FMT_RGB565:36194,RB_FMT_D16:33189,RB_FMT_S8:36168,RB_FMT_D24S8:34041,BLEND_FUNC_ADD:32774,BLEND_FUNC_SUBTRACT:32778,BLEND_FUNC_REVERSE_SUBTRACT:32779,BLEND_ZERO:0,BLEND_ONE:1,BLEND_SRC_COLOR:768,BLEND_ONE_MINUS_SRC_COLOR:769,BLEND_DST_COLOR:774,BLEND_ONE_MINUS_DST_COLOR:775,BLEND_SRC_ALPHA:770,BLEND_ONE_MINUS_SRC_ALPHA:771,BLEND_DST_ALPHA:772,BLEND_ONE_MINUS_DST_ALPHA:773,BLEND_CONSTANT_COLOR:32769,BLEND_ONE_MINUS_CONSTANT_COLOR:32770,BLEND_CONSTANT_ALPHA:32771,BLEND_ONE_MINUS_CONSTANT_ALPHA:32772,BLEND_SRC_ALPHA_SATURATE:776,STENCIL_OP_KEEP:7680,STENCIL_OP_ZERO:0,STENCIL_OP_REPLACE:7681,STENCIL_OP_INCR:7682,STENCIL_OP_INCR_WRAP:34055,STENCIL_OP_DECR:7683,STENCIL_OP_DECR_WRAP:34056,STENCIL_OP_INVERT:5386,CULL_NONE:0,CULL_FRONT:1028,CULL_BACK:1029,CULL_FRONT_AND_BACK:1032,PT_POINTS:0,PT_LINES:1,PT_LINE_LOOP:2,PT_LINE_STRIP:3,PT_TRIANGLES:4,PT_TRIANGLE_STRIP:5,PT_TRIANGLE_FAN:6};function M(e){if(e===I.ATTR_TYPE_INT8){return 1}else if(e===I.ATTR_TYPE_UINT8){return 1}else if(e===I.ATTR_TYPE_INT16){return 2}else if(e===I.ATTR_TYPE_UINT16){return 2}else if(e===I.ATTR_TYPE_INT32){return 4}else if(e===I.ATTR_TYPE_UINT32){return 4}else if(e===I.ATTR_TYPE_FLOAT32){return 4}console.warn("Unknown ATTR_TYPE: "+e);return 0}function N(e,t,i){if(i===void 0)i=-1;var r=U[t][i+1];if(r===undefined){console.warn("Unknown FILTER: "+t);return i===-1?e.LINEAR:e.LINEAR_MIPMAP_LINEAR}return r}function O(e){var t=L[e];if(t===undefined){console.warn("Unknown TEXTURE_FMT: "+e);return L[I.TEXTURE_FMT_RGBA8]}return t}var y=function e(t){var i=this;this._attr2el={};this._elements=[];this._bytes=0;var r=0;for(var n=0,s=t.length;n<s;++n){var a=t[n];var l={name:a.name,offset:r,stride:0,stream:-1,type:a.type,num:a.num,normalize:a.normalize===undefined?false:a.normalize,bytes:a.num*M(a.type)};i._attr2el[l.name]=l;i._elements.push(l);i._bytes+=l.bytes;r+=l.bytes}for(var _=0,o=this._elements.length;_<o;++_){var f=i._elements[_];f.stride=i._bytes}};y.prototype.element=function e(t){return this._attr2el[t]};var D=function e(t,i,r,n,s){this._device=t;this._format=i;this._usage=r;this._numIndices=s;this._bytesPerIndex=0;if(i===I.INDEX_FMT_UINT8){this._bytesPerIndex=1}else if(i===I.INDEX_FMT_UINT16){this._bytesPerIndex=2}else if(i===I.INDEX_FMT_UINT32){this._bytesPerIndex=4}this._bytes=this._bytesPerIndex*s;this._glID=t._gl.createBuffer();this.update(0,n);t._stats.ib+=this._bytes};var C={count:{configurable:true}};D.prototype.destroy=function e(){if(this._glID===-1){console.error("The buffer already destroyed");return}var t=this._device._gl;t.deleteBuffer(this._glID);this._device._stats.ib-=this.bytes;this._glID=-1};D.prototype.update=function e(t,i){if(this._glID===-1){console.error("The buffer is destroyed");return}if(i&&i.byteLength+t>this._bytes){console.error("Failed to update data, bytes exceed.");return}var r=this._device._gl;var n=this._usage;r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this._glID);if(!i){if(this._bytes){r.bufferData(r.ELEMENT_ARRAY_BUFFER,this._bytes,n)}else{console.warn("bufferData should not submit 0 bytes data")}}else{if(t){r.bufferSubData(r.ELEMENT_ARRAY_BUFFER,t,i)}else{r.bufferData(r.ELEMENT_ARRAY_BUFFER,i,n)}}this._device._restoreIndexBuffer()};C.count.get=function(){return this._numIndices};Object.defineProperties(D.prototype,C);var k=function e(t,i,r,n,s){this._device=t;this._format=i;this._usage=r;this._numVertices=s;this._bytes=this._format._bytes*s;this._glID=t._gl.createBuffer();this.update(0,n);t._stats.vb+=this._bytes};var X={count:{configurable:true}};k.prototype.destroy=function e(){if(this._glID===-1){console.error("The buffer already destroyed");return}var t=this._device._gl;t.deleteBuffer(this._glID);this._device._stats.vb-=this.bytes;this._glID=-1};k.prototype.update=function e(t,i){if(this._glID===-1){console.error("The buffer is destroyed");return}if(i&&i.byteLength+t>this._bytes){console.error("Failed to update data, bytes exceed.");return}var r=this._device._gl;var n=this._usage;r.bindBuffer(r.ARRAY_BUFFER,this._glID);if(!i){if(this._bytes){r.bufferData(r.ARRAY_BUFFER,this._bytes,n)}else{console.warn("bufferData should not submit 0 bytes data")}}else{if(t){r.bufferSubData(r.ARRAY_BUFFER,t,i)}else{r.bufferData(r.ARRAY_BUFFER,i,n)}}r.bindBuffer(r.ARRAY_BUFFER,null)};X.count.get=function(){return this._numVertices};Object.defineProperties(k.prototype,X);var w=0;function W(e,t,i){i.split("\n").forEach(function(i){if(i.length<5){return}var r=/^ERROR\:\s+(\d+)\:(\d+)\:\s*(.*)$/.exec(i);if(r){e.push({type:t,fileID:r[1]|0,line:r[2]|0,message:r[3].trim()})}else if(i.length>0){e.push({type:t,fileID:-1,line:0,message:i})}})}var G=function e(t,i){this._device=t;this._attributes=[];this._uniforms=[];this._samplers=[];this._errors=[];this._linked=false;this._vertSource=i.vert;this._fragSource=i.frag;this._glID=null;this._id=w++};var Y={id:{configurable:true}};Y.id.get=function(){return this._id};G.prototype.link=function e(){var t=this;if(this._linked){return}var i=this._device._gl;var r=V(i,i.VERTEX_SHADER,this._vertSource);var n=V(i,i.FRAGMENT_SHADER,this._fragSource);var s=i.createProgram();i.attachShader(s,r);i.attachShader(s,n);i.linkProgram(s);var a=false;var l=this._errors;if(!i.getShaderParameter(r,i.COMPILE_STATUS)){W(l,"vs",i.getShaderInfoLog(r));a=true}if(!i.getShaderParameter(n,i.COMPILE_STATUS)){W(l,"fs",i.getShaderInfoLog(n));a=true}i.deleteShader(r);i.deleteShader(n);if(a){l.forEach(function(e){console.error("Failed to compile "+e.type+" "+e.fileID+" (ln "+e.line+"): "+e.message)});return}if(!i.getProgramParameter(s,i.LINK_STATUS)){console.error("Failed to link shader program: "+i.getProgramInfoLog(s));a=true}if(a){return}this._glID=s;var _=i.getProgramParameter(s,i.ACTIVE_ATTRIBUTES);for(var o=0;o<_;++o){var f=i.getActiveAttrib(s,o);var c=i.getAttribLocation(s,f.name);t._attributes.push({name:f.name,location:c,type:f.type})}var u=i.getProgramParameter(s,i.ACTIVE_UNIFORMS);for(var p=0;p<u;++p){var h=i.getActiveUniform(s,p);var T=h.name;var d=i.getUniformLocation(s,T);var E=T.substr(T.length-3)==="[0]";if(E){T=T.substr(0,T.length-3)}t._uniforms.push({name:T,location:d,type:h.type,size:E?h.size:undefined})}this._linked=true};G.prototype.destroy=function e(){var t=this._device._gl;t.deleteProgram(this._glID);this._linked=false;this._glID=null;this._attributes=[];this._uniforms=[];this._samplers=[]};Object.defineProperties(G.prototype,Y);function V(e,t,i){var r=e.createShader(t);e.shaderSource(r,i);e.compileShader(r);return r}var Z=function e(t){this._device=t;this._width=4;this._height=4;this._hasMipmap=false;this._compressed=false;this._anisotropy=1;this._minFilter=I.FILTER_LINEAR;this._magFilter=I.FILTER_LINEAR;this._mipFilter=I.FILTER_LINEAR;this._wrapS=I.WRAP_REPEAT;this._wrapT=I.WRAP_REPEAT;this._format=I.TEXTURE_FMT_RGBA8;this._target=-1};Z.prototype.destroy=function e(){if(this._glID===-1){console.error("The texture already destroyed");return}var t=this._device._gl;t.deleteTexture(this._glID);this._device._stats.tex-=this.bytes;this._glID=-1};function H(e){return!(e&e-1)&&!!e}var K=function(e){function t(t,i){e.call(this,t);var r=this._device._gl;this._target=r.TEXTURE_2D;this._glID=r.createTexture();i.images=i.images||[null];this.update(i)}if(e)t.__proto__=e;t.prototype=Object.create(e&&e.prototype);t.prototype.constructor=t;t.prototype.update=function e(t){var i=this._device._gl;var r=this._hasMipmap;if(t){if(t.width!==undefined){this._width=t.width}if(t.height!==undefined){this._height=t.height}if(t.anisotropy!==undefined){this._anisotropy=t.anisotropy}if(t.minFilter!==undefined){this._minFilter=t.minFilter}if(t.magFilter!==undefined){this._magFilter=t.magFilter}if(t.mipFilter!==undefined){this._mipFilter=t.mipFilter}if(t.wrapS!==undefined){this._wrapS=t.wrapS}if(t.wrapT!==undefined){this._wrapT=t.wrapT}if(t.format!==undefined){this._format=t.format;this._compressed=this._format>=I.TEXTURE_FMT_RGB_DXT1&&this._format<=I.TEXTURE_FMT_RGBA_PVRTC_4BPPV1}if(t.mipmap!==undefined){this._hasMipmap=t.mipmap;r=t.mipmap}if(t.images!==undefined){if(t.images.length>1){r=false;var n=t.width>t.height?t.width:t.height;if(n>>t.images.length-1!==1){console.error("texture-2d mipmap is invalid, should have a 1x1 mipmap.")}}}}var s=H(this._width)&&H(this._height);if(!s){r=false}i.activeTexture(i.TEXTURE0);i.bindTexture(i.TEXTURE_2D,this._glID);if(t.images!==undefined&&t.images.length>0){this._setMipmap(t.images,t.flipY,t.premultiplyAlpha)}this._setTexInfo();if(r){i.hint(i.GENERATE_MIPMAP_HINT,i.NICEST);i.generateMipmap(i.TEXTURE_2D)}this._device._restoreTexture(0)};t.prototype.updateSubImage=function e(t){var i=this._device._gl;var r=O(this._format);i.activeTexture(i.TEXTURE0);i.bindTexture(i.TEXTURE_2D,this._glID);this._setSubImage(r,t);this._device._restoreTexture(0)};t.prototype.updateImage=function e(t){var i=this._device._gl;var r=O(this._format);i.activeTexture(i.TEXTURE0);i.bindTexture(i.TEXTURE_2D,this._glID);this._setImage(r,t);this._device._restoreTexture(0)};t.prototype._setSubImage=function e(t,i){var r=this._device._gl;var n=i.flipY;var s=i.premultiplyAlpha;var a=i.image;if(a instanceof HTMLCanvasElement||a instanceof HTMLImageElement||a instanceof HTMLVideoElement){if(n===undefined){r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,true)}else{r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,n)}if(s===undefined){r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,false)}else{r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)}r.texSubImage2D(r.TEXTURE_2D,i.level,i.x,i.y,t.format,t.pixelType,a)}else{if(n===undefined){r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,false)}else{r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,n)}if(s===undefined){r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,false)}else{r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)}if(this._compressed){r.compressedTexSubImage2D(r.TEXTURE_2D,i.level,i.x,i.y,i.width,i.height,t.format,a)}else{r.texSubImage2D(r.TEXTURE_2D,i.level,i.x,i.y,i.width,i.height,t.format,t.pixelType,a)}}};t.prototype._setImage=function e(t,i){var r=this._device._gl;var n=i.flipY;var s=i.premultiplyAlpha;var a=i.image;if(a instanceof HTMLCanvasElement||a instanceof HTMLImageElement||a instanceof HTMLVideoElement){if(n===undefined){r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,true)}else{r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,n)}if(s===undefined){r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,false)}else{r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)}r.texImage2D(r.TEXTURE_2D,i.level,t.internalFormat,t.format,t.pixelType,a)}else{if(n===undefined){r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,false)}else{r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,n)}if(s===undefined){r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,false)}else{r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)}if(this._compressed){r.compressedTexImage2D(r.TEXTURE_2D,i.level,t.internalFormat,i.width,i.height,0,a)}else{r.texImage2D(r.TEXTURE_2D,i.level,t.internalFormat,i.width,i.height,0,t.format,t.pixelType,a)}}};t.prototype._setMipmap=function e(t,i,r){var n=this;var s=O(this._format);var a={width:this._width,height:this._height,flipY:i,premultiplyAlpha:r,level:0,image:null};for(var l=0;l<t.length;++l){a.level=l;a.width=n._width>>l;a.height=n._height>>l;a.image=t[l];n._setImage(s,a)}};t.prototype._setTexInfo=function e(){var t=this._device._gl;var i=H(this._width)&&H(this._height);if(!i&&(this._wrapS!==I.WRAP_CLAMP||this._wrapT!==I.WRAP_CLAMP)){console.warn("WebGL1 doesn't support all wrap modes with NPOT textures");this._wrapS=I.WRAP_CLAMP;this._wrapT=I.WRAP_CLAMP}var r=this._hasMipmap?this._mipFilter:-1;if(!i&&r!==-1){console.warn("NPOT textures do not support mipmap filter");r=-1}t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,N(t,this._minFilter,r));t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,N(t,this._magFilter,-1));t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,this._wrapS);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,this._wrapT);var n=this._device.ext("EXT_texture_filter_anisotropic");if(n){t.texParameteri(t.TEXTURE_2D,n.TEXTURE_MAX_ANISOTROPY_EXT,this._anisotropy)}};return t}(Z);var q=function(e){function t(t,i){e.call(this,t);var r=this._device._gl;this._target=r.TEXTURE_CUBE_MAP;this._glID=r.createTexture();this.update(i)}if(e)t.__proto__=e;t.prototype=Object.create(e&&e.prototype);t.prototype.constructor=t;t.prototype.update=function e(t){var i=this._device._gl;var r=this._hasMipmap;if(t){if(t.width!==undefined){this._width=t.width}if(t.height!==undefined){this._height=t.height}if(t.anisotropy!==undefined){this._anisotropy=t.anisotropy}if(t.minFilter!==undefined){this._minFilter=t.minFilter}if(t.magFilter!==undefined){this._magFilter=t.magFilter}if(t.mipFilter!==undefined){this._mipFilter=t.mipFilter}if(t.wrapS!==undefined){this._wrapS=t.wrapS}if(t.wrapT!==undefined){this._wrapT=t.wrapT}if(t.format!==undefined){this._format=t.format;this._compressed=this._format>=I.TEXTURE_FMT_RGB_DXT1&&this._format<=I.TEXTURE_FMT_RGBA_PVRTC_4BPPV1}if(t.mipmap!==undefined){this._hasMipmap=t.mipmap;r=t.mipmap}if(t.images!==undefined){if(t.images.length>1){r=false;if(t.width!==t.height){console.warn("texture-cube width and height should be identical.")}if(t.width>>t.images.length-1!==1){console.error("texture-cube mipmap is invalid. please set mipmap as 1x1, 2x2, 4x4 ... nxn")}}}}var n=H(this._width)&&H(this._height);if(!n){r=false}i.activeTexture(i.TEXTURE0);i.bindTexture(i.TEXTURE_CUBE_MAP,this._glID);if(t.images!==undefined&&t.images.length>0){this._setMipmap(t.images,t.flipY,t.premultiplyAlpha)}this._setTexInfo();if(r){i.hint(i.GENERATE_MIPMAP_HINT,i.NICEST);i.generateMipmap(i.TEXTURE_CUBE_MAP)}this._device._restoreTexture(0)};t.prototype.updateSubImage=function e(t){var i=this._device._gl;var r=O(this._format);i.activeTexture(i.TEXTURE0);i.bindTexture(i.TEXTURE_CUBE_MAP,this._glID);this._setSubImage(r,t);this._device._restoreTexture(0)};t.prototype.updateImage=function e(t){var i=this._device._gl;var r=O(this._format);i.activeTexture(i.TEXTURE0);i.bindTexture(i.TEXTURE_CUBE_MAP,this._glID);this._setImage(r,t);this._device._restoreTexture(0)};t.prototype._setSubImage=function e(t,i){var r=this._device._gl;var n=i.flipY;var s=i.premultiplyAlpha;var a=i.faceIndex;var l=i.image;if(n===undefined){r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,false)}else{r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,n)}if(s===undefined){r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,false)}else{r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)}if(l instanceof HTMLCanvasElement||l instanceof HTMLImageElement||l instanceof HTMLVideoElement){r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+a,i.level,i.x,i.y,t.format,t.pixelType,l)}else{if(this._compressed){r.compressedTexSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+a,i.level,i.x,i.y,i.width,i.height,t.format,l)}else{r.texSubImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+a,i.level,i.x,i.y,i.width,i.height,t.format,t.pixelType,l)}}};t.prototype._setImage=function e(t,i){var r=this._device._gl;var n=i.flipY;var s=i.premultiplyAlpha;var a=i.faceIndex;var l=i.image;if(n===undefined){r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,false)}else{r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,n)}if(s===undefined){r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,false)}else{r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,s)}if(l instanceof HTMLCanvasElement||l instanceof HTMLImageElement||l instanceof HTMLVideoElement){r.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+a,i.level,t.internalFormat,t.format,t.pixelType,l)}else{if(this._compressed){r.compressedTexImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+a,i.level,t.internalFormat,i.width,i.height,0,l)}else{r.texImage2D(r.TEXTURE_CUBE_MAP_POSITIVE_X+a,i.level,t.internalFormat,i.width,i.height,0,t.format,t.pixelType,l)}}};t.prototype._setMipmap=function e(t,i,r){var n=this;var s=O(this._format);var a={width:this._width,height:this._height,faceIndex:0,flipY:i,premultiplyAlpha:r,level:0,image:null};for(var l=0;l<t.length;++l){var _=t[l];a.level=l;a.width=n._width>>l;a.height=n._height>>l;for(var o=0;o<6;++o){a.faceIndex=o;a.image=_[o];n._setImage(s,a)}}};t.prototype._setTexInfo=function e(){var t=this._device._gl;var i=H(this._width)&&H(this._height);if(!i&&(this._wrapS!==I.WRAP_CLAMP||this._wrapT!==I.WRAP_CLAMP)){console.warn("WebGL1 doesn't support all wrap modes with NPOT textures");this._wrapS=I.WRAP_CLAMP;this._wrapT=I.WRAP_CLAMP}var r=this._hasMipmap?this._mipFilter:-1;if(!i&&r!==-1){console.warn("NPOT textures do not support mipmap filter");r=-1}t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,N(t,this._minFilter,r));t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,N(t,this._magFilter,-1));t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_S,this._wrapS);t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_T,this._wrapT);var n=this._device.ext("EXT_texture_filter_anisotropic");if(n){t.texParameteri(t.TEXTURE_CUBE_MAP,n.TEXTURE_MAX_ANISOTROPY_EXT,this._anisotropy)}};return t}(Z);var j=function e(t,i,r,n){this._device=t;this._format=i;this._width=r;this._height=n;var s=t._gl;this._glID=s.createRenderbuffer();s.bindRenderbuffer(s.RENDERBUFFER,this._glID);s.renderbufferStorage(s.RENDERBUFFER,i,r,n);s.bindRenderbuffer(s.RENDERBUFFER,null)};j.prototype.destroy=function e(){if(this._glID===null){console.error("The render-buffer already destroyed");return}var t=this._device._gl;t.bindRenderbuffer(t.RENDERBUFFER,null);t.deleteRenderbuffer(this._glID);this._glID=null};var z=function e(t,i,r,n){this._device=t;this._width=i;this._height=r;this._colors=n.colors||[];this._depth=n.depth||null;this._stencil=n.stencil||null;this._depthStencil=n.depthStencil||null;this._glID=t._gl.createFramebuffer()};z.prototype.destroy=function e(){if(this._glID===null){console.error("The frame-buffer already destroyed");return}var t=this._device._gl;t.deleteFramebuffer(this._glID);this._glID=null};var Q={blend:false,blendSep:false,blendColor:4294967295,blendEq:I.BLEND_FUNC_ADD,blendAlphaEq:I.BLEND_FUNC_ADD,blendSrc:I.BLEND_ONE,blendDst:I.BLEND_ZERO,blendSrcAlpha:I.BLEND_ONE,blendDstAlpha:I.BLEND_ZERO,depthTest:false,depthWrite:false,depthFunc:I.DS_FUNC_LESS,stencilTest:false,stencilSep:false,stencilFuncFront:I.DS_FUNC_ALWAYS,stencilRefFront:0,stencilMaskFront:255,stencilFailOpFront:I.STENCIL_OP_KEEP,stencilZFailOpFront:I.STENCIL_OP_KEEP,stencilZPassOpFront:I.STENCIL_OP_KEEP,stencilWriteMaskFront:255,stencilFuncBack:I.DS_FUNC_ALWAYS,stencilRefBack:0,stencilMaskBack:255,stencilFailOpBack:I.STENCIL_OP_KEEP,stencilZFailOpBack:I.STENCIL_OP_KEEP,stencilZPassOpBack:I.STENCIL_OP_KEEP,stencilWriteMaskBack:255,cullMode:I.CULL_BACK,primitiveType:I.PT_TRIANGLES,maxStream:-1,vertexBuffers:[],vertexBufferOffsets:[],indexBuffer:null,maxTextureSlot:-1,textureUnits:[],program:null};var J=function e(t){this.vertexBuffers=new Array(t._caps.maxVertexStreams);this.vertexBufferOffsets=new Array(t._caps.maxVertexStreams);this.textureUnits=new Array(t._caps.maxTextureUnits);this.set(Q)};J.initDefault=function e(t){Q.vertexBuffers=new Array(t._caps.maxVertexStreams);Q.vertexBufferOffsets=new Array(t._caps.maxVertexStreams);Q.textureUnits=new Array(t._caps.maxTextureUnits)};J.prototype.reset=function e(){this.set(Q)};J.prototype.set=function e(t){var i=this;this.blend=t.blend;this.blendSep=t.blendSep;this.blendColor=t.blendColor;this.blendEq=t.blendEq;this.blendAlphaEq=t.blendAlphaEq;this.blendSrc=t.blendSrc;this.blendDst=t.blendDst;this.blendSrcAlpha=t.blendSrcAlpha;this.blendDstAlpha=t.blendDstAlpha;this.depthTest=t.depthTest;this.depthWrite=t.depthWrite;this.depthFunc=t.depthFunc;this.stencilTest=t.stencilTest;this.stencilSep=t.stencilSep;this.stencilFuncFront=t.stencilFuncFront;this.stencilRefFront=t.stencilRefFront;this.stencilMaskFront=t.stencilMaskFront;this.stencilFailOpFront=t.stencilFailOpFront;this.stencilZFailOpFront=t.stencilZFailOpFront;this.stencilZPassOpFront=t.stencilZPassOpFront;this.stencilWriteMaskFront=t.stencilWriteMaskFront;this.stencilFuncBack=t.stencilFuncBack;this.stencilRefBack=t.stencilRefBack;this.stencilMaskBack=t.stencilMaskBack;this.stencilFailOpBack=t.stencilFailOpBack;this.stencilZFailOpBack=t.stencilZFailOpBack;this.stencilZPassOpBack=t.stencilZPassOpBack;this.stencilWriteMaskBack=t.stencilWriteMaskBack;this.cullMode=t.cullMode;this.primitiveType=t.primitiveType;this.maxStream=t.maxStream;for(var r=0;r<t.vertexBuffers.length;++r){i.vertexBuffers[r]=t.vertexBuffers[r]}for(var n=0;n<t.vertexBufferOffsets.length;++n){i.vertexBufferOffsets[n]=t.vertexBufferOffsets[n]}this.indexBuffer=t.indexBuffer;this.maxTextureSlot=t.maxTextureSlot;for(var s=0;s<t.textureUnits.length;++s){i.textureUnits[s]=t.textureUnits[s]}this.program=t.program};var $=5124;var ee=5126;var te=35664;var ie=35665;var re=35666;var ne=35667;var se=35668;var ae=35669;var le=35670;var _e=35671;var oe=35672;var fe=35673;var ce=35674;var ue=35675;var pe=35676;var he=35678;var Te=35680;var de={};de[$]=function(e,t,i){e.uniform1i(t,i)};de[ee]=function(e,t,i){e.uniform1f(t,i)};de[te]=function(e,t,i){e.uniform2fv(t,i)};de[ie]=function(e,t,i){e.uniform3fv(t,i)};de[re]=function(e,t,i){e.uniform4fv(t,i)};de[ne]=function(e,t,i){e.uniform2iv(t,i)};de[se]=function(e,t,i){e.uniform3iv(t,i)};de[ae]=function(e,t,i){e.uniform4iv(t,i)};de[le]=function(e,t,i){e.uniform1i(t,i)};de[_e]=function(e,t,i){e.uniform2iv(t,i)};de[oe]=function(e,t,i){e.uniform3iv(t,i)};de[fe]=function(e,t,i){e.uniform4iv(t,i)};de[ce]=function(e,t,i){e.uniformMatrix2fv(t,false,i)};de[ue]=function(e,t,i){e.uniformMatrix3fv(t,false,i)};de[pe]=function(e,t,i){e.uniformMatrix4fv(t,false,i)};de[he]=function(e,t,i){e.uniform1i(t,i)};de[Te]=function(e,t,i){e.uniform1i(t,i)};var Ee={};Ee[$]=function(e,t,i){e.uniform1iv(t,i)};Ee[ee]=function(e,t,i){e.uniform1fv(t,i)};Ee[te]=function(e,t,i){e.uniform2fv(t,i)};Ee[ie]=function(e,t,i){e.uniform3fv(t,i)};Ee[re]=function(e,t,i){e.uniform4fv(t,i)};Ee[ne]=function(e,t,i){e.uniform2iv(t,i)};Ee[se]=function(e,t,i){e.uniform3iv(t,i)};Ee[ae]=function(e,t,i){e.uniform4iv(t,i)};Ee[le]=function(e,t,i){e.uniform1iv(t,i)};Ee[_e]=function(e,t,i){e.uniform2iv(t,i)};Ee[oe]=function(e,t,i){e.uniform3iv(t,i)};Ee[fe]=function(e,t,i){e.uniform4iv(t,i)};Ee[ce]=function(e,t,i){e.uniformMatrix2fv(t,false,i)};Ee[ue]=function(e,t,i){e.uniformMatrix3fv(t,false,i)};Ee[pe]=function(e,t,i){e.uniformMatrix4fv(t,false,i)};Ee[he]=function(e,t,i){e.uniform1iv(t,i)};Ee[Te]=function(e,t,i){e.uniform1iv(t,i)};function Fe(e,t,i){if(t.blend!==i.blend){if(!i.blend){e.disable(e.BLEND);return}e.enable(e.BLEND);if(i.blendSrc===I.BLEND_CONSTANT_COLOR||i.blendSrc===I.BLEND_ONE_MINUS_CONSTANT_COLOR||i.blendDst===I.BLEND_CONSTANT_COLOR||i.blendDst===I.BLEND_ONE_MINUS_CONSTANT_COLOR){e.blendColor((i.blendColor>>24)/255,(i.blendColor>>16&255)/255,(i.blendColor>>8&255)/255,(i.blendColor&255)/255)}if(i.blendSep){e.blendFuncSeparate(i.blendSrc,i.blendDst,i.blendSrcAlpha,i.blendDstAlpha);e.blendEquationSeparate(i.blendEq,i.blendAlphaEq)}else{e.blendFunc(i.blendSrc,i.blendDst);e.blendEquation(i.blendEq)}return}if(i.blend===false){return}if(t.blendColor!==i.blendColor){e.blendColor((i.blendColor>>24)/255,(i.blendColor>>16&255)/255,(i.blendColor>>8&255)/255,(i.blendColor&255)/255)}if(t.blendSep!==i.blendSep){if(i.blendSep){e.blendFuncSeparate(i.blendSrc,i.blendDst,i.blendSrcAlpha,i.blendDstAlpha);e.blendEquationSeparate(i.blendEq,i.blendAlphaEq)}else{e.blendFunc(i.blendSrc,i.blendDst);e.blendEquation(i.blendEq)}return}if(i.blendSep){if(t.blendSrc!==i.blendSrc||t.blendDst!==i.blendDst||t.blendSrcAlpha!==i.blendSrcAlpha||t.blendDstAlpha!==i.blendDstAlpha){e.blendFuncSeparate(i.blendSrc,i.blendDst,i.blendSrcAlpha,i.blendDstAlpha)}if(t.blendEq!==i.blendEq||t.blendAlphaEq!==i.blendAlphaEq){e.blendEquationSeparate(i.blendEq,i.blendAlphaEq)}}else{if(t.blendSrc!==i.blendSrc||t.blendDst!==i.blendDst){e.blendFunc(i.blendSrc,i.blendDst)}if(t.blendEq!==i.blendEq){e.blendEquation(i.blendEq)}}}function me(e,t,i){if(t.depthTest!==i.depthTest){if(!i.depthTest){e.disable(e.DEPTH_TEST);return}e.enable(e.DEPTH_TEST);e.depthFunc(i.depthFunc);e.depthMask(i.depthWrite);return}if(t.depthWrite!==i.depthWrite){e.depthMask(i.depthWrite)}if(i.depthTest===false){if(i.depthWrite){i.depthTest=true;i.depthFunc=I.DS_FUNC_ALWAYS;e.enable(e.DEPTH_TEST);e.depthFunc(i.depthFunc)}return}if(t.depthFunc!==i.depthFunc){e.depthFunc(i.depthFunc)}}function Re(e,t,i){if(i.stencilTest!==t.stencilTest){if(!i.stencilTest){e.disable(e.STENCIL_TEST);return}e.enable(e.STENCIL_TEST);if(i.stencilSep){e.stencilFuncSeparate(e.FRONT,i.stencilFuncFront,i.stencilRefFront,i.stencilMaskFront);e.stencilMaskSeparate(e.FRONT,i.stencilWriteMaskFront);e.stencilOpSeparate(e.FRONT,i.stencilFailOpFront,i.stencilZFailOpFront,i.stencilZPassOpFront);e.stencilFuncSeparate(e.BACK,i.stencilFuncBack,i.stencilRefBack,i.stencilMaskBack);e.stencilMaskSeparate(e.BACK,i.stencilWriteMaskBack);e.stencilOpSeparate(e.BACK,i.stencilFailOpBack,i.stencilZFailOpBack,i.stencilZPassOpBack)}else{e.stencilFunc(i.stencilFuncFront,i.stencilRefFront,i.stencilMaskFront);e.stencilMask(i.stencilWriteMaskFront);e.stencilOp(i.stencilFailOpFront,i.stencilZFailOpFront,i.stencilZPassOpFront)}return}if(!i.stencilTest){return}if(t.stencilSep!==i.stencilSep){if(i.stencilSep){e.stencilFuncSeparate(e.FRONT,i.stencilFuncFront,i.stencilRefFront,i.stencilMaskFront);e.stencilMaskSeparate(e.FRONT,i.stencilWriteMaskFront);e.stencilOpSeparate(e.FRONT,i.stencilFailOpFront,i.stencilZFailOpFront,i.stencilZPassOpFront);e.stencilFuncSeparate(e.BACK,i.stencilFuncBack,i.stencilRefBack,i.stencilMaskBack);e.stencilMaskSeparate(e.BACK,i.stencilWriteMaskBack);e.stencilOpSeparate(e.BACK,i.stencilFailOpBack,i.stencilZFailOpBack,i.stencilZPassOpBack)}else{e.stencilFunc(i.stencilFuncFront,i.stencilRefFront,i.stencilMaskFront);e.stencilMask(i.stencilWriteMaskFront);e.stencilOp(i.stencilFailOpFront,i.stencilZFailOpFront,i.stencilZPassOpFront)}return}if(i.stencilSep){if(t.stencilFuncFront!==i.stencilFuncFront||t.stencilRefFront!==i.stencilRefFront||t.stencilMaskFront!==i.stencilMaskFront){e.stencilFuncSeparate(e.FRONT,i.stencilFuncFront,i.stencilRefFront,i.stencilMaskFront)}if(t.stencilWriteMaskFront!==i.stencilWriteMaskFront){e.stencilMaskSeparate(e.FRONT,i.stencilWriteMaskFront)}if(t.stencilFailOpFront!==i.stencilFailOpFront||t.stencilZFailOpFront!==i.stencilZFailOpFront||t.stencilZPassOpFront!==i.stencilZPassOpFront){e.stencilOpSeparate(e.FRONT,i.stencilFailOpFront,i.stencilZFailOpFront,i.stencilZPassOpFront)}if(t.stencilFuncBack!==i.stencilFuncBack||t.stencilRefBack!==i.stencilRefBack||t.stencilMaskBack!==i.stencilMaskBack){e.stencilFuncSeparate(e.BACK,i.stencilFuncBack,i.stencilRefBack,i.stencilMaskBack)}if(t.stencilWriteMaskBack!==i.stencilWriteMaskBack){e.stencilMaskSeparate(e.BACK,i.stencilWriteMaskBack)}if(t.stencilFailOpBack!==i.stencilFailOpBack||t.stencilZFailOpBack!==i.stencilZFailOpBack||t.stencilZPassOpBack!==i.stencilZPassOpBack){e.stencilOpSeparate(e.BACK,i.stencilFailOpBack,i.stencilZFailOpBack,i.stencilZPassOpBack)}}else{if(t.stencilFuncFront!==i.stencilFuncFront||t.stencilRefFront!==i.stencilRefFront||t.stencilMaskFront!==i.stencilMaskFront){e.stencilFunc(i.stencilFuncFront,i.stencilRefFront,i.stencilMaskFront)}if(t.stencilWriteMaskFront!==i.stencilWriteMaskFront){e.stencilMask(i.stencilWriteMaskFront)}if(t.stencilFailOpFront!==i.stencilFailOpFront||t.stencilZFailOpFront!==i.stencilZFailOpFront||t.stencilZPassOpFront!==i.stencilZPassOpFront){e.stencilOp(i.stencilFailOpFront,i.stencilZFailOpFront,i.stencilZPassOpFront)}}}function xe(e,t,i){if(t.cullMode===i.cullMode){return}if(i.cullMode===I.CULL_NONE){e.disable(e.CULL_FACE);return}e.enable(e.CULL_FACE);e.cullFace(i.cullMode)}function ve(e,t,i,r){var n=false;if(r.maxStream===-1){console.warn("VertexBuffer not assigned, please call setVertexBuffer before every draw.");return}if(i.maxStream!==r.maxStream){n=true}else if(i.program!==r.program){n=true}else{for(var s=0;s<r.maxStream+1;++s){if(i.vertexBuffers[s]!==r.vertexBuffers[s]||i.vertexBufferOffsets[s]!==r.vertexBufferOffsets[s]){n=true;break}}}if(n){for(var a=0;a<e._caps.maxVertexAttribs;++a){e._newAttributes[a]=0}for(var l=0;l<r.maxStream+1;++l){var _=r.vertexBuffers[l];var o=r.vertexBufferOffsets[l];if(!_){continue}t.bindBuffer(t.ARRAY_BUFFER,_._glID);for(var f=0;f<r.program._attributes.length;++f){var c=r.program._attributes[f];var u=_._format.element(c.name);if(!u){console.warn("Can not find vertex attribute: "+c.name);continue}if(e._enabledAttributes[c.location]===0){t.enableVertexAttribArray(c.location);e._enabledAttributes[c.location]=1}e._newAttributes[c.location]=1;t.vertexAttribPointer(c.location,u.num,u.type,u.normalize,u.stride,u.offset+o*u.stride)}}for(var p=0;p<e._caps.maxVertexAttribs;++p){if(e._enabledAttributes[p]!==e._newAttributes[p]){t.disableVertexAttribArray(p);e._enabledAttributes[p]=0}}}}function Ae(e,t,i){for(var r=0;r<i.maxTextureSlot+1;++r){if(t.textureUnits[r]!==i.textureUnits[r]){var n=i.textureUnits[r];if(n!==undefined&&n._glID!==-1){e.activeTexture(e.TEXTURE0+r);e.bindTexture(n._target,n._glID)}}}}function Se(e,t,i,r){if(r===void 0)r=0;if(i instanceof K){e.framebufferTexture2D(e.FRAMEBUFFER,t,e.TEXTURE_2D,i._glID,0)}else if(i instanceof q){e.framebufferTexture2D(e.FRAMEBUFFER,t,e.TEXTURE_CUBE_MAP_POSITIVE_X+r,i._glID,0)}else{e.framebufferRenderbuffer(e.FRAMEBUFFER,t,e.RENDERBUFFER,i._glID)}}var be=function e(t,i){var r=this;var n;i=i||{};if(i.alpha===undefined){i.alpha=false}if(i.stencil===undefined){i.stencil=true}if(i.depth===undefined){i.depth=true}if(i.antialias===undefined){i.antialias=false}if(i.preserveDrawingBuffer===undefined){i.preserveDrawingBuffer=false}try{n=t.getContext("webgl",i)}catch(e){console.error(e);return}this._gl=n;this._extensions={};this._caps={};this._stats={texture:0,vb:0,ib:0,drawcalls:0};this._initExtensions(["EXT_texture_filter_anisotropic","EXT_shader_texture_lod","OES_standard_derivatives","OES_texture_float","OES_texture_float_linear","OES_texture_half_float","OES_texture_half_float_linear","OES_vertex_array_object","WEBGL_compressed_texture_atc","WEBGL_compressed_texture_etc1","WEBGL_compressed_texture_pvrtc","WEBGL_compressed_texture_s3tc","WEBGL_depth_texture","WEBGL_draw_buffers"]);this._initCaps();this._initStates();J.initDefault(this);this._current=new J(this);this._next=new J(this);this._uniforms={};this._vx=this._vy=this._vw=this._vh=0;this._sx=this._sy=this._sw=this._sh=0;this._framebuffer=null;this._enabledAttributes=new Array(this._caps.maxVertexAttribs);this._newAttributes=new Array(this._caps.maxVertexAttribs);for(var s=0;s<this._caps.maxVertexAttribs;++s){r._enabledAttributes[s]=0;r._newAttributes[s]=0}};be.prototype._initExtensions=function e(t){var i=this;var r=this._gl;for(var n=0;n<t.length;++n){var s=t[n];try{var a=r.getExtension(s);if(a){i._extensions[s]=a}}catch(e){console.error(e)}}};be.prototype._initCaps=function e(){var t=this._gl;var i=this.ext("WEBGL_draw_buffers");this._caps.maxVertexStreams=4;this._caps.maxVertexTextures=t.getParameter(t.MAX_VERTEX_TEXTURE_IMAGE_UNITS);this._caps.maxFragUniforms=t.getParameter(t.MAX_FRAGMENT_UNIFORM_VECTORS);this._caps.maxTextureUnits=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);this._caps.maxVertexAttribs=t.getParameter(t.MAX_VERTEX_ATTRIBS);this._caps.maxDrawBuffers=i?t.getParameter(i.MAX_DRAW_BUFFERS_WEBGL):1;this._caps.maxColorAttachments=i?t.getParameter(i.MAX_COLOR_ATTACHMENTS_WEBGL):1};be.prototype._initStates=function e(){var t=this._gl;t.disable(t.BLEND);t.blendFunc(t.ONE,t.ZERO);t.blendEquation(t.FUNC_ADD);t.blendColor(1,1,1,1);t.colorMask(true,true,true,true);t.enable(t.CULL_FACE);t.cullFace(t.BACK);t.disable(t.DEPTH_TEST);t.depthFunc(t.LESS);t.depthMask(false);t.disable(t.POLYGON_OFFSET_FILL);t.depthRange(0,1);t.disable(t.STENCIL_TEST);t.stencilFunc(t.ALWAYS,0,255);t.stencilMask(255);t.stencilOp(t.KEEP,t.KEEP,t.KEEP);t.clearDepth(1);t.clearColor(0,0,0,0);t.clearStencil(0);t.disable(t.SCISSOR_TEST)};be.prototype._restoreTexture=function e(t){var i=this._gl;var r=this._current.textureUnits[t];if(r&&r._glID!==-1){i.bindTexture(r._target,r._glID)}else{i.bindTexture(i.TEXTURE_2D,null)}};be.prototype._restoreIndexBuffer=function e(){var t=this._gl;var i=this._current.indexBuffer;t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,i?i._glID:null)};be.prototype.ext=function e(t){return this._extensions[t]};be.prototype.setFrameBuffer=function e(t){var i=this;if(this._framebuffer===t){return}this._framebuffer=t;var r=this._gl;if(t===null){r.bindFramebuffer(r.FRAMEBUFFER,null);return}r.bindFramebuffer(r.FRAMEBUFFER,t._glID);var n=this._framebuffer._colors.length;for(var s=0;s<n;++s){var a=i._framebuffer._colors[s];Se(r,r.COLOR_ATTACHMENT0+s,a)}for(var l=n;l<this._caps.maxColorAttachments;++l){r.framebufferTexture2D(r.FRAMEBUFFER,r.COLOR_ATTACHMENT0+l,r.TEXTURE_2D,null,0)}if(this._framebuffer._depth){Se(r,r.DEPTH_ATTACHMENT,this._framebuffer._depth)}if(this._framebuffer._stencil){Se(r,r.STENCIL_ATTACHMENT,t._stencil)}if(this._framebuffer._depthStencil){Se(r,r.DEPTH_STENCIL_ATTACHMENT,t._depthStencil)}};be.prototype.setViewport=function e(t,i,r,n){if(this._vx!==t||this._vy!==i||this._vw!==r||this._vh!==n){this._gl.viewport(t,i,r,n);this._vx=t;this._vy=i;this._vw=r;this._vh=n}};be.prototype.setScissor=function e(t,i,r,n){if(this._sx!==t||this._sy!==i||this._sw!==r||this._sh!==n){this._gl.scissor(t,i,r,n);this._sx=t;this._sy=i;this._sw=r;this._sh=n}};be.prototype.clear=function e(t){var i=this._gl;var r=0;if(t.color!==undefined){r|=i.COLOR_BUFFER_BIT;i.clearColor(t.color[0],t.color[1],t.color[2],t.color[3])}if(t.depth!==undefined){r|=i.DEPTH_BUFFER_BIT;i.clearDepth(t.depth);i.enable(i.DEPTH_TEST);i.depthMask(true);i.depthFunc(i.ALWAYS)}if(t.stencil!==undefined){r|=i.STENCIL_BUFFER_BIT;i.clearStencil(t.stencil)}i.clear(r);if(t.depth!==undefined){if(this._current.depthTest===false){i.disable(i.DEPTH_TEST)}else{if(this._current.depthWrite===false){i.depthMask(false)}if(this._current.depthFunc!==I.DS_FUNC_ALWAYS){i.depthFunc(this._current.depthFunc)}}}};be.prototype.enableBlend=function e(){this._next.blend=true};be.prototype.enableDepthTest=function e(){this._next.depthTest=true};be.prototype.enableDepthWrite=function e(){this._next.depthWrite=true};be.prototype.enableStencilTest=function e(){this._next.stencilTest=true};be.prototype.setStencilFunc=function e(t,i,r){this._next.stencilSep=false;this._next.stencilFuncFront=this._next.stencilFuncBack=t;this._next.stencilRefFront=this._next.stencilRefBack=i;this._next.stencilMaskFront=this._next.stencilMaskBack=r};be.prototype.setStencilFuncFront=function e(t,i,r){this._next.stencilSep=true;this._next.stencilFuncFront=t;this._next.stencilRefFront=i;this._next.stencilMaskFront=r};be.prototype.setStencilFuncBack=function e(t,i,r){this._next.stencilSep=true;this._next.stencilFuncBack=t;this._next.stencilRefBack=i;this._next.stencilMaskBack=r};be.prototype.setStencilOp=function e(t,i,r,n){this._next.stencilFailOpFront=this._next.stencilFailOpBack=t;this._next.stencilZFailOpFront=this._next.stencilZFailOpBack=i;this._next.stencilZPassOpFront=this._next.stencilZPassOpBack=r;this._next.stencilWriteMaskFront=this._next.stencilWriteMaskBack=n};be.prototype.setStencilOpFront=function e(t,i,r,n){this._next.stencilSep=true;this._next.stencilFailOpFront=t;this._next.stencilZFailOpFront=i;this._next.stencilZPassOpFront=r;this._next.stencilWriteMaskFront=n};be.prototype.setStencilOpBack=function e(t,i,r,n){this._next.stencilSep=true;this._next.stencilFailOpBack=t;this._next.stencilZFailOpBack=i;this._next.stencilZPassOpBack=r;this._next.stencilWriteMaskBack=n};be.prototype.setDepthFunc=function e(t){this._next.depthFunc=t};be.prototype.setBlendColor32=function e(t){this._next.blendColor=t};be.prototype.setBlendColor=function e(t,i,r,n){this._next.blendColor=(t*255<<24|i*255<<16|r*255<<8|n*255)>>>0};be.prototype.setBlendFunc=function e(t,i){this._next.blendSep=false;this._next.blendSrc=t;this._next.blendDst=i};be.prototype.setBlendFuncSep=function e(t,i,r,n){this._next.blendSep=true;this._next.blendSrc=t;this._next.blendDst=i;this._next.blendSrcAlpha=r;this._next.blendDstAlpha=n};be.prototype.setBlendEq=function e(t){this._next.blendSep=false;this._next.blendEq=t};be.prototype.setBlendEqSep=function e(t,i){this._next.blendSep=true;this._next.blendEq=t;this._next.blendAlphaEq=i};be.prototype.setCullMode=function e(t){this._next.cullMode=t};be.prototype.setVertexBuffer=function e(t,i,r){if(r===void 0)r=0;this._next.vertexBuffers[t]=i;this._next.vertexBufferOffsets[t]=r;if(this._next.maxStream<t){this._next.maxStream=t}};be.prototype.setIndexBuffer=function e(t){this._next.indexBuffer=t};be.prototype.setProgram=function e(t){this._next.program=t};be.prototype.setTexture=function e(t,i,r){if(r>=this._caps.maxTextureUnits){console.warn("Can not set texture "+t+" at stage "+r+", max texture exceed: "+this._caps.maxTextureUnits);return}this._next.textureUnits[r]=i;this.setUniform(t,r);if(this._next.maxTextureSlot<r){this._next.maxTextureSlot=r}};be.prototype.setTextureArray=function e(t,i,r){var n=this;var s=i.length;if(s>=this._caps.maxTextureUnits){console.warn("Can not set "+s+" textures for "+t+", max texture exceed: "+this._caps.maxTextureUnits);return}for(var a=0;a<s;++a){var l=r[a];n._next.textureUnits[l]=i[a]}this.setUniform(t,r)};be.prototype.setUniform=function e(t,i){var r=this._uniforms[t];if(!r){r={dirty:true,value:i}}else{r.dirty=true;r.value=i}this._uniforms[t]=r};be.prototype.setPrimitiveType=function e(t){this._next.primitiveType=t};be.prototype.draw=function e(t,i){var r=this;var n=this._gl;var s=this._current;var a=this._next;Fe(n,s,a);me(n,s,a);Re(n,s,a);xe(n,s,a);ve(this,n,s,a);if(s.indexBuffer!==a.indexBuffer){n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,a.indexBuffer?a.indexBuffer._glID:null)}var l=false;if(s.program!==a.program){if(a.program._linked){n.useProgram(a.program._glID)}else{console.warn("Failed to use program: has not linked yet.")}l=true}Ae(n,s,a);for(var _=0;_<a.program._uniforms.length;++_){var o=a.program._uniforms[_];var f=r._uniforms[o.name];if(!f){continue}if(!l&&!f.dirty){continue}f.dirty=false;var c=o.size===undefined?de[o.type]:Ee[o.type];if(!c){console.warn("Can not find commit function for uniform "+o.name);continue}c(n,o.location,f.value)}if(a.indexBuffer){n.drawElements(this._next.primitiveType,i,a.indexBuffer._format,t*a.indexBuffer._bytesPerIndex)}else{n.drawArrays(this._next.primitiveType,t,i)}this._stats.drawcalls+=1;s.set(a);a.reset()};var Be={VertexFormat:y,IndexBuffer:D,VertexBuffer:k,Program:G,Texture:Z,Texture2D:K,TextureCube:q,RenderBuffer:j,FrameBuffer:z,Device:be,attrTypeBytes:M,glFilter:N,glTextureFmt:O};Object.assign(Be,I);return Be}(); //# sourceMappingURL=gfx.min.js.map