chunk-GDB2KX4Y.js 31 KB

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