dino@apple.com | 3ea423a | 2020-08-26 20:42:28 +0000 | [diff] [blame] | 1 | <style> |
| 2 | body { |
| 3 | font-family: monospace; |
| 4 | } |
| 5 | canvas { |
| 6 | width: 10px; |
| 7 | height: 10px; |
| 8 | } |
| 9 | </style> |
| 10 | <script> |
| 11 | if (window.testRunner) { |
| 12 | testRunner.waitUntilDone(); |
| 13 | } |
| 14 | |
| 15 | const WIDTH = 10; |
| 16 | const HEIGHT = 10; |
| 17 | |
| 18 | const COLORS = [ |
| 19 | [0, 0, 1, 1], |
| 20 | [0, 1, 1, 1], |
| 21 | [0, 0.5, 0, 1], |
| 22 | [1, 0, 1, 1], |
| 23 | [1, 1, 0.5, 1], |
| 24 | [0.5, 0, 1, 1], |
| 25 | [0.5, 0.5, 0.5, 1], |
| 26 | [0.5, 0.5, 1, 1], |
| 27 | [0.25, 1, 1, 1], |
| 28 | [0, 1, 0, 1] |
| 29 | ]; |
| 30 | |
| 31 | let gl; |
| 32 | let currentFrame = 0; |
| 33 | |
| 34 | function output(msg) { |
| 35 | const div = document.getElementById("output"); |
| 36 | div.innerHTML += `${msg}<br>`; |
| 37 | } |
| 38 | |
| 39 | function step1() { |
| 40 | |
| 41 | output("Step 1. Create a WebGL canvas and render into it."); |
| 42 | output("We do this for 10 frames, each time a different color ending in pure green (0, 1, 0, 1)."); |
| 43 | output("-----"); |
| 44 | |
| 45 | const canvas = document.querySelector("canvas"); |
| 46 | canvas.width = WIDTH; |
| 47 | canvas.height = HEIGHT; |
| 48 | |
| 49 | output("Create WebGL context"); |
| 50 | |
| 51 | gl = canvas.getContext("webgl"); |
| 52 | |
| 53 | function clearToColor() { |
| 54 | if (currentFrame >= COLORS.length) { |
| 55 | requestAnimationFrame(step2); |
| 56 | return; |
| 57 | } |
| 58 | |
| 59 | output(`Clear to ${COLORS[currentFrame]}`); |
| 60 | |
| 61 | gl.clearColor(...COLORS[currentFrame]); |
| 62 | gl.clear(gl.COLOR_BUFFER_BIT); |
| 63 | |
| 64 | currentFrame++; |
| 65 | requestAnimationFrame(clearToColor); |
| 66 | } |
| 67 | |
| 68 | clearToColor(); |
| 69 | } |
| 70 | |
| 71 | function step2() { |
| 72 | |
| 73 | output(""); |
| 74 | output("Step 2. Create a framebuffer and render into it, but don't draw into the canvas."); |
| 75 | output("-----"); |
| 76 | |
| 77 | output("Create a texture"); |
| 78 | |
| 79 | // THIS IS WHERE WE CREATE THE TEXTURE IN THE ACTUAL TEST. |
| 80 | |
| 81 | output("Create and bind framebuffer"); |
| 82 | |
| 83 | // THIS IS WHERE WE CREATE THE FRAMEBUFFER IN THE ACTUAL TEST. |
| 84 | |
| 85 | output("Clear framebuffer to red (1, 0, 0, 1). This was not used above."); |
| 86 | |
| 87 | // DON'T DO ANYTHING HERE. |
| 88 | |
| 89 | output("The canvas above should be green."); |
| 90 | if (window.testRunner) |
| 91 | testRunner.notifyDone(); |
| 92 | } |
| 93 | |
| 94 | function runTest() { |
| 95 | requestAnimationFrame(step1); |
| 96 | } |
| 97 | |
| 98 | window.addEventListener("load", runTest, false); |
| 99 | </script> |
| 100 | <canvas></canvas> |
| 101 | <div id="output"></div> |