Spaces:
Running
Running
add to config
Browse files- config.js +3 -1
- index.html +4 -7
config.js
CHANGED
@@ -3,5 +3,7 @@
|
|
3 |
export const config = {
|
4 |
glyphsAcrossTexture: 16,
|
5 |
glyphWidth: 32,
|
6 |
-
glyphHeight: 40
|
|
|
|
|
7 |
};
|
|
|
3 |
export const config = {
|
4 |
glyphsAcrossTexture: 16,
|
5 |
glyphWidth: 32,
|
6 |
+
glyphHeight: 40,
|
7 |
+
maxGlyphs: 100,
|
8 |
+
vertsPerGlyph: 6
|
9 |
};
|
index.html
CHANGED
@@ -54,12 +54,9 @@
|
|
54 |
const glyphCanvas = generateGlyphTextureAtlas();
|
55 |
document.body.appendChild(glyphCanvas);
|
56 |
glyphCanvas.style.backgroundColor = '#222';
|
57 |
-
|
58 |
-
const maxGlyphs = 100;
|
59 |
const floatsPerVertex = 2 + 2 + 4;
|
60 |
const vertexSize = floatsPerVertex * 4;
|
61 |
-
const
|
62 |
-
const vertexBufferSize = maxGlyphs * vertsPerGlyph * vertexSize;
|
63 |
const vertexBuffer = device.createBuffer({
|
64 |
label: 'vertices',
|
65 |
size: vertexBufferSize,
|
@@ -67,18 +64,18 @@
|
|
67 |
});
|
68 |
const indexBuffer = device.createBuffer({
|
69 |
label: 'indices',
|
70 |
-
size: maxGlyphs * vertsPerGlyph * 4,
|
71 |
usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST,
|
72 |
});
|
73 |
|
74 |
-
const indices = Array.from({ length: maxGlyphs * 6 }, (_, i) => {
|
75 |
const ndx = Math.floor(i / 6) * 4;
|
76 |
return (i % 6 < 3 ? [ndx, ndx + 1, ndx + 2] : [ndx + 2, ndx + 1, ndx + 3])[i % 3];
|
77 |
});
|
78 |
device.queue.writeBuffer(indexBuffer, 0, new Uint32Array(indices));
|
79 |
|
80 |
function generateGlyphVerticesForText(s, colors = [[1, 1, 1, 1]]) {
|
81 |
-
const vertexData = new Float32Array(maxGlyphs * floatsPerVertex * vertsPerGlyph);
|
82 |
const glyphUVWidth = config.glyphWidth / glyphCanvas.width;
|
83 |
const glyphUVHeight = config.glyphHeight / glyphCanvas.height;
|
84 |
let offset = 0, x0 = 0, y0 = 0, x1 = 1, y1 = 1, width = 0;
|
|
|
54 |
const glyphCanvas = generateGlyphTextureAtlas();
|
55 |
document.body.appendChild(glyphCanvas);
|
56 |
glyphCanvas.style.backgroundColor = '#222';
|
|
|
|
|
57 |
const floatsPerVertex = 2 + 2 + 4;
|
58 |
const vertexSize = floatsPerVertex * 4;
|
59 |
+
const vertexBufferSize = config.maxGlyphs * config.vertsPerGlyph * vertexSize;
|
|
|
60 |
const vertexBuffer = device.createBuffer({
|
61 |
label: 'vertices',
|
62 |
size: vertexBufferSize,
|
|
|
64 |
});
|
65 |
const indexBuffer = device.createBuffer({
|
66 |
label: 'indices',
|
67 |
+
size: config.maxGlyphs * config.vertsPerGlyph * 4,
|
68 |
usage: GPUBufferUsage.INDEX | GPUBufferUsage.COPY_DST,
|
69 |
});
|
70 |
|
71 |
+
const indices = Array.from({ length: config.maxGlyphs * 6 }, (_, i) => {
|
72 |
const ndx = Math.floor(i / 6) * 4;
|
73 |
return (i % 6 < 3 ? [ndx, ndx + 1, ndx + 2] : [ndx + 2, ndx + 1, ndx + 3])[i % 3];
|
74 |
});
|
75 |
device.queue.writeBuffer(indexBuffer, 0, new Uint32Array(indices));
|
76 |
|
77 |
function generateGlyphVerticesForText(s, colors = [[1, 1, 1, 1]]) {
|
78 |
+
const vertexData = new Float32Array(config.maxGlyphs * floatsPerVertex * config.vertsPerGlyph);
|
79 |
const glyphUVWidth = config.glyphWidth / glyphCanvas.width;
|
80 |
const glyphUVHeight = config.glyphHeight / glyphCanvas.height;
|
81 |
let offset = 0, x0 = 0, y0 = 0, x1 = 1, y1 = 1, width = 0;
|