|
1 |
| -const vsSource = `#version 300 es |
| 1 | +// インラインWebワーカーのコードを文字列で定義 |
| 2 | +export const workerCode = ` |
| 3 | +const vsSource = \`#version 300 es |
2 | 4 | in vec4 a_position;
|
3 | 5 | out vec2 v_tex_coord;
|
4 | 6 |
|
5 | 7 | void main() {
|
6 | 8 | gl_Position = a_position;
|
7 | 9 | v_tex_coord = vec2(a_position.x * 0.5 + 0.5, a_position.y * -0.5 + 0.5);
|
8 | 10 | }
|
9 |
| -`; |
| 11 | +\`; |
10 | 12 |
|
11 |
| -const fsSource = `#version 300 es |
| 13 | +const fsSource = \`#version 300 es |
12 | 14 | #ifdef GL_FRAGMENT_PRECISION_HIGH
|
13 | 15 | precision highp float;
|
14 | 16 | #else
|
@@ -44,24 +46,24 @@ const fsSource = `#version 300 es
|
44 | 46 | float(is_valid)
|
45 | 47 | );
|
46 | 48 | }
|
47 |
| -`; |
| 49 | +\`; |
48 | 50 |
|
49 |
| -let gl: WebGL2RenderingContext | null = null; |
50 |
| -let program: WebGLProgram | null = null; |
51 |
| -let positionBuffer: WebGLBuffer | null = null; |
52 |
| -let heightMapLocation: WebGLUniformLocation | null = null; |
| 51 | +let gl = null; |
| 52 | +let program = null; |
| 53 | +let positionBuffer = null; |
| 54 | +let heightMapLocation = null; |
53 | 55 |
|
54 |
| -const initWebGL = (canvas: OffscreenCanvas) => { |
| 56 | +const initWebGL = (canvas) => { |
55 | 57 | gl = canvas.getContext('webgl2');
|
56 | 58 | if (!gl) {
|
57 | 59 | throw new Error('WebGL not supported');
|
58 | 60 | }
|
59 | 61 |
|
60 | 62 | const loadShader = (
|
61 |
| - gl: WebGL2RenderingContext, |
62 |
| - type: number, |
63 |
| - source: string, |
64 |
| - ): WebGLShader | null => { |
| 63 | + gl, |
| 64 | + type, |
| 65 | + source, |
| 66 | + ) => { |
65 | 67 | const shader = gl.createShader(type);
|
66 | 68 | if (!shader) {
|
67 | 69 | console.error('Unable to create shader');
|
@@ -155,3 +157,4 @@ self.onmessage = async (e) => {
|
155 | 157 | }
|
156 | 158 | }
|
157 | 159 | };
|
| 160 | +`; |
0 commit comments