q5 3.3.3 → 3.4.0
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/deno.json +1 -1
- package/package.json +1 -1
- package/q5.d.ts +278 -373
- package/q5.js +54 -16
- package/q5.min.js +2 -2
package/q5.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* q5.js
|
|
3
|
-
* @version 3.
|
|
3
|
+
* @version 3.4
|
|
4
4
|
* @author quinton-ashley
|
|
5
5
|
* @contributors evanalulu, Tezumie, ormaq, Dukemz, LingDong-
|
|
6
6
|
* @license LGPL-3.0
|
|
@@ -10,6 +10,12 @@ function Q5(scope, parent, renderer) {
|
|
|
10
10
|
let $ = this;
|
|
11
11
|
$._isQ5 = $._q5 = true;
|
|
12
12
|
$._parent = parent;
|
|
13
|
+
|
|
14
|
+
let readyResolve;
|
|
15
|
+
$.ready = new Promise((res) => {
|
|
16
|
+
readyResolve = res;
|
|
17
|
+
});
|
|
18
|
+
|
|
13
19
|
if (renderer == 'webgpu-fallback') {
|
|
14
20
|
$._renderer = 'c2d';
|
|
15
21
|
$._webgpu = $._webgpuFallback = true;
|
|
@@ -21,7 +27,7 @@ function Q5(scope, parent, renderer) {
|
|
|
21
27
|
let autoLoaded = scope == 'auto';
|
|
22
28
|
scope ??= 'global';
|
|
23
29
|
if (scope == 'auto') {
|
|
24
|
-
if (!(window.setup || window.update || window.draw)) return;
|
|
30
|
+
if (!(window.setup || window.update || Q5.update || window.draw || Q5.draw)) return;
|
|
25
31
|
scope = 'global';
|
|
26
32
|
}
|
|
27
33
|
let globalScope;
|
|
@@ -282,6 +288,18 @@ function Q5(scope, parent, renderer) {
|
|
|
282
288
|
// shim if undefined
|
|
283
289
|
for (let name of userFns) $[name] ??= () => {};
|
|
284
290
|
|
|
291
|
+
if ($._isGlobal) {
|
|
292
|
+
for (let name of ['setup', 'update', 'draw', ...userFns]) {
|
|
293
|
+
if (Q5[name]) $[name] = Q5[name];
|
|
294
|
+
else {
|
|
295
|
+
Object.defineProperty(Q5, name, {
|
|
296
|
+
get: () => $[name],
|
|
297
|
+
set: (fn) => ($[name] = fn)
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
285
303
|
function wrapWithFES(name) {
|
|
286
304
|
const fn = t[name] || $[name];
|
|
287
305
|
$[name] = (event) => {
|
|
@@ -295,6 +313,10 @@ function Q5(scope, parent, renderer) {
|
|
|
295
313
|
}
|
|
296
314
|
|
|
297
315
|
async function start() {
|
|
316
|
+
await runHooks('presetup');
|
|
317
|
+
|
|
318
|
+
readyResolve();
|
|
319
|
+
|
|
298
320
|
wrapWithFES('preload');
|
|
299
321
|
$.preload();
|
|
300
322
|
|
|
@@ -306,7 +328,7 @@ function Q5(scope, parent, renderer) {
|
|
|
306
328
|
resolve();
|
|
307
329
|
} else if (!$._setupDone) {
|
|
308
330
|
// render during loading
|
|
309
|
-
if ($._render) {
|
|
331
|
+
if ($.canvas?.ready && $._render) {
|
|
310
332
|
$._beginRender();
|
|
311
333
|
$._render();
|
|
312
334
|
$._finishRender();
|
|
@@ -338,7 +360,6 @@ function Q5(scope, parent, renderer) {
|
|
|
338
360
|
|
|
339
361
|
$.draw ??= t.draw || (() => {});
|
|
340
362
|
|
|
341
|
-
await runHooks('presetup');
|
|
342
363
|
millisStart = performance.now();
|
|
343
364
|
await $.setup();
|
|
344
365
|
$._setupDone = true;
|
|
@@ -402,19 +423,27 @@ Q5.prototype.registerMethod = (m, fn) => {
|
|
|
402
423
|
Q5.preloadMethods = {};
|
|
403
424
|
Q5.prototype.registerPreloadMethod = (n, fn) => (Q5.preloadMethods[n] = fn[n]);
|
|
404
425
|
|
|
405
|
-
if (Q5._server) global.p5 ??= global.Q5 = Q5;
|
|
406
|
-
|
|
407
|
-
if (typeof window == 'object') window.p5 ??= window.Q5 = Q5;
|
|
408
|
-
else global.window = 0;
|
|
409
|
-
|
|
410
426
|
function createCanvas(w, h, opt) {
|
|
411
|
-
if (
|
|
427
|
+
if (Q5._hasGlobal) return;
|
|
428
|
+
|
|
429
|
+
if (w == 'webgpu' || h == 'webgpu' || opt == 'webgpu' || opt?.renderer == 'webgpu') {
|
|
430
|
+
return Q5.WebGPU().then((q) => q.createCanvas(w, h, opt));
|
|
431
|
+
} else {
|
|
412
432
|
let q = new Q5();
|
|
413
|
-
q.createCanvas(w, h, opt);
|
|
433
|
+
let c = q.createCanvas(w, h, opt);
|
|
434
|
+
return q.ready.then(() => c);
|
|
414
435
|
}
|
|
415
436
|
}
|
|
416
437
|
|
|
417
|
-
Q5.
|
|
438
|
+
if (Q5._server) global.p5 ??= global.Q5 = Q5;
|
|
439
|
+
|
|
440
|
+
if (typeof window == 'object') {
|
|
441
|
+
window.p5 ??= window.Q5 = Q5;
|
|
442
|
+
window.createCanvas = createCanvas;
|
|
443
|
+
window.GPU = window.WEBGPU = 'webgpu';
|
|
444
|
+
} else global.window = 0;
|
|
445
|
+
|
|
446
|
+
Q5.version = Q5.VERSION = '3.4';
|
|
418
447
|
|
|
419
448
|
if (typeof document == 'object') {
|
|
420
449
|
document.addEventListener('DOMContentLoaded', () => {
|
|
@@ -473,10 +502,14 @@ Q5.modules.canvas = ($, q) => {
|
|
|
473
502
|
};
|
|
474
503
|
|
|
475
504
|
$.createCanvas = function (w, h, options) {
|
|
476
|
-
if (typeof w == '
|
|
505
|
+
if (isNaN(w) || (typeof w == 'string' && !w.includes(':'))) {
|
|
477
506
|
options = w;
|
|
478
507
|
w = null;
|
|
479
508
|
}
|
|
509
|
+
if (typeof h != 'number') {
|
|
510
|
+
options = h;
|
|
511
|
+
h = null;
|
|
512
|
+
}
|
|
480
513
|
options ??= arguments[3];
|
|
481
514
|
if (typeof options == 'string') options = { renderer: options };
|
|
482
515
|
let opt = Object.assign({}, Q5.canvasOptions);
|
|
@@ -533,6 +566,8 @@ Q5.modules.canvas = ($, q) => {
|
|
|
533
566
|
|
|
534
567
|
if ($._addEventMethods) $._addEventMethods(c);
|
|
535
568
|
|
|
569
|
+
$.canvas.ready = true;
|
|
570
|
+
|
|
536
571
|
return rend;
|
|
537
572
|
};
|
|
538
573
|
|
|
@@ -733,7 +768,7 @@ Q5.HUE_ROTATE = 13;
|
|
|
733
768
|
|
|
734
769
|
Q5.C2D = Q5.P2D = Q5.P2DHDR = 'c2d';
|
|
735
770
|
Q5.WEBGL = 'webgl';
|
|
736
|
-
Q5.WEBGPU = 'webgpu';
|
|
771
|
+
Q5.GPU = Q5.WEBGPU = 'webgpu';
|
|
737
772
|
|
|
738
773
|
Q5.canvasOptions = {
|
|
739
774
|
alpha: false,
|
|
@@ -8110,8 +8145,11 @@ Q5.initWebGPU = async () => {
|
|
|
8110
8145
|
|
|
8111
8146
|
Q5.WebGPU = async function (scope, parent) {
|
|
8112
8147
|
if (!scope || scope == 'global') Q5._hasGlobal = true;
|
|
8148
|
+
let q;
|
|
8113
8149
|
if (!(await Q5.initWebGPU())) {
|
|
8114
|
-
|
|
8150
|
+
q = new Q5(scope, parent, 'webgpu-fallback');
|
|
8115
8151
|
}
|
|
8116
|
-
|
|
8152
|
+
q = new Q5(scope, parent, 'webgpu');
|
|
8153
|
+
await q.ready;
|
|
8154
|
+
return q;
|
|
8117
8155
|
};
|