p3nGu1nZz commited on
Commit
aaffc16
1 Parent(s): a319f30

move to constants

Browse files
Files changed (3) hide show
  1. config.js +10 -0
  2. constants.js +3 -0
  3. index.html +11 -12
config.js CHANGED
@@ -8,6 +8,16 @@ export const config = {
8
  vertsPerGlyph: 6,
9
  floatsPerVertex: 8,
10
  uniformBufferSize: 64,
 
 
 
 
 
 
 
 
 
 
11
  render: {
12
  zNear: 0.001,
13
  zFar: 50
 
8
  vertsPerGlyph: 6,
9
  floatsPerVertex: 8,
10
  uniformBufferSize: 64,
11
+ canvas: {
12
+ width: 512,
13
+ height: 256
14
+ },
15
+ context: {
16
+ font: '32px monospace',
17
+ textBaseline: 'middle',
18
+ textAlign: 'center',
19
+ fillStyle: 'white'
20
+ },
21
  render: {
22
  zNear: 0.001,
23
  zFar: 50
constants.js CHANGED
@@ -1,5 +1,8 @@
1
  // constants.js
2
 
 
 
 
3
  export const COLORS = [
4
  [1, 1, 0, 1],
5
  [0, 1, 1, 1],
 
1
  // constants.js
2
 
3
+ export const CANVAS = document.createElement('canvas');
4
+ export const CTX = CANVAS.getContext('2d');
5
+
6
  export const COLORS = [
7
  [1, 1, 0, 1],
8
  [0, 1, 1, 1],
index.html CHANGED
@@ -13,23 +13,22 @@
13
  import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
14
  import { fetchShaderCode } from './utility.js';
15
  import { config } from './config.js';
16
- import { COLORS, RENDER_PASS_DESCRIPTOR } from './constants.js';
17
 
18
  function generateGlyphTextureAtlas() {
19
- const canvas = document.createElement('canvas');
20
- canvas.width = 512;
21
- canvas.height = 256;
22
- const ctx = canvas.getContext('2d');
23
- ctx.font = '32px monospace';
24
- ctx.textBaseline = 'middle';
25
- ctx.textAlign = 'center';
26
- ctx.fillStyle = 'white';
27
  for (let c = 33, x = 0, y = 0; c < 128; ++c) {
28
- ctx.fillText(String.fromCodePoint(c), x + config.glyphWidth / 2, y + config.glyphHeight / 2);
29
- x = (x + config.glyphWidth) % canvas.width;
30
  if (x === 0) y += config.glyphHeight;
31
  }
32
- return canvas;
33
  }
34
  async function main() {
35
  const adapter = await navigator.gpu?.requestAdapter();
 
13
  import { mat4 } from 'https://webgpufundamentals.org/3rdparty/wgpu-matrix.module.js';
14
  import { fetchShaderCode } from './utility.js';
15
  import { config } from './config.js';
16
+ import { CANVAS, CTX, COLORS, RENDER_PASS_DESCRIPTOR } from './constants.js';
17
 
18
  function generateGlyphTextureAtlas() {
19
+ CANVAS.width = config.canvas.width;
20
+ CANVAS.height = config.canvas.height;
21
+
22
+ CTX.font = config.context.font
23
+ CTX.textBaseline = config.context.textBaseline;
24
+ CTX.textAlign = config.context.textAlign;
25
+ CTX.fillStyle = config.context.fillStyle;
 
26
  for (let c = 33, x = 0, y = 0; c < 128; ++c) {
27
+ CTX.fillText(String.fromCodePoint(c), x + config.glyphWidth / 2, y + config.glyphHeight / 2);
28
+ x = (x + config.glyphWidth) % CANVAS.width;
29
  if (x === 0) y += config.glyphHeight;
30
  }
31
+ return CANVAS;
32
  }
33
  async function main() {
34
  const adapter = await navigator.gpu?.requestAdapter();