p3nGu1nZz commited on
Commit
a908f06
1 Parent(s): d13e19f

more static

Browse files
Files changed (2) hide show
  1. index.js +1 -17
  2. utility.js +16 -0
index.js CHANGED
@@ -1,5 +1,5 @@
1
  import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
2
- import { fetchShaderCode, generateGlyphTextureAtlas } from './utility.js';
3
  import { config } from './config.js';
4
  import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './constants.js';
5
  import { createPipeline } from './wgpu-pipeline.js';
@@ -146,20 +146,4 @@ function generateGlyphVerticesForText(s, COLORS, glyphCanvas) {
146
  return { vertexData, numGlyphs: offset / config.floatsPerVertex, width, height: y1 };
147
  }
148
 
149
- function createTextureFromSource(device, source, options = {}) {
150
- const texture = device.createTexture({
151
- format: 'rgba8unorm',
152
- size: [source.width, source.height],
153
- usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
154
- });
155
-
156
- device.queue.copyExternalImageToTexture(
157
- { source, flipY: options.flipY },
158
- { texture, premultipliedAlpha: true },
159
- { width: source.width, height: source.height }
160
- );
161
-
162
- return texture;
163
- }
164
-
165
  main();
 
1
  import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
2
+ import { fetchShaderCode, generateGlyphTextureAtlas, createTextureFromSource } from './utility.js';
3
  import { config } from './config.js';
4
  import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './constants.js';
5
  import { createPipeline } from './wgpu-pipeline.js';
 
146
  return { vertexData, numGlyphs: offset / config.floatsPerVertex, width, height: y1 };
147
  }
148
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
149
  main();
utility.js CHANGED
@@ -18,4 +18,20 @@ export function generateGlyphTextureAtlas(canvas, ctx, config) {
18
  if (x === 0) y += config.glyphHeight;
19
  }
20
  return canvas;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  }
 
18
  if (x === 0) y += config.glyphHeight;
19
  }
20
  return canvas;
21
+ }
22
+
23
+ export function createTextureFromSource(device, source, options = {}) {
24
+ const texture = device.createTexture({
25
+ format: 'rgba8unorm',
26
+ size: [source.width, source.height],
27
+ usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT,
28
+ });
29
+
30
+ device.queue.copyExternalImageToTexture(
31
+ { source, flipY: options.flipY },
32
+ { texture, premultipliedAlpha: true },
33
+ { width: source.width, height: source.height }
34
+ );
35
+
36
+ return texture;
37
  }