q5 2.4.4 → 2.4.10
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/package.json +1 -1
- package/q5.d.ts +1425 -0
- package/q5.js +402 -226
- package/q5.min.js +1 -1
- package/src/q5-2d-canvas.js +29 -20
- package/src/q5-2d-image.js +1 -0
- package/src/q5-2d-text.js +188 -142
- package/src/q5-canvas.js +2 -2
- package/src/q5-vector.js +3 -3
- package/src/q5-webgpu-canvas.js +103 -45
- package/src/q5-webgpu-drawing.js +11 -0
- package/src/q5-webgpu-image.js +32 -4
- package/src/q5-webgpu-text.js +30 -7
- package/src/readme.md +3 -11
package/src/q5-webgpu-text.js
CHANGED
|
@@ -9,6 +9,8 @@ Q5.renderers.webgpu.text = ($, q) => {
|
|
|
9
9
|
q._preloadCount--;
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
+
|
|
13
|
+
// directly add these text setting functions to the webgpu renderer
|
|
12
14
|
$.textFont = t.textFont;
|
|
13
15
|
$.textSize = t.textSize;
|
|
14
16
|
$.textLeading = t.textLeading;
|
|
@@ -24,7 +26,20 @@ Q5.renderers.webgpu.text = ($, q) => {
|
|
|
24
26
|
$.text = (str, x, y, w, h) => {
|
|
25
27
|
let img = t.createTextImage(str, w, h);
|
|
26
28
|
|
|
27
|
-
if (img.canvas.textureIndex
|
|
29
|
+
if (img.canvas.textureIndex === undefined) {
|
|
30
|
+
$._createTexture(img);
|
|
31
|
+
} else if (img.modified) {
|
|
32
|
+
let cnv = img.canvas;
|
|
33
|
+
let textureSize = [cnv.width, cnv.height, 1];
|
|
34
|
+
let texture = $._textures[cnv.textureIndex];
|
|
35
|
+
|
|
36
|
+
Q5.device.queue.copyExternalImageToTexture(
|
|
37
|
+
{ source: cnv },
|
|
38
|
+
{ texture, colorSpace: $.canvas.colorSpace },
|
|
39
|
+
textureSize
|
|
40
|
+
);
|
|
41
|
+
img.modified = false;
|
|
42
|
+
}
|
|
28
43
|
|
|
29
44
|
$.textImage(img, x, y);
|
|
30
45
|
};
|
|
@@ -32,12 +47,20 @@ Q5.renderers.webgpu.text = ($, q) => {
|
|
|
32
47
|
$.createTextImage = t.createTextImage;
|
|
33
48
|
|
|
34
49
|
$.textImage = (img, x, y) => {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else if (
|
|
50
|
+
let og = $._imageMode;
|
|
51
|
+
$._imageMode = 'corner';
|
|
52
|
+
|
|
53
|
+
let ta = t._textAlign;
|
|
54
|
+
if (ta == 'center') x -= img.canvas.hw;
|
|
55
|
+
else if (ta == 'right') x -= img.width;
|
|
56
|
+
|
|
57
|
+
let bl = t._textBaseline;
|
|
58
|
+
if (bl == 'alphabetic') y -= t._textLeading;
|
|
59
|
+
else if (bl == 'middle') y -= img._middle;
|
|
60
|
+
else if (bl == 'bottom') y -= img._bottom;
|
|
61
|
+
else if (bl == 'top') y -= img._top;
|
|
62
|
+
|
|
41
63
|
$.image(img, x, y);
|
|
64
|
+
$._imageMode = og;
|
|
42
65
|
};
|
|
43
66
|
};
|
package/src/readme.md
CHANGED
|
@@ -105,7 +105,7 @@ Image based features in this module require the q5-2d-image module.
|
|
|
105
105
|
|
|
106
106
|
`textImage(img, x, y)` displays text images, complying with the user's text position settings instead of their image position settings. The idea is that text will appear in the same place as it would if it were drawn with the `text` function.
|
|
107
107
|
|
|
108
|
-
`textCache(bool, maxSize)` enables or disables text caching.
|
|
108
|
+
`textCache(bool, maxSize)` enables or disables text caching.
|
|
109
109
|
|
|
110
110
|
## webgpu-canvas
|
|
111
111
|
|
|
@@ -181,17 +181,9 @@ Implemented functions:
|
|
|
181
181
|
|
|
182
182
|
> Use `textFill` and `textStroke` to set text colors.
|
|
183
183
|
|
|
184
|
-
WebGPU
|
|
184
|
+
Internally, q5's WebGPU renderer uses a q5 graphics object to draw text to a Canvas2D canvas via `createTextImage`, then converts that canvas to a WebGPU texture. Each texture is cached, so it doesn't have to be recreated every frame that users want to display the same text.
|
|
185
185
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
Internally, q5's WebGPU renderer uses a q5 graphics object to draw text to a Canvas2D canvas via `createTextImage`, then converts that canvas to a WebGPU texture. Each texture is cached so it doesn't have to be recreated every frame that users want to display the same text.
|
|
189
|
-
|
|
190
|
-
As long as text content doesn't change often, this method is 4x more efficient.
|
|
191
|
-
|
|
192
|
-
As a best practice, separate static text from dynamic text rendering. For example render labels like "Score: " and corresponding values with separate calls to `text`.
|
|
193
|
-
|
|
194
|
-
Complete implementation of text rendering in WebGPU.
|
|
186
|
+
Implemented functions:
|
|
195
187
|
|
|
196
188
|
`loadFont`,`textFont`, `textSize`, `textLeading`, `textStyle`, `textAlign`, `textWidth`, `textAscent`, `textDescent`, `textFill`, `textStroke`, `text`
|
|
197
189
|
|