OLD | NEW |
(Empty) | |
| 1 <!-- |
| 2 |
| 3 /* |
| 4 ** Copyright (c) 2012 The Khronos Group Inc. |
| 5 ** |
| 6 ** Permission is hereby granted, free of charge, to any person obtaining a |
| 7 ** copy of this software and/or associated documentation files (the |
| 8 ** "Materials"), to deal in the Materials without restriction, including |
| 9 ** without limitation the rights to use, copy, modify, merge, publish, |
| 10 ** distribute, sublicense, and/or sell copies of the Materials, and to |
| 11 ** permit persons to whom the Materials are furnished to do so, subject to |
| 12 ** the following conditions: |
| 13 ** |
| 14 ** The above copyright notice and this permission notice shall be included |
| 15 ** in all copies or substantial portions of the Materials. |
| 16 ** |
| 17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
| 21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS. |
| 24 */ |
| 25 |
| 26 --> |
| 27 |
| 28 <!DOCTYPE html> |
| 29 <html> |
| 30 <head> |
| 31 <meta charset="utf-8"> |
| 32 <title>Rendering Test</title> |
| 33 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
| 34 <script src="../../resources/js-test-pre.js"></script> |
| 35 <script src="../resources/webgl-test.js"> </script> |
| 36 </head> |
| 37 <body> |
| 38 <canvas id="example" width="50" height="50"> |
| 39 There is supposed to be an example drawing here, but it's not important. |
| 40 </canvas> |
| 41 <div id="description"></div> |
| 42 <div id="console"></div> |
| 43 <script id="vshader" type="x-shader/x-vertex"> |
| 44 attribute vec4 vPosition; |
| 45 void main() |
| 46 { |
| 47 gl_Position = vPosition; |
| 48 } |
| 49 </script> |
| 50 |
| 51 <script id="fshader" type="x-shader/x-fragment"> |
| 52 void main() |
| 53 { |
| 54 gl_FragColor = vec4(1.0,0.0,0.0,1.0); |
| 55 } |
| 56 </script> |
| 57 |
| 58 <script> |
| 59 function fail(x,y, buf, shouldBe) |
| 60 { |
| 61 var i = (y*50+x) * 4; |
| 62 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+b
uf[i+2]+","+buf[i+3]+"), should be "+shouldBe; |
| 63 testFailed(reason); |
| 64 } |
| 65 |
| 66 function pass() |
| 67 { |
| 68 testPassed("drawing is correct"); |
| 69 } |
| 70 |
| 71 function init() |
| 72 { |
| 73 if (window.initNonKhronosFramework) { |
| 74 window.initNonKhronosFramework(false); |
| 75 } |
| 76 |
| 77 description(document.title); |
| 78 |
| 79 gl = initWebGL("example"); |
| 80 program = setupProgram(gl, "vshader", "fshader", [ "vPosition"]); |
| 81 |
| 82 var vertexObject = gl.createBuffer(); |
| 83 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 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); |
| 85 gl.enableVertexAttribArray(0); |
| 86 gl.vertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0); |
| 87 |
| 88 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 89 gl.drawArrays(gl.TRIANGLES, 0, 3); |
| 90 |
| 91 var buf = new Uint8Array(50 * 50 * 4); |
| 92 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 93 |
| 94 // Test several locations |
| 95 // First line should be all black |
| 96 for (var i = 0; i < 50; ++i) |
| 97 if (buf[i*4] != 0 || buf[i*4+1] != 0 || buf[i*4+2] != 0 || buf[i
*4+3] != 255) { |
| 98 fail(i, 0, buf, "(0,0,0,255)"); |
| 99 return; |
| 100 } |
| 101 |
| 102 // Line 15 should be red for at least 10 red pixels starting 20 pixe
ls in |
| 103 var offset = (15*50+20) * 4; |
| 104 for (var i = 0; i < 10; ++i) |
| 105 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) { |
| 106 fail(20 + i, 15, buf, "(255,0,0,255)"); |
| 107 return; |
| 108 } |
| 109 // Last line should be all black |
| 110 offset = (49*50) * 4; |
| 111 for (var i = 0; i < 50; ++i) |
| 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) { |
| 113 fail(i, 49, buf, "(0,0,0,255)"); |
| 114 return; |
| 115 } |
| 116 |
| 117 pass(); |
| 118 } |
| 119 |
| 120 init(); |
| 121 successfullyParsed = true; |
| 122 </script> |
| 123 <script src="../../resources/js-test-post.js"></script> |
| 124 |
| 125 </body> |
| 126 </html> |
OLD | NEW |