Spaces:
Running
Running
File size: 1,430 Bytes
e30fbc6 9905bd0 e30fbc6 9905bd0 e30fbc6 9905bd0 e30fbc6 9905bd0 e30fbc6 9905bd0 e30fbc6 9905bd0 e30fbc6 9905bd0 e30fbc6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
export function GenerateVertexDataAndTexture(state, glyphCanvas, generateGlyphVerticesForText, COLORS, config, createTextureFromSource) {
const glyphData = generateGlyphVerticesForText('Hello\nworld!\nText in\nWebGPU!', COLORS, config, glyphCanvas);
state.webgpu.device.queue.writeBuffer(state.webgpu.vertexBuffer, 0, glyphData.vertexData);
state.webgpu.texture = createTextureFromSource(state.webgpu.device, glyphCanvas, { mips: true });
state.webgpu.sampler = state.webgpu.device.createSampler({
minFilter: 'linear',
magFilter: 'linear',
});
state.webgpu.uniformBuffer = state.webgpu.device.createBuffer({
label: 'uniforms for quad',
size: config.uniformBufferSize,
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
});
state.matrices.matrix = state.matrices.uniformValues.subarray(0, 16);
state.webgpu.bindGroup = state.webgpu.device.createBindGroup({
layout: state.webgpu.pipeline.getBindGroupLayout(0),
entries: [
{ binding: 0, resource: state.webgpu.sampler },
{ binding: 1, resource: state.webgpu.texture.createView() },
{ binding: 2, resource: { buffer: state.webgpu.uniformBuffer } },
],
});
// Update state with glyph details
state.glyphs.numGlyphs = glyphData.numGlyphs;
state.glyphs.width = glyphData.width;
state.glyphs.height = glyphData.height;
}
|