p3nGu1nZz commited on
Commit
e30fbc6
·
1 Parent(s): f15ce4c

fixed import for texture CDI

Browse files
Files changed (2) hide show
  1. index.js +2 -35
  2. wgpu-texture.js +34 -0
index.js CHANGED
@@ -4,7 +4,8 @@ import { createState } from './wgpu-state.js';
4
  import { generateGlyphTextureAtlas, createTextureFromSource } from './wgpu-utility.js';
5
  import { createPipeline } from './wgpu-pipeline.js';
6
  import { fetchShaderCode } from './wgpu-shader.js';
7
- import { generateGlyphVerticesForText } from './wgpu-text.js';
 
8
  import { config } from './wgpu-config.js';
9
  import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './wgpu-constants.js';
10
 
@@ -82,40 +83,6 @@ function GenerateIndices(maxGlyphs) {
82
  });
83
  }
84
 
85
- // Function to generate vertex data and texture
86
- function GenerateVertexDataAndTexture(state, glyphCanvas, generateGlyphVerticesForText, COLORS, config, createTextureFromSource) {
87
- const glyphData = generateGlyphVerticesForText('Hello\nworld!\nText in\nWebGPU!', COLORS, config, glyphCanvas);
88
- state.device.queue.writeBuffer(state.vertexBuffer, 0, glyphData.vertexData);
89
-
90
- state.texture = createTextureFromSource(state.device, glyphCanvas, { mips: true });
91
- state.sampler = state.device.createSampler({
92
- minFilter: 'linear',
93
- magFilter: 'linear',
94
- });
95
-
96
- state.uniformBuffer = state.device.createBuffer({
97
- label: 'uniforms for quad',
98
- size: config.uniformBufferSize,
99
- usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
100
- });
101
-
102
- state.matrix = state.uniformValues.subarray(0, 16);
103
-
104
- state.bindGroup = state.device.createBindGroup({
105
- layout: state.pipeline.getBindGroupLayout(0),
106
- entries: [
107
- { binding: 0, resource: state.sampler },
108
- { binding: 1, resource: state.texture.createView() },
109
- { binding: 2, resource: { buffer: state.uniformBuffer } },
110
- ],
111
- });
112
-
113
- // Update state with glyph details
114
- state.numGlyphs = glyphData.numGlyphs;
115
- state.width = glyphData.width;
116
- state.height = glyphData.height;
117
- }
118
-
119
  // Game loop function
120
  function GameLoop(context) {
121
  let lastTime = performance.now();
 
4
  import { generateGlyphTextureAtlas, createTextureFromSource } from './wgpu-utility.js';
5
  import { createPipeline } from './wgpu-pipeline.js';
6
  import { fetchShaderCode } from './wgpu-shader.js';
7
+ import { GenerateVertexDataAndTexture } from './wgpu-texture.js'; // Import the function
8
+ import { generateGlyphVerticesForText } from './wgpu-text.js'; // Corrected import statement
9
  import { config } from './wgpu-config.js';
10
  import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './wgpu-constants.js';
11
 
 
83
  });
84
  }
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  // Game loop function
87
  function GameLoop(context) {
88
  let lastTime = performance.now();
wgpu-texture.js CHANGED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // wgpu-texture.js
2
+
3
+ export function GenerateVertexDataAndTexture(state, glyphCanvas, generateGlyphVerticesForText, COLORS, config, createTextureFromSource) {
4
+ const glyphData = generateGlyphVerticesForText('Hello\nworld!\nText in\nWebGPU!', COLORS, config, glyphCanvas);
5
+ state.device.queue.writeBuffer(state.vertexBuffer, 0, glyphData.vertexData);
6
+
7
+ state.texture = createTextureFromSource(state.device, glyphCanvas, { mips: true });
8
+ state.sampler = state.device.createSampler({
9
+ minFilter: 'linear',
10
+ magFilter: 'linear',
11
+ });
12
+
13
+ state.uniformBuffer = state.device.createBuffer({
14
+ label: 'uniforms for quad',
15
+ size: config.uniformBufferSize,
16
+ usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
17
+ });
18
+
19
+ state.matrix = state.uniformValues.subarray(0, 16);
20
+
21
+ state.bindGroup = state.device.createBindGroup({
22
+ layout: state.pipeline.getBindGroupLayout(0),
23
+ entries: [
24
+ { binding: 0, resource: state.sampler },
25
+ { binding: 1, resource: state.texture.createView() },
26
+ { binding: 2, resource: { buffer: state.uniformBuffer } },
27
+ ],
28
+ });
29
+
30
+ // Update state with glyph details
31
+ state.numGlyphs = glyphData.numGlyphs;
32
+ state.width = glyphData.width;
33
+ state.height = glyphData.height;
34
+ }