|
1 <!-- |
|
2 Copyright (C) 2011 Apple Computer, Inc. All rights reserved. |
|
3 |
|
4 Redistribution and use in source and binary forms, with or without |
|
5 modification, are permitted provided that the following conditions |
|
6 are met: |
|
7 1. Redistributions of source code must retain the above copyright |
|
8 notice, this list of conditions and the following disclaimer. |
|
9 2. Redistributions in binary form must reproduce the above copyright |
|
10 notice, this list of conditions and the following disclaimer in the |
|
11 documentation and/or other materials provided with the distribution. |
|
12 |
|
13 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
|
14 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
16 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
|
17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
18 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
19 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
20 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
21 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
24 --> |
|
25 |
|
26 <!DOCTYPE html> |
|
27 <html> |
|
28 <head> |
|
29 <meta charset="utf-8"> |
|
30 <title>Rendering Test</title> |
|
31 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
|
32 <script src="../../resources/js-test-pre.js"></script> |
|
33 <script src="../resources/webgl-test.js"> </script> |
|
34 </head> |
|
35 <body> |
|
36 <canvas id="example" width="50" height="50"> |
|
37 There is supposed to be an example drawing here, but it's not important. |
|
38 </canvas> |
|
39 <div id="description"></div> |
|
40 <div id="console"></div> |
|
41 <script id="vshader" type="x-shader/x-vertex"> |
|
42 attribute vec4 vPosition; |
|
43 void main() |
|
44 { |
|
45 gl_Position = vPosition; |
|
46 } |
|
47 </script> |
|
48 |
|
49 <script id="fshader" type="x-shader/x-fragment"> |
|
50 void main() |
|
51 { |
|
52 gl_FragColor = vec4(1.0,0.0,0.0,1.0); |
|
53 } |
|
54 </script> |
|
55 |
|
56 <script> |
|
57 function fail(x,y, buf, shouldBe) |
|
58 { |
|
59 var i = (y*50+x) * 4; |
|
60 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe; |
|
61 testFailed(reason); |
|
62 } |
|
63 |
|
64 function pass() |
|
65 { |
|
66 testPassed("drawing is correct"); |
|
67 } |
|
68 |
|
69 function init() |
|
70 { |
|
71 if (window.initNonKhronosFramework) { |
|
72 window.initNonKhronosFramework(false); |
|
73 } |
|
74 |
|
75 description(document.title); |
|
76 |
|
77 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1); |
|
78 |
|
79 var vertexObject = gl.createBuffer(); |
|
80 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
|
81 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW); |
|
82 gl.enableVertexAttribArray(0); |
|
83 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
|
84 |
|
85 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
|
86 gl.drawArrays(gl.TRIANGLES, 0, 3); |
|
87 |
|
88 var buf = new Uint8Array(50 * 50 * 4); |
|
89 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
|
90 |
|
91 // Test several locations |
|
92 // First line should be all black |
|
93 for (var i = 0; i < 50; ++i) |
|
94 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i*4+3] != 255) { |
|
95 fail(i, 0, buf, "(0,0,0,255)"); |
|
96 return; |
|
97 } |
|
98 |
|
99 // Line 15 should be red for at least 10 red pixels starting 20 pixels in |
|
100 var offset = (15*50+20) * 4; |
|
101 for (var i = 0; i < 10; ++i) |
|
102 if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) { |
|
103 fail(20 + i, 15, buf, "(255,0,0,255)"); |
|
104 return; |
|
105 } |
|
106 // Last line should be all black |
|
107 offset = (49*50) * 4; |
|
108 for (var i = 0; i < 50; ++i) |
|
109 if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset+i*4+2] != 0 || buf[offset+i*4+3] != 255) { |
|
110 fail(i, 49, buf, "(0,0,0,255)"); |
|
111 return; |
|
112 } |
|
113 |
|
114 pass(); |
|
115 } |
|
116 |
|
117 init(); |
|
118 successfullyParsed = true; |
|
119 </script> |
|
120 <script>finishTest();</script> |
|
121 |
|
122 </body> |
|
123 </html> |