|
1 | 1 | <html>
|
| 2 | +<title>GPU.js Random Examples</title> |
2 | 3 | <body>
|
3 | 4 | <h2>CPU Random</h2>
|
4 | 5 | <canvas id="cpu-random-output"></canvas>
|
5 |
| -<h2>GPU Random</h2> |
6 |
| -<canvas id="gpu-random-output"></canvas> |
| 6 | +<h2>WebGL1 Random</h2> |
| 7 | +<canvas id="web-gl-random-output"></canvas> |
| 8 | +<h2>WebGL2 Random</h2> |
| 9 | +<canvas id="web-gl2-random-output"></canvas> |
7 | 10 | </body>
|
8 | 11 | <script src="../bin/gpu-browser.js"></script>
|
9 | 12 | <script>
|
| 13 | + const cpu = new GPU({ |
| 14 | + mode: 'cpu', |
| 15 | + canvas: document.getElementById('cpu-random-output') |
| 16 | + }); |
| 17 | + const webGL = new GPU({ |
| 18 | + mode: 'webgl', |
| 19 | + canvas: document.getElementById('web-gl-random-output') |
| 20 | + }); |
| 21 | + const webGL2 = new GPU({ |
| 22 | + mode: 'webgl2', |
| 23 | + canvas: document.getElementById('web-gl2-random-output') |
| 24 | + }); |
| 25 | + |
10 | 26 | function drawRandomFunction() {
|
11 |
| - this.color(Math.random(), Math.random(), Math.random(), 1); |
| 27 | + this.color(Math.random(), Math.random(), Math.random()); |
12 | 28 | }
|
13 | 29 |
|
14 |
| - const cpu = new GPU({ mode: 'cpu', canvas: document.getElementById('cpu-random-output') }); |
15 |
| - const gpu = new GPU({ mode: 'gpu', canvas: document.getElementById('gpu-random-output') }); |
16 |
| - |
17 | 30 | const cpuDrawRandom = cpu.createKernel(drawRandomFunction)
|
18 | 31 | .setGraphical(true)
|
19 | 32 | .setOutput([100, 100]);
|
20 | 33 |
|
21 |
| - const gpuDrawRandom = gpu.createKernel(drawRandomFunction) |
| 34 | + const webGLDrawRandom = webGL.createKernel(drawRandomFunction) |
| 35 | + .setGraphical(true) |
| 36 | + .setOutput([100, 100]); |
| 37 | + |
| 38 | + const webGL2DrawRandom = webGL2.createKernel(drawRandomFunction) |
22 | 39 | .setGraphical(true)
|
23 | 40 | .setOutput([100, 100]);
|
24 | 41 |
|
25 |
| - setInterval(() => { |
| 42 | + function draw() { |
26 | 43 | cpuDrawRandom();
|
27 |
| - gpuDrawRandom(); |
28 |
| - }, 10); |
| 44 | + webGLDrawRandom(); |
| 45 | + webGL2DrawRandom(); |
| 46 | + |
| 47 | + requestAnimationFrame(draw); |
| 48 | + } |
| 49 | + |
| 50 | + requestAnimationFrame(draw); |
29 | 51 | </script>
|
30 | 52 | </html>
|
0 commit comments