Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: third_party/webgl/sdk/tests/conformance/attribs/gl-vertexattribpointer-offsets.html

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

Powered by Google App Engine
This is Rietveld 408576698