1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/canvas/test/webgl-conformance/conformance/rendering/triangle.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,123 @@ 1.4 +<!-- 1.5 +Copyright (C) 2011 Apple Computer, Inc. All rights reserved. 1.6 + 1.7 +Redistribution and use in source and binary forms, with or without 1.8 +modification, are permitted provided that the following conditions 1.9 +are met: 1.10 +1. Redistributions of source code must retain the above copyright 1.11 + notice, this list of conditions and the following disclaimer. 1.12 +2. Redistributions in binary form must reproduce the above copyright 1.13 + notice, this list of conditions and the following disclaimer in the 1.14 + documentation and/or other materials provided with the distribution. 1.15 + 1.16 +THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 1.17 +EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1.18 +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 1.19 +PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 1.20 +CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.21 +EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.22 +PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.23 +PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 1.24 +OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.25 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.26 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.27 +--> 1.28 + 1.29 +<!DOCTYPE html> 1.30 +<html> 1.31 + <head> 1.32 +<meta charset="utf-8"> 1.33 + <title>Rendering Test</title> 1.34 + <link rel="stylesheet" href="../../resources/js-test-style.css"/> 1.35 + <script src="../../resources/js-test-pre.js"></script> 1.36 + <script src="../resources/webgl-test.js"> </script> 1.37 +</head> 1.38 +<body> 1.39 +<canvas id="example" width="50" height="50"> 1.40 +There is supposed to be an example drawing here, but it's not important. 1.41 +</canvas> 1.42 +<div id="description"></div> 1.43 +<div id="console"></div> 1.44 + <script id="vshader" type="x-shader/x-vertex"> 1.45 + attribute vec4 vPosition; 1.46 + void main() 1.47 + { 1.48 + gl_Position = vPosition; 1.49 + } 1.50 + </script> 1.51 + 1.52 + <script id="fshader" type="x-shader/x-fragment"> 1.53 + void main() 1.54 + { 1.55 + gl_FragColor = vec4(1.0,0.0,0.0,1.0); 1.56 + } 1.57 + </script> 1.58 + 1.59 + <script> 1.60 + function fail(x,y, buf, shouldBe) 1.61 + { 1.62 + var i = (y*50+x) * 4; 1.63 + var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe; 1.64 + testFailed(reason); 1.65 + } 1.66 + 1.67 + function pass() 1.68 + { 1.69 + testPassed("drawing is correct"); 1.70 + } 1.71 + 1.72 + function init() 1.73 + { 1.74 + if (window.initNonKhronosFramework) { 1.75 + window.initNonKhronosFramework(false); 1.76 + } 1.77 + 1.78 + description(document.title); 1.79 + 1.80 + gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1); 1.81 + 1.82 + var vertexObject = gl.createBuffer(); 1.83 + gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); 1.84 + gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW); 1.85 + gl.enableVertexAttribArray(0); 1.86 + gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); 1.87 + 1.88 + gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); 1.89 + gl.drawArrays(gl.TRIANGLES, 0, 3); 1.90 + 1.91 + var buf = new Uint8Array(50 * 50 * 4); 1.92 + gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); 1.93 + 1.94 + // Test several locations 1.95 + // First line should be all black 1.96 + for (var i = 0; i < 50; ++i) 1.97 + if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255) { 1.98 + fail(i, 0, buf, "(0,0,0,255)"); 1.99 + return; 1.100 + } 1.101 + 1.102 + // Line 15 should be red for at least 10 red pixels starting 20 pixels in 1.103 + var offset = (15*50+20) * 4; 1.104 + for (var i = 0; i < 10; ++i) 1.105 + if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) { 1.106 + fail(20 + i, 15, buf, "(255,0,0,255)"); 1.107 + return; 1.108 + } 1.109 + // Last line should be all black 1.110 + offset = (49*50) * 4; 1.111 + for (var i = 0; i < 50; ++i) 1.112 + if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) { 1.113 + fail(i, 49, buf, "(0,0,0,255)"); 1.114 + return; 1.115 + } 1.116 + 1.117 + pass(); 1.118 + } 1.119 + 1.120 + init(); 1.121 + successfullyParsed = true; 1.122 + </script> 1.123 +<script>finishTest();</script> 1.124 + 1.125 +</body> 1.126 +</html>