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

Side by Side Diff: third_party/webgl/sdk/tests/conformance/programs/gl-bind-attrib-location-test.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>WebGL BindAttribLocation Conformance Tests</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 <div id="description"></div>
39 <div id="console"></div>
40 <canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></ca nvas>
41 <script id="vshader" type="text/something-not-javascript">
42 attribute vec4 vPosition;
43 attribute vec4 vColor;
44 varying vec4 color;
45 void main()
46 {
47 gl_Position = vPosition;
48 color = vColor;
49 }
50 </script>
51 <script id="fshader" type="text/something-not-javascript">
52 precision mediump float;
53
54 varying vec4 color;
55 void main()
56 {
57 gl_FragColor = color;
58 }
59 </script>
60 <script>
61 description("This test ensures WebGL implementations don't allow names that star t with 'gl_' when calling bindAttribLocation.");
62
63 debug("");
64 debug("Canvas.getContext");
65
66 var gl = create3DContext(document.getElementById("canvas"));
67 shouldBeNonNull("gl");
68
69 function fail(x,y, buf, shouldBe)
70 {
71 var i = (y*50+x) * 4;
72 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+", "+buf[i+3]+"), should be "+shouldBe;
73 testFailed(reason);
74 }
75
76 function pass()
77 {
78 testPassed("drawing is correct");
79 }
80
81 function loadShader(shaderType, shaderId) {
82 // Get the shader source.
83 var shaderSource = document.getElementById(shaderId).text;
84
85 // Create the shader object
86 var shader = gl.createShader(shaderType);
87 if (shader == null) {
88 debug("*** Error: unable to create shader '"+shaderId+"'");
89 return null;
90 }
91
92 // Load the shader source
93 gl.shaderSource(shader, shaderSource);
94
95 // Compile the shader
96 gl.compileShader(shader);
97
98 // Check the compile status
99 var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
100 if (!compiled) {
101 // Something went wrong during compilation; get the error
102 var error = gl.getShaderInfoLog(shader);
103 debug("*** Error compiling shader '"+shader+"':"+error);
104 gl.deleteShader(shader);
105 return null;
106 }
107 return shader;
108 }
109
110 debug("");
111 debug("Checking gl.bindAttribLocation.");
112
113 var program = gl.createProgram();
114 gl.bindAttribLocation(program, 0, "gl_foo");
115 glErrorShouldBe(gl, gl.INVALID_OPERATION,
116 "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_ '");
117 gl.bindAttribLocation(program, 0, "gl_TexCoord0");
118 glErrorShouldBe(gl, gl.INVALID_OPERATION,
119 "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_ '");
120
121 var vs = loadShader(gl.VERTEX_SHADER, "vshader");
122 var fs = loadShader(gl.FRAGMENT_SHADER, "fshader");
123 gl.attachShader(program, vs);
124 gl.attachShader(program, fs);
125
126 var positions = gl.createBuffer();
127 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
128 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5 ,0 ]), gl.STATIC_DRAW);
129
130 var colors = gl.createBuffer();
131 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
132 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
133 0,1,0,1,
134 0,1,0,1,
135 0,1,0,1]), gl.STATIC_DRAW);
136
137 function setBindLocations(colorLocation, positionLocation) {
138 gl.bindAttribLocation(program, positionLocation, "vPosition");
139 gl.bindAttribLocation(program, colorLocation, "vColor");
140 gl.linkProgram(program);
141 gl.useProgram(program);
142 var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
143 assertMsg(linked, "program linked successfully");
144
145 debug("vPosition:" + gl.getAttribLocation(program, "vPosition"))
146 debug("vColor :" + gl.getAttribLocation(program, "vColor"))
147 assertMsg(gl.getAttribLocation(program, "vPosition") == positionLocation,
148 "location of vPosition should be " + positionLocation);
149 assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
150 "location of vColor should be " + colorLocation);
151
152 var ploc = gl.getAttribLocation(program, "vPosition");
153 var cloc = gl.getAttribLocation(program, "vColor");
154 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
155 gl.enableVertexAttribArray(positionLocation);
156 gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
157 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
158 gl.enableVertexAttribArray(colorLocation);
159 gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
160 }
161
162 function checkDraw(colorLocation, positionLocation, r, g, b, a) {
163 gl.clearColor(0, 0, 0, 1);
164 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
165 gl.drawArrays(gl.TRIANGLES, 0, 3);
166
167 var width = 50;
168 var height = 50;
169 var buf = new Uint8Array(width * height * 4);
170 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
171
172 function checkPixel(x, y, r, g, b, a) {
173 var offset = (y * width + x) * 4;
174 if (buf[offset + 0] != r ||
175 buf[offset + 1] != g ||
176 buf[offset + 2] != b ||
177 buf[offset + 3] != a) {
178 fail(x, y, buf, "(" + r + "," + g + "," + b + "," + a + ")");
179 return false;
180 }
181 return true;
182 }
183
184 // Test several locations
185 // First line should be all black
186 var success = true;
187 for (var i = 0; i < 50; ++i)
188 success = success && checkPixel(i, 0, 0, 0, 0, 255);
189
190 // Line 15 should be red for at least 10 rgba pixels starting 20 pixels in
191 var offset = (15 * 50 + 20) * 4;
192 for (var i = 0; i < 10; ++i)
193 success = success && checkPixel(20 + i, 15, r, g, b, a);
194
195 // Last line should be all black
196 for (var i = 0; i < 50; ++i)
197 success = success && checkPixel(i, 49, 0, 0, 0, 255);
198
199 if (success)
200 pass();
201
202 gl.disableVertexAttribArray(positionLocation);
203 gl.disableVertexAttribArray(colorLocation);
204 }
205
206 setBindLocations(2, 3);
207 checkDraw(2, 3, 0, 255, 0, 255);
208
209 setBindLocations(0, 3);
210 gl.disableVertexAttribArray(0);
211 gl.vertexAttrib4f(0, 1, 0, 0, 1);
212 checkDraw(0, 3, 255, 0, 0, 255);
213
214 glErrorShouldBe(gl, gl.NO_ERROR);
215
216 debug("");
217 successfullyParsed = true;
218
219 </script>
220 <script src="../../resources/js-test-post.js"></script>
221
222 </body>
223 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698