@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
|
@@ -1,296 +1,315 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { makeProgram, makeTestFBO, destroyTestFBO } from "../test-utils.js";
|
|
1
|
+
import { destroyTestFBO, 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/attribs.spec.ts
|
|
4
6
|
var attribs_spec_default = async () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
7
|
+
await on("Display", async () => {
|
|
8
|
+
const setup = createGLSetup();
|
|
9
|
+
if (!setup) {
|
|
10
|
+
console.warn("WebGL context not available — skipping conformance/attribs tests");
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { gl, glArea, win } = setup;
|
|
14
|
+
glArea.make_current();
|
|
15
|
+
await describe("conformance/attribs/gl-vertex-attrib: vertexAttrib round-trip", async () => {
|
|
16
|
+
beforeEach(async () => {
|
|
17
|
+
glArea.make_current();
|
|
18
|
+
});
|
|
19
|
+
await it("vertexAttrib1f stores value in slot 0 and defaults to [x,0,0,1]", async () => {
|
|
20
|
+
gl.vertexAttrib1f(0, 5);
|
|
21
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
22
|
+
expect(v instanceof Float32Array).toBeTruthy();
|
|
23
|
+
expect(v[0]).toBe(5);
|
|
24
|
+
expect(v[1]).toBe(0);
|
|
25
|
+
expect(v[2]).toBe(0);
|
|
26
|
+
expect(v[3]).toBe(1);
|
|
27
|
+
});
|
|
28
|
+
await it("vertexAttrib2f stores two values and defaults the rest to [_,_,0,1]", async () => {
|
|
29
|
+
gl.vertexAttrib2f(0, 6, 7);
|
|
30
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
31
|
+
expect(v[0]).toBe(6);
|
|
32
|
+
expect(v[1]).toBe(7);
|
|
33
|
+
expect(v[2]).toBe(0);
|
|
34
|
+
expect(v[3]).toBe(1);
|
|
35
|
+
});
|
|
36
|
+
await it("vertexAttrib3f stores three values and defaults last to 1", async () => {
|
|
37
|
+
gl.vertexAttrib3f(0, 7, 8, 9);
|
|
38
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
39
|
+
expect(v[0]).toBe(7);
|
|
40
|
+
expect(v[1]).toBe(8);
|
|
41
|
+
expect(v[2]).toBe(9);
|
|
42
|
+
expect(v[3]).toBe(1);
|
|
43
|
+
});
|
|
44
|
+
await it("vertexAttrib4f stores all four values", async () => {
|
|
45
|
+
gl.vertexAttrib4f(0, 6, 7, 8, 9);
|
|
46
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
47
|
+
expect(v[0]).toBe(6);
|
|
48
|
+
expect(v[1]).toBe(7);
|
|
49
|
+
expect(v[2]).toBe(8);
|
|
50
|
+
expect(v[3]).toBe(9);
|
|
51
|
+
});
|
|
52
|
+
await it("vertexAttrib1fv with array round-trips correctly", async () => {
|
|
53
|
+
gl.vertexAttrib1fv(0, [1]);
|
|
54
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
55
|
+
expect(v[0]).toBe(1);
|
|
56
|
+
expect(v[1]).toBe(0);
|
|
57
|
+
expect(v[2]).toBe(0);
|
|
58
|
+
expect(v[3]).toBe(1);
|
|
59
|
+
});
|
|
60
|
+
await it("vertexAttrib1fv with Float32Array round-trips correctly", async () => {
|
|
61
|
+
gl.vertexAttrib1fv(0, new Float32Array([-1]));
|
|
62
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
63
|
+
expect(v[0]).toBe(-1);
|
|
64
|
+
expect(v[3]).toBe(1);
|
|
65
|
+
});
|
|
66
|
+
await it("vertexAttrib2fv with array round-trips correctly", async () => {
|
|
67
|
+
gl.vertexAttrib2fv(0, [1, 2]);
|
|
68
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
69
|
+
expect(v[0]).toBe(1);
|
|
70
|
+
expect(v[1]).toBe(2);
|
|
71
|
+
expect(v[2]).toBe(0);
|
|
72
|
+
expect(v[3]).toBe(1);
|
|
73
|
+
});
|
|
74
|
+
await it("vertexAttrib3fv with Float32Array round-trips correctly", async () => {
|
|
75
|
+
gl.vertexAttrib3fv(0, new Float32Array([
|
|
76
|
+
1,
|
|
77
|
+
-2,
|
|
78
|
+
3
|
|
79
|
+
]));
|
|
80
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
81
|
+
expect(v[0]).toBe(1);
|
|
82
|
+
expect(v[1]).toBe(-2);
|
|
83
|
+
expect(v[2]).toBe(3);
|
|
84
|
+
expect(v[3]).toBe(1);
|
|
85
|
+
});
|
|
86
|
+
await it("vertexAttrib4fv with Float32Array round-trips correctly", async () => {
|
|
87
|
+
gl.vertexAttrib4fv(0, new Float32Array([
|
|
88
|
+
1,
|
|
89
|
+
2,
|
|
90
|
+
-3,
|
|
91
|
+
4
|
|
92
|
+
]));
|
|
93
|
+
const v = gl.getVertexAttrib(0, gl.CURRENT_VERTEX_ATTRIB);
|
|
94
|
+
expect(v[0]).toBe(1);
|
|
95
|
+
expect(v[1]).toBe(2);
|
|
96
|
+
expect(v[2]).toBe(-3);
|
|
97
|
+
expect(v[3]).toBe(4);
|
|
98
|
+
});
|
|
99
|
+
await it("setting attrib values generates no GL error", async () => {
|
|
100
|
+
const numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
101
|
+
for (let i = 0; i < numAttribs; i++) {
|
|
102
|
+
gl.vertexAttrib4f(i, i * .1, i * .2, i * .3, i * .4);
|
|
103
|
+
}
|
|
104
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
await describe("conformance/attribs/gl-vertex-attrib: out-of-range index", async () => {
|
|
108
|
+
beforeEach(async () => {
|
|
109
|
+
glArea.make_current();
|
|
110
|
+
});
|
|
111
|
+
await it("getVertexAttrib with out-of-range index generates INVALID_VALUE", async () => {
|
|
112
|
+
const numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
113
|
+
gl.getVertexAttrib(numAttribs, gl.CURRENT_VERTEX_ATTRIB);
|
|
114
|
+
expect(gl.getError()).toBe(gl.INVALID_VALUE);
|
|
115
|
+
});
|
|
116
|
+
await it("vertexAttrib1fv with out-of-range index generates INVALID_VALUE", async () => {
|
|
117
|
+
const numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
118
|
+
gl.vertexAttrib1fv(numAttribs, [1]);
|
|
119
|
+
expect(gl.getError()).toBe(gl.INVALID_VALUE);
|
|
120
|
+
});
|
|
121
|
+
await it("vertexAttrib4fv with out-of-range index generates INVALID_VALUE", async () => {
|
|
122
|
+
const numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
123
|
+
gl.vertexAttrib4fv(numAttribs, new Float32Array([
|
|
124
|
+
1,
|
|
125
|
+
2,
|
|
126
|
+
3,
|
|
127
|
+
4
|
|
128
|
+
]));
|
|
129
|
+
expect(gl.getError()).toBe(gl.INVALID_VALUE);
|
|
130
|
+
});
|
|
131
|
+
await it("vertexAttrib4f with out-of-range index generates INVALID_VALUE", async () => {
|
|
132
|
+
const numAttribs = gl.getParameter(gl.MAX_VERTEX_ATTRIBS);
|
|
133
|
+
gl.vertexAttrib4f(numAttribs, 1, 2, 3, 4);
|
|
134
|
+
expect(gl.getError()).toBe(gl.INVALID_VALUE);
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
await describe("conformance/attribs/gl-enable-vertex-attrib", async () => {
|
|
138
|
+
beforeEach(async () => {
|
|
139
|
+
glArea.make_current();
|
|
140
|
+
});
|
|
141
|
+
await it("drawArrays with enabled attrib that has no buffer bound generates INVALID_OPERATION", async () => {
|
|
142
|
+
const vsSrc = `attribute vec4 vPosition; void main() { gl_Position = vPosition; }`;
|
|
143
|
+
const fsSrc = `void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }`;
|
|
144
|
+
const prog = makeProgram(gl, vsSrc, fsSrc);
|
|
145
|
+
gl.useProgram(prog);
|
|
146
|
+
const vertexObject = gl.createBuffer();
|
|
147
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
|
|
148
|
+
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
|
|
149
|
+
0,
|
|
150
|
+
.5,
|
|
151
|
+
0,
|
|
152
|
+
-.5,
|
|
153
|
+
-.5,
|
|
154
|
+
0,
|
|
155
|
+
.5,
|
|
156
|
+
-.5,
|
|
157
|
+
0
|
|
158
|
+
]), gl.STATIC_DRAW);
|
|
159
|
+
gl.enableVertexAttribArray(0);
|
|
160
|
+
gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0);
|
|
161
|
+
gl.enableVertexAttribArray(3);
|
|
162
|
+
expect(gl.getError()).toBe(gl.NO_ERROR);
|
|
163
|
+
gl.drawArrays(gl.TRIANGLES, 0, 3);
|
|
164
|
+
expect(gl.getError()).toBe(gl.INVALID_OPERATION);
|
|
165
|
+
gl.disableVertexAttribArray(0);
|
|
166
|
+
gl.disableVertexAttribArray(3);
|
|
167
|
+
gl.deleteBuffer(vertexObject);
|
|
168
|
+
gl.deleteProgram(prog);
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
await describe("conformance/attribs/gl-bindAttribLocation-repeated", async () => {
|
|
172
|
+
beforeEach(async () => {
|
|
173
|
+
glArea.make_current();
|
|
174
|
+
});
|
|
175
|
+
await it("getAttribLocation returns the bound location after linkProgram", async () => {
|
|
176
|
+
const vsSrc = `attribute vec4 vPosition; void main() { gl_Position = vPosition; }`;
|
|
177
|
+
const fsSrc = `void main() { gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); }`;
|
|
178
|
+
function setup(attribIndex) {
|
|
179
|
+
const vs = gl.createShader(gl.VERTEX_SHADER);
|
|
180
|
+
gl.shaderSource(vs, vsSrc);
|
|
181
|
+
gl.compileShader(vs);
|
|
182
|
+
const fs = gl.createShader(gl.FRAGMENT_SHADER);
|
|
183
|
+
gl.shaderSource(fs, fsSrc);
|
|
184
|
+
gl.compileShader(fs);
|
|
185
|
+
const prog = gl.createProgram();
|
|
186
|
+
gl.attachShader(prog, vs);
|
|
187
|
+
gl.attachShader(prog, fs);
|
|
188
|
+
gl.bindAttribLocation(prog, attribIndex, "vPosition");
|
|
189
|
+
gl.linkProgram(prog);
|
|
190
|
+
expect(gl.getProgramParameter(prog, gl.LINK_STATUS)).toBeTruthy();
|
|
191
|
+
expect(gl.getAttribLocation(prog, "vPosition")).toBe(attribIndex);
|
|
192
|
+
gl.deleteShader(vs);
|
|
193
|
+
gl.deleteShader(fs);
|
|
194
|
+
return prog;
|
|
195
|
+
}
|
|
196
|
+
const p0 = setup(0);
|
|
197
|
+
const p3 = setup(3);
|
|
198
|
+
const p1 = setup(1);
|
|
199
|
+
const p3b = setup(3);
|
|
200
|
+
gl.deleteProgram(p0);
|
|
201
|
+
gl.deleteProgram(p3);
|
|
202
|
+
gl.deleteProgram(p1);
|
|
203
|
+
gl.deleteProgram(p3b);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
await describe("conformance/attribs/attribute-weirdness", async () => {
|
|
207
|
+
beforeEach(async () => {
|
|
208
|
+
glArea.make_current();
|
|
209
|
+
});
|
|
210
|
+
const W = 2, H = 2;
|
|
211
|
+
const VDATA = new Int16Array([
|
|
212
|
+
0,
|
|
213
|
+
0,
|
|
214
|
+
0,
|
|
215
|
+
0,
|
|
216
|
+
4,
|
|
217
|
+
0,
|
|
218
|
+
1,
|
|
219
|
+
0,
|
|
220
|
+
0,
|
|
221
|
+
4,
|
|
222
|
+
0,
|
|
223
|
+
1,
|
|
224
|
+
4,
|
|
225
|
+
4,
|
|
226
|
+
1,
|
|
227
|
+
1
|
|
228
|
+
]);
|
|
229
|
+
function renderAttribWeirdness(flipAttributes, flipLocations) {
|
|
230
|
+
const fbo = makeTestFBO(gl, W, H);
|
|
231
|
+
const attrs = ["attribute vec2 a_pos;", "attribute vec2 a_texture_pos;"];
|
|
232
|
+
if (flipAttributes) attrs.reverse();
|
|
233
|
+
const vsSrc = [
|
|
234
|
+
"precision mediump float;",
|
|
235
|
+
attrs[0],
|
|
236
|
+
attrs[1],
|
|
237
|
+
"varying vec2 v_pos0;",
|
|
238
|
+
"void main() {",
|
|
239
|
+
" v_pos0 = a_texture_pos;",
|
|
240
|
+
" gl_Position = vec4(a_pos - 1.0, 0.0, 1.0);",
|
|
241
|
+
"}"
|
|
242
|
+
].join("\n");
|
|
243
|
+
const fsSrc = [
|
|
244
|
+
"precision mediump float;",
|
|
245
|
+
"varying vec2 v_pos0;",
|
|
246
|
+
"void main() {",
|
|
247
|
+
" gl_FragColor = vec4(v_pos0.x, 0.0, 0.0, 1.0);",
|
|
248
|
+
"}"
|
|
249
|
+
].join("\n");
|
|
250
|
+
gl.clearColor(0, 0, 0, 0);
|
|
251
|
+
gl.clear(gl.COLOR_BUFFER_BIT);
|
|
252
|
+
const prog = makeProgram(gl, vsSrc, fsSrc);
|
|
253
|
+
gl.useProgram(prog);
|
|
254
|
+
const buf = gl.createBuffer();
|
|
255
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
|
|
256
|
+
gl.bufferData(gl.ARRAY_BUFFER, VDATA, gl.STATIC_DRAW);
|
|
257
|
+
let aPos = gl.getAttribLocation(prog, "a_pos");
|
|
258
|
+
let aTexPos = gl.getAttribLocation(prog, "a_texture_pos");
|
|
259
|
+
gl.enableVertexAttribArray(aPos);
|
|
260
|
+
gl.enableVertexAttribArray(aTexPos);
|
|
261
|
+
if (flipLocations) {
|
|
262
|
+
const tmp = aPos;
|
|
263
|
+
aPos = aTexPos;
|
|
264
|
+
aTexPos = tmp;
|
|
265
|
+
}
|
|
266
|
+
gl.vertexAttribPointer(aPos, 2, gl.SHORT, false, 8, 0);
|
|
267
|
+
gl.vertexAttribPointer(aTexPos, 2, gl.SHORT, false, 8, 4);
|
|
268
|
+
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
|
269
|
+
gl.bindBuffer(gl.ARRAY_BUFFER, null);
|
|
270
|
+
gl.deleteBuffer(buf);
|
|
271
|
+
const pixels = new Uint8Array(W * H * 4);
|
|
272
|
+
gl.readPixels(0, 0, W, H, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
|
|
273
|
+
destroyTestFBO(gl, fbo);
|
|
274
|
+
return pixels;
|
|
275
|
+
}
|
|
276
|
+
await it("normal order: all alpha values are 255 (quad covers canvas)", async () => {
|
|
277
|
+
const pixels = renderAttribWeirdness(false, false);
|
|
278
|
+
let ok = true;
|
|
279
|
+
for (let i = 3; i < W * H * 4; i += 4) {
|
|
280
|
+
if (pixels[i] !== 255) {
|
|
281
|
+
ok = false;
|
|
282
|
+
break;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
expect(ok).toBe(true);
|
|
286
|
+
});
|
|
287
|
+
await it("flipped attribute declarations: all alpha values are still 255", async () => {
|
|
288
|
+
const pixels = renderAttribWeirdness(true, false);
|
|
289
|
+
let ok = true;
|
|
290
|
+
for (let i = 3; i < W * H * 4; i += 4) {
|
|
291
|
+
if (pixels[i] !== 255) {
|
|
292
|
+
ok = false;
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
expect(ok).toBe(true);
|
|
297
|
+
});
|
|
298
|
+
await it("swapped location assignments: quad does not cover canvas (some alpha ≠ 255)", async () => {
|
|
299
|
+
const pixels = renderAttribWeirdness(false, true);
|
|
300
|
+
let hasNonAlpha = false;
|
|
301
|
+
for (let i = 3; i < W * H * 4; i += 4) {
|
|
302
|
+
if (pixels[i] !== 255) {
|
|
303
|
+
hasNonAlpha = true;
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
expect(hasNonAlpha).toBe(true);
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
win.destroy();
|
|
311
|
+
});
|
|
296
312
|
};
|
|
313
|
+
|
|
314
|
+
//#endregion
|
|
315
|
+
export { attribs_spec_default as default };
|