chunk-546QCRS4.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. import {
  2. s
  3. } from "./chunk-QXZVBSBH.js";
  4. import {
  5. D,
  6. G,
  7. L,
  8. M,
  9. P,
  10. U,
  11. t,
  12. u
  13. } from "./chunk-MI7HWWFL.js";
  14. import {
  15. o
  16. } from "./chunk-LGW7TID4.js";
  17. import {
  18. i2 as i
  19. } from "./chunk-XNLG7T2T.js";
  20. import {
  21. e,
  22. r
  23. } from "./chunk-GZT4BVFP.js";
  24. // node_modules/@arcgis/core/views/webgl/capabilities/isWebGL2Context.js
  25. function n(n2) {
  26. return window.WebGL2RenderingContext && n2 instanceof window.WebGL2RenderingContext;
  27. }
  28. // node_modules/@arcgis/core/views/webgl/Texture.js
  29. var c = 4;
  30. var u2 = class {
  31. constructor(t2, e2, i2 = null) {
  32. if (this._context = t2, this.type = "texture", this._glName = null, this._descriptor = void 0, this._samplingModeDirty = false, this._wrapModeDirty = false, this._wasImmutablyAllocated = false, t2.instanceCounter.increment(t.Texture, this), this._descriptor = { target: M.TEXTURE_2D, samplingMode: L.LINEAR, wrapMode: D.REPEAT, flipped: false, hasMipmap: false, isOpaque: false, unpackAlignment: 4, preMultiplyAlpha: false, isImmutable: false, ...e2 }, t2.type !== o.WEBGL2 && (this._descriptor.isImmutable && (this._descriptor.isImmutable = false), A(this._descriptor.target)))
  33. throw new Error("3D and array textures are not supported in WebGL1");
  34. this._descriptor.target === M.TEXTURE_CUBE_MAP ? this._setDataCubeMap(i2) : this.setData(i2);
  35. }
  36. get glName() {
  37. return this._glName;
  38. }
  39. get descriptor() {
  40. return this._descriptor;
  41. }
  42. get isDirty() {
  43. return this._samplingModeDirty || this._wrapModeDirty;
  44. }
  45. dispose() {
  46. this._context.gl && this._glName && (this._context.unbindTexture(this), this._context.gl.deleteTexture(this._glName), this._glName = null, this._context.instanceCounter.decrement(t.Texture, this));
  47. }
  48. release() {
  49. this.dispose();
  50. }
  51. resize(t2, e2) {
  52. const i2 = this._descriptor;
  53. if (i2.width !== t2 || i2.height !== e2) {
  54. if (this._wasImmutablyAllocated)
  55. throw new Error("Immutable textures can't be resized!");
  56. i2.width = t2, i2.height = e2, this._descriptor.target === M.TEXTURE_CUBE_MAP ? this._setDataCubeMap(null) : this.setData(null);
  57. }
  58. }
  59. _setDataCubeMap(t2 = null) {
  60. for (let e2 = M.TEXTURE_CUBE_MAP_POSITIVE_X; e2 <= M.TEXTURE_CUBE_MAP_NEGATIVE_Z; e2++)
  61. this._setData(t2, e2);
  62. }
  63. setData(t2) {
  64. this._setData(t2);
  65. }
  66. _setData(t2, i2) {
  67. if (!this._context || !this._context.gl)
  68. return;
  69. const a = this._context.gl;
  70. this._glName || (this._glName = a.createTexture()), t2 === void 0 && (t2 = null);
  71. const s2 = this._descriptor;
  72. i2 ?? (i2 = s2.target);
  73. const o2 = A(i2);
  74. t2 === null && (s2.width = s2.width || c, s2.height = s2.height || c, o2 && (s2.depth = s2.depth ?? 1));
  75. const n2 = this._context.bindTexture(this, u2.TEXTURE_UNIT_FOR_UPDATES);
  76. this._context.setActiveTexture(u2.TEXTURE_UNIT_FOR_UPDATES), u2._validateTexture(this._context, s2), this._configurePixelStorage();
  77. const p = s2.pixelFormat;
  78. let h = s2.internalFormat ? s2.internalFormat : this._deriveInternalFormat(p, s2.dataType);
  79. if (M2(t2)) {
  80. let e2 = t2.width, n3 = t2.height;
  81. const p2 = 1;
  82. t2 instanceof HTMLVideoElement && (e2 = t2.videoWidth, n3 = t2.videoHeight), s2.width && s2.height, o2 && s2.depth, s2.isImmutable && !this._wasImmutablyAllocated && this._texStorage(i2, h, s2.hasMipmap, e2, n3, p2), this._texImage(i2, 0, h, e2, n3, p2, t2), s(a), s2.hasMipmap && this.generateMipmap(), s2.width === void 0 && (s2.width = e2), s2.height === void 0 && (s2.height = n3), o2 && s2.depth === void 0 && (s2.depth = p2);
  83. } else {
  84. const { width: n3, height: p2, depth: _ } = s2;
  85. if (n3 != null && p2 != null || console.error("Width and height must be specified!"), o2 && _ == null && console.error("Depth must be specified!"), s2.isImmutable && !this._wasImmutablyAllocated && this._texStorage(i2, h, s2.hasMipmap, n3, p2, _), a.DEPTH24_STENCIL8 && h === a.DEPTH_STENCIL && (h = a.DEPTH24_STENCIL8), g(t2)) {
  86. const e2 = t2.levels, r2 = I(i2, n3, p2, _), o3 = Math.min(r2 - 1, e2.length - 1);
  87. n(a) ? a.texParameteri(s2.target, a.TEXTURE_MAX_LEVEL, o3) : s2.hasMipmap = s2.hasMipmap && r2 === e2.length;
  88. const l = h;
  89. if (!T(l))
  90. throw new Error("Attempting to use compressed data with an umcompressed format!");
  91. this._forEachMipmapLevel((t3, r3, a2, s3) => {
  92. const o4 = e2[Math.min(t3, e2.length - 1)];
  93. this._compressedTexImage(i2, t3, l, r3, a2, s3, o4);
  94. }, o3);
  95. } else
  96. r(t2) ? (this._texImage(i2, 0, h, n3, p2, _, t2), s(a), s2.hasMipmap && this.generateMipmap()) : this._forEachMipmapLevel((t3, e2, s3, o3) => {
  97. this._texImage(i2, t3, h, e2, s3, o3, null), s(a);
  98. });
  99. }
  100. u2._applySamplingMode(a, this._descriptor), u2._applyWrapMode(a, this._descriptor), u2._applyAnisotropicFilteringParameters(this._context, this._descriptor), s(a), this._context.bindTexture(n2, u2.TEXTURE_UNIT_FOR_UPDATES);
  101. }
  102. updateData(t2, e2, i2, r2, a, s2) {
  103. s2 || console.error("An attempt to use uninitialized data!"), this._glName || console.error("An attempt to update uninitialized texture!");
  104. const o2 = this._context.gl, n2 = this._descriptor, { pixelFormat: p, internalFormat: h, dataType: _, isImmutable: l, target: m } = n2;
  105. if (l && !this._wasImmutablyAllocated)
  106. throw new Error("Cannot update immutable texture before allocation!");
  107. const d = this._context.bindTexture(this, u2.TEXTURE_UNIT_FOR_UPDATES);
  108. (e2 < 0 || i2 < 0 || r2 > n2.width || a > n2.height || e2 + r2 > n2.width || i2 + a > n2.height) && console.error("An attempt to update out of bounds of the texture!"), this._configurePixelStorage(), M2(s2) ? o2.texSubImage2D(m, t2, e2, i2, p, _, s2) : g(s2) ? o2.compressedTexSubImage2D(m, t2, e2, i2, r2, a, h, s2.levels[t2]) : o2.texSubImage2D(m, t2, e2, i2, r2, a, p, _, s2), this._context.bindTexture(d, u2.TEXTURE_UNIT_FOR_UPDATES);
  109. }
  110. updateData3D(t2, e2, i2, r2, a, s2, o2, n2) {
  111. n2 || console.error("An attempt to use uninitialized data!"), this._glName || console.error("An attempt to update uninitialized texture!");
  112. const p = this._context.gl;
  113. if (!n(p))
  114. throw new Error("3D textures are not supported in WebGL1");
  115. const h = this._descriptor, { pixelFormat: _, dataType: l, isImmutable: m, target: c2, internalFormat: E2 } = h;
  116. if (m && !this._wasImmutablyAllocated)
  117. throw new Error("Cannot update immutable texture before allocation!");
  118. A(c2) || console.warn("Attempting to set 3D texture data on a non-3D texture");
  119. const T2 = this._context.bindTexture(this, u2.TEXTURE_UNIT_FOR_UPDATES);
  120. if (this._context.setActiveTexture(u2.TEXTURE_UNIT_FOR_UPDATES), (e2 < 0 || i2 < 0 || r2 < 0 || a > h.width || s2 > h.height || o2 > h.depth || e2 + a > h.width || i2 + s2 > h.height || r2 + o2 > h.depth) && console.error("An attempt to update out of bounds of the texture!"), this._configurePixelStorage(), g(n2))
  121. n2 = n2.levels[t2], p.compressedTexSubImage3D(c2, t2, e2, i2, r2, a, s2, o2, E2, n2);
  122. else {
  123. const h2 = n2;
  124. p.texSubImage3D(c2, t2, e2, i2, r2, a, s2, o2, _, l, h2);
  125. }
  126. this._context.bindTexture(T2, u2.TEXTURE_UNIT_FOR_UPDATES);
  127. }
  128. generateMipmap() {
  129. const t2 = this._descriptor;
  130. if (!t2.hasMipmap) {
  131. if (this._wasImmutablyAllocated)
  132. throw new Error("Cannot add mipmaps to immutable texture after allocation");
  133. t2.hasMipmap = true, this._samplingModeDirty = true, u2._validateTexture(this._context, t2);
  134. }
  135. t2.samplingMode === L.LINEAR ? (this._samplingModeDirty = true, t2.samplingMode = L.LINEAR_MIPMAP_NEAREST) : t2.samplingMode === L.NEAREST && (this._samplingModeDirty = true, t2.samplingMode = L.NEAREST_MIPMAP_NEAREST);
  136. const e2 = this._context.bindTexture(this, u2.TEXTURE_UNIT_FOR_UPDATES);
  137. this._context.setActiveTexture(u2.TEXTURE_UNIT_FOR_UPDATES);
  138. this._context.gl.generateMipmap(t2.target), this._context.bindTexture(e2, u2.TEXTURE_UNIT_FOR_UPDATES);
  139. }
  140. setSamplingMode(t2) {
  141. t2 !== this._descriptor.samplingMode && (this._descriptor.samplingMode = t2, this._samplingModeDirty = true);
  142. }
  143. setWrapMode(t2) {
  144. t2 !== this._descriptor.wrapMode && (this._descriptor.wrapMode = t2, u2._validateTexture(this._context, this._descriptor), this._wrapModeDirty = true);
  145. }
  146. applyChanges() {
  147. const t2 = this._context.gl, e2 = this._descriptor;
  148. this._samplingModeDirty && (u2._applySamplingMode(t2, e2), this._samplingModeDirty = false), this._wrapModeDirty && (u2._applyWrapMode(t2, e2), this._wrapModeDirty = false);
  149. }
  150. _deriveInternalFormat(t2, e2) {
  151. if (this._context.type === o.WEBGL1)
  152. return t2;
  153. switch (e2) {
  154. case G.FLOAT:
  155. switch (t2) {
  156. case P.RGBA:
  157. return U.RGBA32F;
  158. case P.RGB:
  159. return U.RGB32F;
  160. default:
  161. throw new Error("Unable to derive format");
  162. }
  163. case G.UNSIGNED_BYTE:
  164. switch (t2) {
  165. case P.RGBA:
  166. return U.RGBA8;
  167. case P.RGB:
  168. return U.RGB8;
  169. }
  170. default:
  171. return t2;
  172. }
  173. }
  174. _configurePixelStorage() {
  175. const t2 = this._context.gl, { unpackAlignment: e2, flipped: i2, preMultiplyAlpha: r2 } = this._descriptor;
  176. t2.pixelStorei(t2.UNPACK_ALIGNMENT, e2), t2.pixelStorei(t2.UNPACK_FLIP_Y_WEBGL, i2 ? 1 : 0), t2.pixelStorei(t2.UNPACK_PREMULTIPLY_ALPHA_WEBGL, r2 ? 1 : 0);
  177. }
  178. _texStorage(t2, e2, i2, r2, a, s2) {
  179. const o2 = this._context.gl;
  180. if (!n(o2))
  181. throw new Error("Immutable textures are not supported in WebGL1");
  182. if (!E(e2))
  183. throw new Error("Immutable textures must have a sized internal format");
  184. if (!this._descriptor.isImmutable)
  185. return;
  186. const n2 = i2 ? I(t2, r2, a, s2) : 1;
  187. A(t2) ? o2.texStorage3D(t2, n2, e2, r2, a, s2) : o2.texStorage2D(t2, n2, e2, r2, a), this._wasImmutablyAllocated = true;
  188. }
  189. _texImage(t2, r2, s2, o2, n2, p, h) {
  190. const _ = this._context.gl;
  191. let l = null;
  192. const m = this._context.type === o.WEBGL2, d = A(t2), { isImmutable: c2, pixelFormat: u3, dataType: E2 } = this._descriptor;
  193. if (m && (l = _), m || !M2(h))
  194. if (c2) {
  195. if (r(h)) {
  196. const e2 = h;
  197. d ? l.texSubImage3D(t2, r2, 0, 0, 0, o2, n2, p, u3, E2, e2) : _.texSubImage2D(t2, r2, 0, 0, o2, n2, u3, E2, e2);
  198. }
  199. } else {
  200. const e2 = e(h);
  201. d ? l.texImage3D(t2, r2, s2, o2, n2, p, 0, u3, E2, e2) : _.texImage2D(t2, r2, s2, o2, n2, 0, u3, E2, e2);
  202. }
  203. else
  204. _.texImage2D(t2, 0, s2, u3, E2, h);
  205. }
  206. _compressedTexImage(t2, i2, r2, s2, o2, n2, p) {
  207. const h = this._context.gl;
  208. let _ = null;
  209. const l = A(t2), m = this._descriptor.isImmutable;
  210. if (l) {
  211. if (this._context.type !== o.WEBGL2)
  212. throw new Error("3D textures are not supported in WebGL1");
  213. _ = h;
  214. }
  215. m ? r(p) && (l ? _.compressedTexSubImage3D(t2, i2, 0, 0, 0, s2, o2, n2, r2, p) : h.compressedTexSubImage2D(t2, i2, 0, 0, s2, o2, r2, p)) : l ? _.compressedTexImage3D(t2, i2, r2, s2, o2, n2, 0, p) : h.compressedTexImage2D(t2, i2, r2, s2, o2, 0, p);
  216. }
  217. _forEachMipmapLevel(t2, e2 = 1 / 0) {
  218. let { width: i2, height: r2, depth: a, hasMipmap: s2, target: n2 } = this._descriptor;
  219. const p = n2 === M.TEXTURE_3D;
  220. for (let o2 = 0; t2(o2, i2, r2, a), s2 && (i2 !== 1 || r2 !== 1 || p && a !== 1) && !(o2 >= e2); ++o2)
  221. i2 = Math.max(1, i2 >> 1), r2 = Math.max(1, r2 >> 1), p && (a = Math.max(1, a >> 1));
  222. }
  223. static _validateTexture(e2, i2) {
  224. (i2.width < 0 || i2.height < 0 || i2.depth < 0) && console.error("Negative dimension parameters are not allowed!");
  225. const r2 = n(e2.gl), a = i(i2.width) && i(i2.height);
  226. r2 || !i2.isImmutable && !A(i2.target) || console.error("Immutable and 3D-like textures are not supported in WebGL1!"), r2 || a || (typeof i2.wrapMode == "number" ? i2.wrapMode !== D.CLAMP_TO_EDGE && console.error("Non-power-of-two textures must have a wrap mode of CLAMP_TO_EDGE!") : i2.wrapMode.s === D.CLAMP_TO_EDGE && i2.wrapMode.t === D.CLAMP_TO_EDGE || console.error("Non-power-of-two textures must have a wrap mode of CLAMP_TO_EDGE!"), i2.hasMipmap && console.error("Mipmapping requires power-of-two textures!"));
  227. }
  228. static _applySamplingMode(t2, e2) {
  229. let i2 = e2.samplingMode, r2 = e2.samplingMode;
  230. i2 === L.LINEAR_MIPMAP_NEAREST || i2 === L.LINEAR_MIPMAP_LINEAR ? (i2 = L.LINEAR, e2.hasMipmap || (r2 = L.LINEAR)) : i2 !== L.NEAREST_MIPMAP_NEAREST && i2 !== L.NEAREST_MIPMAP_LINEAR || (i2 = L.NEAREST, e2.hasMipmap || (r2 = L.NEAREST)), t2.texParameteri(e2.target, t2.TEXTURE_MAG_FILTER, i2), t2.texParameteri(e2.target, t2.TEXTURE_MIN_FILTER, r2);
  231. }
  232. static _applyWrapMode(t2, e2) {
  233. typeof e2.wrapMode == "number" ? (t2.texParameteri(e2.target, t2.TEXTURE_WRAP_S, e2.wrapMode), t2.texParameteri(e2.target, t2.TEXTURE_WRAP_T, e2.wrapMode)) : (t2.texParameteri(e2.target, t2.TEXTURE_WRAP_S, e2.wrapMode.s), t2.texParameteri(e2.target, t2.TEXTURE_WRAP_T, e2.wrapMode.t));
  234. }
  235. static _applyAnisotropicFilteringParameters(t2, e2) {
  236. const i2 = t2.capabilities.textureFilterAnisotropic;
  237. if (!i2)
  238. return;
  239. t2.gl.texParameterf(e2.target, i2.TEXTURE_MAX_ANISOTROPY, e2.maxAnisotropy ?? 1);
  240. }
  241. };
  242. function E(t2) {
  243. return t2 in U;
  244. }
  245. function T(t2) {
  246. return t2 in u;
  247. }
  248. function g(t2) {
  249. return r(t2) && "type" in t2 && t2.type === "compressed";
  250. }
  251. function x(t2) {
  252. return r(t2) && "byteLength" in t2;
  253. }
  254. function M2(t2) {
  255. return r(t2) && !g(t2) && !x(t2);
  256. }
  257. function A(t2) {
  258. return t2 === M.TEXTURE_3D || t2 === M.TEXTURE_2D_ARRAY;
  259. }
  260. function I(t2, e2, i2, r2 = 1) {
  261. let a = Math.max(e2, i2);
  262. return t2 === M.TEXTURE_3D && (a = Math.max(a, r2)), Math.round(Math.log(a) / Math.LN2) + 1;
  263. }
  264. u2.TEXTURE_UNIT_FOR_UPDATES = 0;
  265. export {
  266. n,
  267. u2 as u
  268. };
  269. //# sourceMappingURL=chunk-546QCRS4.js.map