@gjsify/webgl 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/README.md +78 -6
  2. package/lib/esm/canvas-webgl-widget.js +116 -0
  3. package/lib/esm/html-canvas-element.js +31 -50
  4. package/lib/esm/index.js +7 -0
  5. package/lib/esm/index.spec.js +629 -120
  6. package/lib/esm/test-utils.js +87 -0
  7. package/lib/esm/test.js +5 -1
  8. package/lib/esm/utils.js +1 -1
  9. package/lib/esm/webgl-active-info.js +2 -2
  10. package/lib/esm/webgl-buffer.js +2 -3
  11. package/lib/esm/webgl-context-attributes.js +2 -3
  12. package/lib/esm/webgl-framebuffer.js +3 -4
  13. package/lib/esm/webgl-program.js +2 -3
  14. package/lib/esm/webgl-query.js +15 -0
  15. package/lib/esm/webgl-renderbuffer.js +2 -3
  16. package/lib/esm/webgl-rendering-context.js +105 -101
  17. package/lib/esm/webgl-sampler.js +15 -0
  18. package/lib/esm/webgl-shader-precision-format.js +2 -3
  19. package/lib/esm/webgl-shader.js +2 -3
  20. package/lib/esm/webgl-sync.js +15 -0
  21. package/lib/esm/webgl-texture.js +2 -3
  22. package/lib/esm/webgl-transform-feedback.js +15 -0
  23. package/lib/esm/webgl-uniform-location.js +2 -3
  24. package/lib/esm/webgl-vertex-array-object.js +21 -0
  25. package/lib/esm/webgl2-rendering-context.js +591 -0
  26. package/lib/esm/webgl2.spec.js +578 -0
  27. package/lib/types/canvas-webgl-widget.d.ts +509 -0
  28. package/lib/types/extensions/ext-blend-minmax.d.ts +2 -2
  29. package/lib/types/extensions/ext-texture-filter-anisotropic.d.ts +2 -2
  30. package/lib/types/extensions/oes-element-index-unit.d.ts +2 -2
  31. package/lib/types/extensions/oes-standard-derivatives.d.ts +2 -2
  32. package/lib/types/extensions/oes-texture-float-linear.d.ts +2 -2
  33. package/lib/types/extensions/oes-texture-float.d.ts +2 -2
  34. package/lib/types/extensions/stackgl-destroy-context.d.ts +3 -3
  35. package/lib/types/extensions/stackgl-resize-drawing-buffer.d.ts +3 -3
  36. package/lib/types/html-canvas-element.d.ts +19 -31
  37. package/lib/types/index.d.ts +7 -0
  38. package/lib/types/test-utils.d.ts +45 -0
  39. package/lib/types/types/extension.d.ts +2 -2
  40. package/lib/types/utils.d.ts +14 -15
  41. package/lib/types/webgl-active-info.d.ts +1 -2
  42. package/lib/types/webgl-buffer.d.ts +5 -6
  43. package/lib/types/webgl-context-attributes.d.ts +1 -2
  44. package/lib/types/webgl-framebuffer.d.ts +4 -5
  45. package/lib/types/webgl-program.d.ts +4 -5
  46. package/lib/types/webgl-query.d.ts +7 -0
  47. package/lib/types/webgl-renderbuffer.d.ts +4 -5
  48. package/lib/types/webgl-rendering-context.d.ts +15 -13
  49. package/lib/types/webgl-sampler.d.ts +7 -0
  50. package/lib/types/webgl-shader-precision-format.d.ts +1 -2
  51. package/lib/types/webgl-shader.d.ts +4 -5
  52. package/lib/types/webgl-sync.d.ts +7 -0
  53. package/lib/types/webgl-texture-unit.d.ts +3 -3
  54. package/lib/types/webgl-texture.d.ts +6 -7
  55. package/lib/types/webgl-transform-feedback.d.ts +7 -0
  56. package/lib/types/webgl-uniform-location.d.ts +3 -4
  57. package/lib/types/webgl-vertex-array-object.d.ts +9 -0
  58. package/lib/types/webgl-vertex-attribute.d.ts +5 -5
  59. package/lib/types/webgl2-rendering-context.d.ts +124 -0
  60. package/package.json +27 -26
  61. package/prebuilds/linux-aarch64/Gwebgl-0.1.typelib +0 -0
  62. package/prebuilds/linux-aarch64/libgwebgl.so +0 -0
  63. package/prebuilds/linux-x86_64/Gwebgl-0.1.typelib +0 -0
  64. package/prebuilds/linux-x86_64/libgwebgl.so +0 -0
  65. package/lib/cjs/@types/glsl-tokenizer/index.d.js +0 -0
  66. package/lib/cjs/extensions/ext-blend-minmax.js +0 -18
  67. package/lib/cjs/extensions/ext-texture-filter-anisotropic.js +0 -18
  68. package/lib/cjs/extensions/oes-element-index-unit.js +0 -14
  69. package/lib/cjs/extensions/oes-standard-derivatives.js +0 -17
  70. package/lib/cjs/extensions/oes-texture-float-linear.js +0 -14
  71. package/lib/cjs/extensions/oes-texture-float.js +0 -14
  72. package/lib/cjs/extensions/stackgl-destroy-context.js +0 -12
  73. package/lib/cjs/extensions/stackgl-resize-drawing-buffer.js +0 -12
  74. package/lib/cjs/html-canvas-element.js +0 -70
  75. package/lib/cjs/index.js +0 -18
  76. package/lib/cjs/index.spec.js +0 -146
  77. package/lib/cjs/linkable.js +0 -50
  78. package/lib/cjs/test.js +0 -3
  79. package/lib/cjs/types/constructor.js +0 -0
  80. package/lib/cjs/types/extension.js +0 -0
  81. package/lib/cjs/types/index.js +0 -5
  82. package/lib/cjs/types/typed-array.js +0 -0
  83. package/lib/cjs/types/webgl-constants.js +0 -0
  84. package/lib/cjs/types/webgl-context-attribute-options.js +0 -0
  85. package/lib/cjs/utils.js +0 -212
  86. package/lib/cjs/webgl-active-info.js +0 -10
  87. package/lib/cjs/webgl-buffer.js +0 -18
  88. package/lib/cjs/webgl-context-attributes.js +0 -24
  89. package/lib/cjs/webgl-drawing-buffer-wrapper.js +0 -10
  90. package/lib/cjs/webgl-framebuffer.js +0 -109
  91. package/lib/cjs/webgl-program.js +0 -26
  92. package/lib/cjs/webgl-renderbuffer.js +0 -24
  93. package/lib/cjs/webgl-rendering-context.js +0 -3343
  94. package/lib/cjs/webgl-shader-precision-format.js +0 -11
  95. package/lib/cjs/webgl-shader.js +0 -23
  96. package/lib/cjs/webgl-texture-unit.js +0 -12
  97. package/lib/cjs/webgl-texture.js +0 -22
  98. package/lib/cjs/webgl-uniform-location.js +0 -15
  99. package/lib/cjs/webgl-vertex-attribute.js +0 -147
  100. package/meson.build +0 -39
  101. package/src/test/app.vala +0 -60
  102. package/src/ts/@types/glsl-tokenizer/index.d.ts +0 -18
  103. package/src/ts/extensions/angle-instanced-arrays.ts.off +0 -232
  104. package/src/ts/extensions/ext-blend-minmax.ts +0 -18
  105. package/src/ts/extensions/ext-texture-filter-anisotropic.ts +0 -18
  106. package/src/ts/extensions/oes-element-index-unit.ts +0 -14
  107. package/src/ts/extensions/oes-standard-derivatives.ts +0 -17
  108. package/src/ts/extensions/oes-texture-float-linear.ts +0 -14
  109. package/src/ts/extensions/oes-texture-float.ts +0 -14
  110. package/src/ts/extensions/oes-vertex-array-object.ts.off +0 -128
  111. package/src/ts/extensions/stackgl-destroy-context.ts +0 -12
  112. package/src/ts/extensions/stackgl-resize-drawing-buffer.ts +0 -14
  113. package/src/ts/extensions/webgl-draw-buffers.ts.off +0 -107
  114. package/src/ts/html-canvas-element.ts +0 -98
  115. package/src/ts/index.spec.ts +0 -186
  116. package/src/ts/index.ts +0 -21
  117. package/src/ts/linkable.ts +0 -55
  118. package/src/ts/test.ts +0 -6
  119. package/src/ts/types/constructor.ts +0 -3
  120. package/src/ts/types/extension.ts +0 -3
  121. package/src/ts/types/index.ts +0 -26
  122. package/src/ts/types/typed-array.ts +0 -1
  123. package/src/ts/types/webgl-constants.ts +0 -300
  124. package/src/ts/types/webgl-context-attribute-options.ts +0 -12
  125. package/src/ts/utils.ts +0 -266
  126. package/src/ts/webgl-active-info.ts +0 -13
  127. package/src/ts/webgl-buffer.ts +0 -21
  128. package/src/ts/webgl-context-attributes.ts +0 -24
  129. package/src/ts/webgl-drawing-buffer-wrapper.ts +0 -10
  130. package/src/ts/webgl-framebuffer.ts +0 -133
  131. package/src/ts/webgl-program.ts +0 -30
  132. package/src/ts/webgl-renderbuffer.ts +0 -28
  133. package/src/ts/webgl-rendering-context.ts +0 -4050
  134. package/src/ts/webgl-shader-precision-format.ts +0 -12
  135. package/src/ts/webgl-shader.ts +0 -29
  136. package/src/ts/webgl-texture-unit.ts +0 -16
  137. package/src/ts/webgl-texture.ts +0 -27
  138. package/src/ts/webgl-uniform-location.ts +0 -18
  139. package/src/ts/webgl-vertex-attribute.ts +0 -169
  140. package/src/vala/handle-types.vala +0 -23
  141. package/src/vala/webgl-rendering-context-base.vala +0 -1265
  142. package/src/vala/webgl-rendering-context.vala +0 -265
  143. package/src/vapi/epoxy.vapi +0 -14558
  144. package/src/vapi/glesv2.vapi +0 -670
  145. package/test.gjs.js +0 -39937
  146. package/test.gjs.js.meta.json +0 -1
  147. package/tmp/.tsbuildinfo +0 -1
  148. package/tsconfig.json +0 -38
  149. package/tsconfig.types.json +0 -7
@@ -0,0 +1,591 @@
1
+ import Gwebgl from "@girs/gwebgl-0.1";
2
+ import { WebGLRenderingContext } from "./webgl-rendering-context.js";
3
+ import { WebGLQuery } from "./webgl-query.js";
4
+ import { WebGLSampler } from "./webgl-sampler.js";
5
+ import { WebGLSync } from "./webgl-sync.js";
6
+ import { WebGLTransformFeedback } from "./webgl-transform-feedback.js";
7
+ import { WebGLVertexArrayObject } from "./webgl-vertex-array-object.js";
8
+ import { WebGLActiveInfo } from "./webgl-active-info.js";
9
+ import { WebGLTexture } from "./webgl-texture.js";
10
+ import { WebGLRenderbuffer } from "./webgl-renderbuffer.js";
11
+ import { Uint8ArrayToVariant, arrayToUint8Array, vertexCount } from "./utils.js";
12
+ import { warnNotImplemented } from "@gjsify/utils";
13
+ class WebGL2RenderingContext extends WebGLRenderingContext {
14
+ constructor(canvas, options = {}) {
15
+ super(canvas, options);
16
+ this._queries = {};
17
+ this._samplers = {};
18
+ this._transformFeedbacks = {};
19
+ this._vertexArrayObjects = {};
20
+ this._syncs = {};
21
+ this._native2 = new Gwebgl.WebGL2RenderingContext({});
22
+ }
23
+ _getGlslVersion(es) {
24
+ return es ? "300 es" : "130";
25
+ }
26
+ // ─── WebGL2 overrides for WebGL1 validation that's too strict ─────────
27
+ /** WebGL2 allows COLOR_ATTACHMENT1–15 as framebuffer attachment points. */
28
+ _validFramebufferAttachment(attachment) {
29
+ if (super._validFramebufferAttachment(attachment)) return true;
30
+ return attachment >= 36065 && attachment <= 36079;
31
+ }
32
+ /**
33
+ * Apply COLOR_ATTACHMENT1–15 to the native GL FBO when they have attachments.
34
+ * The base class only knows about CA0, DEPTH, STENCIL, DEPTH_STENCIL.
35
+ */
36
+ _updateFramebufferAttachments(framebuffer) {
37
+ super._updateFramebufferAttachments(framebuffer);
38
+ if (!framebuffer) return;
39
+ for (let i = 1; i <= 15; i++) {
40
+ const attachmentEnum = 36064 + i;
41
+ if (!(attachmentEnum in framebuffer._attachments)) continue;
42
+ const attachment = framebuffer._attachments[attachmentEnum];
43
+ if (attachment instanceof WebGLTexture) {
44
+ const face = framebuffer._attachmentFace[attachmentEnum] || this.TEXTURE_2D;
45
+ const level = framebuffer._attachmentLevel[attachmentEnum] ?? 0;
46
+ this._native.framebufferTexture2D(this.FRAMEBUFFER, attachmentEnum, face, attachment._ | 0, level | 0);
47
+ } else if (attachment instanceof WebGLRenderbuffer) {
48
+ this._native.framebufferRenderbuffer(this.FRAMEBUFFER, attachmentEnum, this.RENDERBUFFER, attachment._ | 0);
49
+ } else {
50
+ this._native.framebufferTexture2D(this.FRAMEBUFFER, attachmentEnum, this.TEXTURE_2D, 0, 0);
51
+ }
52
+ }
53
+ }
54
+ /** WebGL2 adds UNIFORM_BUFFER, TRANSFORM_FEEDBACK_BUFFER, etc. targets. */
55
+ bindBuffer(target, buffer) {
56
+ const isWebGL2Target = target === 35345 || target === 35982 || target === 36662 || target === 36663;
57
+ if (isWebGL2Target) {
58
+ const id = buffer ? buffer._ | 0 : 0;
59
+ this._native.bindBuffer(target, id);
60
+ return;
61
+ }
62
+ super.bindBuffer(target, buffer);
63
+ }
64
+ /** WebGL2 adds READ/COPY buffer usages and additional buffer targets. */
65
+ bufferData(target, dataOrSize, usage) {
66
+ const isWebGL2Target = target === 35345 || target === 35982 || target === 36662 || target === 36663;
67
+ const isReadOrCopy = usage === 35041 || usage === 35043 || usage === 35045 || usage === 35042 || usage === 35044 || usage === 35046;
68
+ const remappedUsage = isReadOrCopy ? this.STATIC_DRAW : usage;
69
+ if (isWebGL2Target) {
70
+ if (typeof dataOrSize === "number") {
71
+ if (dataOrSize >= 0) this._native.bufferDataSizeOnly(target, dataOrSize, remappedUsage);
72
+ } else if (dataOrSize !== null && typeof dataOrSize === "object") {
73
+ const u8Data = arrayToUint8Array(dataOrSize);
74
+ this._native.bufferData(target, Uint8ArrayToVariant(u8Data), remappedUsage);
75
+ }
76
+ return;
77
+ }
78
+ super.bufferData(target, dataOrSize, remappedUsage);
79
+ }
80
+ /** WebGL2 adds TEXTURE_3D and TEXTURE_2D_ARRAY target support. */
81
+ bindTexture(target, texture) {
82
+ if (target === 32879 || target === 35866) {
83
+ const id = texture ? texture._ | 0 : 0;
84
+ this._native.bindTexture(target, id);
85
+ if (texture) texture._binding = target;
86
+ return;
87
+ }
88
+ super.bindTexture(target, texture);
89
+ }
90
+ /** WebGL2 adds TEXTURE_3D/TEXTURE_2D_ARRAY targets and TEXTURE_WRAP_R pname. */
91
+ texParameteri(target, pname, param) {
92
+ if (target === 32879 || target === 35866) {
93
+ this._native.texParameteri(target, pname, param);
94
+ return;
95
+ }
96
+ if (pname === 32882) {
97
+ this._native.texParameteri(target, pname, param);
98
+ return;
99
+ }
100
+ super.texParameteri(target, pname, param);
101
+ }
102
+ /**
103
+ * In WebGL2/GLES3 the attribute-0 requirement from WebGL1 does not apply.
104
+ * Override drawArrays to skip the attrib0 hack and call glDrawArrays directly.
105
+ */
106
+ drawArrays(mode, first, count) {
107
+ if (first < 0 || count < 0) {
108
+ this.setError(this.INVALID_VALUE);
109
+ return;
110
+ }
111
+ if (!this._checkStencilState()) return;
112
+ const rc = vertexCount(this, mode, count);
113
+ if (rc < 0) {
114
+ this.setError(this.INVALID_ENUM);
115
+ return;
116
+ }
117
+ if (!this._framebufferOk()) return;
118
+ if (count === 0) return;
119
+ if (this._checkVertexAttribState(count + first - 1 >>> 0)) {
120
+ this._native.drawArrays(mode, first, rc);
121
+ }
122
+ }
123
+ // ─── Vertex Array Objects ─────────────────────────────────────────────
124
+ createVertexArray() {
125
+ const id = this._native2.createVertexArray();
126
+ if (!id) return null;
127
+ const vao = new WebGLVertexArrayObject(id, this);
128
+ this._vertexArrayObjects[id] = vao;
129
+ return vao;
130
+ }
131
+ deleteVertexArray(vertexArray) {
132
+ if (!vertexArray || !(vertexArray instanceof WebGLVertexArrayObject)) return;
133
+ vertexArray._pendingDelete = true;
134
+ vertexArray._checkDelete();
135
+ }
136
+ isVertexArray(vertexArray) {
137
+ if (!vertexArray || !(vertexArray instanceof WebGLVertexArrayObject)) return false;
138
+ return this._native2.isVertexArray(vertexArray._);
139
+ }
140
+ bindVertexArray(array) {
141
+ if (array === null) {
142
+ this._native2.bindVertexArray(0);
143
+ this._vertexObjectState = this._defaultVertexObjectState;
144
+ } else if (array instanceof WebGLVertexArrayObject) {
145
+ this._native2.bindVertexArray(array._);
146
+ this._vertexObjectState = array._objectState;
147
+ } else {
148
+ this.setError(this.INVALID_OPERATION);
149
+ }
150
+ }
151
+ // ─── Query Objects ────────────────────────────────────────────────────
152
+ createQuery() {
153
+ const id = this._native2.createQuery();
154
+ if (!id) return null;
155
+ const query = new WebGLQuery(id, this);
156
+ this._queries[id] = query;
157
+ return query;
158
+ }
159
+ deleteQuery(query) {
160
+ if (!query || !(query instanceof WebGLQuery)) return;
161
+ query._pendingDelete = true;
162
+ query._checkDelete();
163
+ }
164
+ isQuery(query) {
165
+ if (!query || !(query instanceof WebGLQuery)) return false;
166
+ return this._native2.isQuery(query._);
167
+ }
168
+ beginQuery(target, query) {
169
+ if (!(query instanceof WebGLQuery)) return;
170
+ this._native2.beginQuery(target, query._);
171
+ }
172
+ endQuery(target) {
173
+ this._native2.endQuery(target);
174
+ }
175
+ getQuery(_target, _pname) {
176
+ warnNotImplemented("WebGL2RenderingContext.getQuery");
177
+ return null;
178
+ }
179
+ getQueryParameter(query, pname) {
180
+ if (!(query instanceof WebGLQuery)) return null;
181
+ return this._native2.getQueryParameter(query._, pname);
182
+ }
183
+ // ─── Sampler Objects ──────────────────────────────────────────────────
184
+ createSampler() {
185
+ const id = this._native2.createSampler();
186
+ if (!id) return null;
187
+ const sampler = new WebGLSampler(id, this);
188
+ this._samplers[id] = sampler;
189
+ return sampler;
190
+ }
191
+ deleteSampler(sampler) {
192
+ if (!sampler || !(sampler instanceof WebGLSampler)) return;
193
+ sampler._pendingDelete = true;
194
+ sampler._checkDelete();
195
+ }
196
+ isSampler(sampler) {
197
+ if (!sampler || !(sampler instanceof WebGLSampler)) return false;
198
+ return this._native2.isSampler(sampler._);
199
+ }
200
+ bindSampler(unit, sampler) {
201
+ this._native2.bindSampler(unit, sampler ? sampler._ : 0);
202
+ }
203
+ samplerParameteri(sampler, pname, param) {
204
+ if (!(sampler instanceof WebGLSampler)) return;
205
+ this._native2.samplerParameteri(sampler._, pname, param);
206
+ }
207
+ samplerParameterf(sampler, pname, param) {
208
+ if (!(sampler instanceof WebGLSampler)) return;
209
+ this._native2.samplerParameterf(sampler._, pname, param);
210
+ }
211
+ getSamplerParameter(sampler, pname) {
212
+ if (!(sampler instanceof WebGLSampler)) return null;
213
+ if (pname === 33082 || pname === 33083) {
214
+ return this._native2.getSamplerParameterf(sampler._, pname);
215
+ }
216
+ return this._native2.getSamplerParameteri(sampler._, pname);
217
+ }
218
+ // ─── Sync Objects ─────────────────────────────────────────────────────
219
+ fenceSync(condition, flags) {
220
+ const id = this._native2.fenceSync(condition, flags);
221
+ if (!id) return null;
222
+ const sync = new WebGLSync(id, this);
223
+ this._syncs[id] = sync;
224
+ return sync;
225
+ }
226
+ isSync(sync) {
227
+ if (!sync || !(sync instanceof WebGLSync)) return false;
228
+ return this._native2.isSync(sync._);
229
+ }
230
+ deleteSync(sync) {
231
+ if (!sync || !(sync instanceof WebGLSync)) return;
232
+ sync._pendingDelete = true;
233
+ sync._checkDelete();
234
+ }
235
+ clientWaitSync(sync, flags, timeout) {
236
+ if (!(sync instanceof WebGLSync)) return 37148;
237
+ return this._native2.clientWaitSync(sync._, flags, timeout);
238
+ }
239
+ waitSync(sync, flags, timeout) {
240
+ if (!(sync instanceof WebGLSync)) return;
241
+ this._native2.waitSync(sync._, flags, timeout);
242
+ }
243
+ getSyncParameter(sync, pname) {
244
+ if (!(sync instanceof WebGLSync)) return null;
245
+ return this._native2.getSyncParameter(sync._, pname);
246
+ }
247
+ // ─── Transform Feedback ───────────────────────────────────────────────
248
+ createTransformFeedback() {
249
+ const id = this._native2.createTransformFeedback();
250
+ if (!id) return null;
251
+ const tf = new WebGLTransformFeedback(id, this);
252
+ this._transformFeedbacks[id] = tf;
253
+ return tf;
254
+ }
255
+ deleteTransformFeedback(tf) {
256
+ if (!tf || !(tf instanceof WebGLTransformFeedback)) return;
257
+ tf._pendingDelete = true;
258
+ tf._checkDelete();
259
+ }
260
+ isTransformFeedback(tf) {
261
+ if (!tf || !(tf instanceof WebGLTransformFeedback)) return false;
262
+ return this._native2.isTransformFeedback(tf._);
263
+ }
264
+ bindTransformFeedback(target, tf) {
265
+ this._native2.bindTransformFeedback(target, tf ? tf._ : 0);
266
+ }
267
+ beginTransformFeedback(primitiveMode) {
268
+ this._native2.beginTransformFeedback(primitiveMode);
269
+ }
270
+ endTransformFeedback() {
271
+ this._native2.endTransformFeedback();
272
+ }
273
+ pauseTransformFeedback() {
274
+ this._native2.pauseTransformFeedback();
275
+ }
276
+ resumeTransformFeedback() {
277
+ this._native2.resumeTransformFeedback();
278
+ }
279
+ transformFeedbackVaryings(program, varyings, bufferMode) {
280
+ this._native2.transformFeedbackVaryings(program._, varyings, bufferMode);
281
+ }
282
+ getTransformFeedbackVarying(program, index) {
283
+ const result = this._native2.getTransformFeedbackVarying(program._, index).deepUnpack();
284
+ return new WebGLActiveInfo({ size: result.size, type: result.type, name: result.name });
285
+ }
286
+ // ─── Indexed Buffer Binding ───────────────────────────────────────────
287
+ bindBufferBase(target, index, buffer) {
288
+ this._native2.bindBufferBase(target, index, buffer ? buffer._ : 0);
289
+ }
290
+ bindBufferRange(target, index, buffer, offset, size) {
291
+ this._native2.bindBufferRange(target, index, buffer ? buffer._ : 0, offset, size);
292
+ }
293
+ copyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size) {
294
+ this._native2.copyBufferSubData(readTarget, writeTarget, readOffset, writeOffset, size);
295
+ }
296
+ getBufferSubData(target, srcByteOffset, dstBuffer, dstOffset, length) {
297
+ const byteLength = length !== void 0 ? length : dstBuffer.byteLength - (dstOffset ?? 0);
298
+ const data = this._native2.getBufferSubData(target, srcByteOffset, byteLength);
299
+ const dst = new Uint8Array(dstBuffer.buffer, dstBuffer.byteOffset + (dstOffset ?? 0) * (dstBuffer instanceof Uint8Array ? 1 : dstBuffer.BYTES_PER_ELEMENT ?? 1));
300
+ dst.set(data.subarray(0, dst.byteLength));
301
+ }
302
+ // ─── 3D Textures ──────────────────────────────────────────────────────
303
+ texImage3D(target, level, internalformat, width, height, depth, border, format, type, pixels) {
304
+ if (pixels === null) {
305
+ this._native2.texImage3DNull(target, level, internalformat, width, height, depth, border, format, type);
306
+ } else {
307
+ this._native2.texImage3D(target, level, internalformat, width, height, depth, border, format, type, Uint8ArrayToVariant(new Uint8Array(pixels.buffer, pixels.byteOffset, pixels.byteLength)));
308
+ }
309
+ }
310
+ texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, pixels) {
311
+ if (pixels === null) return;
312
+ this._native2.texSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, type, Uint8ArrayToVariant(new Uint8Array(pixels.buffer, pixels.byteOffset, pixels.byteLength)));
313
+ }
314
+ compressedTexImage3D(target, level, internalformat, width, height, depth, border, _imageSize, data) {
315
+ this._native2.compressedTexImage3D(target, level, internalformat, width, height, depth, border, Uint8ArrayToVariant(new Uint8Array(data.buffer, data.byteOffset, data.byteLength)));
316
+ }
317
+ compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, _imageSize, data) {
318
+ this._native2.compressedTexSubImage3D(target, level, xoffset, yoffset, zoffset, width, height, depth, format, Uint8ArrayToVariant(new Uint8Array(data.buffer, data.byteOffset, data.byteLength)));
319
+ }
320
+ copyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height) {
321
+ this._native2.copyTexSubImage3D(target, level, xoffset, yoffset, zoffset, x, y, width, height);
322
+ }
323
+ texStorage2D(target, levels, internalformat, width, height) {
324
+ this._native2.texStorage2D(target, levels, internalformat, width, height);
325
+ }
326
+ texStorage3D(target, levels, internalformat, width, height, depth) {
327
+ this._native2.texStorage3D(target, levels, internalformat, width, height, depth);
328
+ }
329
+ framebufferTextureLayer(target, attachment, texture, level, layer) {
330
+ this._native2.framebufferTextureLayer(target, attachment, texture ? texture._ : 0, level, layer);
331
+ }
332
+ // ─── Instancing & Advanced Draw ───────────────────────────────────────
333
+ drawArraysInstanced(mode, first, count, instanceCount) {
334
+ this._native2.drawArraysInstanced(mode, first, count, instanceCount);
335
+ }
336
+ drawElementsInstanced(mode, count, type, offset, instanceCount) {
337
+ this._native2.drawElementsInstanced(mode, count, type, offset, instanceCount);
338
+ }
339
+ vertexAttribDivisor(index, divisor) {
340
+ this._native2.vertexAttribDivisor(index, divisor);
341
+ }
342
+ vertexAttribIPointer(index, size, type, stride, offset) {
343
+ this._native2.vertexAttribIPointer(index, size, type, stride, offset);
344
+ }
345
+ drawBuffers(buffers) {
346
+ this._native2.drawBuffers(Array.from(buffers));
347
+ }
348
+ drawRangeElements(mode, start, end, count, type, offset) {
349
+ this._native2.drawRangeElements(mode, start, end, count, type, offset);
350
+ }
351
+ blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter) {
352
+ this._native2.blitFramebuffer(srcX0, srcY0, srcX1, srcY1, dstX0, dstY0, dstX1, dstY1, mask, filter);
353
+ }
354
+ invalidateFramebuffer(target, attachments) {
355
+ this._native2.invalidateFramebuffer(target, Array.from(attachments));
356
+ }
357
+ invalidateSubFramebuffer(target, attachments, x, y, width, height) {
358
+ this._native2.invalidateSubFramebuffer(target, Array.from(attachments), x, y, width, height);
359
+ }
360
+ readBuffer(src) {
361
+ this._native2.readBuffer(src);
362
+ }
363
+ renderbufferStorageMultisample(target, samples, internalformat, width, height) {
364
+ this._native2.renderbufferStorageMultisample(target, samples, internalformat, width, height);
365
+ }
366
+ // ─── Unsigned Integer Uniforms ────────────────────────────────────────
367
+ uniform1ui(location, v0) {
368
+ if (!location) return;
369
+ this._native2.uniform1ui(location._, v0);
370
+ }
371
+ uniform2ui(location, v0, v1) {
372
+ if (!location) return;
373
+ this._native2.uniform2ui(location._, v0, v1);
374
+ }
375
+ uniform3ui(location, v0, v1, v2) {
376
+ if (!location) return;
377
+ this._native2.uniform3ui(location._, v0, v1, v2);
378
+ }
379
+ uniform4ui(location, v0, v1, v2, v3) {
380
+ if (!location) return;
381
+ this._native2.uniform4ui(location._, v0, v1, v2, v3);
382
+ }
383
+ uniform1uiv(location, data, _srcOffset, _srcLength) {
384
+ if (!location) return;
385
+ const arr = data instanceof Uint32Array ? data : new Uint32Array(data);
386
+ this._native2.uniform1uiv(location._, arr.length, Array.from(arr));
387
+ }
388
+ uniform2uiv(location, data, _srcOffset, _srcLength) {
389
+ if (!location) return;
390
+ const arr = data instanceof Uint32Array ? data : new Uint32Array(data);
391
+ this._native2.uniform2uiv(location._, arr.length / 2, Array.from(arr));
392
+ }
393
+ uniform3uiv(location, data, _srcOffset, _srcLength) {
394
+ if (!location) return;
395
+ const arr = data instanceof Uint32Array ? data : new Uint32Array(data);
396
+ this._native2.uniform3uiv(location._, arr.length / 3, Array.from(arr));
397
+ }
398
+ uniform4uiv(location, data, _srcOffset, _srcLength) {
399
+ if (!location) return;
400
+ const arr = data instanceof Uint32Array ? data : new Uint32Array(data);
401
+ this._native2.uniform4uiv(location._, arr.length / 4, Array.from(arr));
402
+ }
403
+ // ─── Non-square Matrix Uniforms ───────────────────────────────────────
404
+ uniformMatrix2x3fv(location, transpose, data, _srcOffset, _srcLength) {
405
+ if (!location) return;
406
+ const arr = data instanceof Float32Array ? data : new Float32Array(data);
407
+ this._native2.uniformMatrix2x3fv(location._, transpose, Array.from(arr));
408
+ }
409
+ uniformMatrix3x2fv(location, transpose, data, _srcOffset, _srcLength) {
410
+ if (!location) return;
411
+ const arr = data instanceof Float32Array ? data : new Float32Array(data);
412
+ this._native2.uniformMatrix3x2fv(location._, transpose, Array.from(arr));
413
+ }
414
+ uniformMatrix2x4fv(location, transpose, data, _srcOffset, _srcLength) {
415
+ if (!location) return;
416
+ const arr = data instanceof Float32Array ? data : new Float32Array(data);
417
+ this._native2.uniformMatrix2x4fv(location._, transpose, Array.from(arr));
418
+ }
419
+ uniformMatrix4x2fv(location, transpose, data, _srcOffset, _srcLength) {
420
+ if (!location) return;
421
+ const arr = data instanceof Float32Array ? data : new Float32Array(data);
422
+ this._native2.uniformMatrix4x2fv(location._, transpose, Array.from(arr));
423
+ }
424
+ uniformMatrix3x4fv(location, transpose, data, _srcOffset, _srcLength) {
425
+ if (!location) return;
426
+ const arr = data instanceof Float32Array ? data : new Float32Array(data);
427
+ this._native2.uniformMatrix3x4fv(location._, transpose, Array.from(arr));
428
+ }
429
+ uniformMatrix4x3fv(location, transpose, data, _srcOffset, _srcLength) {
430
+ if (!location) return;
431
+ const arr = data instanceof Float32Array ? data : new Float32Array(data);
432
+ this._native2.uniformMatrix4x3fv(location._, transpose, Array.from(arr));
433
+ }
434
+ // ─── getUniform — WebGL2 uint type support ────────────────────────────
435
+ /** WebGL1 getUniform falls to default:null for UNSIGNED_INT types. Handle them here. */
436
+ getUniform(program, location) {
437
+ const type = location?._activeInfo?.type;
438
+ const UINT = 5125, UVEC2 = 36294, UVEC3 = 36295, UVEC4 = 36296;
439
+ const isUintType = type === UINT || type === UVEC2 || type === UVEC3 || type === UVEC4;
440
+ if (!isUintType) return super.getUniform(program, location);
441
+ if (!program || !location) return null;
442
+ const data = this._native.getUniformi(program._ | 0, location._ | 0);
443
+ if (!data) return null;
444
+ if (type === UINT) return data[0] >>> 0;
445
+ if (type === UVEC2) return new Uint32Array([data[0] >>> 0, data[1] >>> 0]);
446
+ if (type === UVEC3) return new Uint32Array([data[0] >>> 0, data[1] >>> 0, data[2] >>> 0]);
447
+ return new Uint32Array([data[0] >>> 0, data[1] >>> 0, data[2] >>> 0, data[3] >>> 0]);
448
+ }
449
+ // ─── Uniform Blocks ───────────────────────────────────────────────────
450
+ getUniformBlockIndex(program, uniformBlockName) {
451
+ return this._native2.getUniformBlockIndex(program._, uniformBlockName);
452
+ }
453
+ uniformBlockBinding(program, uniformBlockIndex, uniformBlockBinding) {
454
+ this._native2.uniformBlockBinding(program._, uniformBlockIndex, uniformBlockBinding);
455
+ }
456
+ getActiveUniformBlockName(program, uniformBlockIndex) {
457
+ const name = this._native2.getActiveUniformBlockName(program._, uniformBlockIndex);
458
+ return name.length > 0 ? name : null;
459
+ }
460
+ getActiveUniformBlockParameter(program, uniformBlockIndex, pname) {
461
+ return this._native2.getActiveUniformBlockParameter(program._, uniformBlockIndex, pname);
462
+ }
463
+ getActiveUniforms(program, uniformIndices, pname) {
464
+ const result = this._native2.getActiveUniforms(program._, uniformIndices, pname);
465
+ return result;
466
+ }
467
+ // ─── Program Queries ──────────────────────────────────────────────────
468
+ getFragDataLocation(program, name) {
469
+ return this._native2.getFragDataLocation(program._, name);
470
+ }
471
+ // ─── Indexed Parameter Queries ────────────────────────────────────────
472
+ getIndexedParameter(target, index) {
473
+ return this._native2.getIndexedParameteri(target, index);
474
+ }
475
+ getInternalformatParameter(target, internalformat, pname) {
476
+ return this._native2.getInternalformatParameter(target, internalformat, pname);
477
+ }
478
+ getParameter(pname) {
479
+ if (pname === 7938) return "WebGL 2.0";
480
+ if (pname === 35724) return "WebGL GLSL ES 3.00";
481
+ if (pname === 7939) {
482
+ warnNotImplemented("WebGL2RenderingContext.getParameter(GL_EXTENSIONS)");
483
+ return "";
484
+ }
485
+ switch (pname) {
486
+ case 36183:
487
+ // MAX_SAMPLES
488
+ case 35071:
489
+ // MAX_ARRAY_TEXTURE_LAYERS
490
+ case 32883:
491
+ // MAX_3D_TEXTURE_SIZE
492
+ case 36063:
493
+ // MAX_COLOR_ATTACHMENTS
494
+ case 34852:
495
+ // MAX_DRAW_BUFFERS
496
+ case 36203:
497
+ // MAX_ELEMENT_INDEX
498
+ case 33001:
499
+ // MAX_ELEMENTS_INDICES
500
+ case 33e3:
501
+ // MAX_ELEMENTS_VERTICES
502
+ case 37157:
503
+ // MAX_FRAGMENT_INPUT_COMPONENTS
504
+ case 35373:
505
+ // MAX_FRAGMENT_UNIFORM_BLOCKS
506
+ case 35657:
507
+ // MAX_FRAGMENT_UNIFORM_COMPONENTS
508
+ case 35077:
509
+ // MAX_PROGRAM_TEXEL_OFFSET
510
+ case 35978:
511
+ // MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS
512
+ case 35979:
513
+ // MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS
514
+ case 35968:
515
+ // MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS
516
+ case 35376:
517
+ // MAX_UNIFORM_BLOCK_SIZE
518
+ case 35375:
519
+ // MAX_UNIFORM_BUFFER_BINDINGS
520
+ case 35659:
521
+ // MAX_VARYING_COMPONENTS
522
+ case 37154:
523
+ // MAX_VERTEX_OUTPUT_COMPONENTS
524
+ case 35371:
525
+ // MAX_VERTEX_UNIFORM_BLOCKS
526
+ case 35658:
527
+ // MAX_VERTEX_UNIFORM_COMPONENTS
528
+ case 35379:
529
+ // MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS
530
+ case 35374:
531
+ // MAX_COMBINED_UNIFORM_BLOCKS
532
+ case 35377:
533
+ // MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS
534
+ case 35076:
535
+ // MIN_PROGRAM_TEXEL_OFFSET
536
+ case 3330:
537
+ // PACK_ROW_LENGTH
538
+ case 3332:
539
+ // PACK_SKIP_PIXELS
540
+ case 3331:
541
+ // PACK_SKIP_ROWS
542
+ case 35053:
543
+ // PIXEL_PACK_BUFFER_BINDING
544
+ case 35055:
545
+ // PIXEL_UNPACK_BUFFER_BINDING
546
+ case 3074:
547
+ // READ_BUFFER
548
+ case 36010:
549
+ // READ_FRAMEBUFFER_BINDING
550
+ case 32874:
551
+ // TEXTURE_BINDING_3D
552
+ case 35869:
553
+ // TEXTURE_BINDING_2D_ARRAY
554
+ case 36389:
555
+ // TRANSFORM_FEEDBACK_BINDING
556
+ case 35983:
557
+ // TRANSFORM_FEEDBACK_BUFFER_BINDING
558
+ case 35368:
559
+ // UNIFORM_BUFFER_BINDING
560
+ case 35380:
561
+ // UNIFORM_BUFFER_OFFSET_ALIGNMENT
562
+ case 32878:
563
+ // UNPACK_IMAGE_HEIGHT
564
+ case 3314:
565
+ // UNPACK_ROW_LENGTH
566
+ case 32877:
567
+ // UNPACK_SKIP_IMAGES
568
+ case 3316:
569
+ // UNPACK_SKIP_PIXELS
570
+ case 3315:
571
+ // UNPACK_SKIP_ROWS
572
+ case 34045:
573
+ return this._native2.getParameterx(pname)?.deepUnpack() | 0;
574
+ case 35977:
575
+ // RASTERIZER_DISCARD
576
+ case 36388:
577
+ // TRANSFORM_FEEDBACK_ACTIVE
578
+ case 36387:
579
+ return !!this._native2.getParameterx(pname)?.deepUnpack();
580
+ }
581
+ return super.getParameter(pname);
582
+ }
583
+ // ─── Misc ─────────────────────────────────────────────────────────────
584
+ getStringi(name, index) {
585
+ const s = this._native2.getStringi(name, index);
586
+ return s.length > 0 ? s : null;
587
+ }
588
+ }
589
+ export {
590
+ WebGL2RenderingContext
591
+ };