summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/deqp/functional/gles3/es3fFragDepthTests.js
blob: 8a892a09267d06212838bfa9d2edac2c4dcf37f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
/*-------------------------------------------------------------------------
 * drawElements Quality Program OpenGL ES Utilities
 * ------------------------------------------------
 *
 * Copyright 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

'use strict';
goog.provide('functional.gles3.es3fFragDepthTests');
goog.require('framework.common.tcuImageCompare');
goog.require('framework.common.tcuRGBA');
goog.require('framework.common.tcuSurface');
goog.require('framework.common.tcuTestCase');
goog.require('framework.delibs.debase.deMath');
goog.require('framework.delibs.debase.deRandom');
goog.require('framework.delibs.debase.deString');
goog.require('framework.opengl.gluShaderProgram');
goog.require('framework.opengl.gluDrawUtil');
goog.require('modules.shared.glsShaderRenderCase');

goog.scope(function() {
	var es3fFragDepthTests = functional.gles3.es3fFragDepthTests;
	var deMath = framework.delibs.debase.deMath;
	var deRandom = framework.delibs.debase.deRandom;
	var deString = framework.delibs.debase.deString;
	var glsShaderRenderCase = modules.shared.glsShaderRenderCase;
	var gluShaderProgram = framework.opengl.gluShaderProgram;
	var gluDrawUtil = framework.opengl.gluDrawUtil;
	var tcuImageCompare = framework.common.tcuImageCompare;
	var tcuRGBA = framework.common.tcuRGBA;
	var tcuSurface = framework.common.tcuSurface;
	var tcuTestCase = framework.common.tcuTestCase;
	/** @typedef {function(Array<number>):number} */ es3fFragDepthTests.EvalFragDepthFunc;

	/** @const {string} */ es3fFragDepthTests.s_vertexShaderSrc = '' +
		'#version 300 es\n' +
		'in highp vec4 a_position;\n' +
		'in highp vec2 a_coord;\n' +
		'out highp vec2 v_coord;\n' +
		'void main (void)\n' +
		'{\n' +
		'	gl_Position = a_position;\n' +
		'	v_coord = a_coord;\n' +
		'}\n';

	/** @const {string} */ es3fFragDepthTests.s_defaultFragmentShaderSrc = '' +
		'#version 300 es\n' +
		'uniform highp vec4 u_color;\n' +
		'layout(location = 0) out mediump vec4 o_color;\n' +
		'void main (void)\n' +
		'{\n' +
		'	o_color = u_color;\n' +
		'}\n';

	/**
	 * @param {number} func
	 * @param {*} a
	 * @param {*} b
	 * @return {boolean}
	 */
	es3fFragDepthTests.compare = function(func, a, b)	{
		switch (func) {
			case gl.NEVER: return false;
			case gl.ALWAYS: return true;
			case gl.LESS: return a < b;
			case gl.LEQUAL: return a <= b;
			case gl.EQUAL: return a === b;
			case gl.NOTEQUAL: return a !== b;
			case gl.GEQUAL: return a >= b;
			case gl.GREATER: return a > b;
		}
		bufferedLogToConsole('Compare function not supported.');
		return false;
	};

	/**
	 * @constructor
	 * @extends {tcuTestCase.DeqpTest}
	 * @param {string} name
	 * @param {string} desc
	 * @param {string} fragSrc
	 * @param {?es3fFragDepthTests.EvalFragDepthFunc} evalFunc
	 * @param {number} compareFunc
	 */
	es3fFragDepthTests.FragDepthCompareCase = function(name, desc, fragSrc, evalFunc, compareFunc) {
		tcuTestCase.DeqpTest.call(this, name, desc);
		/** @type {string} */ this.m_fragSrc = fragSrc;
		/** @type {?es3fFragDepthTests.EvalFragDepthFunc} */ this.m_evalFunc = evalFunc;
		/** @type {number} */ this.m_compareFunc = compareFunc;
	};

	es3fFragDepthTests.FragDepthCompareCase.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
	es3fFragDepthTests.FragDepthCompareCase.prototype.constructor = es3fFragDepthTests.FragDepthCompareCase;

	/**
	 * @return {tcuTestCase.IterateResult}
	 */
	es3fFragDepthTests.FragDepthCompareCase.prototype.iterate = function() {
		/** @type {deRandom.Random} */ var rnd = new deRandom.Random(deString.deStringHash(this.name));
		/** @type {number} */ var viewportW = Math.min(128, gl.drawingBufferWidth);
		/** @type {number} */ var viewportH = Math.min(128, gl.drawingBufferHeight);
		/** @type {number} */ var viewportX = rnd.getInt(0, gl.drawingBufferWidth - viewportW);
		/** @type {number} */ var viewportY = rnd.getInt(0, gl.drawingBufferHeight - viewportH);
		/** @type {tcuSurface.Surface} */ var renderedFrame = new tcuSurface.Surface(viewportW, viewportH);
		/** @type {tcuSurface.Surface} */ var referenceFrame = new tcuSurface.Surface(viewportW, viewportH);
		/** @type {number} */ var constDepth = 0.1;
		var depthBits = /** @type {number} */ (gl.getParameter(gl.DEPTH_BITS));

		/** @type {number} */ var xf;
		/** @type {number} */ var d;
		/** @type {boolean} */ var dpass;

		if (depthBits == 0)
			throw new Error('Depth buffer is required');

		gl.depthMask(true);
		gl.viewport(viewportX, viewportY, viewportW, viewportH);
		gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
		gl.enable(gl.DEPTH_TEST);

		/** @type {Array<number>} */ var quadIndices = [0, 1, 2, 2, 1, 3];

		// Fill viewport with 2 quads - one with constant depth and another with d = [-1..1]
		/** @type {gluShaderProgram.ShaderProgram} */
		var basicQuadProgram = new gluShaderProgram.ShaderProgram(gl, gluShaderProgram.makeVtxFragSources(es3fFragDepthTests.s_vertexShaderSrc, es3fFragDepthTests.s_defaultFragmentShaderSrc));

		if (!basicQuadProgram.isOk()) {
			bufferedLogToConsole(basicQuadProgram.getProgramInfo().infoLog);
			throw new Error('Compile failed');
		}

		/** @type {Array<number>} */ var constDepthCoord = [
			 -1.0, -1.0, constDepth, 1.0,
			 -1.0, 1.0, constDepth, 1.0,
			 0.0, -1.0, constDepth, 1.0,
			 0.0, 1.0, constDepth, 1.0
		];

		/** @type {Array<number>} */ var varyingDepthCoord = [
			 0.0, -1.0, 1.0, 1.0,
			 0.0, 1.0, 0.0, 1.0,
			 1.0, -1.0, 0.0, 1.0,
			 1.0, 1.0, -1.0, 1.0
		];

		gl.useProgram(basicQuadProgram.getProgram());
		gl.uniform4f(gl.getUniformLocation(basicQuadProgram.getProgram(), 'u_color'), 0.0, 0.0, 1.0, 1.0);
		gl.depthFunc(gl.ALWAYS);

		/** @type {gluDrawUtil.VertexArrayBinding} */ var posBinding = gluDrawUtil.newFloatVertexArrayBinding('a_position', 4, 4, 0, constDepthCoord);
		gluDrawUtil.draw(gl, basicQuadProgram.getProgram(), [posBinding], gluDrawUtil.triangles(quadIndices));

		posBinding = gluDrawUtil.newFloatVertexArrayBinding('a_position', 4, 4, 0, varyingDepthCoord);
		gluDrawUtil.draw(gl, basicQuadProgram.getProgram(), [posBinding], gluDrawUtil.triangles(quadIndices));

		// Render with depth test.
		/** @type {gluShaderProgram.ShaderProgram} */
		var program = new gluShaderProgram.ShaderProgram(gl, gluShaderProgram.makeVtxFragSources(es3fFragDepthTests.s_vertexShaderSrc, this.m_fragSrc));
		bufferedLogToConsole(program.getProgramInfo().infoLog);

		if (!program.isOk())
			throw new Error('Compile failed');

		/** @type {Array<number>} */ var coord = [
			0.0, 0.0,
			0.0, 1.0,
			1.0, 0.0,
			1.0, 1.0
		];

		/** @type {Array<number>} */ var position = [
			-1.0, -1.0, 1.0, 1.0,
			-1.0, 1.0, 0.0, 1.0,
			1.0, -1.0, 0.0, 1.0,
			1.0, 1.0, -1.0, 1.0
		];

		gl.useProgram(program.getProgram());
		gl.depthFunc(this.m_compareFunc);
		gl.uniform4f(gl.getUniformLocation(program.getProgram(), 'u_color'), 0.0, 1.0, 0.0, 1.0);

		// Setup default helper uniforms.
		glsShaderRenderCase.setupDefaultUniforms(program.getProgram());

		/** @type {Array<gluDrawUtil.VertexArrayBinding>} */ var  vertexArrays = [
			gluDrawUtil.newFloatVertexArrayBinding('a_position', 4, 4, 0, position),
			gluDrawUtil.newFloatVertexArrayBinding('a_coord', 2, 4, 0, coord)
		];

		gluDrawUtil.draw(gl, program.getProgram(), vertexArrays, gluDrawUtil.triangles(quadIndices));

		renderedFrame.readViewport(gl, [viewportX, viewportY, viewportW, viewportH]);

		// Render reference.
		for (var y = 0; y < referenceFrame.getHeight(); y++) {
			/** @type {number} */ var yf = (y + 0.5) / referenceFrame.getHeight();
			/** @type {number} */ var half = deMath.clamp(Math.floor(referenceFrame.getWidth() * 0.5 + 0.5), 0, referenceFrame.getWidth());

			// Fill left half - comparison to constant 0.5
			for (var x = 0; x < half; x++) {
				xf = (x + 0.5) / referenceFrame.getWidth();
				d = this.m_evalFunc([xf, yf]);
				dpass = es3fFragDepthTests.compare(this.m_compareFunc, d, constDepth * 0.5 + 0.5);

				referenceFrame.setPixel(x, y, dpass ? tcuRGBA.RGBA.green.toIVec() : tcuRGBA.RGBA.blue.toIVec());
			}

			// Fill right half - comparison to interpolated depth
			for (var x = half; x < referenceFrame.getWidth(); x++) {
				xf = (x + 0.5) / referenceFrame.getWidth();
				/** @type {number} */ var xh = (x - half + 0.5) / (referenceFrame.getWidth() - half);
				/** @type {number} */ var rd = 1.0 - (xh + yf) * 0.5;
				d = this.m_evalFunc([xf, yf]);
				dpass = es3fFragDepthTests.compare(this.m_compareFunc, d, rd);

				referenceFrame.setPixel(x, y, dpass ? tcuRGBA.RGBA.green.toIVec() : tcuRGBA.RGBA.blue.toIVec());
			}
		}

		/** @type {boolean} */ var isOk = tcuImageCompare.fuzzyCompare('Result', 'Image comparison result', referenceFrame.getAccess(), renderedFrame.getAccess(), 0.05);

		if (!isOk)
			testFailedOptions('Fail', false);
		else
			testPassedOptions('Pass', true);

		return tcuTestCase.IterateResult.STOP;
	};

	/**
	 * @constructor
	 * @extends {tcuTestCase.DeqpTest}
	 * @param {string} name
	 * @param {string} desc
	 * @param {string} fragSrc
	 * @param {es3fFragDepthTests.EvalFragDepthFunc} evalFunc
	 */
	es3fFragDepthTests.FragDepthWriteCase = function(name, desc, fragSrc, evalFunc) {
		tcuTestCase.DeqpTest.call(this, name, desc);
		/** @type {string} */ this.m_fragSrc = fragSrc;
		/** @type {es3fFragDepthTests.EvalFragDepthFunc} */ this.m_evalFunc = evalFunc;
	};

	es3fFragDepthTests.FragDepthWriteCase.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
	es3fFragDepthTests.FragDepthWriteCase.prototype.constructor = es3fFragDepthTests.FragDepthWriteCase;

	/**
	 * @return {tcuTestCase.IterateResult}
	 */
	es3fFragDepthTests.FragDepthWriteCase.prototype.iterate = function() {
		/** @type {deRandom.Random} */ var rnd = new deRandom.Random(deString.deStringHash(this.name));
		/** @type {number} */ var viewportW = Math.min(128, gl.drawingBufferWidth);
		/** @type {number} */ var viewportH = Math.min(128, gl.drawingBufferHeight);
		/** @type {number} */ var viewportX = rnd.getInt(0, gl.drawingBufferWidth - viewportW);
		/** @type {number} */ var viewportY = rnd.getInt(0, gl.drawingBufferHeight - viewportH);
		/** @type {tcuSurface.Surface} */ var renderedFrame = new tcuSurface.Surface(viewportW, viewportH);
		/** @type {tcuSurface.Surface} */ var referenceFrame = new tcuSurface.Surface(viewportW, viewportH);
		/** @type {number} */ var numDepthSteps = 16;
		/** @type {number} */ var depthStep = 1.0 / (numDepthSteps - 1);
		var depthBits = /** @type {number} */ (gl.getParameter(gl.DEPTH_BITS));

		if (depthBits === 0)
			throw new Error('Depth buffer is required');

		gl.depthMask(true);
		gl.viewport(viewportX, viewportY, viewportW, viewportH);
		gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
		gl.enable(gl.DEPTH_TEST);
		gl.depthFunc(gl.LESS);

		/** @type {Array<number>} */ var quadIndices = [0, 1, 2, 2, 1, 3];

		// Render with given shader.
		/** @type {gluShaderProgram.ShaderProgram} */
		var program = new gluShaderProgram.ShaderProgram(gl, gluShaderProgram.makeVtxFragSources(es3fFragDepthTests.s_vertexShaderSrc, this.m_fragSrc));
		bufferedLogToConsole(program.getProgramInfo().infoLog);

		if (!program.isOk())
			throw new Error('Compile failed');

		/** @type {Array<number>} */ var coord = [
			0.0, 0.0,
			0.0, 1.0,
			1.0, 0.0,
			1.0, 1.0
		];

		/** @type {Array<number>} */ var position = [
			-1.0, -1.0, +1.0, 1.0,
			-1.0, 1.0, 0.0, 1.0,
			1.0, -1.0, 0.0, 1.0,
			1.0, 1.0, -1.0, 1.0
		];

		gl.useProgram(program.getProgram());
		gl.uniform4f(gl.getUniformLocation(program.getProgram(), 'u_color'), 0.0, 1.0, 0.0, 1.0);

		// Setup default helper uniforms.
		glsShaderRenderCase.setupDefaultUniforms(program.getProgram());

		/** @type {Array<gluDrawUtil.VertexArrayBinding>} */ var  vertexArrays = [
			gluDrawUtil.newFloatVertexArrayBinding('a_position', 4, 4, 0, position),
			gluDrawUtil.newFloatVertexArrayBinding('a_coord', 2, 4, 0, coord)
		];
		gluDrawUtil.draw(gl, program.getProgram(), vertexArrays, gluDrawUtil.triangles(quadIndices));

		// Visualize by rendering full-screen quads with increasing depth and color.
		program = new gluShaderProgram.ShaderProgram(gl, gluShaderProgram.makeVtxFragSources(es3fFragDepthTests.s_vertexShaderSrc, es3fFragDepthTests.s_defaultFragmentShaderSrc));

		if (!program.isOk()) {
			bufferedLogToConsole(program.getProgramInfo().infoLog);
			throw new Error('Compile failed');
		}

		/** @type {WebGLUniformLocation} */ var colorLoc = gl.getUniformLocation(program.getProgram(), 'u_color');

		gl.useProgram(program.getProgram());
		gl.depthMask(false);

		for (var stepNdx = 0; stepNdx < numDepthSteps; stepNdx++) {
			/** @type {number} */ var f = stepNdx * depthStep;
			/** @type {number} */ var depth = f * 2.0 - 1.0;
			/** @type {Array<number>} */ var color = [f, f, f, 1.0];

			position = [
				-1.0, -1.0, depth, 1.0,
				-1.0, 1.0, depth, 1.0,
				1.0, -1.0, depth, 1.0,
				1.0, 1.0, depth, 1.0
			];

			/** @type {gluDrawUtil.VertexArrayBinding} */
			var posBinding = gluDrawUtil.newFloatVertexArrayBinding('a_position', 4, 4, 0, position);

			gl.uniform4fv(colorLoc, color);
			gluDrawUtil.draw(gl, program.getProgram(), [posBinding], gluDrawUtil.triangles(quadIndices));
		}

		renderedFrame.readViewport(gl, [viewportX, viewportY, viewportW, viewportH]);

		// Render reference.
		for (var y = 0; y < referenceFrame.getHeight(); y++)
		for (var x = 0; x < referenceFrame.getWidth(); x++) {
			/** @type {number} */ var xf = (x + 0.5) / referenceFrame.getWidth();
			/** @type {number} */ var yf = (y + 0.5) / referenceFrame.getHeight();
			/** @type {number} */ var d = this.m_evalFunc([xf, yf]);
			/** @type {number} */ var step = Math.floor(d / depthStep);
			/** @type {number} */ var col = deMath.clamp(Math.floor(step * depthStep * 255.0), 0, 255);

			referenceFrame.setPixel(x, y, [col, col, col, 0xff]);
		}

		/** @type {boolean} */ var isOk = tcuImageCompare.fuzzyCompare('Result', 'Image comparison result', referenceFrame.getAccess(), renderedFrame.getAccess(), 0.05);

		if (!isOk)
			testFailedOptions('Fail', false);
		else
			testPassedOptions('Pass', true);

		return tcuTestCase.IterateResult.STOP;
	};


	/**
	 * @constructor
	 * @extends {tcuTestCase.DeqpTest}
	 */
	es3fFragDepthTests.FragDepthTests = function() {
		tcuTestCase.DeqpTest.call(this, 'fragdepth', 'gl_FragDepth tests');
	};

	es3fFragDepthTests.FragDepthTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
	es3fFragDepthTests.FragDepthTests.prototype.constructor = es3fFragDepthTests.FragDepthTests;

	/**
	 * @param {Array<number>} coord
	 * @return {number}
	 */
	es3fFragDepthTests.evalConstDepth = function(coord) {
		return 0.5;
	};

	/**
	 * @param {Array<number>} coord
	 * @return {number}
	 */
	es3fFragDepthTests.evalDynamicDepth = function(coord) {
		return (coord[0] + coord[1]) * 0.5;
	};

	/**
	 * @param {Array<number>} coord
	 * @return {number}
	 */
	es3fFragDepthTests.evalNoWrite = function(coord) {
		return 1.0 - (coord[0] + coord[1]) * 0.5;
	};

	/**
	 * @param {Array<number>} coord
	 * @return {number}
	 */
	es3fFragDepthTests.evalDynamicConditionalDepth = function(coord) {
		/** @type {number} */ var d = (coord[0] + coord[1]) * 0.5;
		if (coord[1] < 0.5)
			return d;
		else
			return 1.0 - d;
	};

	es3fFragDepthTests.FragDepthTests.prototype.init = function() {
		/**
		 * @struct
		 * @constructor
		 * @param {string} name
		 * @param {string} desc
		 * @param {es3fFragDepthTests.EvalFragDepthFunc} evalFunc
		 * @param {string} fragSrc
		 */
		var Case = function(name, desc, evalFunc, fragSrc) {
			/** @type {string} */ this.name = name;
			/** @type {string} */ this.desc = desc;
			/** @type {es3fFragDepthTests.EvalFragDepthFunc} */ this.evalFunc = evalFunc;
			/** @type {string} */ this.fragSrc = fragSrc;
		};

		/** @type {Array<Case>} */ var cases = [
			new Case('no_write', 'No gl_FragDepth write', es3fFragDepthTests.evalNoWrite,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'}\n'
			),
			new Case('const', 'Const depth write', es3fFragDepthTests.evalConstDepth,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	gl_FragDepth = 0.5;\n' +
				'}\n'
			),
			new Case('uniform', 'Uniform depth write', es3fFragDepthTests.evalConstDepth,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'uniform highp float uf_half;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	gl_FragDepth = uf_half;\n' +
				'}\n'
			),
			new Case('dynamic', 'Dynamic depth write', es3fFragDepthTests.evalDynamicDepth,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'in highp vec2 v_coord;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	gl_FragDepth = (v_coord.x+v_coord.y)*0.5;\n' +
				'}\n'
			),
			new Case('fragcoord_z', 'gl_FragDepth write from gl_FragCoord.z', es3fFragDepthTests.evalNoWrite,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	gl_FragDepth = gl_FragCoord.z;\n' +
				'}\n'
			),
			new Case('uniform_conditional_write', 'Uniform conditional write', es3fFragDepthTests.evalDynamicDepth,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'uniform bool ub_true;\n' +
				'in highp vec2 v_coord;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	if (ub_true)\n' +
				'		gl_FragDepth = (v_coord.x+v_coord.y)*0.5;\n' +
				'}\n'
			),
			new Case('dynamic_conditional_write', 'Uniform conditional write', es3fFragDepthTests.evalDynamicConditionalDepth,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'uniform bool ub_true;\n' +
				'in highp vec2 v_coord;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	mediump float d = (v_coord.x+v_coord.y)*0.5f;\n' +
				'	if (v_coord.y < 0.5)\n' +
				'		gl_FragDepth = d;\n' +
				'	else\n' +
				'		gl_FragDepth = 1.0 - d;\n' +
				'}\n'
			),
			new Case('uniform_loop_write', 'Uniform loop write', es3fFragDepthTests.evalConstDepth,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'uniform int ui_two;\n' +
				'uniform highp float uf_fourth;\n' +
				'in highp vec2 v_coord;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	gl_FragDepth = 0.0;\n' +
				'	for (int i = 0; i < ui_two; i++)\n' +
				'		gl_FragDepth += uf_fourth;\n' +
				'}\n'
			),
			new Case('write_in_function', 'Uniform loop write', es3fFragDepthTests.evalDynamicDepth,
				'#version 300 es\n' +
				'uniform highp vec4 u_color;\n' +
				'uniform highp float uf_half;\n' +
				'in highp vec2 v_coord;\n' +
				'layout(location = 0) out mediump vec4 o_color;\n' +
				'void myfunc (highp vec2 coord)\n' +
				'{\n' +
				'	gl_FragDepth = (coord.x+coord.y)*0.5;\n' +
				'}\n' +
				'void main (void)\n' +
				'{\n' +
				'	o_color = u_color;\n' +
				'	myfunc(v_coord);\n' +
				'}\n'
			)
		];

		var testGroup = tcuTestCase.runner.testCases;

		// .write
		/** @type {tcuTestCase.DeqpTest} */ var writeGroup = tcuTestCase.newTest('write', 'gl_FragDepth write tests');
		testGroup.addChild(writeGroup);
		for (var ndx = 0; ndx < cases.length; ndx++)
			writeGroup.addChild(new es3fFragDepthTests.FragDepthWriteCase(cases[ndx].name, cases[ndx].desc, cases[ndx].fragSrc, cases[ndx].evalFunc));

		// .compare
		/** @type {tcuTestCase.DeqpTest} */ var compareGroup = tcuTestCase.newTest('compare', 'gl_FragDepth used with depth comparison');
		testGroup.addChild(compareGroup);
		for (var ndx = 0; ndx < cases.length; ndx++)
			compareGroup.addChild(new es3fFragDepthTests.FragDepthCompareCase(cases[ndx].name, cases[ndx].desc, cases[ndx].fragSrc, cases[ndx].evalFunc, gl.LESS));
	};

    /**
    * Run test
    * @param {WebGL2RenderingContext} context
    */
    es3fFragDepthTests.run = function(context) {
    	gl = context;
    	//Set up Test Root parameters
    	var state = tcuTestCase.runner;
    	state.setRoot(new es3fFragDepthTests.FragDepthTests());

    	//Set up name and description of this test series.
    	setCurrentTestName(state.testCases.fullName());
    	description(state.testCases.getDescription());

    	try {
    		//Run test cases
    		tcuTestCase.runTestCases();
    	}
    	catch (err) {
    		testFailedOptions('Failed to es3fFragDepthTests.run tests', false);
    		tcuTestCase.runner.terminate();
    	}
    };

});