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

Side by Side Diff: conformance/resources/glsl-conformance-test.js

Issue 8342021: Add webgl conformance tests r15841. (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/webgl/sdk/tests/
Patch Set: Created 9 years, 2 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
« no previous file with comments | « conformance/resources/fragmentShader.frag ('k') | conformance/resources/glsl-feature-tests.css » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 GLSLConformanceTester = (function(){
2
3 var wtu = WebGLTestUtils;
4 var defaultVertexShader = [
5 "attribute vec4 vPosition;",
6 "void main()",
7 "{",
8 " gl_Position = vPosition;",
9 "}"
10 ].join('\n');
11
12 var defaultFragmentShader = [
13 "precision mediump float;",
14 "void main()",
15 "{",
16 " gl_FragColor = vec4(1.0,0.0,0.0,1.0);",
17 "}"
18 ].join('\n');
19
20 function log(msg) {
21 if (window.console && window.console.log) {
22 window.console.log(msg);
23 }
24 }
25
26 var vShaderDB = {};
27 var fShaderDB = {};
28
29 /**
30 * vShaderSource: the source code for vertex shader
31 * vShaderSuccess: true if vertex shader compiliation should
32 * succeed.
33 * fShaderSource: the source code for fragment shader
34 * fShaderSuccess: true if fragment shader compiliation should
35 * succeed.
36 * linkSuccess: true of link should succeed
37 * passMsg: msg to describe success condition.
38 *
39 */
40 function runOneTest(gl, info) {
41 var passMsg = info.passMsg
42 log(passMsg);
43
44 if (info.vShaderSource === undefined) {
45 if (info.vShaderId) {
46 info.vShaderSource = document.getElementById(info.vShaderId).text;
47 } else {
48 info.vShader = 'defaultVertexShader';
49 info.vShaderSource = defaultVertexShader;
50 }
51 }
52 if (info.fShaderSource === undefined) {
53 if (info.fShaderId) {
54 info.fShaderSource = document.getElementById(info.fShaderId).text;
55 } else {
56 info.fShader = 'defaultFragmentShader';
57 info.fShaderSource = defaultFragmentShader;
58 }
59 }
60
61 var vSource = info.vShaderPrep ? info.vShaderPrep(info.vShaderSource) :
62 info.vShaderSource;
63
64 // Reuse identical shaders so we test shared shader.
65 var vShader = vShaderDB[vSource];
66 if (!vShader) {
67 vShader = wtu.loadShader(gl, vSource, gl.VERTEX_SHADER);
68 if (info.vShaderTest) {
69 if (!info.vShaderTest(vShader)) {
70 testFailed("[vertex shader test] " + passMsg);
71 return;
72 }
73 }
74 if ((vShader != null) != info.vShaderSuccess) {
75 testFailed("[unexpected vertex shader compile status] (expected: " +
76 info.vShaderSuccess + ") " + passMsg);
77 return;
78 }
79 // Save the shaders so we test shared shader.
80 if (vShader) {
81 vShaderDB[vSource] = vShader;
82 }
83 }
84
85 var fSource = info.fShaderPrep ? info.fShaderPrep(info.fShaderSource) :
86 info.fShaderSource;
87
88 // Reuse identical shaders so we test shared shader.
89 var fShader = fShaderDB[fSource];
90 if (!fShader) {
91 fShader = wtu.loadShader(gl, fSource, gl.FRAGMENT_SHADER);
92 if (info.fShaderTest) {
93 if (!info.fShaderTest(fShader)) {
94 testFailed("[fragment shdaer test] " + passMsg);
95 return;
96 }
97 }
98 //debug(fShader == null ? "fail" : "succeed");
99 if ((fShader != null) != info.fShaderSuccess) {
100 testFailed("[unexpected fragment shader compile status] (expected: " +
101 info.fShaderSuccess + ") " + passMsg);
102 return;
103 }
104 // Safe the shaders so we test shared shader.
105 if (fShader) {
106 fShaderDB[fSource] = fShader;
107 }
108 }
109
110 if (vShader && fShader) {
111 var program = gl.createProgram();
112 gl.attachShader(program, vShader);
113 gl.attachShader(program, fShader);
114 gl.linkProgram(program);
115 var linked = (gl.getProgramParameter(program, gl.LINK_STATUS) != 0);
116 if (!linked) {
117 var error = gl.getProgramInfoLog(program);
118 log("*** Error linking program '"+program+"':"+error);
119 }
120 if (linked != info.linkSuccess) {
121 testFailed("[unexpected link status] " + passMsg);
122 return;
123 }
124 } else {
125 if (info.linkSuccess) {
126 testFailed("[link failed] " + passMsg);
127 return;
128 }
129 }
130 testPassed(passMsg);
131 }
132
133 function runTests(shaderInfos) {
134 var wtu = WebGLTestUtils;
135 var canvas = document.createElement('canvas');
136 var gl = wtu.create3DContext();
137 if (!gl) {
138 testFailed("context does not exist");
139 finishTest();
140 return;
141 }
142
143 for (var ii = 0; ii < shaderInfos.length; ++ii) {
144 runOneTest(gl, shaderInfos[ii]);
145 }
146
147 finishTest();
148 };
149
150 function loadExternalShaders(filename, passMsg) {
151 var shaderInfos = [];
152 var lines = wtu.readFileList(filename);
153 for (var ii = 0; ii < lines.length; ++ii) {
154 var info = {
155 vShaderSource: defaultVertexShader,
156 vShaderSuccess: true,
157 fShaderSource: defaultFragmentShader,
158 fShaderSuccess: true,
159 linkSuccess: true,
160 };
161
162 var line = lines[ii];
163 var files = line.split(/ +/);
164 var passMsg = "";
165 for (var jj = 0; jj < files.length; ++jj) {
166 var file = files[jj];
167 var shaderSource = wtu.readFile(file);
168 var firstLine = shaderSource.split("\n")[0];
169 var success = undefined;
170 if (firstLine.indexOf("fail") >= 0) {
171 success = false;
172 } else if (firstLine.indexOf("succeed") >= 0) {
173 success = true;
174 }
175 if (success === undefined) {
176 testFailed("bad first line in " + file + ":" + firstLine);
177 continue;
178 }
179 if (!wtu.startsWith(firstLine, "// ")) {
180 testFailed("bad first line in " + file + ":" + firstLine);
181 continue;
182 }
183 passMsg = passMsg + (passMsg.length ? ", " : "") + firstLine.substr(3);
184 if (wtu.endsWith(file, ".vert")) {
185 info.vShaderSource = shaderSource;
186 info.vShaderSuccess = success;
187 } else if (wtu.endsWith(file, ".frag")) {
188 info.fShaderSource = shaderSource;
189 info.fShaderSuccess = success;
190 }
191 }
192 info.linkSuccess = info.vShaderSuccess && info.fShaderSuccess;
193 info.passMsg = passMsg;
194 shaderInfos.push(info);
195 }
196 return shaderInfos;
197 }
198
199 function getSource(elem) {
200 var str = elem.text;
201 return str.replace(/^\s*/, '').replace(/\s*$/, '');
202 }
203
204 function getPassMessage(source) {
205 var lines = source.split('\n');
206 return lines[0].substring(3);
207 }
208
209 function getSuccess(msg) {
210 if (msg.indexOf("fail") >= 0) {
211 return false;
212 }
213 if (msg.indexOf("succeed") >= 0) {
214 return true;
215 }
216 testFailed("bad test description. Must have 'fail' or 'success'");
217 }
218
219 function runTest() {
220 var vShaderElem = document.getElementById('vertexShader');
221 var vShaderSource = defaultVertexShader;
222 var vShaderSuccess = true;
223
224 var fShaderElem = document.getElementById('fragmentShader');
225 var fShaderSource = defaultFragmentShader;
226 var fShaderSuccess = true;
227
228 var passMsg = undefined;
229
230 if (vShaderElem) {
231 vShaderSource = getSource(vShaderElem);
232 passMsg = getPassMessage(vShaderSource);
233 vShaderSuccess = getSuccess(passMsg);
234 }
235
236 if (fShaderElem) {
237 fShaderSource = getSource(fShaderElem);
238 passMsg = getPassMessage(fShaderSource);
239 fShaderSuccess = getSuccess(passMsg);
240 }
241
242 var linkSuccess = vShaderSuccess && fShaderSuccess;
243
244 if (passMsg === undefined) {
245 testFailed("no test shader found.");
246 finishTest();
247 return;
248 }
249
250 var info = {
251 vShaderSource: vShaderSource,
252 vShaderSuccess: vShaderSuccess,
253 fShaderSource: fShaderSource,
254 fShaderSuccess: fShaderSuccess,
255 linkSuccess: linkSuccess,
256 passMsg: passMsg
257 };
258 description(passMsg);
259 runTests([info]);
260 }
261
262 return {
263 runTest: runTest,
264 runTests: runTests,
265 loadExternalShaders: loadExternalShaders,
266
267 none: false,
268 };
269 }());
OLDNEW
« no previous file with comments | « conformance/resources/fragmentShader.frag ('k') | conformance/resources/glsl-feature-tests.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698