@gjsify/webgl 0.3.13 → 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
|
@@ -1,6 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { makeProgram, drawTriangle, makeTestFBO, destroyTestFBO } from "../test-utils.js";
|
|
1
|
+
import { destroyTestFBO, drawTriangle, makeProgram, makeTestFBO } from "../test-utils.js";
|
|
3
2
|
import { createGLSetup } from "./setup.js";
|
|
3
|
+
import { beforeEach, describe, expect, it, on } from "@gjsify/unit";
|
|
4
|
+
|
|
5
|
+
//#region src/ts/conformance/textures.spec.ts
|
|
4
6
|
const VS_TEX = `
|
|
5
7
|
precision mediump float;
|
|
6
8
|
attribute vec2 position;
|
|
@@ -15,340 +17,330 @@ const FS_TEX = `
|
|
|
15
17
|
varying vec2 vTexCoord;
|
|
16
18
|
void main() { gl_FragColor = texture2D(uTex, vTexCoord); }`;
|
|
17
19
|
var textures_spec_default = async () => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const W = 4, H = 4;
|
|
342
|
-
const data = new Uint8Array(W * H * 4).fill(255);
|
|
343
|
-
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, W, H, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
344
|
-
gl.generateMipmap(gl.TEXTURE_2D);
|
|
345
|
-
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
346
|
-
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
347
|
-
gl.deleteTexture(tex);
|
|
348
|
-
});
|
|
349
|
-
});
|
|
350
|
-
});
|
|
351
|
-
};
|
|
352
|
-
export {
|
|
353
|
-
textures_spec_default as default
|
|
20
|
+
await on("Display", async () => {
|
|
21
|
+
const setup = createGLSetup();
|
|
22
|
+
if (!setup) {
|
|
23
|
+
console.warn("WebGL context not available — skipping conformance/textures tests");
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const { gl, glArea } = setup;
|
|
27
|
+
glArea.make_current();
|
|
28
|
+
await describe("textures/texImage2D-rgba", async () => {
|
|
29
|
+
beforeEach(async () => {
|
|
30
|
+
glArea.make_current();
|
|
31
|
+
});
|
|
32
|
+
await it("upload 2×2 RGBA Uint8Array and sample it back", async () => {
|
|
33
|
+
const W = 2, H = 2;
|
|
34
|
+
const fbo = makeTestFBO(gl, W, H);
|
|
35
|
+
const data = new Uint8Array([
|
|
36
|
+
255,
|
|
37
|
+
0,
|
|
38
|
+
0,
|
|
39
|
+
255,
|
|
40
|
+
0,
|
|
41
|
+
255,
|
|
42
|
+
0,
|
|
43
|
+
255,
|
|
44
|
+
0,
|
|
45
|
+
0,
|
|
46
|
+
255,
|
|
47
|
+
255,
|
|
48
|
+
255,
|
|
49
|
+
255,
|
|
50
|
+
0,
|
|
51
|
+
255
|
|
52
|
+
]);
|
|
53
|
+
const tex = gl.createTexture();
|
|
54
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
55
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
56
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
57
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
58
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
59
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, W, H, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
60
|
+
const prog = makeProgram(gl, VS_TEX, FS_TEX);
|
|
61
|
+
gl.useProgram(prog);
|
|
62
|
+
gl.uniform1i(gl.getUniformLocation(prog, "uTex"), 0);
|
|
63
|
+
drawTriangle(gl);
|
|
64
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
65
|
+
gl.deleteTexture(tex);
|
|
66
|
+
destroyTestFBO(gl, fbo);
|
|
67
|
+
});
|
|
68
|
+
await it("createTexture returns non-null; deleteTexture cleans up", async () => {
|
|
69
|
+
const tex = gl.createTexture();
|
|
70
|
+
expect(tex).toBeDefined();
|
|
71
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
72
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([
|
|
73
|
+
128,
|
|
74
|
+
128,
|
|
75
|
+
128,
|
|
76
|
+
255
|
|
77
|
+
]));
|
|
78
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
79
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
80
|
+
gl.deleteTexture(tex);
|
|
81
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
await describe("textures/alpha-texture", async () => {
|
|
85
|
+
beforeEach(async () => {
|
|
86
|
+
glArea.make_current();
|
|
87
|
+
});
|
|
88
|
+
await it("ALPHA format texImage2D: RGB channels zero, alpha matches upload data", async () => {
|
|
89
|
+
const W = 4, H = 4;
|
|
90
|
+
const fbo = makeTestFBO(gl, W, H);
|
|
91
|
+
const data = new Uint8Array(W * H);
|
|
92
|
+
for (let i = 0; i < H; i++) {
|
|
93
|
+
for (let j = 0; j < W; j++) {
|
|
94
|
+
data[i * W + j] = (i + j) % 255;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
const tex = gl.createTexture();
|
|
98
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
99
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
100
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
101
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
102
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
103
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, W, H, 0, gl.ALPHA, gl.UNSIGNED_BYTE, data);
|
|
104
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
105
|
+
gl.clearColor(0, 0, 0, 0);
|
|
106
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
107
|
+
const prog = makeProgram(gl, VS_TEX, FS_TEX);
|
|
108
|
+
gl.useProgram(prog);
|
|
109
|
+
gl.uniform1i(gl.getUniformLocation(prog, "uTex"), 0);
|
|
110
|
+
drawTriangle(gl);
|
|
111
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
112
|
+
const pixels = new Uint8Array(W * H * 4);
|
|
113
|
+
gl.readPixels(0, 0, W, H, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
114
|
+
let ok = true;
|
|
115
|
+
for (let k = 0; k < W * H; k++) {
|
|
116
|
+
const i = k * 4;
|
|
117
|
+
if (pixels[i] !== 0 || pixels[i + 1] !== 0 || pixels[i + 2] !== 0) {
|
|
118
|
+
ok = false;
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
if (Math.abs(pixels[i + 3] - data[k]) > 3) {
|
|
122
|
+
ok = false;
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
expect(ok).toBe(true);
|
|
127
|
+
gl.deleteTexture(tex);
|
|
128
|
+
destroyTestFBO(gl, fbo);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
await describe("textures/texSubImage2D", async () => {
|
|
132
|
+
beforeEach(async () => {
|
|
133
|
+
glArea.make_current();
|
|
134
|
+
});
|
|
135
|
+
await it("texSubImage2D overwrites a sub-region of an RGBA texture", async () => {
|
|
136
|
+
const W = 4, H = 4;
|
|
137
|
+
const fbo = makeTestFBO(gl, W, H);
|
|
138
|
+
const redData = new Uint8Array(W * H * 4).fill(0);
|
|
139
|
+
for (let i = 0; i < W * H; i++) {
|
|
140
|
+
redData[i * 4] = 255;
|
|
141
|
+
redData[i * 4 + 3] = 255;
|
|
142
|
+
}
|
|
143
|
+
const tex = gl.createTexture();
|
|
144
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
145
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
146
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
147
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
148
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
149
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, W, H, 0, gl.RGBA, gl.UNSIGNED_BYTE, redData);
|
|
150
|
+
const greenPatch = new Uint8Array([
|
|
151
|
+
0,
|
|
152
|
+
255,
|
|
153
|
+
0,
|
|
154
|
+
255,
|
|
155
|
+
0,
|
|
156
|
+
255,
|
|
157
|
+
0,
|
|
158
|
+
255,
|
|
159
|
+
0,
|
|
160
|
+
255,
|
|
161
|
+
0,
|
|
162
|
+
255,
|
|
163
|
+
0,
|
|
164
|
+
255,
|
|
165
|
+
0,
|
|
166
|
+
255
|
|
167
|
+
]);
|
|
168
|
+
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 2, 2, gl.RGBA, gl.UNSIGNED_BYTE, greenPatch);
|
|
169
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
170
|
+
gl.deleteTexture(tex);
|
|
171
|
+
destroyTestFBO(gl, fbo);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
await describe("textures/parameters", async () => {
|
|
175
|
+
beforeEach(async () => {
|
|
176
|
+
glArea.make_current();
|
|
177
|
+
});
|
|
178
|
+
await it("getTexParameter returns set WRAP and FILTER values", async () => {
|
|
179
|
+
const tex = gl.createTexture();
|
|
180
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
181
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
182
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
|
|
183
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
184
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
185
|
+
expect(gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)).toBe(gl.CLAMP_TO_EDGE);
|
|
186
|
+
expect(gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T)).toBe(gl.REPEAT);
|
|
187
|
+
expect(gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)).toBe(gl.LINEAR);
|
|
188
|
+
expect(gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER)).toBe(gl.NEAREST);
|
|
189
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
190
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
191
|
+
gl.deleteTexture(tex);
|
|
192
|
+
});
|
|
193
|
+
await it("MIRRORED_REPEAT wrap mode is accepted", async () => {
|
|
194
|
+
const tex = gl.createTexture();
|
|
195
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
196
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
|
|
197
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
198
|
+
expect(gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S)).toBe(gl.MIRRORED_REPEAT);
|
|
199
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
200
|
+
gl.deleteTexture(tex);
|
|
201
|
+
});
|
|
202
|
+
await it("LINEAR_MIPMAP_LINEAR min filter is accepted", async () => {
|
|
203
|
+
const tex = gl.createTexture();
|
|
204
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
205
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
206
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
207
|
+
expect(gl.getTexParameter(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER)).toBe(gl.LINEAR_MIPMAP_LINEAR);
|
|
208
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
209
|
+
gl.deleteTexture(tex);
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
await describe("textures/active-texture", async () => {
|
|
213
|
+
beforeEach(async () => {
|
|
214
|
+
glArea.make_current();
|
|
215
|
+
});
|
|
216
|
+
await it("activeTexture switches binding slot; each unit holds independent binding", async () => {
|
|
217
|
+
const tex0 = gl.createTexture();
|
|
218
|
+
const tex1 = gl.createTexture();
|
|
219
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
220
|
+
gl.bindTexture(gl.TEXTURE_2D, tex0);
|
|
221
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
222
|
+
gl.bindTexture(gl.TEXTURE_2D, tex1);
|
|
223
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
224
|
+
expect(gl.getParameter(gl.TEXTURE_BINDING_2D)).toBe(tex0);
|
|
225
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
226
|
+
expect(gl.getParameter(gl.TEXTURE_BINDING_2D)).toBe(tex1);
|
|
227
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
228
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
229
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
230
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
231
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
232
|
+
gl.deleteTexture(tex0);
|
|
233
|
+
gl.deleteTexture(tex1);
|
|
234
|
+
});
|
|
235
|
+
await it("getParameter ACTIVE_TEXTURE reflects activeTexture call", async () => {
|
|
236
|
+
gl.activeTexture(gl.TEXTURE3);
|
|
237
|
+
expect(gl.getParameter(gl.ACTIVE_TEXTURE)).toBe(gl.TEXTURE3);
|
|
238
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
239
|
+
expect(gl.getParameter(gl.ACTIVE_TEXTURE)).toBe(gl.TEXTURE0);
|
|
240
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
await describe("textures/cubemap", async () => {
|
|
244
|
+
beforeEach(async () => {
|
|
245
|
+
glArea.make_current();
|
|
246
|
+
});
|
|
247
|
+
await it("attach all 6 cubemap faces to FBO — no GL error", async () => {
|
|
248
|
+
const tex = gl.createTexture();
|
|
249
|
+
const fb = gl.createFramebuffer();
|
|
250
|
+
const whitePixel = new Uint8Array([
|
|
251
|
+
255,
|
|
252
|
+
255,
|
|
253
|
+
255,
|
|
254
|
+
255
|
|
255
|
+
]);
|
|
256
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
257
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex);
|
|
258
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
259
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
260
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
261
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
262
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
|
|
263
|
+
for (let i = 0; i < 6; i++) {
|
|
264
|
+
gl.texImage2D(gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, whitePixel);
|
|
265
|
+
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, tex, 0);
|
|
266
|
+
}
|
|
267
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
268
|
+
gl.bindFramebuffer(gl.FRAMEBUFFER, null);
|
|
269
|
+
gl.activeTexture(gl.TEXTURE1);
|
|
270
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
|
|
271
|
+
gl.activeTexture(gl.TEXTURE0);
|
|
272
|
+
gl.deleteTexture(tex);
|
|
273
|
+
gl.deleteFramebuffer(fb);
|
|
274
|
+
});
|
|
275
|
+
await it("createTexture with TEXTURE_CUBE_MAP binding — no error", async () => {
|
|
276
|
+
const tex = gl.createTexture();
|
|
277
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, tex);
|
|
278
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
|
|
279
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
280
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
|
|
281
|
+
gl.texParameteri(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
|
|
282
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
283
|
+
gl.bindTexture(gl.TEXTURE_CUBE_MAP, null);
|
|
284
|
+
gl.deleteTexture(tex);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
await describe("textures/luminance", async () => {
|
|
288
|
+
beforeEach(async () => {
|
|
289
|
+
glArea.make_current();
|
|
290
|
+
});
|
|
291
|
+
await it("LUMINANCE format texImage2D — no error", async () => {
|
|
292
|
+
const tex = gl.createTexture();
|
|
293
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
294
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
295
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
296
|
+
const data = new Uint8Array([
|
|
297
|
+
128,
|
|
298
|
+
64,
|
|
299
|
+
192,
|
|
300
|
+
32
|
|
301
|
+
]);
|
|
302
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE, 4, 1, 0, gl.LUMINANCE, gl.UNSIGNED_BYTE, data);
|
|
303
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
304
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
305
|
+
gl.deleteTexture(tex);
|
|
306
|
+
});
|
|
307
|
+
await it("LUMINANCE_ALPHA format texImage2D — no error", async () => {
|
|
308
|
+
const tex = gl.createTexture();
|
|
309
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
310
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
|
|
311
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
|
|
312
|
+
const data = new Uint8Array([
|
|
313
|
+
128,
|
|
314
|
+
255,
|
|
315
|
+
64,
|
|
316
|
+
128
|
|
317
|
+
]);
|
|
318
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.LUMINANCE_ALPHA, 2, 1, 0, gl.LUMINANCE_ALPHA, gl.UNSIGNED_BYTE, data);
|
|
319
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
320
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
321
|
+
gl.deleteTexture(tex);
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
await describe("textures/generateMipmap", async () => {
|
|
325
|
+
beforeEach(async () => {
|
|
326
|
+
glArea.make_current();
|
|
327
|
+
});
|
|
328
|
+
await it("generateMipmap on power-of-two RGBA texture — no error", async () => {
|
|
329
|
+
const tex = gl.createTexture();
|
|
330
|
+
gl.bindTexture(gl.TEXTURE_2D, tex);
|
|
331
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR);
|
|
332
|
+
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
|
|
333
|
+
const W = 4, H = 4;
|
|
334
|
+
const data = new Uint8Array(W * H * 4).fill(255);
|
|
335
|
+
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, W, H, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);
|
|
336
|
+
gl.generateMipmap(gl.TEXTURE_2D);
|
|
337
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
338
|
+
gl.bindTexture(gl.TEXTURE_2D, null);
|
|
339
|
+
gl.deleteTexture(tex);
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
});
|
|
354
343
|
};
|
|
344
|
+
|
|
345
|
+
//#endregion
|
|
346
|
+
export { textures_spec_default as default };
|