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 | uniform float uDepth; |
michael@0 | 14 | |
michael@0 | 15 | void main(void) { |
michael@0 | 16 | gl_Position = vec4(aVertexPosition, uDepth); |
michael@0 | 17 | } |
michael@0 | 18 | </script> |
michael@0 | 19 | |
michael@0 | 20 | <script id="shader-fs-0" type="x-shader/x-fragment"> |
michael@0 | 21 | precision lowp float; |
michael@0 | 22 | |
michael@0 | 23 | void main(void) { |
michael@0 | 24 | gl_FragColor = vec4(1.0, 1.0, 0.0, 1.0); |
michael@0 | 25 | } |
michael@0 | 26 | </script> |
michael@0 | 27 | |
michael@0 | 28 | <script id="shader-fs-1" type="x-shader/x-fragment"> |
michael@0 | 29 | precision lowp float; |
michael@0 | 30 | |
michael@0 | 31 | void main(void) { |
michael@0 | 32 | gl_FragColor = vec4(0.0, 1.0, 1.0, 1.0); |
michael@0 | 33 | } |
michael@0 | 34 | </script> |
michael@0 | 35 | </head> |
michael@0 | 36 | |
michael@0 | 37 | <body> |
michael@0 | 38 | <canvas id="canvas" width="128" height="128"></canvas> |
michael@0 | 39 | |
michael@0 | 40 | <script type="text/javascript;version=1.8"> |
michael@0 | 41 | "use strict"; |
michael@0 | 42 | |
michael@0 | 43 | let canvas, gl; |
michael@0 | 44 | let program = []; |
michael@0 | 45 | let squareVerticesPositionBuffer; |
michael@0 | 46 | let vertexPositionAttribute = []; |
michael@0 | 47 | let depthUniform = []; |
michael@0 | 48 | |
michael@0 | 49 | window.onload = function() { |
michael@0 | 50 | canvas = document.querySelector("canvas"); |
michael@0 | 51 | gl = canvas.getContext("webgl", { preserveDrawingBuffer: true }); |
michael@0 | 52 | gl.clearColor(0.0, 0.0, 0.0, 1.0); |
michael@0 | 53 | |
michael@0 | 54 | initProgram(0); |
michael@0 | 55 | initProgram(1); |
michael@0 | 56 | initBuffers(); |
michael@0 | 57 | drawScene(); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function initProgram(i) { |
michael@0 | 61 | let vertexShader = getShader("shader-vs"); |
michael@0 | 62 | let fragmentShader = getShader("shader-fs-" + i); |
michael@0 | 63 | |
michael@0 | 64 | program[i] = gl.createProgram(); |
michael@0 | 65 | gl.attachShader(program[i], vertexShader); |
michael@0 | 66 | gl.attachShader(program[i], fragmentShader); |
michael@0 | 67 | gl.linkProgram(program[i]); |
michael@0 | 68 | |
michael@0 | 69 | vertexPositionAttribute[i] = gl.getAttribLocation(program[i], "aVertexPosition"); |
michael@0 | 70 | gl.enableVertexAttribArray(vertexPositionAttribute[i]); |
michael@0 | 71 | |
michael@0 | 72 | depthUniform[i] = gl.getUniformLocation(program[i], "uDepth"); |
michael@0 | 73 | } |
michael@0 | 74 | |
michael@0 | 75 | function getShader(id) { |
michael@0 | 76 | let script = document.getElementById(id); |
michael@0 | 77 | let source = script.textContent; |
michael@0 | 78 | let shader; |
michael@0 | 79 | |
michael@0 | 80 | if (script.type == "x-shader/x-fragment") { |
michael@0 | 81 | shader = gl.createShader(gl.FRAGMENT_SHADER); |
michael@0 | 82 | } else if (script.type == "x-shader/x-vertex") { |
michael@0 | 83 | shader = gl.createShader(gl.VERTEX_SHADER); |
michael@0 | 84 | } |
michael@0 | 85 | |
michael@0 | 86 | gl.shaderSource(shader, source); |
michael@0 | 87 | gl.compileShader(shader); |
michael@0 | 88 | |
michael@0 | 89 | return shader; |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function initBuffers() { |
michael@0 | 93 | squareVerticesPositionBuffer = gl.createBuffer(); |
michael@0 | 94 | gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesPositionBuffer); |
michael@0 | 95 | gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ |
michael@0 | 96 | 1.0, 1.0, 0.0, |
michael@0 | 97 | -1.0, 1.0, 0.0, |
michael@0 | 98 | 1.0, -1.0, 0.0, |
michael@0 | 99 | -1.0, -1.0, 0.0 |
michael@0 | 100 | ]), gl.STATIC_DRAW); |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | function drawScene() { |
michael@0 | 104 | gl.clear(gl.COLOR_BUFFER_BIT); |
michael@0 | 105 | |
michael@0 | 106 | for (let i = 0; i < 2; i++) { |
michael@0 | 107 | gl.bindBuffer(gl.ARRAY_BUFFER, squareVerticesPositionBuffer); |
michael@0 | 108 | gl.vertexAttribPointer(vertexPositionAttribute[i], 3, gl.FLOAT, false, 0, 0); |
michael@0 | 109 | |
michael@0 | 110 | gl.useProgram(program[i]); |
michael@0 | 111 | gl.uniform1f(depthUniform[i], i + 1); |
michael@0 | 112 | gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | window.requestAnimationFrame(drawScene); |
michael@0 | 116 | } |
michael@0 | 117 | </script> |
michael@0 | 118 | </body> |
michael@0 | 119 | |
michael@0 | 120 | </html> |