@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.
- package/lib/esm/conformance/attribs.spec.js +312 -293
- package/lib/esm/conformance/buffers.spec.js +217 -200
- package/lib/esm/conformance/context.spec.js +295 -295
- package/lib/esm/conformance/programs.spec.js +458 -445
- package/lib/esm/conformance/rendering-basic.spec.js +134 -128
- package/lib/esm/conformance/rendering.spec.js +502 -400
- package/lib/esm/conformance/setup.js +42 -31
- package/lib/esm/conformance/state.spec.js +360 -343
- package/lib/esm/conformance/textures.spec.js +330 -338
- package/lib/esm/conformance/uniforms.spec.js +465 -309
- package/lib/esm/conformance-test.js +24 -22
- package/lib/esm/extensions/ext-blend-minmax.js +16 -16
- package/lib/esm/extensions/ext-color-buffer-float.js +10 -11
- package/lib/esm/extensions/ext-color-buffer-half-float.js +10 -11
- package/lib/esm/extensions/ext-texture-filter-anisotropic.js +16 -16
- package/lib/esm/extensions/oes-element-index-unit.js +11 -12
- package/lib/esm/extensions/oes-standard-derivatives.js +15 -15
- package/lib/esm/extensions/oes-texture-float-linear.js +11 -12
- package/lib/esm/extensions/oes-texture-float.js +11 -12
- package/lib/esm/extensions/oes-texture-half-float.js +17 -17
- package/lib/esm/extensions/stackgl-destroy-context.js +10 -10
- package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +10 -10
- package/lib/esm/html-canvas-element.js +64 -64
- package/lib/esm/index.js +29 -26
- package/lib/esm/linkable.js +49 -49
- package/lib/esm/test-utils.js +158 -107
- package/lib/esm/test.js +8 -4
- package/lib/esm/types/index.js +5 -5
- package/lib/esm/utils.js +164 -187
- package/lib/esm/webgl-active-info.js +10 -9
- package/lib/esm/webgl-bridge.js +162 -147
- package/lib/esm/webgl-buffer.js +17 -15
- package/lib/esm/webgl-context-attributes.js +23 -22
- package/lib/esm/webgl-context-base.js +3039 -3351
- package/lib/esm/webgl-drawing-buffer-wrapper.js +10 -9
- package/lib/esm/webgl-framebuffer.js +108 -106
- package/lib/esm/webgl-program.js +25 -23
- package/lib/esm/webgl-query.js +15 -13
- package/lib/esm/webgl-renderbuffer.js +23 -21
- package/lib/esm/webgl-rendering-context.js +173 -187
- package/lib/esm/webgl-sampler.js +15 -13
- package/lib/esm/webgl-shader-precision-format.js +10 -9
- package/lib/esm/webgl-shader.js +23 -21
- package/lib/esm/webgl-sync.js +15 -13
- package/lib/esm/webgl-texture-unit.js +12 -11
- package/lib/esm/webgl-texture.js +21 -19
- package/lib/esm/webgl-transform-feedback.js +15 -13
- package/lib/esm/webgl-uniform-location.js +14 -13
- package/lib/esm/webgl-vertex-array-object.js +20 -18
- package/lib/esm/webgl-vertex-attribute.js +149 -145
- package/lib/esm/webgl1.spec.js +1039 -650
- package/lib/esm/webgl2-rendering-context.js +1210 -1273
- package/lib/esm/webgl2.spec.js +1284 -1252
- package/package.json +9 -9
- 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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
-
|
|
22
|
+
return typeof object === "object" || object === undefined;
|
|
21
23
|
}
|
|
22
24
|
function checkUniform(program, location) {
|
|
23
|
-
|
|
25
|
+
return location instanceof WebGLUniformLocation && location._program === program && location._linkCount === program._linkCount;
|
|
24
26
|
}
|
|
25
27
|
function isTypedArray(data) {
|
|
26
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
+
const c = str.replace(/(?:\/\*(?:[\s\S]*?)\*\/)|(?:([\s;])+\/\/(?:.*)$)/gm, "");
|
|
32
|
+
return !/["$`@\\'\0]/.test(c);
|
|
31
33
|
}
|
|
32
34
|
function vertexCount(gl, primitive, count) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
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
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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 };
|