OLD | NEW |
(Empty) | |
| 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 <script src="../resources/webgl-test-utils.js"> </script> |
| 35 </head> |
| 36 <body> |
| 37 <canvas id="example" width="50" height="50"> |
| 38 There is supposed to be an example drawing here, but it's not important. |
| 39 </canvas> |
| 40 <div id="description"></div> |
| 41 <div id="console"></div> |
| 42 <script id="vshader" type="x-shader/x-vertex"> |
| 43 attribute vec4 vPosition; |
| 44 void main() |
| 45 { |
| 46 gl_Position = vPosition; |
| 47 } |
| 48 </script> |
| 49 |
| 50 <script id="fshader" type="x-shader/x-fragment"> |
| 51 precision mediump float; |
| 52 uniform vec4 color; |
| 53 void main() |
| 54 { |
| 55 gl_FragColor = color; |
| 56 } |
| 57 </script> |
| 58 |
| 59 <script> |
| 60 function fail(x,y, buf, shouldBe) |
| 61 { |
| 62 var i = (y*50+x) * 4; |
| 63 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+b
uf[i+2]+","+buf[i+3]+"), should be "+shouldBe; |
| 64 testFailed(reason); |
| 65 } |
| 66 |
| 67 function pass() |
| 68 { |
| 69 testPassed("drawing is correct"); |
| 70 } |
| 71 |
| 72 function init() |
| 73 { |
| 74 if (window.initNonKhronosFramework) { |
| 75 window.initNonKhronosFramework(false); |
| 76 } |
| 77 |
| 78 wtu = WebGLTestUtils; |
| 79 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0,
0, 0, 1 ], 1); |
| 80 |
| 81 var tests = [ |
| 82 { data: new Float32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]), |
| 83 type: gl.FLOAT, |
| 84 componentSize: 4, |
| 85 normalize: false, |
| 86 }, |
| 87 { data: new Float32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]), |
| 88 type: gl.FLOAT, |
| 89 componentSize: 4, |
| 90 normalize: false, |
| 91 }, |
| 92 { data: new Uint16Array([ 0, 32767, 0, 32767, 0, 0, 0, 0, 0 ]), |
| 93 type: gl.SHORT, |
| 94 componentSize: 2, |
| 95 normalize: true, |
| 96 }, |
| 97 { data: new Uint16Array([ 0, 65535, 0, 65535, 0, 0, 0, 0, 0 ]), |
| 98 type: gl.UNSIGNED_SHORT, |
| 99 componentSize: 2, |
| 100 normalize: true, |
| 101 }, |
| 102 { data: new Uint16Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]), |
| 103 type: gl.UNSIGNED_SHORT, |
| 104 componentSize: 2, |
| 105 normalize: false, |
| 106 }, |
| 107 { data: new Uint16Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]), |
| 108 type: gl.SHORT, |
| 109 componentSize: 2, |
| 110 normalize: false, |
| 111 }, |
| 112 { data: new Uint8Array([ 0, 127, 0, 127, 0, 0, 0, 0, 0 ]), |
| 113 type: gl.BYTE, |
| 114 componentSize: 1, |
| 115 normalize: true, |
| 116 }, |
| 117 { data: new Uint8Array([ 0, 255, 0, 255, 0, 0, 0, 0, 0 ]), |
| 118 type: gl.UNSIGNED_BYTE, |
| 119 componentSize: 1, |
| 120 normalize: true, |
| 121 }, |
| 122 { data: new Uint8Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]), |
| 123 type: gl.BYTE, |
| 124 componentSize: 1, |
| 125 normalize: false, |
| 126 }, |
| 127 { data: new Uint8Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]), |
| 128 type: gl.UNSIGNED_BYTE, |
| 129 componentSize: 1, |
| 130 normalize: false, |
| 131 } |
| 132 ]; |
| 133 |
| 134 var vertexObject = gl.createBuffer(); |
| 135 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject); |
| 136 gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW); |
| 137 gl.enableVertexAttribArray(0); |
| 138 |
| 139 var colorLoc = gl.getUniformLocation(gl.program, "color"); |
| 140 var kNumVerts = 3; |
| 141 var kNumComponents = 3; |
| 142 |
| 143 var count = 0; |
| 144 for (var tt = 0; tt < tests.length; ++tt) { |
| 145 var test = tests[tt]; |
| 146 for (var oo = 0; oo < 3; ++oo) { |
| 147 for (var ss = 0; ss < 3; ++ss) { |
| 148 var offset = (oo + 1) * test.componentSize; |
| 149 var color = (count % 2) ? [1, 0, 0, 1] : [0, 1, 0, 1]; |
| 150 var stride = test.componentSize * kNumComponents + test.compon
entSize * ss; |
| 151 debug(""); |
| 152 debug("check with " + wtu.glEnumToString(gl, test.type) + " at
offset: " + offset + " with stride:" + stride + " normalize: " + test.normalize
); |
| 153 gl.uniform4fv(colorLoc, color); |
| 154 var data = new Uint8Array(test.componentSize * kNumVerts * kNu
mComponents + stride * (kNumVerts - 1)); |
| 155 var view = new Uint8Array(test.data.buffer); |
| 156 var size = test.componentSize * kNumComponents; |
| 157 for (var jj = 0; jj < kNumVerts; ++jj) { |
| 158 var off1 = jj * size; |
| 159 var off2 = jj * stride; |
| 160 for (var zz = 0; zz < size; ++zz) { |
| 161 data[off2 + zz] = view[off1 + zz]; |
| 162 } |
| 163 } |
| 164 gl.bufferSubData(gl.ARRAY_BUFFER, offset, data); |
| 165 gl.vertexAttribPointer(0, 3, test.type, test.normalize, stride
, offset); |
| 166 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT); |
| 167 gl.drawArrays(gl.TRIANGLES, 0, 3); |
| 168 |
| 169 var buf = new Uint8Array(50 * 50 * 4); |
| 170 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf); |
| 171 |
| 172 var black = [0, 0, 0, 255]; |
| 173 var other = [color[0] * 255, color[1] * 255, color[2] * 255, c
olor[3] * 255]; |
| 174 var otherMsg = "should be " + ((count % 2) ? "red" : "green") |
| 175 wtu.checkCanvasRect(gl, 0, 0, 1, 1, black, "should be black",
0); |
| 176 wtu.checkCanvasRect(gl, 0, 49, 1, 1, black, "should be black",
0); |
| 177 wtu.checkCanvasRect(gl, 26, 40, 1, 1, other, otherMsg, 0); |
| 178 wtu.checkCanvasRect(gl, 26, 27, 1, 1, other, otherMsg, 0); |
| 179 wtu.checkCanvasRect(gl, 40, 27, 1, 1, other, otherMsg, 0); |
| 180 ++count; |
| 181 } |
| 182 } |
| 183 } |
| 184 } |
| 185 |
| 186 init(); |
| 187 successfullyParsed = true; |
| 188 </script> |
| 189 <script src="../../resources/js-test-post.js"></script> |
| 190 |
| 191 </body> |
| 192 </html> |
OLD | NEW |