1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/misc/program-test-1.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +<!-- 1.5 +Copyright (c) 2010 Mozilla Foundation. All rights reserved. 1.6 +Use of this source code is governed by a BSD-style license that can be 1.7 +found in the LICENSE file. 1.8 +--> 1.9 +<!DOCTYPE HTML> 1.10 +<html> 1.11 +<head> 1.12 +<meta charset="utf-8"> 1.13 +<!-- This is a visual test that programs must have both a vertex and 1.14 + fragment shader attached; the fixed function pipeline on the 1.15 + desktop must remain disabled. --> 1.16 +<script type="text/javascript"> 1.17 + function log() { 1.18 + var s = ""; 1.19 + for (var i = 0; i < arguments.length; ++i) { 1.20 + s += arguments[i] + " "; 1.21 + } 1.22 + 1.23 + document.getElementById("log").innerHTML += s + "<br>"; 1.24 + } 1.25 + 1.26 + function go() { 1.27 + var gl = document.getElementById("c").getContext("experimental-webgl"); 1.28 + 1.29 + gl.clearColor(0.0, 0.0, 0.0, 0.0); 1.30 + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 1.31 + 1.32 + var vs = gl.createShader(gl.VERTEX_SHADER); 1.33 + gl.shaderSource(vs, "attribute vec4 aVertex; attribute vec4 aColor; varying vec4 vColor; void main() { vColor = aColor; gl_Position = aVertex; }"); 1.34 + gl.compileShader(vs); 1.35 + 1.36 + var fs = gl.createShader(gl.FRAGMENT_SHADER); 1.37 + gl.shaderSource(fs, "precision mediump float; varying vec4 vColor; void main() { gl_FragColor = vColor; }"); 1.38 + gl.compileShader(fs); 1.39 + 1.40 + var prog = gl.createProgram(); 1.41 + gl.attachShader(prog, vs); 1.42 + // don't attach a fragment shader -- may use fixed pipeline on desktop if the implementation doesn't check! 1.43 + //gl.attachShader(prog, fs); 1.44 + 1.45 + gl.bindAttribLocation(prog, 0, "aVertex"); 1.46 + gl.bindAttribLocation(prog, 1, "aColor"); 1.47 + 1.48 + gl.linkProgram(prog); 1.49 + 1.50 + var vbuf = gl.createBuffer(); 1.51 + gl.bindBuffer(gl.ARRAY_BUFFER, vbuf); 1.52 + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 1.53 + -1.0, -1.0, 0.0, 1.0, 1.54 + -1.0, 1.0, 0.0, 1.0, 1.55 + 1.0, -1.0, 0.0, 1.0, 1.56 + 1.0, 1.0, 0.0, 1.0]), gl.STATIC_DRAW); 1.57 + gl.vertexAttribPointer(0, 4, gl.FLOAT, false, 0, 0); 1.58 + 1.59 + var cbuf = gl.createBuffer(); 1.60 + gl.bindBuffer(gl.ARRAY_BUFFER, cbuf); 1.61 + gl.bufferData(gl.ARRAY_BUFFER, new Uint8Array([255, 0, 0, 1.62 + 0, 255, 0, 1.63 + 0, 0, 255, 1.64 + 255, 255, 0]), gl.STATIC_DRAW); 1.65 + gl.vertexAttribPointer(1, 3, gl.UNSIGNED_BYTE, false, 0, 0); 1.66 + 1.67 + gl.enableVertexAttribArray(0); 1.68 + gl.enableVertexAttribArray(1); 1.69 + 1.70 + gl.useProgram(prog); 1.71 + 1.72 + gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4); 1.73 + 1.74 + log("glError", "0x" + gl.getError().toString(16)); 1.75 + } 1.76 +</script> 1.77 +</head> 1.78 + 1.79 +<body onload="go()"> 1.80 +<p>Should be green in the rectangle below:</p> 1.81 +<canvas style="background: green;" id="c"></canvas> 1.82 +<div id="log"></div> 1.83 +</body> 1.84 +</html>