content/canvas/test/webgl-conformance/misc/program-test-1.html

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 <!--
michael@0 2 Copyright (c) 2010 Mozilla Foundation. All rights reserved.
michael@0 3 Use of this source code is governed by a BSD-style license that can be
michael@0 4 found in the LICENSE file.
michael@0 5 -->
michael@0 6 <!DOCTYPE HTML>
michael@0 7 <html>
michael@0 8 <head>
michael@0 9 <meta charset="utf-8">
michael@0 10 <!-- This is a visual test that programs must have both a vertex and
michael@0 11 fragment shader attached; the fixed function pipeline on the
michael@0 12 desktop must remain disabled. -->
michael@0 13 <script type="text/javascript">
michael@0 14 function log() {
michael@0 15 var s = "";
michael@0 16 for (var i = 0; i < arguments.length; ++i) {
michael@0 17 s += arguments[i] + " ";
michael@0 18 }
michael@0 19
michael@0 20 document.getElementById("log").innerHTML += s + "<br>";
michael@0 21 }
michael@0 22
michael@0 23 function go() {
michael@0 24 var gl = document.getElementById("c").getContext("experimental-webgl");
michael@0 25
michael@0 26 gl.clearColor(0.0, 0.0, 0.0, 0.0);
michael@0 27 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
michael@0 28
michael@0 29 var vs = gl.createShader(gl.VERTEX_SHADER);
michael@0 30 gl.shaderSource(vs, "attribute vec4 aVertex; attribute vec4 aColor; varying vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex; }");
michael@0 31 gl.compileShader(vs);
michael@0 32
michael@0 33 var fs = gl.createShader(gl.FRAGMENT_SHADER);
michael@0 34 gl.shaderSource(fs, "precision mediump float; varying vec4 vColor; void main() { gl_FragColor = vColor; }");
michael@0 35 gl.compileShader(fs);
michael@0 36
michael@0 37 var prog = gl.createProgram();
michael@0 38 gl.attachShader(prog, vs);
michael@0 39 // don't attach a fragment shader -- may use fixed pipeline on desktop if the implementation doesn't check!
michael@0 40 //gl.attachShader(prog, fs);
michael@0 41
michael@0 42 gl.bindAttribLocation(prog, 0, "aVertex");
michael@0 43 gl.bindAttribLocation(prog, 1, "aColor");
michael@0 44
michael@0 45 gl.linkProgram(prog);
michael@0 46
michael@0 47 var vbuf = gl.createBuffer();
michael@0 48 gl.bindBuffer(gl.ARRAY_BUFFER, vbuf);
michael@0 49 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
michael@0 50 -1.0, -1.0, 0.0, 1.0,
michael@0 51 -1.0, 1.0, 0.0, 1.0,
michael@0 52 1.0, -1.0, 0.0, 1.0,
michael@0 53 1.0, 1.0, 0.0, 1.0]), gl.STATIC_DRAW);
michael@0 54 gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0);
michael@0 55
michael@0 56 var cbuf = gl.createBuffer();
michael@0 57 gl.bindBuffer(gl.ARRAY_BUFFER, cbuf);
michael@0 58 gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([255, 0, 0,
michael@0 59 0, 255, 0,
michael@0 60 0, 0, 255,
michael@0 61 255, 255, 0]), gl.STATIC_DRAW);
michael@0 62 gl.vertexAttribPointer(1, 3, gl.UNSIGNED_BYTE, false, 0, 0);
michael@0 63
michael@0 64 gl.enableVertexAttribArray(0);
michael@0 65 gl.enableVertexAttribArray(1);
michael@0 66
michael@0 67 gl.useProgram(prog);
michael@0 68
michael@0 69 gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
michael@0 70
michael@0 71 log("glError", "0x" + gl.getError().toString(16));
michael@0 72 }
michael@0 73 </script>
michael@0 74 </head>
michael@0 75
michael@0 76 <body onload="go()">
michael@0 77 <p>Should be green in the rectangle below:</p>
michael@0 78 <canvas style="background: green;" id="c"></canvas>
michael@0 79 <div id="log"></div>
michael@0 80 </body>
michael@0 81 </html>

mercurial