@gjsify/webgl 0.3.15 → 0.3.17
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 +3 -315
- package/lib/esm/conformance/buffers.spec.js +1 -220
- package/lib/esm/conformance/context.spec.js +3 -302
- package/lib/esm/conformance/programs.spec.js +3 -477
- package/lib/esm/conformance/rendering-basic.spec.js +3 -141
- package/lib/esm/conformance/rendering.spec.js +7 -514
- package/lib/esm/conformance/setup.js +1 -47
- package/lib/esm/conformance/state.spec.js +1 -365
- package/lib/esm/conformance/textures.spec.js +3 -337
- package/lib/esm/conformance/uniforms.spec.js +1 -484
- package/lib/esm/conformance-test.js +1 -25
- package/lib/esm/extensions/ext-blend-minmax.js +1 -18
- package/lib/esm/extensions/ext-color-buffer-float.js +1 -12
- package/lib/esm/extensions/ext-color-buffer-half-float.js +1 -12
- package/lib/esm/extensions/ext-texture-filter-anisotropic.js +1 -18
- package/lib/esm/extensions/oes-element-index-unit.js +1 -13
- package/lib/esm/extensions/oes-standard-derivatives.js +1 -17
- package/lib/esm/extensions/oes-texture-float-linear.js +1 -13
- package/lib/esm/extensions/oes-texture-float.js +1 -13
- package/lib/esm/extensions/oes-texture-half-float.js +1 -19
- package/lib/esm/extensions/stackgl-destroy-context.js +1 -12
- package/lib/esm/extensions/stackgl-resize-drawing-buffer.js +1 -12
- package/lib/esm/html-canvas-element.js +1 -65
- package/lib/esm/index.js +1 -33
- package/lib/esm/linkable.js +1 -50
- package/lib/esm/test-utils.js +4 -186
- package/lib/esm/test.js +1 -11
- package/lib/esm/types/index.js +1 -5
- package/lib/esm/utils.js +1 -201
- package/lib/esm/webgl-active-info.js +1 -11
- package/lib/esm/webgl-bridge.js +1 -167
- package/lib/esm/webgl-buffer.js +1 -19
- package/lib/esm/webgl-context-attributes.js +1 -24
- package/lib/esm/webgl-context-base.js +8 -3069
- package/lib/esm/webgl-drawing-buffer-wrapper.js +1 -11
- package/lib/esm/webgl-framebuffer.js +1 -110
- package/lib/esm/webgl-program.js +1 -27
- package/lib/esm/webgl-query.js +1 -17
- package/lib/esm/webgl-renderbuffer.js +1 -25
- package/lib/esm/webgl-rendering-context.js +1 -175
- package/lib/esm/webgl-sampler.js +1 -17
- package/lib/esm/webgl-shader-precision-format.js +1 -11
- package/lib/esm/webgl-shader.js +1 -25
- package/lib/esm/webgl-sync.js +1 -17
- package/lib/esm/webgl-texture-unit.js +1 -13
- package/lib/esm/webgl-texture.js +1 -23
- package/lib/esm/webgl-transform-feedback.js +1 -17
- package/lib/esm/webgl-uniform-location.js +1 -15
- package/lib/esm/webgl-vertex-array-object.js +1 -23
- package/lib/esm/webgl-vertex-attribute.js +1 -151
- package/lib/esm/webgl1.spec.js +10 -1044
- package/lib/esm/webgl2-rendering-context.js +1 -1218
- package/lib/esm/webgl2.spec.js +45 -1288
- package/lib/types/webgl-bridge.d.ts +9 -9
- package/package.json +9 -9
|
@@ -1,346 +1,12 @@
|
|
|
1
|
-
import
|
|
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
|
|
6
|
-
const VS_TEX = `
|
|
1
|
+
import{destroyTestFBO as e,drawTriangle as t,makeProgram as n,makeTestFBO as r}from"../test-utils.js";import{createGLSetup as i}from"./setup.js";import{beforeEach as a,describe as o,expect as s,it as c,on as l}from"@gjsify/unit";const u=`
|
|
7
2
|
precision mediump float;
|
|
8
3
|
attribute vec2 position;
|
|
9
4
|
varying vec2 vTexCoord;
|
|
10
5
|
void main() {
|
|
11
6
|
vTexCoord = 0.5 * (position + 1.0);
|
|
12
7
|
gl_Position = vec4(position, 0.0, 1.0);
|
|
13
|
-
}
|
|
14
|
-
const FS_TEX = `
|
|
8
|
+
}`,d=`
|
|
15
9
|
precision mediump float;
|
|
16
10
|
uniform sampler2D uTex;
|
|
17
11
|
varying vec2 vTexCoord;
|
|
18
|
-
void main() { gl_FragColor = texture2D(uTex, vTexCoord); }`;
|
|
19
|
-
var textures_spec_default = async () => {
|
|
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
|
-
});
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
//#endregion
|
|
346
|
-
export { textures_spec_default as default };
|
|
12
|
+
void main() { gl_FragColor = texture2D(uTex, vTexCoord); }`;var f=async()=>{await l(`Display`,async()=>{let l=i();if(!l){console.warn(`WebGL context not available — skipping conformance/textures tests`);return}let{gl:f,glArea:p}=l;p.make_current(),await o(`textures/texImage2D-rgba`,async()=>{a(async()=>{p.make_current()}),await c(`upload 2×2 RGBA Uint8Array and sample it back`,async()=>{let i=r(f,2,2),a=new Uint8Array([255,0,0,255,0,255,0,255,0,0,255,255,255,255,0,255]),o=f.createTexture();f.bindTexture(f.TEXTURE_2D,o),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,2,2,0,f.RGBA,f.UNSIGNED_BYTE,a);let c=n(f,u,d);f.useProgram(c),f.uniform1i(f.getUniformLocation(c,`uTex`),0),t(f),s(f.getError()).toBe(f.NO_ERROR),f.deleteTexture(o),e(f,i)}),await c(`createTexture returns non-null; deleteTexture cleans up`,async()=>{let e=f.createTexture();s(e).toBeDefined(),f.bindTexture(f.TEXTURE_2D,e),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,1,1,0,f.RGBA,f.UNSIGNED_BYTE,new Uint8Array([128,128,128,255])),s(f.getError()).toBe(f.NO_ERROR),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e),s(f.getError()).toBe(f.NO_ERROR)})}),await o(`textures/alpha-texture`,async()=>{a(async()=>{p.make_current()}),await c(`ALPHA format texImage2D: RGB channels zero, alpha matches upload data`,async()=>{let i=r(f,4,4),a=new Uint8Array(16);for(let e=0;e<4;e++)for(let t=0;t<4;t++)a[e*4+t]=(e+t)%255;let o=f.createTexture();f.bindTexture(f.TEXTURE_2D,o),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texImage2D(f.TEXTURE_2D,0,f.ALPHA,4,4,0,f.ALPHA,f.UNSIGNED_BYTE,a),s(f.getError()).toBe(f.NO_ERROR),f.clearColor(0,0,0,0),f.clear(f.COLOR_BUFFER_BIT);let c=n(f,u,d);f.useProgram(c),f.uniform1i(f.getUniformLocation(c,`uTex`),0),t(f),s(f.getError()).toBe(f.NO_ERROR);let l=new Uint8Array(64);f.readPixels(0,0,4,4,f.RGBA,f.UNSIGNED_BYTE,l);let p=!0;for(let e=0;e<16;e++){let t=e*4;if(l[t]!==0||l[t+1]!==0||l[t+2]!==0){p=!1;break}if(Math.abs(l[t+3]-a[e])>3){p=!1;break}}s(p).toBe(!0),f.deleteTexture(o),e(f,i)})}),await o(`textures/texSubImage2D`,async()=>{a(async()=>{p.make_current()}),await c(`texSubImage2D overwrites a sub-region of an RGBA texture`,async()=>{let t=r(f,4,4),n=new Uint8Array(64).fill(0);for(let e=0;e<16;e++)n[e*4]=255,n[e*4+3]=255;let i=f.createTexture();f.bindTexture(f.TEXTURE_2D,i),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texImage2D(f.TEXTURE_2D,0,f.RGBA,4,4,0,f.RGBA,f.UNSIGNED_BYTE,n);let a=new Uint8Array([0,255,0,255,0,255,0,255,0,255,0,255,0,255,0,255]);f.texSubImage2D(f.TEXTURE_2D,0,0,0,2,2,f.RGBA,f.UNSIGNED_BYTE,a),s(f.getError()).toBe(f.NO_ERROR),f.deleteTexture(i),e(f,t)})}),await o(`textures/parameters`,async()=>{a(async()=>{p.make_current()}),await c(`getTexParameter returns set WRAP and FILTER values`,async()=>{let e=f.createTexture();f.bindTexture(f.TEXTURE_2D,e),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_T,f.REPEAT),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.LINEAR),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST),s(f.getTexParameter(f.TEXTURE_2D,f.TEXTURE_WRAP_S)).toBe(f.CLAMP_TO_EDGE),s(f.getTexParameter(f.TEXTURE_2D,f.TEXTURE_WRAP_T)).toBe(f.REPEAT),s(f.getTexParameter(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER)).toBe(f.LINEAR),s(f.getTexParameter(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER)).toBe(f.NEAREST),s(f.getError()).toBe(f.NO_ERROR),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e)}),await c(`MIRRORED_REPEAT wrap mode is accepted`,async()=>{let e=f.createTexture();f.bindTexture(f.TEXTURE_2D,e),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_WRAP_S,f.MIRRORED_REPEAT),s(f.getError()).toBe(f.NO_ERROR),s(f.getTexParameter(f.TEXTURE_2D,f.TEXTURE_WRAP_S)).toBe(f.MIRRORED_REPEAT),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e)}),await c(`LINEAR_MIPMAP_LINEAR min filter is accepted`,async()=>{let e=f.createTexture();f.bindTexture(f.TEXTURE_2D,e),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.LINEAR_MIPMAP_LINEAR),s(f.getError()).toBe(f.NO_ERROR),s(f.getTexParameter(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER)).toBe(f.LINEAR_MIPMAP_LINEAR),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e)})}),await o(`textures/active-texture`,async()=>{a(async()=>{p.make_current()}),await c(`activeTexture switches binding slot; each unit holds independent binding`,async()=>{let e=f.createTexture(),t=f.createTexture();f.activeTexture(f.TEXTURE0),f.bindTexture(f.TEXTURE_2D,e),f.activeTexture(f.TEXTURE1),f.bindTexture(f.TEXTURE_2D,t),f.activeTexture(f.TEXTURE0),s(f.getParameter(f.TEXTURE_BINDING_2D)).toBe(e),f.activeTexture(f.TEXTURE1),s(f.getParameter(f.TEXTURE_BINDING_2D)).toBe(t),s(f.getError()).toBe(f.NO_ERROR),f.activeTexture(f.TEXTURE0),f.bindTexture(f.TEXTURE_2D,null),f.activeTexture(f.TEXTURE1),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e),f.deleteTexture(t)}),await c(`getParameter ACTIVE_TEXTURE reflects activeTexture call`,async()=>{f.activeTexture(f.TEXTURE3),s(f.getParameter(f.ACTIVE_TEXTURE)).toBe(f.TEXTURE3),f.activeTexture(f.TEXTURE0),s(f.getParameter(f.ACTIVE_TEXTURE)).toBe(f.TEXTURE0),s(f.getError()).toBe(f.NO_ERROR)})}),await o(`textures/cubemap`,async()=>{a(async()=>{p.make_current()}),await c(`attach all 6 cubemap faces to FBO — no GL error`,async()=>{let e=f.createTexture(),t=f.createFramebuffer(),n=new Uint8Array([255,255,255,255]);f.activeTexture(f.TEXTURE1),f.bindTexture(f.TEXTURE_CUBE_MAP,e),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_MAG_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_MIN_FILTER,f.NEAREST),f.bindFramebuffer(f.FRAMEBUFFER,t);for(let t=0;t<6;t++)f.texImage2D(f.TEXTURE_CUBE_MAP_POSITIVE_X+t,0,f.RGBA,1,1,0,f.RGBA,f.UNSIGNED_BYTE,n),f.framebufferTexture2D(f.FRAMEBUFFER,f.COLOR_ATTACHMENT0,f.TEXTURE_CUBE_MAP_POSITIVE_X+t,e,0);s(f.getError()).toBe(f.NO_ERROR),f.bindFramebuffer(f.FRAMEBUFFER,null),f.activeTexture(f.TEXTURE1),f.bindTexture(f.TEXTURE_CUBE_MAP,null),f.activeTexture(f.TEXTURE0),f.deleteTexture(e),f.deleteFramebuffer(t)}),await c(`createTexture with TEXTURE_CUBE_MAP binding — no error`,async()=>{let e=f.createTexture();f.bindTexture(f.TEXTURE_CUBE_MAP,e),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_MIN_FILTER,f.LINEAR),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_MAG_FILTER,f.LINEAR),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_WRAP_S,f.CLAMP_TO_EDGE),f.texParameteri(f.TEXTURE_CUBE_MAP,f.TEXTURE_WRAP_T,f.CLAMP_TO_EDGE),s(f.getError()).toBe(f.NO_ERROR),f.bindTexture(f.TEXTURE_CUBE_MAP,null),f.deleteTexture(e)})}),await o(`textures/luminance`,async()=>{a(async()=>{p.make_current()}),await c(`LUMINANCE format texImage2D — no error`,async()=>{let e=f.createTexture();f.bindTexture(f.TEXTURE_2D,e),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST);let t=new Uint8Array([128,64,192,32]);f.texImage2D(f.TEXTURE_2D,0,f.LUMINANCE,4,1,0,f.LUMINANCE,f.UNSIGNED_BYTE,t),s(f.getError()).toBe(f.NO_ERROR),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e)}),await c(`LUMINANCE_ALPHA format texImage2D — no error`,async()=>{let e=f.createTexture();f.bindTexture(f.TEXTURE_2D,e),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.NEAREST),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.NEAREST);let t=new Uint8Array([128,255,64,128]);f.texImage2D(f.TEXTURE_2D,0,f.LUMINANCE_ALPHA,2,1,0,f.LUMINANCE_ALPHA,f.UNSIGNED_BYTE,t),s(f.getError()).toBe(f.NO_ERROR),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e)})}),await o(`textures/generateMipmap`,async()=>{a(async()=>{p.make_current()}),await c(`generateMipmap on power-of-two RGBA texture — no error`,async()=>{let e=f.createTexture();f.bindTexture(f.TEXTURE_2D,e),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MIN_FILTER,f.LINEAR_MIPMAP_LINEAR),f.texParameteri(f.TEXTURE_2D,f.TEXTURE_MAG_FILTER,f.LINEAR);let t=new Uint8Array(64).fill(255);f.texImage2D(f.TEXTURE_2D,0,f.RGBA,4,4,0,f.RGBA,f.UNSIGNED_BYTE,t),f.generateMipmap(f.TEXTURE_2D),s(f.getError()).toBe(f.NO_ERROR),f.bindTexture(f.TEXTURE_2D,null),f.deleteTexture(e)})})})};export{f as default};
|