Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!-- Any copyright is dedicated to the Public Domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ --> |
michael@0 | 3 | <!doctype html> |
michael@0 | 4 | |
michael@0 | 5 | <html> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"/> |
michael@0 | 8 | <title>WebGL editor test page</title> |
michael@0 | 9 | |
michael@0 | 10 | <script id="shader-vs" type="x-shader/x-vertex"> |
michael@0 | 11 | precision lowp float; |
michael@0 | 12 | attribute vec3 aVertexPosition; |
michael@0 | 13 | |
michael@0 | 14 | void main(void) { |
michael@0 | 15 | gl_Position = vec4(aVertexPosition, 1); |
michael@0 | 16 | } |
michael@0 | 17 | </script> |
michael@0 | 18 | |
michael@0 | 19 | <script id="shader-fs" type="x-shader/x-fragment"> |
michael@0 | 20 | precision lowp float; |
michael@0 | 21 | uniform vec3 uColor; |
michael@0 | 22 | |
michael@0 | 23 | void main(void) { |
michael@0 | 24 | gl_FragColor = vec4(uColor, 1); |
michael@0 | 25 | } |
michael@0 | 26 | </script> |
michael@0 | 27 | </head> |
michael@0 | 28 | |
michael@0 | 29 | <body> |
michael@0 | 30 | <canvas id="canvas1" width="128" height="128"></canvas> |
michael@0 | 31 | <canvas id="canvas2" width="128" height="128"></canvas> |
michael@0 | 32 | |
michael@0 | 33 | <script type="text/javascript;version=1.8"> |
michael@0 | 34 | "use strict"; |
michael@0 | 35 | |
michael@0 | 36 | let canvas = [], gl = []; |
michael@0 | 37 | let program = []; |
michael@0 | 38 | let squareVerticesPositionBuffer = []; |
michael@0 | 39 | let vertexPositionAttribute = []; |
michael@0 | 40 | let colorUniform = []; |
michael@0 | 41 | |
michael@0 | 42 | window.onload = function() { |
michael@0 | 43 | for (let i = 0; i < 2; i++) { |
michael@0 | 44 | canvas[i] = document.querySelector("#canvas" + (i + 1)); |
michael@0 | 45 | gl[i] = canvas[i].getContext("webgl", { preserveDrawingBuffer: true }); |
michael@0 | 46 | gl[i].clearColor(0.0, 0.0, 0.0, 1.0); |
michael@0 | 47 | |
michael@0 | 48 | initProgram(i); |
michael@0 | 49 | initBuffers(i); |
michael@0 | 50 | drawScene(i); |
michael@0 | 51 | } |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | function initProgram(i) { |
michael@0 | 55 | let vertexShader = getShader(gl[i], "shader-vs"); |
michael@0 | 56 | let fragmentShader = getShader(gl[i], "shader-fs"); |
michael@0 | 57 | |
michael@0 | 58 | program[i] = gl[i].createProgram(); |
michael@0 | 59 | gl[i].attachShader(program[i], vertexShader); |
michael@0 | 60 | gl[i].attachShader(program[i], fragmentShader); |
michael@0 | 61 | gl[i].linkProgram(program[i]); |
michael@0 | 62 | |
michael@0 | 63 | vertexPositionAttribute[i] = gl[i].getAttribLocation(program[i], "aVertexPosition"); |
michael@0 | 64 | gl[i].enableVertexAttribArray(vertexPositionAttribute[i]); |
michael@0 | 65 | |
michael@0 | 66 | colorUniform[i] = gl[i].getUniformLocation(program[i], "uColor"); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function getShader(gl, id) { |
michael@0 | 70 | let script = document.getElementById(id); |
michael@0 | 71 | let source = script.textContent; |
michael@0 | 72 | let shader; |
michael@0 | 73 | |
michael@0 | 74 | if (script.type == "x-shader/x-fragment") { |
michael@0 | 75 | shader = gl.createShader(gl.FRAGMENT_SHADER); |
michael@0 | 76 | } else if (script.type == "x-shader/x-vertex") { |
michael@0 | 77 | shader = gl.createShader(gl.VERTEX_SHADER); |
michael@0 | 78 | } |
michael@0 | 79 | |
michael@0 | 80 | gl.shaderSource(shader, source); |
michael@0 | 81 | gl.compileShader(shader); |
michael@0 | 82 | |
michael@0 | 83 | return shader; |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | function initBuffers(i) { |
michael@0 | 87 | squareVerticesPositionBuffer[i] = gl[i].createBuffer(); |
michael@0 | 88 | gl[i].bindBuffer(gl[i].ARRAY_BUFFER, squareVerticesPositionBuffer[i]); |
michael@0 | 89 | gl[i].bufferData(gl[i].ARRAY_BUFFER, new Float32Array([ |
michael@0 | 90 | 1.0, 1.0, 0.0, |
michael@0 | 91 | -1.0, 1.0, 0.0, |
michael@0 | 92 | 1.0, -1.0, 0.0, |
michael@0 | 93 | -1.0, -1.0, 0.0 |
michael@0 | 94 | ]), gl[i].STATIC_DRAW); |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | function drawScene(i) { |
michael@0 | 98 | gl[i].clear(gl[i].COLOR_BUFFER_BIT); |
michael@0 | 99 | |
michael@0 | 100 | gl[i].bindBuffer(gl[i].ARRAY_BUFFER, squareVerticesPositionBuffer[i]); |
michael@0 | 101 | gl[i].vertexAttribPointer(vertexPositionAttribute[i], 3, gl[i].FLOAT, false, 0, 0); |
michael@0 | 102 | |
michael@0 | 103 | gl[i].useProgram(program[i]); |
michael@0 | 104 | gl[i].uniform3fv(colorUniform[i], i == 0 ? [1, 1, 0] : [0, 1, 1]); |
michael@0 | 105 | gl[i].drawArrays(gl[i].TRIANGLE_STRIP, 0, 4); |
michael@0 | 106 | |
michael@0 | 107 | window.requestAnimationFrame(() => drawScene(i)); |
michael@0 | 108 | } |
michael@0 | 109 | </script> |
michael@0 | 110 | </body> |
michael@0 | 111 | |
michael@0 | 112 | </html> |