content/canvas/test/webgl-conformance/conformance/attribs/gl-vertexattribpointer-offsets.html

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 <!--
michael@0 2 Copyright (C) 2011 Apple Computer, Inc. All rights reserved.
michael@0 3
michael@0 4 Redistribution and use in source and binary forms, with or without
michael@0 5 modification, are permitted provided that the following conditions
michael@0 6 are met:
michael@0 7 1. Redistributions of source code must retain the above copyright
michael@0 8 notice, this list of conditions and the following disclaimer.
michael@0 9 2. Redistributions in binary form must reproduce the above copyright
michael@0 10 notice, this list of conditions and the following disclaimer in the
michael@0 11 documentation and/or other materials provided with the distribution.
michael@0 12
michael@0 13 THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
michael@0 14 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
michael@0 15 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
michael@0 16 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
michael@0 17 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
michael@0 18 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
michael@0 19 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
michael@0 20 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
michael@0 21 OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
michael@0 22 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
michael@0 23 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
michael@0 24 -->
michael@0 25
michael@0 26 <!DOCTYPE html>
michael@0 27 <html>
michael@0 28 <head>
michael@0 29 <meta charset="utf-8">
michael@0 30 <title>vertexattribpointer offsets test</title>
michael@0 31 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
michael@0 32 <script src="../../resources/js-test-pre.js"></script>
michael@0 33 <script src="../resources/webgl-test.js"> </script>
michael@0 34 <script src="../resources/webgl-test-utils.js"> </script>
michael@0 35 </head>
michael@0 36 <body>
michael@0 37 <canvas id="example" width="50" height="50">
michael@0 38 There is supposed to be an example drawing here, but it's not important.
michael@0 39 </canvas>
michael@0 40 <div id="description"></div>
michael@0 41 <div id="console"></div>
michael@0 42 <script id="vshader" type="x-shader/x-vertex">
michael@0 43 attribute vec4 vPosition;
michael@0 44 void main()
michael@0 45 {
michael@0 46 gl_Position = vPosition;
michael@0 47 }
michael@0 48 </script>
michael@0 49
michael@0 50 <script id="fshader" type="x-shader/x-fragment">
michael@0 51 precision mediump float;
michael@0 52 uniform vec4 color;
michael@0 53 void main()
michael@0 54 {
michael@0 55 gl_FragColor = color;
michael@0 56 }
michael@0 57 </script>
michael@0 58
michael@0 59 <script>
michael@0 60 function fail(x,y, buf, shouldBe)
michael@0 61 {
michael@0 62 var i = (y*50+x) * 4;
michael@0 63 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+","+buf[i+3]+"), should be "+shouldBe;
michael@0 64 testFailed(reason);
michael@0 65 }
michael@0 66
michael@0 67 function pass()
michael@0 68 {
michael@0 69 testPassed("drawing is correct");
michael@0 70 }
michael@0 71
michael@0 72 function init()
michael@0 73 {
michael@0 74 if (window.initNonKhronosFramework) {
michael@0 75 window.initNonKhronosFramework(false);
michael@0 76 }
michael@0 77 description("test vertexattribpointer offsets work");
michael@0 78
michael@0 79 wtu = WebGLTestUtils;
michael@0 80 gl = initWebGL("example", "vshader", "fshader", [ "vPosition"], [ 0, 0, 0, 1 ], 1);
michael@0 81
michael@0 82 var tests = [
michael@0 83 { data: new Float32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
michael@0 84 type: gl.FLOAT,
michael@0 85 componentSize: 4,
michael@0 86 normalize: false,
michael@0 87 },
michael@0 88 { data: new Float32Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
michael@0 89 type: gl.FLOAT,
michael@0 90 componentSize: 4,
michael@0 91 normalize: false,
michael@0 92 },
michael@0 93 { data: new Uint16Array([ 0, 32767, 0, 32767, 0, 0, 0, 0, 0 ]),
michael@0 94 type: gl.SHORT,
michael@0 95 componentSize: 2,
michael@0 96 normalize: true,
michael@0 97 },
michael@0 98 { data: new Uint16Array([ 0, 65535, 0, 65535, 0, 0, 0, 0, 0 ]),
michael@0 99 type: gl.UNSIGNED_SHORT,
michael@0 100 componentSize: 2,
michael@0 101 normalize: true,
michael@0 102 },
michael@0 103 { data: new Uint16Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
michael@0 104 type: gl.UNSIGNED_SHORT,
michael@0 105 componentSize: 2,
michael@0 106 normalize: false,
michael@0 107 },
michael@0 108 { data: new Uint16Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
michael@0 109 type: gl.SHORT,
michael@0 110 componentSize: 2,
michael@0 111 normalize: false,
michael@0 112 },
michael@0 113 { data: new Uint8Array([ 0, 127, 0, 127, 0, 0, 0, 0, 0 ]),
michael@0 114 type: gl.BYTE,
michael@0 115 componentSize: 1,
michael@0 116 normalize: true,
michael@0 117 },
michael@0 118 { data: new Uint8Array([ 0, 255, 0, 255, 0, 0, 0, 0, 0 ]),
michael@0 119 type: gl.UNSIGNED_BYTE,
michael@0 120 componentSize: 1,
michael@0 121 normalize: true,
michael@0 122 },
michael@0 123 { data: new Uint8Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
michael@0 124 type: gl.BYTE,
michael@0 125 componentSize: 1,
michael@0 126 normalize: false,
michael@0 127 },
michael@0 128 { data: new Uint8Array([ 0, 1, 0, 1, 0, 0, 0, 0, 0 ]),
michael@0 129 type: gl.UNSIGNED_BYTE,
michael@0 130 componentSize: 1,
michael@0 131 normalize: false,
michael@0 132 }
michael@0 133 ];
michael@0 134
michael@0 135 var vertexObject = gl.createBuffer();
michael@0 136 gl.bindBuffer(gl.ARRAY_BUFFER, vertexObject);
michael@0 137 gl.bufferData(gl.ARRAY_BUFFER, 1024, gl.STATIC_DRAW);
michael@0 138 gl.enableVertexAttribArray(0);
michael@0 139
michael@0 140 var colorLoc = gl.getUniformLocation(gl.program, "color");
michael@0 141 var kNumVerts = 3;
michael@0 142 var kNumComponents = 3;
michael@0 143
michael@0 144 var count = 0;
michael@0 145 for (var tt = 0; tt < tests.length; ++tt) {
michael@0 146 var test = tests[tt];
michael@0 147 for (var oo = 0; oo < 3; ++oo) {
michael@0 148 for (var ss = 0; ss < 3; ++ss) {
michael@0 149 var offset = (oo + 1) * test.componentSize;
michael@0 150 var color = (count % 2) ? [1, 0, 0, 1] : [0, 1, 0, 1];
michael@0 151 var stride = test.componentSize * kNumComponents + test.componentSize * ss;
michael@0 152 debug("");
michael@0 153 debug("check with " + wtu.glEnumToString(gl, test.type) + " at offset: " + offset + " with stride:" + stride + " normalize: " + test.normalize);
michael@0 154 gl.uniform4fv(colorLoc, color);
michael@0 155 var data = new Uint8Array(test.componentSize * kNumVerts * kNumComponents + stride * (kNumVerts - 1));
michael@0 156 var view = new Uint8Array(test.data.buffer);
michael@0 157 var size = test.componentSize * kNumComponents;
michael@0 158 for (var jj = 0; jj < kNumVerts; ++jj) {
michael@0 159 var off1 = jj * size;
michael@0 160 var off2 = jj * stride;
michael@0 161 for (var zz = 0; zz < size; ++zz) {
michael@0 162 data[off2 + zz] = view[off1 + zz];
michael@0 163 }
michael@0 164 }
michael@0 165 gl.bufferSubData(gl.ARRAY_BUFFER, offset, data);
michael@0 166 gl.vertexAttribPointer(0, 3, test.type, test.normalize, stride, offset);
michael@0 167 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
michael@0 168 gl.drawArrays(gl.TRIANGLES, 0, 3);
michael@0 169
michael@0 170 var buf = new Uint8Array(50 * 50 * 4);
michael@0 171 gl.readPixels(0, 0, 50, 50, gl.RGBA, gl.UNSIGNED_BYTE, buf);
michael@0 172
michael@0 173 var black = [0, 0, 0, 255];
michael@0 174 var other = [color[0] * 255, color[1] * 255, color[2] * 255, color[3] * 255];
michael@0 175 var otherMsg = "should be " + ((count % 2) ? "red" : "green")
michael@0 176 wtu.checkCanvasRect(gl, 0, 0, 1, 1, black, "should be black", 0);
michael@0 177 wtu.checkCanvasRect(gl, 0, 49, 1, 1, black, "should be black", 0);
michael@0 178 wtu.checkCanvasRect(gl, 26, 40, 1, 1, other, otherMsg, 0);
michael@0 179 wtu.checkCanvasRect(gl, 26, 27, 1, 1, other, otherMsg, 0);
michael@0 180 wtu.checkCanvasRect(gl, 40, 27, 1, 1, other, otherMsg, 0);
michael@0 181 ++count;
michael@0 182 }
michael@0 183 }
michael@0 184 }
michael@0 185 }
michael@0 186
michael@0 187 init();
michael@0 188 successfullyParsed = true;
michael@0 189 </script>
michael@0 190 <script>finishTest();</script>
michael@0 191
michael@0 192 </body>
michael@0 193 </html>

mercurial