@gjsify/webgl 0.3.12 → 0.3.14

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 (55) hide show
  1. package/lib/esm/conformance/attribs.spec.js +312 -293
  2. package/lib/esm/conformance/buffers.spec.js +217 -200
  3. package/lib/esm/conformance/context.spec.js +295 -295
  4. package/lib/esm/conformance/programs.spec.js +458 -445
  5. package/lib/esm/conformance/rendering-basic.spec.js +134 -128
  6. package/lib/esm/conformance/rendering.spec.js +502 -400
  7. package/lib/esm/conformance/setup.js +42 -31
  8. package/lib/esm/conformance/state.spec.js +360 -343
  9. package/lib/esm/conformance/textures.spec.js +330 -338
  10. package/lib/esm/conformance/uniforms.spec.js +465 -309
  11. package/lib/esm/conformance-test.js +24 -22
  12. package/lib/esm/extensions/ext-blend-minmax.js +16 -16
  13. package/lib/esm/extensions/ext-color-buffer-float.js +10 -11
  14. package/lib/esm/extensions/ext-color-buffer-half-float.js +10 -11
  15. package/lib/esm/extensions/ext-texture-filter-anisotropic.js +16 -16
  16. package/lib/esm/extensions/oes-element-index-unit.js +11 -12
  17. package/lib/esm/extensions/oes-standard-derivatives.js +15 -15
  18. package/lib/esm/extensions/oes-texture-float-linear.js +11 -12
  19. package/lib/esm/extensions/oes-texture-float.js +11 -12
  20. package/lib/esm/extensions/oes-texture-half-float.js +17 -17
  21. package/lib/esm/extensions/stackgl-destroy-context.js +10 -10
  22. package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +10 -10
  23. package/lib/esm/html-canvas-element.js +64 -64
  24. package/lib/esm/index.js +29 -26
  25. package/lib/esm/linkable.js +49 -49
  26. package/lib/esm/test-utils.js +158 -107
  27. package/lib/esm/test.js +8 -4
  28. package/lib/esm/types/index.js +5 -5
  29. package/lib/esm/utils.js +164 -187
  30. package/lib/esm/webgl-active-info.js +10 -9
  31. package/lib/esm/webgl-bridge.js +162 -147
  32. package/lib/esm/webgl-buffer.js +17 -15
  33. package/lib/esm/webgl-context-attributes.js +23 -22
  34. package/lib/esm/webgl-context-base.js +3039 -3351
  35. package/lib/esm/webgl-drawing-buffer-wrapper.js +10 -9
  36. package/lib/esm/webgl-framebuffer.js +108 -106
  37. package/lib/esm/webgl-program.js +25 -23
  38. package/lib/esm/webgl-query.js +15 -13
  39. package/lib/esm/webgl-renderbuffer.js +23 -21
  40. package/lib/esm/webgl-rendering-context.js +173 -187
  41. package/lib/esm/webgl-sampler.js +15 -13
  42. package/lib/esm/webgl-shader-precision-format.js +10 -9
  43. package/lib/esm/webgl-shader.js +23 -21
  44. package/lib/esm/webgl-sync.js +15 -13
  45. package/lib/esm/webgl-texture-unit.js +12 -11
  46. package/lib/esm/webgl-texture.js +21 -19
  47. package/lib/esm/webgl-transform-feedback.js +15 -13
  48. package/lib/esm/webgl-uniform-location.js +14 -13
  49. package/lib/esm/webgl-vertex-array-object.js +20 -18
  50. package/lib/esm/webgl-vertex-attribute.js +149 -145
  51. package/lib/esm/webgl1.spec.js +1039 -650
  52. package/lib/esm/webgl2-rendering-context.js +1210 -1273
  53. package/lib/esm/webgl2.spec.js +1284 -1252
  54. package/package.json +9 -9
  55. package/lib/esm/@types/glsl-tokenizer/index.d.js +0 -0
package/lib/esm/utils.js CHANGED
@@ -1,224 +1,201 @@
1
1
  import { WebGLUniformLocation } from "./webgl-uniform-location.js";
2
2
  import GLib from "@girs/glib-2.0";
3
+
4
+ //#region src/ts/utils.ts
3
5
  function bindPublics(props, wrapper, privateInstance, privateMethods) {
4
- for (let i = 0; i < props.length; i++) {
5
- const prop = props[i];
6
- const value = privateInstance[prop];
7
- if (typeof value === "function") {
8
- if (privateMethods.indexOf(prop) === -1) {
9
- wrapper[prop] = value.bind(privateInstance);
10
- }
11
- } else {
12
- if (prop[0] === "_" || prop[0] === "0" || prop[0] === "1") {
13
- continue;
14
- }
15
- wrapper[prop] = value;
16
- }
17
- }
6
+ for (let i = 0; i < props.length; i++) {
7
+ const prop = props[i];
8
+ const value = privateInstance[prop];
9
+ if (typeof value === "function") {
10
+ if (privateMethods.indexOf(prop) === -1) {
11
+ wrapper[prop] = value.bind(privateInstance);
12
+ }
13
+ } else {
14
+ if (prop[0] === "_" || prop[0] === "0" || prop[0] === "1") {
15
+ continue;
16
+ }
17
+ wrapper[prop] = value;
18
+ }
19
+ }
18
20
  }
19
21
  function checkObject(object) {
20
- return typeof object === "object" || object === void 0;
22
+ return typeof object === "object" || object === undefined;
21
23
  }
22
24
  function checkUniform(program, location) {
23
- return location instanceof WebGLUniformLocation && location._program === program && location._linkCount === program._linkCount;
25
+ return location instanceof WebGLUniformLocation && location._program === program && location._linkCount === program._linkCount;
24
26
  }
25
27
  function isTypedArray(data) {
26
- return data instanceof Uint8Array || data instanceof Uint8ClampedArray || data instanceof Int8Array || data instanceof Uint16Array || data instanceof Int16Array || data instanceof Uint32Array || data instanceof Int32Array || data instanceof Float32Array || data instanceof Float64Array;
28
+ return data instanceof Uint8Array || data instanceof Uint8ClampedArray || data instanceof Int8Array || data instanceof Uint16Array || data instanceof Int16Array || data instanceof Uint32Array || data instanceof Int32Array || data instanceof Float32Array || data instanceof Float64Array;
27
29
  }
28
30
  function isValidString(str) {
29
- const c = str.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm, "");
30
- return !/["$`@\\'\0]/.test(c);
31
+ const c = str.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm, "");
32
+ return !/["$`@\\'\0]/.test(c);
31
33
  }
32
34
  function vertexCount(gl, primitive, count) {
33
- switch (primitive) {
34
- case gl.TRIANGLES:
35
- return count - count % 3;
36
- case gl.LINES:
37
- return count - count % 2;
38
- case gl.LINE_LOOP:
39
- case gl.POINTS:
40
- return count;
41
- case gl.TRIANGLE_FAN:
42
- case gl.LINE_STRIP:
43
- if (count < 2) {
44
- return 0;
45
- }
46
- return count;
47
- case gl.TRIANGLE_STRIP:
48
- if (count < 3) {
49
- return 0;
50
- }
51
- return count;
52
- default:
53
- return -1;
54
- }
35
+ switch (primitive) {
36
+ case gl.TRIANGLES: return count - count % 3;
37
+ case gl.LINES: return count - count % 2;
38
+ case gl.LINE_LOOP:
39
+ case gl.POINTS: return count;
40
+ case gl.TRIANGLE_FAN:
41
+ case gl.LINE_STRIP:
42
+ if (count < 2) {
43
+ return 0;
44
+ }
45
+ return count;
46
+ case gl.TRIANGLE_STRIP:
47
+ if (count < 3) {
48
+ return 0;
49
+ }
50
+ return count;
51
+ default: return -1;
52
+ }
55
53
  }
56
54
  function typeSize(gl, type) {
57
- switch (type) {
58
- case gl.UNSIGNED_BYTE:
59
- case gl.BYTE:
60
- return 1;
61
- case gl.UNSIGNED_SHORT:
62
- case gl.SHORT:
63
- return 2;
64
- case gl.UNSIGNED_INT:
65
- case gl.INT:
66
- case gl.FLOAT:
67
- return 4;
68
- }
69
- return 0;
55
+ switch (type) {
56
+ case gl.UNSIGNED_BYTE:
57
+ case gl.BYTE: return 1;
58
+ case gl.UNSIGNED_SHORT:
59
+ case gl.SHORT: return 2;
60
+ case gl.UNSIGNED_INT:
61
+ case gl.INT:
62
+ case gl.FLOAT: return 4;
63
+ }
64
+ return 0;
70
65
  }
71
66
  function uniformTypeSize(gl, type) {
72
- switch (type) {
73
- case gl.BOOL_VEC4:
74
- case gl.INT_VEC4:
75
- case gl.FLOAT_VEC4:
76
- return 4;
77
- case gl.BOOL_VEC3:
78
- case gl.INT_VEC3:
79
- case gl.FLOAT_VEC3:
80
- return 3;
81
- case gl.BOOL_VEC2:
82
- case gl.INT_VEC2:
83
- case gl.FLOAT_VEC2:
84
- return 2;
85
- case gl.BOOL:
86
- case gl.INT:
87
- case gl.FLOAT:
88
- case gl.SAMPLER_2D:
89
- case gl.SAMPLER_CUBE:
90
- return 1;
91
- default:
92
- return 0;
93
- }
67
+ switch (type) {
68
+ case gl.BOOL_VEC4:
69
+ case gl.INT_VEC4:
70
+ case gl.FLOAT_VEC4: return 4;
71
+ case gl.BOOL_VEC3:
72
+ case gl.INT_VEC3:
73
+ case gl.FLOAT_VEC3: return 3;
74
+ case gl.BOOL_VEC2:
75
+ case gl.INT_VEC2:
76
+ case gl.FLOAT_VEC2: return 2;
77
+ case gl.BOOL:
78
+ case gl.INT:
79
+ case gl.FLOAT:
80
+ case gl.SAMPLER_2D:
81
+ case gl.SAMPLER_CUBE: return 1;
82
+ default: return 0;
83
+ }
94
84
  }
95
85
  const listToArray = (values) => {
96
- const array = [];
97
- for (const value of values.values()) {
98
- array.push(value);
99
- }
100
- return array;
86
+ const array = [];
87
+ for (const value of values.values()) {
88
+ array.push(value);
89
+ }
90
+ return array;
101
91
  };
102
92
  function arrayToUint8Array(array) {
103
- if (isTypedArray(array)) {
104
- return new Uint8Array(array.buffer).subarray(
105
- array.byteOffset,
106
- array.byteLength + array.byteOffset
107
- );
108
- }
109
- if (Array.isArray(array) || array instanceof ArrayBuffer) {
110
- return new Uint8Array(array);
111
- }
112
- if (typeof array.values === "function") {
113
- return new Uint8Array(listToArray(array));
114
- }
115
- throw new Error("Can't unpack typed array!");
93
+ if (isTypedArray(array)) {
94
+ return new Uint8Array(array.buffer).subarray(array.byteOffset, array.byteLength + array.byteOffset);
95
+ }
96
+ if (Array.isArray(array) || array instanceof ArrayBuffer) {
97
+ return new Uint8Array(array);
98
+ }
99
+ if (typeof array.values === "function") {
100
+ return new Uint8Array(listToArray(array));
101
+ }
102
+ throw new Error("Can't unpack typed array!");
116
103
  }
117
104
  function Uint8ArrayToVariant(array) {
118
- const variant = new GLib.Variant("ay", array);
119
- return variant;
120
- }
105
+ const variant = new GLib.Variant("ay", array);
106
+ return variant;
107
+ }
108
+ /**
109
+ * Converts an ArrayBufferView to an array of bools. gjs returns
110
+ * Uint8Array, but the elements are actually 4 bytes each.
111
+ * @param array
112
+ * @returns
113
+ */
121
114
  function boolArray(array) {
122
- return Array.from(new Int32Array(array.buffer)).map(
123
- (a) => a ? true : false
124
- );
115
+ return Array.from(new Int32Array(array.buffer)).map((a) => a ? true : false);
125
116
  }
126
117
  const extractImageData = (pixels) => {
127
- const width = pixels.width;
128
- const height = pixels.height;
129
- if (typeof pixels === "object" && typeof width !== "undefined" && typeof height !== "undefined") {
130
- if (typeof pixels.data !== "undefined") {
131
- return pixels;
132
- }
133
- let context = null;
134
- if (typeof pixels.getContext === "function") {
135
- context = pixels.getContext("2d");
136
- } else if (typeof pixels.isPixbuf === "function" && pixels.isPixbuf()) {
137
- return pixels.getImageData();
138
- } else if (typeof pixels.src !== "undefined" && typeof document === "object" && typeof document.createElement === "function") {
139
- const canvas = document.createElement("canvas");
140
- if (typeof canvas === "object" && typeof canvas.getContext === "function") {
141
- canvas.width = width;
142
- canvas.height = height;
143
- context = canvas.getContext("2d");
144
- if (context !== null) {
145
- context.drawImage(pixels, 0, 0);
146
- }
147
- }
148
- }
149
- if (context !== null) {
150
- return context.getImageData(0, 0, width, height);
151
- }
152
- }
153
- return null;
118
+ const width = pixels.width;
119
+ const height = pixels.height;
120
+ if (typeof pixels === "object" && typeof width !== "undefined" && typeof height !== "undefined") {
121
+ if (typeof pixels.data !== "undefined") {
122
+ return pixels;
123
+ }
124
+ let context = null;
125
+ if (typeof pixels.getContext === "function") {
126
+ context = pixels.getContext("2d");
127
+ } else if (typeof pixels.isPixbuf === "function" && pixels.isPixbuf()) {
128
+ return pixels.getImageData();
129
+ } else if (typeof pixels.src !== "undefined" && typeof document === "object" && typeof document.createElement === "function") {
130
+ const canvas = document.createElement("canvas");
131
+ if (typeof canvas === "object" && typeof canvas.getContext === "function") {
132
+ canvas.width = width;
133
+ canvas.height = height;
134
+ context = canvas.getContext("2d");
135
+ if (context !== null) {
136
+ context.drawImage(pixels, 0, 0);
137
+ }
138
+ }
139
+ }
140
+ if (context !== null) {
141
+ return context.getImageData(0, 0, width, height);
142
+ }
143
+ }
144
+ return null;
154
145
  };
155
146
  function formatSize(gl, internalFormat) {
156
- switch (internalFormat) {
157
- case gl.ALPHA:
158
- case gl.LUMINANCE:
159
- return 1;
160
- case gl.LUMINANCE_ALPHA:
161
- return 2;
162
- case gl.RGB:
163
- return 3;
164
- case gl.RGBA:
165
- return 4;
166
- }
167
- return 0;
147
+ switch (internalFormat) {
148
+ case gl.ALPHA:
149
+ case gl.LUMINANCE: return 1;
150
+ case gl.LUMINANCE_ALPHA: return 2;
151
+ case gl.RGB: return 3;
152
+ case gl.RGBA: return 4;
153
+ }
154
+ return 0;
168
155
  }
169
156
  function convertPixels(pixels) {
170
- if (typeof pixels === "object" && pixels !== null) {
171
- if (pixels instanceof ArrayBuffer) {
172
- return new Uint8Array(pixels);
173
- } else if (pixels instanceof Uint8Array || pixels instanceof Uint16Array || pixels instanceof Uint8ClampedArray || pixels instanceof Float32Array) {
174
- return arrayToUint8Array(pixels);
175
- } else if (pixels instanceof Buffer) {
176
- return new Uint8Array(pixels);
177
- }
178
- }
179
- return null;
157
+ if (typeof pixels === "object" && pixels !== null) {
158
+ if (pixels instanceof ArrayBuffer) {
159
+ return new Uint8Array(pixels);
160
+ } else if (pixels instanceof Uint8Array || pixels instanceof Uint16Array || pixels instanceof Uint8ClampedArray || pixels instanceof Float32Array) {
161
+ return arrayToUint8Array(pixels);
162
+ } else if (pixels instanceof Buffer) {
163
+ return new Uint8Array(pixels);
164
+ }
165
+ }
166
+ return null;
180
167
  }
181
168
  function checkFormat(gl, format) {
182
- return format === gl.ALPHA || format === gl.LUMINANCE_ALPHA || format === gl.LUMINANCE || format === gl.RGB || format === gl.RGBA;
169
+ return format === gl.ALPHA || format === gl.LUMINANCE_ALPHA || format === gl.LUMINANCE || format === gl.RGB || format === gl.RGBA;
183
170
  }
184
171
  function validCubeTarget(gl, target) {
185
- return target === gl.TEXTURE_CUBE_MAP_POSITIVE_X || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_X || target === gl.TEXTURE_CUBE_MAP_POSITIVE_Y || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Y || target === gl.TEXTURE_CUBE_MAP_POSITIVE_Z || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Z;
172
+ return target === gl.TEXTURE_CUBE_MAP_POSITIVE_X || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_X || target === gl.TEXTURE_CUBE_MAP_POSITIVE_Y || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Y || target === gl.TEXTURE_CUBE_MAP_POSITIVE_Z || target === gl.TEXTURE_CUBE_MAP_NEGATIVE_Z;
186
173
  }
187
174
  function flag(options, name, dflt) {
188
- if (!options || !(typeof options === "object") || !(name in options)) {
189
- return dflt;
190
- }
191
- return !!options[name];
192
- }
175
+ if (!options || !(typeof options === "object") || !(name in options)) {
176
+ return dflt;
177
+ }
178
+ return !!options[name];
179
+ }
180
+ /**
181
+ * Premultiply RGB channels by the alpha channel (in-place copy).
182
+ * Required when UNPACK_PREMULTIPLY_ALPHA_WEBGL is set.
183
+ * Excalibur uses blendFunc(ONE, ONE_MINUS_SRC_ALPHA) (premultiplied alpha
184
+ * blending), so textures must have RGB already multiplied by alpha before
185
+ * upload. Without this, transparent-background PNGs (alpha=0 but RGB=255)
186
+ * bleed through as white rectangles.
187
+ */
193
188
  function premultiplyAlpha(data) {
194
- const out = new Uint8Array(data.length);
195
- for (let i = 0; i < data.length; i += 4) {
196
- const a = data[i + 3] / 255;
197
- out[i] = Math.round(data[i] * a);
198
- out[i + 1] = Math.round(data[i + 1] * a);
199
- out[i + 2] = Math.round(data[i + 2] * a);
200
- out[i + 3] = data[i + 3];
201
- }
202
- return out;
203
- }
204
- export {
205
- Uint8ArrayToVariant,
206
- arrayToUint8Array,
207
- bindPublics,
208
- boolArray,
209
- checkFormat,
210
- checkObject,
211
- checkUniform,
212
- convertPixels,
213
- extractImageData,
214
- flag,
215
- formatSize,
216
- isTypedArray,
217
- isValidString,
218
- listToArray,
219
- premultiplyAlpha,
220
- typeSize,
221
- uniformTypeSize,
222
- validCubeTarget,
223
- vertexCount
224
- };
189
+ const out = new Uint8Array(data.length);
190
+ for (let i = 0; i < data.length; i += 4) {
191
+ const a = data[i + 3] / 255;
192
+ out[i] = Math.round(data[i] * a);
193
+ out[i + 1] = Math.round(data[i + 1] * a);
194
+ out[i + 2] = Math.round(data[i + 2] * a);
195
+ out[i + 3] = data[i + 3];
196
+ }
197
+ return out;
198
+ }
199
+
200
+ //#endregion
201
+ export { Uint8ArrayToVariant, arrayToUint8Array, bindPublics, boolArray, checkFormat, checkObject, checkUniform, convertPixels, extractImageData, flag, formatSize, isTypedArray, isValidString, listToArray, premultiplyAlpha, typeSize, uniformTypeSize, validCubeTarget, vertexCount };
@@ -1,10 +1,11 @@
1
- class WebGLActiveInfo {
2
- constructor(_) {
3
- this.size = _.size;
4
- this.type = _.type;
5
- this.name = _.name;
6
- }
7
- }
8
- export {
9
- WebGLActiveInfo
1
+ //#region src/ts/webgl-active-info.ts
2
+ var WebGLActiveInfo = class {
3
+ constructor(_) {
4
+ this.size = _.size;
5
+ this.type = _.type;
6
+ this.name = _.name;
7
+ }
10
8
  };
9
+
10
+ //#endregion
11
+ export { WebGLActiveInfo };