p3nGu1nZz commited on
Commit
594b86d
1 Parent(s): 80dd0f2

🔧 Refactor vertex size calculation in config

Browse files
Files changed (3) hide show
  1. wgpu-config.js +1 -0
  2. wgpu-device.js +7 -11
  3. 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
- const context = state.canvas.getContext('webgpu');
5
- const device = await state.webgpu.adapter?.requestDevice();
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
- const presentationFormat = navigator.gpu.getPreferredCanvasFormat();
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 * 4,
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),