Spaces:
Running
Running
🔧 Refactor vertex size calculation in config
Browse files- wgpu-config.js +1 -0
- wgpu-device.js +7 -11
- wgpu-state.js +1 -1
wgpu-config.js
CHANGED
@@ -8,6 +8,7 @@ export const config = {
|
|
8 |
uniformBufferSize: 64,
|
9 |
floatsInUniformBuffer: 16,
|
10 |
matrixSize: 16,
|
|
|
11 |
canvas: {
|
12 |
width: 512,
|
13 |
height: 256
|
|
|
8 |
uniformBufferSize: 64,
|
9 |
floatsInUniformBuffer: 16,
|
10 |
matrixSize: 16,
|
11 |
+
vertexMultiplier: 4,
|
12 |
canvas: {
|
13 |
width: 512,
|
14 |
height: 256
|
wgpu-device.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1 |
// wgpu-device.js
|
2 |
|
3 |
export async function initializeDevice(state) {
|
4 |
-
|
5 |
-
|
6 |
|
7 |
-
if (!device) {
|
8 |
alert('need a browser that supports WebGPU');
|
9 |
state.webgpu.device = null;
|
10 |
state.webgpu.context = null;
|
@@ -12,13 +12,9 @@ export async function initializeDevice(state) {
|
|
12 |
return;
|
13 |
}
|
14 |
|
15 |
-
|
16 |
-
context.configure({
|
17 |
-
device,
|
18 |
-
format: presentationFormat,
|
19 |
});
|
20 |
-
|
21 |
-
state.webgpu.device = device;
|
22 |
-
state.webgpu.context = context;
|
23 |
-
state.webgpu.presentationFormat = presentationFormat;
|
24 |
}
|
|
|
1 |
// wgpu-device.js
|
2 |
|
3 |
export async function initializeDevice(state) {
|
4 |
+
state.webgpu.context = state.canvas.getContext('webgpu');
|
5 |
+
state.webgpu.device = await state.webgpu.adapter?.requestDevice();
|
6 |
|
7 |
+
if (!state.webgpu.device) {
|
8 |
alert('need a browser that supports WebGPU');
|
9 |
state.webgpu.device = null;
|
10 |
state.webgpu.context = null;
|
|
|
12 |
return;
|
13 |
}
|
14 |
|
15 |
+
state.webgpu.presentationFormat = navigator.gpu.getPreferredCanvasFormat();
|
16 |
+
state.webgpu.context.configure({
|
17 |
+
device: state.webgpu.device,
|
18 |
+
format: state.webgpu.presentationFormat,
|
19 |
});
|
|
|
|
|
|
|
|
|
20 |
}
|
wgpu-state.js
CHANGED
@@ -15,7 +15,7 @@ export function createState(config) {
|
|
15 |
sampler: null,
|
16 |
bindGroup: null,
|
17 |
shaderCode: null,
|
18 |
-
vertexSize: config.floatsPerVertex *
|
19 |
},
|
20 |
matrices: {
|
21 |
uniformValues: new Float32Array(config.floatsInUniformBuffer),
|
|
|
15 |
sampler: null,
|
16 |
bindGroup: null,
|
17 |
shaderCode: null,
|
18 |
+
vertexSize: config.floatsPerVertex * config.vertexMultiplier,
|
19 |
},
|
20 |
matrices: {
|
21 |
uniformValues: new Float32Array(config.floatsInUniformBuffer),
|