@gjsify/webgl 0.1.2 → 0.1.4

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 (59) hide show
  1. package/lib/esm/canvas-webgl-widget.js +12 -0
  2. package/lib/esm/conformance/attribs.spec.js +296 -0
  3. package/lib/esm/conformance/buffers.spec.js +203 -0
  4. package/lib/esm/conformance/context.spec.js +302 -0
  5. package/lib/esm/conformance/programs.spec.js +468 -0
  6. package/lib/esm/conformance/rendering-basic.spec.js +136 -0
  7. package/lib/esm/conformance/rendering.spec.js +424 -0
  8. package/lib/esm/conformance/setup.js +36 -0
  9. package/lib/esm/conformance/state.spec.js +348 -0
  10. package/lib/esm/conformance/textures.spec.js +354 -0
  11. package/lib/esm/conformance/uniforms.spec.js +305 -0
  12. package/lib/esm/conformance-test.js +23 -0
  13. package/lib/esm/extensions/ext-color-buffer-float.js +13 -0
  14. package/lib/esm/extensions/ext-color-buffer-half-float.js +13 -0
  15. package/lib/esm/extensions/oes-texture-half-float.js +19 -0
  16. package/lib/esm/index.js +5 -0
  17. package/lib/esm/test-utils.js +65 -0
  18. package/lib/esm/test.js +2 -2
  19. package/lib/esm/webgl-buffer.js +1 -1
  20. package/lib/esm/webgl-context-base.js +3371 -0
  21. package/lib/esm/webgl-framebuffer.js +1 -1
  22. package/lib/esm/webgl-program.js +1 -1
  23. package/lib/esm/webgl-renderbuffer.js +1 -1
  24. package/lib/esm/webgl-rendering-context.js +95 -3253
  25. package/lib/esm/webgl-shader.js +2 -1
  26. package/lib/esm/webgl-texture.js +1 -1
  27. package/lib/esm/{index.spec.js → webgl1.spec.js} +2 -2
  28. package/lib/esm/webgl2-rendering-context.js +617 -27
  29. package/lib/esm/webgl2.spec.js +573 -1
  30. package/lib/types/conformance/setup.d.ts +14 -0
  31. package/lib/types/extensions/ext-blend-minmax.d.ts +2 -2
  32. package/lib/types/extensions/ext-color-buffer-float.d.ts +4 -0
  33. package/lib/types/extensions/ext-color-buffer-half-float.d.ts +4 -0
  34. package/lib/types/extensions/ext-texture-filter-anisotropic.d.ts +2 -2
  35. package/lib/types/extensions/oes-element-index-unit.d.ts +2 -2
  36. package/lib/types/extensions/oes-standard-derivatives.d.ts +2 -2
  37. package/lib/types/extensions/oes-texture-float-linear.d.ts +2 -2
  38. package/lib/types/extensions/oes-texture-float.d.ts +2 -2
  39. package/lib/types/extensions/oes-texture-half-float.d.ts +5 -0
  40. package/lib/types/extensions/stackgl-destroy-context.d.ts +3 -3
  41. package/lib/types/extensions/stackgl-resize-drawing-buffer.d.ts +3 -3
  42. package/lib/types/index.d.ts +1 -0
  43. package/lib/types/test-utils.d.ts +24 -0
  44. package/lib/types/types/extension.d.ts +2 -2
  45. package/lib/types/utils.d.ts +9 -10
  46. package/lib/types/webgl-buffer.d.ts +3 -3
  47. package/lib/types/webgl-context-base.d.ts +267 -0
  48. package/lib/types/webgl-framebuffer.d.ts +3 -3
  49. package/lib/types/webgl-program.d.ts +3 -3
  50. package/lib/types/webgl-renderbuffer.d.ts +3 -3
  51. package/lib/types/webgl-rendering-context.d.ts +5 -250
  52. package/lib/types/webgl-shader.d.ts +4 -3
  53. package/lib/types/webgl-texture-unit.d.ts +3 -3
  54. package/lib/types/webgl-texture.d.ts +3 -3
  55. package/lib/types/webgl-vertex-attribute.d.ts +5 -5
  56. package/lib/types/webgl2-rendering-context.d.ts +95 -6
  57. package/package.json +13 -11
  58. package/prebuilds/linux-x86_64/Gwebgl-0.1.typelib +0 -0
  59. package/prebuilds/linux-x86_64/libgwebgl.so +0 -0
@@ -0,0 +1,302 @@
1
+ import { describe, it, expect, beforeEach, on } from "@gjsify/unit";
2
+ import { WebGLRenderingContext as OurWebGLRenderingContext } from "@gjsify/webgl";
3
+ import { createGLSetup } from "./setup.js";
4
+ const WEBGL_METHODS = [
5
+ "getContextAttributes",
6
+ "activeTexture",
7
+ "attachShader",
8
+ "bindAttribLocation",
9
+ "bindBuffer",
10
+ "bindFramebuffer",
11
+ "bindRenderbuffer",
12
+ "bindTexture",
13
+ "blendColor",
14
+ "blendEquation",
15
+ "blendEquationSeparate",
16
+ "blendFunc",
17
+ "blendFuncSeparate",
18
+ "bufferData",
19
+ "bufferSubData",
20
+ "checkFramebufferStatus",
21
+ "clear",
22
+ "clearColor",
23
+ "clearDepth",
24
+ "clearStencil",
25
+ "colorMask",
26
+ "compileShader",
27
+ "compressedTexImage2D",
28
+ "compressedTexSubImage2D",
29
+ "copyTexImage2D",
30
+ "copyTexSubImage2D",
31
+ "createBuffer",
32
+ "createFramebuffer",
33
+ "createProgram",
34
+ "createRenderbuffer",
35
+ "createShader",
36
+ "createTexture",
37
+ "cullFace",
38
+ "deleteBuffer",
39
+ "deleteFramebuffer",
40
+ "deleteProgram",
41
+ "deleteRenderbuffer",
42
+ "deleteShader",
43
+ "deleteTexture",
44
+ "depthFunc",
45
+ "depthMask",
46
+ "depthRange",
47
+ "detachShader",
48
+ "disable",
49
+ "disableVertexAttribArray",
50
+ "drawArrays",
51
+ "drawElements",
52
+ "enable",
53
+ "enableVertexAttribArray",
54
+ "finish",
55
+ "flush",
56
+ "framebufferRenderbuffer",
57
+ "framebufferTexture2D",
58
+ "frontFace",
59
+ "generateMipmap",
60
+ "getActiveAttrib",
61
+ "getActiveUniform",
62
+ "getAttachedShaders",
63
+ "getAttribLocation",
64
+ "getParameter",
65
+ "getBufferParameter",
66
+ "getError",
67
+ "getExtension",
68
+ "getFramebufferAttachmentParameter",
69
+ "getProgramParameter",
70
+ "getProgramInfoLog",
71
+ "getRenderbufferParameter",
72
+ "getShaderParameter",
73
+ "getShaderInfoLog",
74
+ "getShaderPrecisionFormat",
75
+ "getShaderSource",
76
+ "getSupportedExtensions",
77
+ "getTexParameter",
78
+ "getUniform",
79
+ "getUniformLocation",
80
+ "getVertexAttrib",
81
+ "getVertexAttribOffset",
82
+ "hint",
83
+ "isBuffer",
84
+ "isContextLost",
85
+ "isEnabled",
86
+ "isFramebuffer",
87
+ "isProgram",
88
+ "isRenderbuffer",
89
+ "isShader",
90
+ "isTexture",
91
+ "lineWidth",
92
+ "linkProgram",
93
+ "pixelStorei",
94
+ "polygonOffset",
95
+ "readPixels",
96
+ "renderbufferStorage",
97
+ "sampleCoverage",
98
+ "scissor",
99
+ "shaderSource",
100
+ "stencilFunc",
101
+ "stencilFuncSeparate",
102
+ "stencilMask",
103
+ "stencilMaskSeparate",
104
+ "stencilOp",
105
+ "stencilOpSeparate",
106
+ "texImage2D",
107
+ "texParameterf",
108
+ "texParameteri",
109
+ "texSubImage2D",
110
+ "uniform1f",
111
+ "uniform1fv",
112
+ "uniform1i",
113
+ "uniform1iv",
114
+ "uniform2f",
115
+ "uniform2fv",
116
+ "uniform2i",
117
+ "uniform2iv",
118
+ "uniform3f",
119
+ "uniform3fv",
120
+ "uniform3i",
121
+ "uniform3iv",
122
+ "uniform4f",
123
+ "uniform4fv",
124
+ "uniform4i",
125
+ "uniform4iv",
126
+ "uniformMatrix2fv",
127
+ "uniformMatrix3fv",
128
+ "uniformMatrix4fv",
129
+ "useProgram",
130
+ "validateProgram",
131
+ "vertexAttrib1f",
132
+ "vertexAttrib1fv",
133
+ "vertexAttrib2f",
134
+ "vertexAttrib2fv",
135
+ "vertexAttrib3f",
136
+ "vertexAttrib3fv",
137
+ "vertexAttrib4f",
138
+ "vertexAttrib4fv",
139
+ "vertexAttribPointer",
140
+ "viewport"
141
+ ];
142
+ const WEBGL_CONSTANTS = [
143
+ ["DEPTH_BUFFER_BIT", 256],
144
+ ["STENCIL_BUFFER_BIT", 1024],
145
+ ["COLOR_BUFFER_BIT", 16384],
146
+ ["POINTS", 0],
147
+ ["LINES", 1],
148
+ ["LINE_LOOP", 2],
149
+ ["LINE_STRIP", 3],
150
+ ["TRIANGLES", 4],
151
+ ["TRIANGLE_STRIP", 5],
152
+ ["TRIANGLE_FAN", 6],
153
+ ["ZERO", 0],
154
+ ["ONE", 1],
155
+ ["SRC_COLOR", 768],
156
+ ["SRC_ALPHA", 770],
157
+ ["FUNC_ADD", 32774],
158
+ ["ARRAY_BUFFER", 34962],
159
+ ["ELEMENT_ARRAY_BUFFER", 34963],
160
+ ["STREAM_DRAW", 35040],
161
+ ["STATIC_DRAW", 35044],
162
+ ["DYNAMIC_DRAW", 35048],
163
+ ["FRAGMENT_SHADER", 35632],
164
+ ["VERTEX_SHADER", 35633],
165
+ ["COMPILE_STATUS", 35713],
166
+ ["LINK_STATUS", 35714],
167
+ ["VALIDATE_STATUS", 35715],
168
+ ["FLOAT", 5126],
169
+ ["FLOAT_VEC2", 35664],
170
+ ["FLOAT_VEC3", 35665],
171
+ ["FLOAT_VEC4", 35666],
172
+ ["FLOAT_MAT2", 35674],
173
+ ["FLOAT_MAT3", 35675],
174
+ ["FLOAT_MAT4", 35676],
175
+ ["INT", 5124],
176
+ ["TEXTURE_2D", 3553],
177
+ ["TEXTURE_CUBE_MAP", 34067],
178
+ ["RGBA", 6408],
179
+ ["RGB", 6407],
180
+ ["UNSIGNED_BYTE", 5121],
181
+ ["UNSIGNED_SHORT", 5123],
182
+ ["UNSIGNED_INT", 5125],
183
+ ["FRAMEBUFFER", 36160],
184
+ ["RENDERBUFFER", 36161],
185
+ ["DEPTH_COMPONENT16", 33189],
186
+ ["DEPTH_ATTACHMENT", 36096],
187
+ ["COLOR_ATTACHMENT0", 36064],
188
+ ["FRAMEBUFFER_COMPLETE", 36053],
189
+ ["NO_ERROR", 0],
190
+ ["INVALID_ENUM", 1280],
191
+ ["INVALID_VALUE", 1281],
192
+ ["INVALID_OPERATION", 1282],
193
+ ["OUT_OF_MEMORY", 1285]
194
+ ];
195
+ var context_spec_default = async () => {
196
+ await on("Display", async () => {
197
+ const setup = createGLSetup();
198
+ if (!setup) {
199
+ console.warn("WebGL context not available \u2014 skipping conformance/context tests");
200
+ return;
201
+ }
202
+ const { gl, glArea, win } = setup;
203
+ glArea.make_current();
204
+ await describe("conformance/context/methods: all WebGL methods present", async () => {
205
+ beforeEach(async () => {
206
+ glArea.make_current();
207
+ });
208
+ await it("all standard WebGL methods are functions on the context", async () => {
209
+ const missing = [];
210
+ for (const method of WEBGL_METHODS) {
211
+ if (typeof gl[method] !== "function") {
212
+ missing.push(method);
213
+ }
214
+ }
215
+ if (missing.length > 0) {
216
+ throw new Error(`Missing WebGL methods: ${missing.join(", ")}`);
217
+ }
218
+ });
219
+ });
220
+ await describe("conformance/context/constants-and-properties: constant values", async () => {
221
+ beforeEach(async () => {
222
+ glArea.make_current();
223
+ });
224
+ await it("all sampled WebGL constants have the correct numeric value", async () => {
225
+ const wrong = [];
226
+ for (const [name, expected] of WEBGL_CONSTANTS) {
227
+ const actual = gl[name];
228
+ if (actual !== expected) {
229
+ wrong.push(`${name}: expected ${expected}, got ${actual}`);
230
+ }
231
+ }
232
+ if (wrong.length > 0) {
233
+ throw new Error(`Wrong constant values:
234
+ ${wrong.join("\n")}`);
235
+ }
236
+ });
237
+ await it("WebGLRenderingContext class constant values match instance constants", async () => {
238
+ const wrong = [];
239
+ for (const [name, expected] of WEBGL_CONSTANTS) {
240
+ const classVal = OurWebGLRenderingContext[name];
241
+ if (classVal !== void 0 && classVal !== expected) {
242
+ wrong.push(`${name}: expected ${expected}, got ${classVal}`);
243
+ }
244
+ }
245
+ if (wrong.length > 0) {
246
+ throw new Error(`Wrong class constant values:
247
+ ${wrong.join("\n")}`);
248
+ }
249
+ });
250
+ });
251
+ await describe("conformance/context/context-type-test", async () => {
252
+ beforeEach(async () => {
253
+ glArea.make_current();
254
+ });
255
+ await it("WebGLRenderingContext should exist in globalThis", async () => {
256
+ expect(typeof globalThis.WebGLRenderingContext !== "undefined").toBeTruthy();
257
+ });
258
+ await it("gl should be an instance of WebGLRenderingContext", async () => {
259
+ expect(gl instanceof OurWebGLRenderingContext).toBeTruthy();
260
+ });
261
+ await it("getContextAttributes returns an object", async () => {
262
+ const attrs = gl.getContextAttributes();
263
+ expect(attrs).not.toBeNull();
264
+ expect(typeof attrs).toBe("object");
265
+ });
266
+ await it("isContextLost returns false initially", async () => {
267
+ expect(gl.isContextLost()).toBe(false);
268
+ });
269
+ await it("canvas property points to the HTMLCanvasElement", async () => {
270
+ expect(gl.canvas).not.toBeNull();
271
+ expect(typeof gl.canvas.getContext).toBe("function");
272
+ });
273
+ await it("drawingBufferWidth and drawingBufferHeight are positive integers", async () => {
274
+ expect(gl.drawingBufferWidth).toBeGreaterThan(0);
275
+ expect(gl.drawingBufferHeight).toBeGreaterThan(0);
276
+ expect(Number.isInteger(gl.drawingBufferWidth)).toBeTruthy();
277
+ expect(Number.isInteger(gl.drawingBufferHeight)).toBeTruthy();
278
+ });
279
+ await it("getSupportedExtensions returns an array of strings", async () => {
280
+ const exts = gl.getSupportedExtensions();
281
+ expect(Array.isArray(exts)).toBeTruthy();
282
+ for (const ext of exts) {
283
+ expect(typeof ext).toBe("string");
284
+ }
285
+ });
286
+ await it("getParameter(VENDOR) and getParameter(RENDERER) return strings", async () => {
287
+ const vendor = gl.getParameter(gl.VENDOR);
288
+ const renderer = gl.getParameter(gl.RENDERER);
289
+ const version = gl.getParameter(gl.VERSION);
290
+ const shadingLang = gl.getParameter(gl.SHADING_LANGUAGE_VERSION);
291
+ expect(typeof vendor).toBe("string");
292
+ expect(typeof renderer).toBe("string");
293
+ expect(typeof version).toBe("string");
294
+ expect(typeof shadingLang).toBe("string");
295
+ });
296
+ });
297
+ win.destroy();
298
+ });
299
+ };
300
+ export {
301
+ context_spec_default as default
302
+ };