OLD | NEW |
| (Empty) |
1 <!-- | |
2 Copyright (C) 2009 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 <title>Rendering Test</title> | |
30 <link rel="stylesheet" href="../resources/js-test-style.css"/> | |
31 <script src="../resources/js-test-pre.js"></script> | |
32 <script src="resources/webgl-test.js"> </script> | |
33 </head> | |
34 <body> | |
35 <canvas id="example" width="50" height="50"> | |
36 There is supposed to be an example drawing here, but it's not important. | |
37 </canvas> | |
38 <div id="description"></div> | |
39 <div id="console"></div> | |
40 <script id="vshader" type="x-shader/x-vertex"> | |
41 attribute vec4 vPosition; | |
42 void main() | |
43 { | |
44 gl_Position = vPosition; | |
45 } | |
46 </script> | |
47 | |
48 <script id="fshader" type="x-shader/x-fragment"> | |
49 void main() | |
50 { | |
51 gl_FragColor = vec4(1.0,0.0,0.0,1.0); | |
52 } | |
53 </script> | |
54 | |
55 <script> | |
56 function fail(x,y, buf, shouldBe) | |
57 { | |
58 var i = (y*50+x) * 4; | |
59 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+b
uf[i+2]+","+buf[i+3]+"), should be "+shouldBe; | |
60 testFailed(reason); | |
61 } | |
62 | |
63 function pass() | |
64 { | |
65 testPassed("drawing is correct"); | |
66 } | |
67 | |
68 function init() | |
69 { | |
70 if (window.initNonKhronosFramework) { | |
71 window.initNonKhronosFramework(false); | |
72 } | |
73 | |
74 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0,
0, 0, 1 ], 1); | |
75 | |
76 var vertexObject = gl.createBuffer(); | |
77 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); | |
78 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5
,0, 0.5,-0.5,0 ]), gl.STATIC_DRAW); | |
79 gl.enableVertexAttribArray(0); | |
80 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); | |
81 | |
82 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); | |
83 gl.drawArrays(gl.TRIANGLES, 0, 3); | |
84 | |
85 var buf = new Uint8Array(50 * 50 * 4); | |
86 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); | |
87 | |
88 // Test several locations | |
89 // First line should be all black | |
90 for (var i = 0; i < 50; ++i) | |
91 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i
*4+3] != 255) { | |
92 fail(i, 0, buf, "(0,0,0,255)"); | |
93 return; | |
94 } | |
95 | |
96 // Line 15 should be red for at least 10 red pixels starting 20 pixe
ls in | |
97 var offset = (15*50+20) * 4; | |
98 for (var i = 0; i < 10; ++i) | |
99 if (buf[offset+i*4] != 255 || buf[offset+i*4+1] != 0 || buf[offs
et+i*4+2] != 0 || buf[offset+i*4+3] != 255) { | |
100 fail(20 + i, 15, buf, "(255,0,0,255)"); | |
101 return; | |
102 } | |
103 // Last line should be all black | |
104 offset = (49*50) * 4; | |
105 for (var i = 0; i < 50; ++i) | |
106 if (buf[offset+i*4] != 0 || buf[offset+i*4+1] != 0 || buf[offset
+i*4+2] != 0 || buf[offset+i*4+3] != 255) { | |
107 fail(i, 49, buf, "(0,0,0,255)"); | |
108 return; | |
109 } | |
110 | |
111 pass(); | |
112 } | |
113 | |
114 init(); | |
115 successfullyParsed = true; | |
116 </script> | |
117 </body> | |
118 <script src="../resources/js-test-post.js"></script> | |
119 | |
120 </body> | |
121 </html> | |
OLD | NEW |