chunk-WBWQJQK4.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. import {
  2. E,
  3. a as a3,
  4. u as u2
  5. } from "./chunk-H2VOWDMO.js";
  6. import {
  7. A,
  8. B,
  9. C,
  10. D,
  11. F,
  12. G,
  13. L,
  14. M,
  15. P,
  16. U,
  17. V,
  18. Y,
  19. c,
  20. f,
  21. n,
  22. t as t2,
  23. u
  24. } from "./chunk-3OFVLRSL.js";
  25. import {
  26. r as r2
  27. } from "./chunk-RWQH5X3O.js";
  28. import {
  29. s2
  30. } from "./chunk-E5O6P5I2.js";
  31. import {
  32. a as a2,
  33. i2 as i,
  34. s2 as s
  35. } from "./chunk-2TIUKVZN.js";
  36. import {
  37. a,
  38. d,
  39. r,
  40. t
  41. } from "./chunk-YXWMMD76.js";
  42. // node_modules/@arcgis/core/views/webgl/Util.js
  43. function i2(e) {
  44. const r3 = e.gl;
  45. switch (r3.getError()) {
  46. case r3.NO_ERROR:
  47. return null;
  48. case r3.INVALID_ENUM:
  49. return "An unacceptable value has been specified for an enumerated argument";
  50. case r3.INVALID_VALUE:
  51. return "A numeric argument is out of range";
  52. case r3.INVALID_OPERATION:
  53. return "The specified command is not allowed for the current state";
  54. case r3.INVALID_FRAMEBUFFER_OPERATION:
  55. return "The currently bound framebuffer is not framebuffer complete";
  56. case r3.OUT_OF_MEMORY:
  57. return "Not enough memory is left to execute the command";
  58. case r3.CONTEXT_LOST_WEBGL:
  59. return "WebGL context is lost";
  60. }
  61. return "Unknown error";
  62. }
  63. function n2(e, r3) {
  64. return e.vertexBuffers[r3].size / o(e.layout[r3]);
  65. }
  66. function o(e) {
  67. return e[0].stride;
  68. }
  69. function R(e, r3, t3, s4, a5 = 0) {
  70. const c3 = e.gl, i3 = e.capabilities.instancing;
  71. e.bindBuffer(t3);
  72. for (const n3 of s4) {
  73. const e2 = r3.get(n3.name);
  74. void 0 === e2 && console.error(`There is no location for vertex attribute '${n3.name}' defined.`);
  75. const t4 = a5 * n3.stride;
  76. if (n3.count <= 4)
  77. c3.vertexAttribPointer(e2, n3.count, n3.type, n3.normalized, n3.stride, n3.offset + t4), c3.enableVertexAttribArray(e2), n3.divisor > 0 && i3 && i3.vertexAttribDivisor(e2, n3.divisor);
  78. else if (9 === n3.count)
  79. for (let r4 = 0; r4 < 3; r4++)
  80. c3.vertexAttribPointer(e2 + r4, 3, n3.type, n3.normalized, n3.stride, n3.offset + 12 * r4 + t4), c3.enableVertexAttribArray(e2 + r4), n3.divisor > 0 && i3 && i3.vertexAttribDivisor(e2 + r4, n3.divisor);
  81. else if (16 === n3.count)
  82. for (let r4 = 0; r4 < 4; r4++)
  83. c3.vertexAttribPointer(e2 + r4, 4, n3.type, n3.normalized, n3.stride, n3.offset + 16 * r4 + t4), c3.enableVertexAttribArray(e2 + r4), n3.divisor > 0 && i3 && i3.vertexAttribDivisor(e2 + r4, n3.divisor);
  84. else
  85. console.error("Unsupported vertex attribute element count: " + n3.count);
  86. }
  87. }
  88. function E2(e, t3, s4, a5) {
  89. const c3 = e.gl, i3 = e.capabilities.instancing;
  90. e.bindBuffer(s4);
  91. for (const r3 of a5) {
  92. const e2 = t3.get(r3.name);
  93. if (r3.count <= 4)
  94. c3.disableVertexAttribArray(e2), r3.divisor && r3.divisor > 0 && i3 && i3.vertexAttribDivisor(e2, 0);
  95. else if (9 === r3.count)
  96. for (let t4 = 0; t4 < 3; t4++)
  97. c3.disableVertexAttribArray(e2 + t4), r3.divisor && r3.divisor > 0 && i3 && i3.vertexAttribDivisor(e2 + t4, 0);
  98. else if (16 === r3.count)
  99. for (let t4 = 0; t4 < 4; t4++)
  100. c3.disableVertexAttribArray(e2 + t4), r3.divisor && r3.divisor > 0 && i3 && i3.vertexAttribDivisor(e2 + t4, 0);
  101. else
  102. console.error("Unsupported vertex attribute element count: " + r3.count);
  103. }
  104. e.unbindBuffer(A.ARRAY_BUFFER);
  105. }
  106. function _(e) {
  107. switch (e) {
  108. case P.ALPHA:
  109. case P.LUMINANCE:
  110. case P.RED:
  111. case P.RED_INTEGER:
  112. case U.R8:
  113. case U.R8I:
  114. case U.R8UI:
  115. case U.R8_SNORM:
  116. case B.STENCIL_INDEX8:
  117. return 1;
  118. case P.LUMINANCE_ALPHA:
  119. case P.RG:
  120. case P.RG_INTEGER:
  121. case U.RGBA4:
  122. case U.R16F:
  123. case U.R16I:
  124. case U.R16UI:
  125. case U.RG8:
  126. case U.RG8I:
  127. case U.RG8UI:
  128. case U.RG8_SNORM:
  129. case U.RGB565:
  130. case U.RGB5_A1:
  131. case B.DEPTH_COMPONENT16:
  132. return 2;
  133. case P.DEPTH_COMPONENT:
  134. case P.RGB:
  135. case P.RGB_INTEGER:
  136. case U.RGB8:
  137. case U.RGB8I:
  138. case U.RGB8UI:
  139. case U.RGB8_SNORM:
  140. case U.SRGB8:
  141. case B.DEPTH_COMPONENT24:
  142. return 3;
  143. case P.DEPTH_STENCIL:
  144. case P.RGBA:
  145. case P.RGBA_INTEGER:
  146. case U.RGBA8:
  147. case U.R32F:
  148. case U.R11F_G11F_B10F:
  149. case U.RG16F:
  150. case U.R32I:
  151. case U.R32UI:
  152. case U.RG16I:
  153. case U.RG16UI:
  154. case U.RGBA8I:
  155. case U.RGBA8UI:
  156. case U.RGBA8_SNORM:
  157. case U.SRGB8_ALPHA8:
  158. case U.RGB9_E5:
  159. case U.RGB10_A2UI:
  160. case U.RGB10_A2:
  161. case B.DEPTH_STENCIL:
  162. case B.DEPTH_COMPONENT32F:
  163. case B.DEPTH24_STENCIL8:
  164. return 4;
  165. case B.DEPTH32F_STENCIL8:
  166. return 5;
  167. case U.RGB16F:
  168. case U.RGB16I:
  169. case U.RGB16UI:
  170. return 6;
  171. case U.RG32F:
  172. case U.RG32I:
  173. case U.RG32UI:
  174. case U.RGBA16F:
  175. case U.RGBA16I:
  176. case U.RGBA16UI:
  177. return 8;
  178. case U.RGB32F:
  179. case U.RGB32I:
  180. case U.RGB32UI:
  181. return 12;
  182. case U.RGBA32F:
  183. case U.RGBA32I:
  184. case U.RGBA32UI:
  185. return 16;
  186. case u.COMPRESSED_RGB_S3TC_DXT1_EXT:
  187. case u.COMPRESSED_RGBA_S3TC_DXT1_EXT:
  188. return 0.5;
  189. case u.COMPRESSED_RGBA_S3TC_DXT3_EXT:
  190. case u.COMPRESSED_RGBA_S3TC_DXT5_EXT:
  191. return 1;
  192. case u.COMPRESSED_R11_EAC:
  193. case u.COMPRESSED_SIGNED_R11_EAC:
  194. case u.COMPRESSED_RGB8_ETC2:
  195. case u.COMPRESSED_SRGB8_ETC2:
  196. case u.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
  197. case u.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
  198. return 0.5;
  199. case u.COMPRESSED_RG11_EAC:
  200. case u.COMPRESSED_SIGNED_RG11_EAC:
  201. case u.COMPRESSED_RGBA8_ETC2_EAC:
  202. case u.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
  203. return 1;
  204. }
  205. return 0;
  206. }
  207. function u3(r3) {
  208. if (t(r3))
  209. return 0;
  210. if ("descriptor" in r3)
  211. return r3.glName ? u3(r3.descriptor) : 0;
  212. const t3 = r3.internalFormat || "pixelFormat" in r3 && r3.pixelFormat;
  213. if (!t3)
  214. return 0;
  215. const s4 = "hasMipmap" in r3 && r3.hasMipmap ? 1.3 : 1, a5 = r3.width * r3.height;
  216. return _(t3) * a5 * s4;
  217. }
  218. // node_modules/@arcgis/core/views/webgl/VertexArrayObject.js
  219. var f2 = s2.getLogger("esri.views.webgl.VertexArrayObject");
  220. var a4 = class {
  221. constructor(t3, e, i3, r3, n3 = null) {
  222. this._context = t3, this._locations = e, this._layout = i3, this._buffers = r3, this._indexBuffer = n3, this._glName = null, this._initialized = false, t3.instanceCounter.increment(t2.VertexArrayObject, this);
  223. }
  224. get glName() {
  225. return this._glName;
  226. }
  227. get context() {
  228. return this._context;
  229. }
  230. get vertexBuffers() {
  231. return this._buffers;
  232. }
  233. get indexBuffer() {
  234. return this._indexBuffer;
  235. }
  236. get size() {
  237. return Object.keys(this._buffers).reduce((t3, e) => t3 + this._buffers[e].size, r(this._indexBuffer) ? this._indexBuffer.size : 0);
  238. }
  239. get layout() {
  240. return this._layout;
  241. }
  242. get locations() {
  243. return this._locations;
  244. }
  245. dispose(t3 = true) {
  246. var _a2, _b, _c;
  247. if (!this._context)
  248. return void ((this._glName || t3 && Object.getOwnPropertyNames(this._buffers).length > 0) && f2.warn("Leaked WebGL VAO"));
  249. if (this._glName) {
  250. const t4 = (_b = (_a2 = this._context) == null ? void 0 : _a2.capabilities) == null ? void 0 : _b.vao;
  251. t4 ? (t4.deleteVertexArray(this._glName), this._glName = null) : f2.warn("Leaked WebGL VAO");
  252. }
  253. if (this._context.getBoundVAO() === this && this._context.bindVAO(null), t3) {
  254. for (const t4 in this._buffers)
  255. (_c = this._buffers[t4]) == null ? void 0 : _c.dispose(), delete this._buffers[t4];
  256. this._indexBuffer = a(this._indexBuffer);
  257. }
  258. this._context.instanceCounter.decrement(t2.VertexArrayObject, this), this._context = d(this._context);
  259. }
  260. initialize() {
  261. if (this._initialized)
  262. return;
  263. const t3 = this._context.capabilities.vao;
  264. if (t3) {
  265. const e = t3.createVertexArray();
  266. t3.bindVertexArray(e), this._bindLayout(), t3.bindVertexArray(null), this._glName = e;
  267. }
  268. this._initialized = true;
  269. }
  270. bind() {
  271. this.initialize();
  272. const t3 = this._context.capabilities.vao;
  273. t3 ? t3.bindVertexArray(this.glName) : (this._context.bindVAO(null), this._bindLayout());
  274. }
  275. _bindLayout() {
  276. const { _buffers: t3, _layout: i3, _indexBuffer: r3 } = this;
  277. t3 || f2.error("Vertex buffer dictionary is empty!");
  278. const s4 = this._context.gl;
  279. for (const e in t3) {
  280. const r4 = t3[e];
  281. r4 || f2.error("Vertex buffer is uninitialized!");
  282. const s5 = i3[e];
  283. s5 || f2.error("Vertex element descriptor is empty!"), R(this._context, this._locations, r4, s5);
  284. }
  285. if (r(r3)) {
  286. !!this._context.capabilities.vao ? s4.bindBuffer(s4.ELEMENT_ARRAY_BUFFER, r3.glName) : this._context.bindBuffer(r3);
  287. }
  288. }
  289. unbind() {
  290. this.initialize();
  291. const t3 = this._context.capabilities.vao;
  292. t3 ? t3.bindVertexArray(null) : this._unbindLayout();
  293. }
  294. _unbindLayout() {
  295. const { _buffers: t3, _layout: i3 } = this;
  296. t3 || f2.error("Vertex buffer dictionary is empty!");
  297. for (const e in t3) {
  298. const r3 = t3[e];
  299. r3 || f2.error("Vertex buffer is uninitialized!");
  300. const s4 = i3[e];
  301. E2(this._context, this._locations, r3, s4);
  302. }
  303. r(this._indexBuffer) && this._context.unbindBuffer(this._indexBuffer.bufferType);
  304. }
  305. };
  306. // node_modules/@arcgis/core/views/webgl/BufferObject.js
  307. var c2 = s2.getLogger("esri.views.webgl.BufferObject");
  308. function b(t3) {
  309. return a2(t3);
  310. }
  311. var E3 = class {
  312. constructor(e, t3, r3, i3) {
  313. this._context = e, this.bufferType = t3, this.usage = r3, this._glName = null, this._size = -1, this._indexType = void 0, e.instanceCounter.increment(t2.BufferObject, this), this._glName = this._context.gl.createBuffer(), u2(this._context.gl), i3 && this.setData(i3);
  314. }
  315. static createIndex(e, t3, r3) {
  316. return new E3(e, A.ELEMENT_ARRAY_BUFFER, t3, r3);
  317. }
  318. static createVertex(e, t3, r3) {
  319. return new E3(e, A.ARRAY_BUFFER, t3, r3);
  320. }
  321. static createUniform(e, t3, r3) {
  322. if (e.type !== r2.WEBGL2)
  323. throw new Error("Uniform buffers are supported in WebGL2 only!");
  324. return new E3(e, A.UNIFORM_BUFFER, t3, r3);
  325. }
  326. static createPixelPack(e, t3 = F.STREAM_READ, r3) {
  327. if (e.type !== r2.WEBGL2)
  328. throw new Error("Pixel pack buffers are supported in WebGL2 only!");
  329. const i3 = new E3(e, A.PIXEL_PACK_BUFFER, t3);
  330. return r3 && i3.setSize(r3), i3;
  331. }
  332. static createPixelUnpack(e, t3 = F.STREAM_DRAW, r3) {
  333. if (e.type !== r2.WEBGL2)
  334. throw new Error("Pixel unpack buffers are supported in WebGL2 only!");
  335. return new E3(e, A.PIXEL_UNPACK_BUFFER, t3, r3);
  336. }
  337. get glName() {
  338. return this._glName;
  339. }
  340. get size() {
  341. return this._size;
  342. }
  343. get indexType() {
  344. return this._indexType;
  345. }
  346. get byteSize() {
  347. return this.bufferType === A.ELEMENT_ARRAY_BUFFER ? this._indexType === C.UNSIGNED_INT ? 4 * this._size : 2 * this._size : this._size;
  348. }
  349. get _isVAOAware() {
  350. return this.bufferType === A.ELEMENT_ARRAY_BUFFER || this.bufferType === A.ARRAY_BUFFER;
  351. }
  352. dispose() {
  353. var _a;
  354. if ((_a = this._context) == null ? void 0 : _a.gl) {
  355. if (this._glName) {
  356. this._context.gl.deleteBuffer(this._glName), this._glName = null;
  357. }
  358. this._context.instanceCounter.decrement(t2.BufferObject, this), this._context = d(this._context);
  359. } else
  360. this._glName && c2.warn("Leaked WebGL buffer object");
  361. }
  362. setSize(e, t3 = null) {
  363. if (e <= 0 && c2.error("Buffer size needs to be positive!"), this.bufferType === A.ELEMENT_ARRAY_BUFFER && r(t3))
  364. switch (this._indexType = t3, t3) {
  365. case C.UNSIGNED_SHORT:
  366. e *= 2;
  367. break;
  368. case C.UNSIGNED_INT:
  369. e *= 4;
  370. }
  371. this._setBufferData(e);
  372. }
  373. setData(e) {
  374. if (!e)
  375. return;
  376. let t3 = e.byteLength;
  377. this.bufferType === A.ELEMENT_ARRAY_BUFFER && (i(e) && (t3 /= 2, this._indexType = C.UNSIGNED_SHORT), s(e) && (t3 /= 4, this._indexType = C.UNSIGNED_INT)), this._setBufferData(t3, e);
  378. }
  379. _setBufferData(e, t3 = null) {
  380. this._size = e;
  381. const r3 = this._context.getBoundVAO();
  382. this._isVAOAware && this._context.bindVAO(null), this._context.bindBuffer(this);
  383. const s4 = this._context.gl;
  384. r(t3) ? s4.bufferData(this.bufferType, t3, this.usage) : s4.bufferData(this.bufferType, e, this.usage), u2(s4), this._isVAOAware && this._context.bindVAO(r3);
  385. }
  386. setSubData(e, t3, r3, i3) {
  387. if (!e)
  388. return;
  389. (t3 < 0 || t3 >= this._size) && c2.error("offset is out of range!"), r3 >= i3 && c2.error("end must be bigger than start!"), t3 + (i3 - r3) > this._size && c2.error("An attempt to write beyond the end of the buffer!");
  390. const s4 = this._context.getBoundVAO();
  391. this._isVAOAware && this._context.bindVAO(null), this._context.bindBuffer(this);
  392. const n3 = this._context.gl;
  393. if (this._context.type === r2.WEBGL2)
  394. n3.bufferSubData(this.bufferType, t3 * e.BYTES_PER_ELEMENT, e, r3, i3 - r3);
  395. else {
  396. const s5 = 0 === r3 && i3 === e.length ? e : e.subarray(r3, i3);
  397. n3.bufferSubData(this.bufferType, t3 * e.BYTES_PER_ELEMENT, s5);
  398. }
  399. u2(n3), this._isVAOAware && this._context.bindVAO(s4);
  400. }
  401. getSubData(e, t3 = 0, r3, i3) {
  402. if (this._context.type !== r2.WEBGL2)
  403. return void c2.error("Get buffer subdata is supported in WebGL2 only!");
  404. if (r3 < 0 || i3 < 0)
  405. return void c2.error("Problem getting subdata: offset and length were less than zero!");
  406. const s4 = b(e) ? e.BYTES_PER_ELEMENT : 1;
  407. if (s4 * ((r3 != null ? r3 : 0) + (i3 != null ? i3 : 0)) > e.byteLength)
  408. return void c2.error("Problem getting subdata: offset and length exceeded destination size!");
  409. t3 + s4 * (i3 != null ? i3 : 0) > this.byteSize && c2.warn("Potential problem getting subdata: requested data exceeds buffer size!");
  410. const n3 = this._context.gl;
  411. this._context.bindBuffer(this, A.COPY_READ_BUFFER), n3.getBufferSubData(A.COPY_READ_BUFFER, t3, e, r3, i3), this._context.unbindBuffer(A.COPY_READ_BUFFER);
  412. }
  413. async getSubDataAsync(e, t3 = 0, r3, i3) {
  414. this._context.type === r2.WEBGL2 ? (await this._context.clientWaitAsync(), this.getSubData(e, t3, r3, i3)) : c2.error("Get buffer subdata is supported in WebGL2 only!");
  415. }
  416. };
  417. // node_modules/@arcgis/core/views/webgl/Renderbuffer.js
  418. var s3 = class {
  419. constructor(e, s4) {
  420. this._context = e, this._desc = s4, this.type = "renderbuffer", this._context.instanceCounter.increment(t2.Renderbuffer, this);
  421. const i3 = this._context.gl;
  422. this.glName = i3.createRenderbuffer(), this._context.bindRenderbuffer(this);
  423. const { width: n3, height: o2, internalFormat: h, multisampled: c3 } = s4;
  424. if (c3) {
  425. if (this._context.type !== r2.WEBGL2)
  426. throw new Error("Multisampled renderbuffers are not supported in WebGL1!");
  427. i3.renderbufferStorageMultisample(i3.RENDERBUFFER, this.samples, h, n3, o2);
  428. } else
  429. i3.renderbufferStorage(i3.RENDERBUFFER, h, n3, o2);
  430. }
  431. get descriptor() {
  432. return this._desc;
  433. }
  434. get samples() {
  435. const e = this._desc.samples, t3 = this._context.parameters.maxSamples;
  436. return e ? Math.min(e, t3) : t3;
  437. }
  438. resize(e, t3) {
  439. const r3 = this._desc;
  440. if (r3.width === e && r3.height === t3)
  441. return;
  442. r3.width = e, r3.height = t3;
  443. const s4 = this._context.gl;
  444. if (this._context.bindRenderbuffer(this), r3.multisampled) {
  445. s4.renderbufferStorageMultisample(s4.RENDERBUFFER, this.samples, r3.internalFormat, r3.width, r3.height);
  446. } else
  447. s4.renderbufferStorage(s4.RENDERBUFFER, r3.internalFormat, r3.width, r3.height);
  448. }
  449. dispose() {
  450. this._context && (this._context.gl.deleteRenderbuffer(this.glName), this._context.instanceCounter.decrement(t2.Renderbuffer, this), this._context = d(this._context));
  451. }
  452. };
  453. // node_modules/@arcgis/core/views/webgl/FramebufferObject.js
  454. var x = class {
  455. constructor(t3, i3, r3 = null, h = null) {
  456. var _a;
  457. if (this._context = t3, this._glName = null, this._depthAttachment = null, this._stencilAttachment = null, this._colorAttachments = /* @__PURE__ */ new Map(), this._depthStencilTexture = null, this._initialized = false, this._desc = { ...i3 }, t3.instanceCounter.increment(t2.FramebufferObject, this), r(r3)) {
  458. Array.isArray(r3) || (r3 = [r3]);
  459. for (let t4 = 0; t4 < r3.length; ++t4) {
  460. const e = r3[t4], i4 = f.COLOR_ATTACHMENT0 + t4;
  461. let h2;
  462. C2(e) ? (b2(e) ? (h2 = e.descriptor, this._colorAttachments.set(i4, e)) : (h2 = e, this._colorAttachments.set(i4, new E(this._context, h2))), U2(h2, this._desc)) : (D2(e) ? (h2 = e.descriptor, this._colorAttachments.set(i4, e)) : (h2 = e, this._colorAttachments.set(i4, new s3(this._context, h2))), H(h2, this._desc)), this._validateColorAttachmentPoint(i4);
  463. }
  464. }
  465. if (r(h)) {
  466. let t4, e;
  467. if (C2(h))
  468. this._context.capabilities.depthTexture || console.error("Setting the depth/stencil texture as an attachment requires WEBGL_depth_texture or WebGL2"), b2(h) ? (e = h.descriptor, this._depthStencilTexture = h) : (e = h, this._depthStencilTexture = new E(this._context, e)), U2(e, this._desc);
  469. else {
  470. D2(h) ? (e = h.descriptor, t4 = h) : (e = h, t4 = new s3(this._context, e));
  471. const i4 = (_a = this._desc.depthStencilTarget) != null ? _a : V.DEPTH_STENCIL_RENDER_BUFFER;
  472. i4 === V.STENCIL_RENDER_BUFFER ? this._stencilAttachment = t4 : i4 === V.DEPTH_RENDER_BUFFER || i4 === V.DEPTH_STENCIL_RENDER_BUFFER ? this._depthAttachment = t4 : console.error('If a Renderbuffer is provided, "depthStencilTarget" must be one of STENCIL_RENDER_BUFFER, DEPTH_RENDER_BUFFER or DEPTH_STENCIL_RENDER_BUFFER'), this._desc.depthStencilTarget = i4, H(e, this._desc);
  473. }
  474. }
  475. }
  476. dispose() {
  477. if (!this._desc)
  478. return;
  479. const t3 = this._context.getBoundFramebufferObject();
  480. if (this._disposeColorAttachments(), this._disposeDepthStencilAttachments(), this._glName) {
  481. this._context.gl.deleteFramebuffer(this._glName), this._glName = null;
  482. }
  483. this._context.bindFramebuffer(t3), this._context.instanceCounter.decrement(t2.FramebufferObject, this), this._desc = null;
  484. }
  485. get glName() {
  486. return this._glName;
  487. }
  488. get descriptor() {
  489. return this._desc;
  490. }
  491. get colorTexture() {
  492. const t3 = this._colorAttachments.get(f.COLOR_ATTACHMENT0);
  493. return t3 && b2(t3) ? t3 : null;
  494. }
  495. get colorAttachment() {
  496. return this._colorAttachments.get(f.COLOR_ATTACHMENT0);
  497. }
  498. get depthStencilAttachment() {
  499. return this._depthStencilTexture || this._depthAttachment || this._stencilAttachment;
  500. }
  501. get depthStencilTexture() {
  502. return this._depthStencilTexture;
  503. }
  504. get width() {
  505. var _a;
  506. return (_a = this._desc.width) != null ? _a : 0;
  507. }
  508. get height() {
  509. var _a;
  510. return (_a = this._desc.height) != null ? _a : 0;
  511. }
  512. get gpuMemoryUsage() {
  513. return [...this._colorAttachments].reduce((t3, [e, i3]) => t3 + u3(i3), 0) + u3(this.depthStencilAttachment);
  514. }
  515. getColorTexture(t3) {
  516. const e = this._colorAttachments.get(t3);
  517. return e && b2(e) ? e : null;
  518. }
  519. attachColorTexture(t3, e = f.COLOR_ATTACHMENT0) {
  520. if (!t3)
  521. return;
  522. this._validateColorAttachmentPoint(e);
  523. U2(t3.descriptor, this._desc), this._disposeColorAttachments(), this._initialized && (this._context.bindFramebuffer(this), this._framebufferTexture2D(t3.glName, e)), this._colorAttachments.set(e, t3);
  524. }
  525. detachColorTexture(t3 = f.COLOR_ATTACHMENT0) {
  526. const e = this._colorAttachments.get(t3);
  527. if (b2(e)) {
  528. const i3 = e;
  529. return this._initialized && (this._context.bindFramebuffer(this), this._framebufferTexture2D(null, t3)), this._colorAttachments.delete(t3), i3;
  530. }
  531. }
  532. setColorTextureTarget(t3, e = f.COLOR_ATTACHMENT0) {
  533. const i3 = this._colorAttachments.get(e);
  534. b2(i3) && this._framebufferTexture2D(i3.glName, e, t3);
  535. }
  536. attachDepthStencilTexture(t3) {
  537. if (t(t3))
  538. return;
  539. const e = t3.descriptor;
  540. e.pixelFormat !== P.DEPTH_STENCIL && console.error("Depth/Stencil texture must have a pixel type of DEPTH_STENCIL!"), e.dataType !== G.UNSIGNED_INT_24_8 && console.error("Depth/Stencil texture must have data type of UNSIGNED_INT_24_8!"), this._context.capabilities.depthTexture || console.error("Extension WEBGL_depth_texture isn't supported therefore it is no possible to set the depth/stencil texture!"), U2(e, this._desc), this._desc.depthStencilTarget && this._desc.depthStencilTarget !== V.DEPTH_STENCIL_TEXTURE && (this._desc.depthStencilTarget = V.DEPTH_STENCIL_TEXTURE), this._disposeDepthStencilAttachments(), this._initialized && (this._context.bindFramebuffer(this), this._framebufferTexture2D(t3.glName, c)), this._depthStencilTexture = t3;
  541. }
  542. detachDepthStencilTexture() {
  543. const t3 = this._depthStencilTexture;
  544. return t3 && this._initialized && (this._context.bindFramebuffer(this), this._framebufferTexture2D(null, c)), this._depthStencilTexture = null, t3;
  545. }
  546. attachDepthStencilBuffer(t3) {
  547. if (t(t3))
  548. return;
  549. const e = t3.descriptor;
  550. if (e.internalFormat !== B.DEPTH_STENCIL && e.internalFormat !== B.DEPTH_COMPONENT16 && console.error("Depth/Stencil buffer must have correct internalFormat"), H(e, this._desc), this._disposeDepthStencilAttachments(), this._desc.depthStencilTarget = e.internalFormat === B.DEPTH_STENCIL ? V.DEPTH_STENCIL_RENDER_BUFFER : V.DEPTH_RENDER_BUFFER, this._initialized) {
  551. this._context.bindFramebuffer(this);
  552. const e2 = this._context.gl, i3 = this._desc.depthStencilTarget === V.DEPTH_RENDER_BUFFER ? e2.DEPTH_ATTACHMENT : e2.DEPTH_STENCIL_ATTACHMENT;
  553. e2.framebufferRenderbuffer(n.FRAMEBUFFER, i3, e2.RENDERBUFFER, t3.glName);
  554. }
  555. this._depthAttachment = t3;
  556. }
  557. detachDepthStencilBuffer() {
  558. const t3 = this._context.gl, e = this._depthAttachment;
  559. if (e && this._initialized) {
  560. this._context.bindFramebuffer(this);
  561. const e2 = this._desc.depthStencilTarget === V.DEPTH_RENDER_BUFFER ? t3.DEPTH_ATTACHMENT : t3.DEPTH_STENCIL_ATTACHMENT;
  562. t3.framebufferRenderbuffer(n.FRAMEBUFFER, e2, t3.RENDERBUFFER, null);
  563. }
  564. return this._depthAttachment = null, e;
  565. }
  566. detachAll() {
  567. this._colorAttachments.forEach((t3, e) => this._detachColorAttachment(e)), this.detachDepthStencilBuffer(), this.detachDepthStencilTexture();
  568. }
  569. copyToTexture(t3, e, i3, r3, h, s4, n3) {
  570. (t3 < 0 || e < 0 || h < 0 || s4 < 0) && console.error("Offsets cannot be negative!"), (i3 <= 0 || r3 <= 0) && console.error("Copy width and height must be greater than zero!");
  571. const c3 = this._desc, o2 = n3.descriptor;
  572. n3.descriptor.target !== M.TEXTURE_2D && console.error("Texture target must be TEXTURE_2D!"), (null == (c3 == null ? void 0 : c3.width) || null == (c3 == null ? void 0 : c3.height) || null == (o2 == null ? void 0 : o2.width) || null == (o2 == null ? void 0 : o2.height) || t3 + i3 > c3.width || e + r3 > c3.height || h + i3 > o2.width || s4 + r3 > o2.height) && console.error("Bad dimensions, the current input values will attempt to read or copy out of bounds!");
  573. const _2 = this._context, a5 = _2.bindTexture(n3, E.TEXTURE_UNIT_FOR_UPDATES);
  574. _2.setActiveTexture(E.TEXTURE_UNIT_FOR_UPDATES), _2.bindFramebuffer(this), _2.gl.copyTexSubImage2D(M.TEXTURE_2D, 0, h, s4, t3, e, i3, r3), _2.bindTexture(a5, E.TEXTURE_UNIT_FOR_UPDATES);
  575. }
  576. readPixels(t3, e, i3, r3, h, s4, n3) {
  577. (i3 <= 0 || r3 <= 0) && console.error("Copy width and height must be greater than zero!"), n3 || console.error("Target memory is not initialized!"), this._context.bindFramebuffer(this);
  578. this._context.gl.readPixels(t3, e, i3, r3, h, s4, n3);
  579. }
  580. async readPixelsAsync(t3, e, i3, n3, c3, o2, _2) {
  581. if (this._context.type !== r2.WEBGL2)
  582. return a3() && console.warn("Attempting to read pixels using pixel buffer object without WebGL2"), void this.readPixels(t3, e, i3, n3, c3, o2, _2);
  583. const a5 = this._context.gl, l = E3.createPixelPack(this._context, F.STREAM_READ, _2.byteLength);
  584. this._context.bindBuffer(l), this._context.bindFramebuffer(this), a5.readPixels(t3, e, i3, n3, c3, o2, 0), this._context.unbindBuffer(A.PIXEL_PACK_BUFFER), await l.getSubDataAsync(_2), l.dispose();
  585. }
  586. resize(t3, e) {
  587. const i3 = this._desc;
  588. if (i3.width !== t3 || i3.height !== e) {
  589. if (!this._initialized)
  590. return i3.width = t3, i3.height = e, this._colorAttachments.forEach((i4) => {
  591. i4 && i4.resize(t3, e);
  592. }), void (this._depthStencilTexture && this._depthStencilTexture.resize(t3, e));
  593. i3.width = t3, i3.height = e, this._colorAttachments.forEach((i4) => {
  594. i4 && i4.resize(t3, e);
  595. }), null != this._depthStencilTexture ? this._depthStencilTexture.resize(t3, e) : (this._depthAttachment || this._stencilAttachment) && (this._depthAttachment && this._depthAttachment.resize(t3, e), this._stencilAttachment && this._stencilAttachment.resize(t3, e)), this._context.getBoundFramebufferObject() === this && this._context.bindFramebuffer(null), this._initialized = false;
  596. }
  597. }
  598. initializeAndBind(t3 = n.FRAMEBUFFER) {
  599. var _a, _b, _c, _d;
  600. const e = this._context.gl;
  601. if (this._initialized)
  602. return void e.bindFramebuffer(t3, this.glName);
  603. this._glName && e.deleteFramebuffer(this._glName);
  604. const i3 = this._context, r3 = e.createFramebuffer(), s4 = this._desc, n3 = (_a = s4.colorTarget) != null ? _a : Y.RENDER_BUFFER, l = (_b = s4.width) != null ? _b : 1, u4 = (_c = s4.height) != null ? _c : 1;
  605. if (e.bindFramebuffer(t3, r3), 0 === this._colorAttachments.size)
  606. if (n3 === Y.TEXTURE || n3 === Y.CUBEMAP)
  607. this._colorAttachments.set(f.COLOR_ATTACHMENT0, S(i3, s4, this.descriptor.colorTarget === Y.CUBEMAP ? M.TEXTURE_CUBE_MAP : M.TEXTURE_2D));
  608. else {
  609. const t4 = new s3(i3, { internalFormat: U.RGBA4, width: l, height: u4 });
  610. this._colorAttachments.set(f.COLOR_ATTACHMENT0, t4);
  611. }
  612. this._colorAttachments.forEach((i4, r4) => {
  613. i4 && (b2(i4) ? this._framebufferTexture2D(i4.glName, r4, P2(i4), t3) : e.framebufferRenderbuffer(t3, r4, e.RENDERBUFFER, i4.glName));
  614. });
  615. const f3 = (_d = s4.depthStencilTarget) != null ? _d : V.NONE;
  616. switch (f3) {
  617. case V.DEPTH_RENDER_BUFFER:
  618. case V.DEPTH_STENCIL_RENDER_BUFFER: {
  619. this._depthAttachment || (this._depthAttachment = new s3(i3, { internalFormat: s4.depthStencilTarget === V.DEPTH_RENDER_BUFFER ? B.DEPTH_COMPONENT16 : B.DEPTH_STENCIL, width: l, height: u4 }));
  620. const r4 = f3 === V.DEPTH_RENDER_BUFFER ? e.DEPTH_ATTACHMENT : e.DEPTH_STENCIL_ATTACHMENT;
  621. e.framebufferRenderbuffer(t3, r4, e.RENDERBUFFER, this._depthAttachment.glName);
  622. break;
  623. }
  624. case V.STENCIL_RENDER_BUFFER:
  625. this._stencilAttachment || (this._stencilAttachment = new s3(i3, { internalFormat: B.STENCIL_INDEX8, width: l, height: u4 })), e.framebufferRenderbuffer(t3, e.STENCIL_ATTACHMENT, e.RENDERBUFFER, this._stencilAttachment.glName);
  626. break;
  627. case V.DEPTH_STENCIL_TEXTURE:
  628. if (!this._depthStencilTexture) {
  629. i3.capabilities.depthTexture || console.error("Extension WEBGL_depth_texture isn't supported therefore it is no possible to set the depth/stencil texture as an attachment!");
  630. const t4 = { target: M.TEXTURE_2D, pixelFormat: P.DEPTH_STENCIL, dataType: G.UNSIGNED_INT_24_8, samplingMode: L.NEAREST, wrapMode: D.CLAMP_TO_EDGE, width: l, height: u4 };
  631. this._depthStencilTexture = new E(i3, t4);
  632. }
  633. this._framebufferTexture2D(this._depthStencilTexture.glName, e.DEPTH_STENCIL_ATTACHMENT, P2(this._depthStencilTexture), t3);
  634. }
  635. if (a3()) {
  636. e.checkFramebufferStatus(t3) !== e.FRAMEBUFFER_COMPLETE && console.error("Framebuffer is incomplete!");
  637. }
  638. this._glName = r3, this._initialized = true;
  639. }
  640. _framebufferTexture2D(t3, e = f.COLOR_ATTACHMENT0, i3 = M.TEXTURE_2D, r3 = n.FRAMEBUFFER, h = 0) {
  641. this._context.gl.framebufferTexture2D(r3, e, i3, t3, h);
  642. }
  643. _detachColorAttachment(t3) {
  644. a3() && console.warn("Detaching an FBO attachment can be a slow due to invalidating framebuffer completeness!");
  645. const e = this._context.gl, i3 = this._colorAttachments.get(t3);
  646. return b2(i3) ? this._initialized && (this._context.bindFramebuffer(this), this._framebufferTexture2D(null, t3)) : this._initialized && (this._context.bindFramebuffer(this), e.framebufferRenderbuffer(n.FRAMEBUFFER, t3, e.RENDERBUFFER, null)), this._colorAttachments.delete(t3), i3;
  647. }
  648. _disposeColorAttachments() {
  649. this._colorAttachments.forEach((t3, e) => {
  650. this._detachColorAttachment(e), t3.dispose();
  651. }), this._colorAttachments.clear();
  652. }
  653. _disposeDepthStencilAttachments() {
  654. const t3 = this._context.gl;
  655. if (this._depthAttachment) {
  656. if (this._initialized) {
  657. this._context.bindFramebuffer(this);
  658. const e = this._desc.depthStencilTarget === V.DEPTH_RENDER_BUFFER ? t3.DEPTH_ATTACHMENT : t3.DEPTH_STENCIL_ATTACHMENT;
  659. t3.framebufferRenderbuffer(n.FRAMEBUFFER, e, t3.RENDERBUFFER, null);
  660. }
  661. this._depthAttachment.dispose(), this._depthAttachment = null;
  662. }
  663. this._stencilAttachment && (this._initialized && (this._context.bindFramebuffer(this), t3.framebufferRenderbuffer(n.FRAMEBUFFER, t3.STENCIL_ATTACHMENT, t3.RENDERBUFFER, null)), this._stencilAttachment.dispose(), this._stencilAttachment = null), this._depthStencilTexture && (this._initialized && (this._context.bindFramebuffer(this), this._framebufferTexture2D(null, t3.DEPTH_STENCIL_ATTACHMENT)), this._depthStencilTexture.dispose(), this._depthStencilTexture = null);
  664. }
  665. _validateColorAttachmentPoint(e) {
  666. if (-1 === x._MAX_COLOR_ATTACHMENTS) {
  667. const t3 = this._context.capabilities.drawBuffers;
  668. if (t3) {
  669. const e2 = this._context.gl;
  670. x._MAX_COLOR_ATTACHMENTS = e2.getParameter(t3.MAX_COLOR_ATTACHMENTS);
  671. } else
  672. x._MAX_COLOR_ATTACHMENTS = 1;
  673. }
  674. const i3 = e - f.COLOR_ATTACHMENT0;
  675. i3 + 1 > x._MAX_COLOR_ATTACHMENTS && s2.getLogger("esri.views.webgl.FrameBufferObject").error("esri.FrameBufferObject", `illegal attachment point for color attachment: ${i3 + 1}. Implementation supports up to ${x._MAX_COLOR_ATTACHMENTS} color attachments`);
  676. }
  677. };
  678. function b2(t3) {
  679. return null != t3 && "type" in t3 && "texture" === t3.type;
  680. }
  681. function D2(t3) {
  682. return null != t3 && "type" in t3 && "renderbuffer" === t3.type;
  683. }
  684. function C2(t3) {
  685. return b2(t3) || null != t3 && "pixelFormat" in t3;
  686. }
  687. function S(t3, e, i3) {
  688. return new E(t3, { target: i3, pixelFormat: P.RGBA, dataType: G.UNSIGNED_BYTE, samplingMode: L.NEAREST, wrapMode: D.CLAMP_TO_EDGE, width: e.width, height: e.height });
  689. }
  690. function U2(t3, e) {
  691. t3.target !== M.TEXTURE_2D && t3.target !== M.TEXTURE_CUBE_MAP && console.error("Texture type must be TEXTURE_2D or TEXTURE_CUBE_MAP!"), void 0 !== e.width && e.width >= 0 && void 0 !== e.height && e.height >= 0 ? e.width === t3.width && e.height === t3.height || console.error("Color attachment texture must match the framebuffer's!") : (e.width = t3.width, e.height = t3.height);
  692. }
  693. function H(t3, e) {
  694. void 0 !== e.width && e.width >= 0 && void 0 !== e.height && e.height >= 0 ? e.width === t3.width && e.height === t3.height || console.error("Renderbuffer dimensions must match the framebuffer's!") : (e.width = t3.width, e.height = t3.height);
  695. }
  696. function P2(t3) {
  697. return t3.descriptor.target === M.TEXTURE_CUBE_MAP ? M.TEXTURE_CUBE_MAP_POSITIVE_X : M.TEXTURE_2D;
  698. }
  699. x._MAX_COLOR_ATTACHMENTS = -1;
  700. export {
  701. i2 as i,
  702. n2 as n,
  703. _,
  704. a4 as a,
  705. E3 as E,
  706. s3 as s,
  707. x
  708. };
  709. //# sourceMappingURL=chunk-WBWQJQK4.js.map