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

Side by Side Diff: third_party/webgl/conformance-suites/1.0.0/conformance/gl-bind-attrib-location-test.html

Issue 9360034: Remove everthing except conformance tests in the deps/third_party/webgl (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/
Patch Set: Created 8 years, 10 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
OLDNEW
(Empty)
1 <!--
2 Copyright (c) 2009 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
7 "http://www.w3.org/TR/html4/loose.dtd">
8 <html>
9 <head>
10 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
11 <title>WebGL BindAttribLocation Conformance Tests</title>
12 <link rel="stylesheet" href="../resources/js-test-style.css"/>
13 <script src="../resources/js-test-pre.js"></script>
14 <script src="resources/webgl-test.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <div id="console"></div>
19 <canvas style="border: 1px solid black;" id="canvas" width="50" height="50"></ca nvas>
20 <script id="vshader" type="text/something-not-javascript">
21 attribute vec4 vPosition;
22 attribute vec4 vColor;
23 varying vec4 color;
24 void main()
25 {
26 gl_Position = vPosition;
27 color = vColor;
28 }
29 </script>
30 <script id="fshader" type="text/something-not-javascript">
31 #ifdef GL_ES
32 precision highp float;
33 #endif
34 varying vec4 color;
35 void main()
36 {
37 gl_FragColor = color;
38 }
39 </script>
40 <script>
41 description("This test ensures WebGL implementations don't allow names that star t with 'gl_' when calling bindAttribLocation.");
42
43 debug("");
44 debug("Canvas.getContext");
45
46 var gl = create3DContext(document.getElementById("canvas"));
47 shouldBeNonNull(gl);
48
49 function fail(x,y, buf, shouldBe)
50 {
51 var i = (y*50+x) * 4;
52 var reason = "pixel at ("+x+","+y+") is ("+buf[i]+","+buf[i+1]+","+buf[i+2]+", "+buf[i+3]+"), should be "+shouldBe;
53 testFailed(reason);
54 }
55
56 function pass()
57 {
58 testPassed("drawing is correct");
59 }
60
61 function loadShader(shaderType, shaderId) {
62 // Get the shader source.
63 var shaderSource = document.getElementById(shaderId).text;
64
65 // Create the shader object
66 var shader = gl.createShader(shaderType);
67 if (shader == null) {
68 debug("*** Error: unable to create shader '"+shaderId+"'");
69 return null;
70 }
71
72 // Load the shader source
73 gl.shaderSource(shader, shaderSource);
74
75 // Compile the shader
76 gl.compileShader(shader);
77
78 // Check the compile status
79 var compiled = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
80 if (!compiled) {
81 // Something went wrong during compilation; get the error
82 var error = gl.getShaderInfoLog(shader);
83 debug("*** Error compiling shader '"+shader+"':"+error);
84 gl.deleteShader(shader);
85 return null;
86 }
87 return shader;
88 }
89
90 debug("");
91 debug("Checking gl.bindAttribLocation.");
92
93 var program = gl.createProgram();
94 gl.bindAttribLocation(program, 0, "gl_foo");
95 glErrorShouldBe(gl, gl.INVALID_OPERATION,
96 "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_ '");
97 gl.bindAttribLocation(program, 0, "gl_TexCoord0");
98 glErrorShouldBe(gl, gl.INVALID_OPERATION,
99 "bindAttribLocation should return INVALID_OPERATION if name starts with 'gl_ '");
100
101 var vs = loadShader(gl.VERTEX_SHADER, "vshader");
102 var fs = loadShader(gl.FRAGMENT_SHADER, "fshader");
103 gl.attachShader(program, vs);
104 gl.attachShader(program, fs);
105
106 var positions = gl.createBuffer();
107 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
108 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([ 0,0.5,0, -0.5,-0.5,0, 0.5,-0.5 ,0 ]), gl.STATIC_DRAW);
109
110 var colors = gl.createBuffer();
111 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
112 gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([
113 0,1,0,1,
114 0,1,0,1,
115 0,1,0,1]), gl.STATIC_DRAW);
116
117 function setBindLocations(colorLocation, positionLocation) {
118 gl.bindAttribLocation(program, positionLocation, "vPosition");
119 gl.bindAttribLocation(program, colorLocation, "vColor");
120 gl.linkProgram(program);
121 gl.useProgram(program);
122 var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
123 assertMsg(linked, "program linked successfully");
124
125 debug("vPosition:" + gl.getAttribLocation(program, "vPosition"))
126 debug("vColor :" + gl.getAttribLocation(program, "vColor"))
127 assertMsg(gl.getAttribLocation(program, "vPosition") == positionLocation,
128 "location of vPosition should be " + positionLocation);
129 assertMsg(gl.getAttribLocation(program, "vColor") == colorLocation,
130 "location of vColor should be " + colorLocation);
131
132 var ploc = gl.getAttribLocation(program, "vPosition");
133 var cloc = gl.getAttribLocation(program, "vColor");
134 gl.bindBuffer(gl.ARRAY_BUFFER, positions);
135 gl.enableVertexAttribArray(positionLocation);
136 gl.vertexAttribPointer(positionLocation, 3, gl.FLOAT, false, 0, 0);
137 gl.bindBuffer(gl.ARRAY_BUFFER, colors);
138 gl.enableVertexAttribArray(colorLocation);
139 gl.vertexAttribPointer(colorLocation, 4, gl.FLOAT, false, 0, 0);
140 }
141
142 function checkDraw(colorLocation, positionLocation, r, g, b, a) {
143 gl.clearColor(0, 0, 0, 1);
144 gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
145 gl.drawArrays(gl.TRIANGLES, 0, 3);
146
147 var width = 50;
148 var height = 50;
149 var buf = new Uint8Array(width * height * 4);
150 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, buf);
151
152 function checkPixel(x, y, r, g, b, a) {
153 var offset = (y * width + x) * 4;
154 if (buf[offset + 0] != r ||
155 buf[offset + 1] != g ||
156 buf[offset + 2] != b ||
157 buf[offset + 3] != a) {
158 fail(x, y, buf, "(" + r + "," + g + "," + b + "," + a + ")");
159 return false;
160 }
161 return true;
162 }
163
164 // Test several locations
165 // First line should be all black
166 var success = true;
167 for (var i = 0; i < 50; ++i)
168 success = success && checkPixel(i, 0, 0, 0, 0, 255);
169
170 // Line 15 should be red for at least 10 rgba pixels starting 20 pixels in
171 var offset = (15 * 50 + 20) * 4;
172 for (var i = 0; i < 10; ++i)
173 success = success && checkPixel(20 + i, 15, r, g, b, a);
174
175 // Last line should be all black
176 for (var i = 0; i < 50; ++i)
177 success = success && checkPixel(i, 49, 0, 0, 0, 255);
178
179 if (success)
180 pass();
181
182 gl.disableVertexAttribArray(positionLocation);
183 gl.disableVertexAttribArray(colorLocation);
184 }
185
186 setBindLocations(2, 3);
187 checkDraw(2, 3, 0, 255, 0, 255);
188
189 setBindLocations(0, 3);
190 gl.disableVertexAttribArray(0);
191 gl.vertexAttrib4f(0, 1, 0, 0, 1);
192 checkDraw(0, 3, 255, 0, 0, 255);
193
194 glErrorShouldBe(gl, gl.NO_ERROR);
195
196 debug("");
197 successfullyParsed = true;
198
199 </script>
200 <script src="../resources/js-test-post.js"></script>
201
202 </body>
203 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698