|
1 <!-- |
|
2 Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
3 Use of this source code is governed by a BSD-style license that can be |
|
4 found in the LICENSE file. |
|
5 --> |
|
6 <!DOCTYPE html> |
|
7 <html> |
|
8 <head> |
|
9 <meta charset="utf-8"> |
|
10 <title>WebGL getActiveAttrib conformance test.</title> |
|
11 <link rel="stylesheet" href="../../resources/js-test-style.css"/> |
|
12 <script src="../../resources/js-test-pre.js"></script> |
|
13 <script src="../resources/webgl-test.js"> </script> |
|
14 <script src="../resources/webgl-test-utils.js"> </script> |
|
15 </head> |
|
16 <body> |
|
17 <canvas id="example" width="16" height="16"></canvas> |
|
18 <div id="description"></div> |
|
19 <div id="console"></div> |
|
20 <script id="vshader" type="x-shader/x-vertex"> |
|
21 attribute $type attr0; |
|
22 void main() |
|
23 { |
|
24 gl_Position = vec4(0, 0, 0, attr0$access); |
|
25 } |
|
26 </script> |
|
27 <script id="fshader" type="x-shader/x-fragment"> |
|
28 void main() |
|
29 { |
|
30 gl_FragColor = vec4(0,1,0,1); |
|
31 } |
|
32 </script> |
|
33 <script> |
|
34 description("Tests getActiveAttrib for various types"); |
|
35 |
|
36 var wtu = WebGLTestUtils; |
|
37 var gl = wtu.create3DContext("example"); |
|
38 |
|
39 var tests = [ |
|
40 { glType: gl.FLOAT, size: 1, type: 'float', access: ''}, |
|
41 { glType: gl.FLOAT_VEC2, size: 1, type: 'vec2', access: '[1]'}, |
|
42 { glType: gl.FLOAT_VEC3, size: 1, type: 'vec3', access: '[2]'}, |
|
43 { glType: gl.FLOAT_VEC4, size: 1, type: 'vec4', access: '[3]'}, |
|
44 { glType: gl.FLOAT_MAT2, size: 1, type: 'mat2', access: '[1][1]'}, |
|
45 { glType: gl.FLOAT_MAT3, size: 1, type: 'mat3', access: '[2][2]'}, |
|
46 { glType: gl.FLOAT_MAT4, size: 1, type: 'mat4', access: '[3][3]'}, |
|
47 ]; |
|
48 |
|
49 var source = document.getElementById('vshader').text; |
|
50 var fs = wtu.loadShaderFromScript(gl, 'fshader', gl.FRAGMENT_SHADER); |
|
51 for (var tt = 0; tt < tests.length; ++tt) { |
|
52 var t = tests[tt]; |
|
53 var vs = wtu.loadShader( |
|
54 gl, |
|
55 source.replace('$type', t.type).replace('$access', t.access), |
|
56 gl.VERTEX_SHADER); |
|
57 var program = wtu.setupProgram(gl, [vs, fs]); |
|
58 glErrorShouldBe(gl, gl.NO_ERROR, "no errors from setup"); |
|
59 var numAttribs = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES); |
|
60 var found = false; |
|
61 for (var ii = 0; ii < numAttribs; ++ii) { |
|
62 var info = gl.getActiveAttrib(program, ii); |
|
63 if (info.name == 'attr0') { |
|
64 found = true; |
|
65 assertMsg(info.type == t.glType, |
|
66 "type must be " + wtu.glEnumToString(gl, t.glType) + " was " + |
|
67 wtu.glEnumToString(gl, info.type)); |
|
68 assertMsg(info.size == t.size, |
|
69 "size must be " + t.size + ' was ' + info.size); |
|
70 } |
|
71 } |
|
72 if (!found) { |
|
73 testFailed("attrib 'attr0' not found"); |
|
74 } |
|
75 } |
|
76 |
|
77 successfullyParsed = true; |
|
78 </script> |
|
79 <script>finishTest();</script> |
|
80 |
|
81 </body> |
|
82 </html> |
|
83 |
|
84 |