Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / deqp / functional / gles3 / es3fFloatStateQueryTests.js
blob6b5431061e0e733a6ffea57089b81c3c269dbab8
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL ES Utilities
3  * ------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the 'License');
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an 'AS IS' BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
21 'use strict';
22 goog.provide('functional.gles3.es3fFloatStateQueryTests');
23 goog.require('framework.common.tcuTestCase');
24 goog.require('framework.delibs.debase.deMath');
25 goog.require('framework.delibs.debase.deRandom');
26 goog.require('functional.gles3.es3fApiCase');
27 goog.require('modules.shared.glsStateQuery');
29 goog.scope(function() {
30         var es3fFloatStateQueryTests = functional.gles3.es3fFloatStateQueryTests;
31     var tcuTestCase = framework.common.tcuTestCase;
32         var deRandom = framework.delibs.debase.deRandom;
33         var deMath = framework.delibs.debase.deMath;
34         var es3fApiCase = functional.gles3.es3fApiCase;
35         var glsStateQuery = modules.shared.glsStateQuery;
37         /**
38          * @constructor
39          * @extends {es3fApiCase.ApiCase}
40          * @param {string} name
41          * @param {string} description
42          */
43         es3fFloatStateQueryTests.DepthRangeCase = function(name, description) {
44                 es3fApiCase.ApiCase.call(this, name, description, gl);
45         };
47         es3fFloatStateQueryTests.DepthRangeCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
48         es3fFloatStateQueryTests.DepthRangeCase.prototype.constructor = es3fFloatStateQueryTests.DepthRangeCase;
50         es3fFloatStateQueryTests.DepthRangeCase.prototype.test = function() {
51                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
53                 this.check(glsStateQuery.verify(gl.DEPTH_RANGE, new Float32Array([0.0, 1.0])));
55                 /** @type {Array<Float32Array>} */ var fixedTests = [
56                         new Float32Array([0.5, 1.0]),
57                         new Float32Array([0.0, 0.5]),
58                         new Float32Array([0.0, 0.0]),
59                         new Float32Array([1.0, 1.0])
60                 ];
62                 for (var ndx = 0; ndx < fixedTests.length; ++ndx) {
63                         gl.depthRange(fixedTests[ndx][0], fixedTests[ndx][1]);
64                         this.check(glsStateQuery.verify(gl.DEPTH_RANGE, fixedTests[ndx]));
65                 }
67                 /** @type {number} */ var numIterations = 120;
68                 for (var i = 0; i < numIterations; ++i) {
69                         // [dag] sorting to keep zNear < zFar
70                         /** @type {Array<number>} */ var values = [rnd.getFloat(0, 1), rnd.getFloat(0, 1)].sort();
71                         /** @type {Float32Array} */ var depth = new Float32Array(values);
72                         gl.depthRange(depth[0], depth[1]);
73                         this.check(glsStateQuery.verify(gl.DEPTH_RANGE, depth));
74                 }
75         };
77         /**
78          * @constructor
79          * @extends {es3fApiCase.ApiCase}
80          * @param {string} name
81          * @param {string} description
82          */
83         es3fFloatStateQueryTests.LineWidthCase = function(name, description) {
84                 es3fApiCase.ApiCase.call(this, name, description, gl);
85         };
87         es3fFloatStateQueryTests.LineWidthCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
88         es3fFloatStateQueryTests.LineWidthCase.prototype.constructor = es3fFloatStateQueryTests.LineWidthCase;
90         es3fFloatStateQueryTests.LineWidthCase.prototype.test = function() {
91                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
93                 this.check(glsStateQuery.verify(gl.LINE_WIDTH, 1.0));
95                 /** @type {Float32Array} */ var range = /** @type {Float32Array} */ (gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE));
97                 /** @type {number} */ var numIterations = 120;
98                 for (var i = 0; i < numIterations; ++i) {
99                         /** @type {number} */ var reference = rnd.getFloat(range[0], range[1]);
101                         gl.lineWidth(reference);
102                         this.check(glsStateQuery.verify(gl.LINE_WIDTH, reference));
103                 }
104         };
106         /**
107          * @constructor
108          * @extends {es3fApiCase.ApiCase}
109          * @param {string} name
110          * @param {string} description
111          */
112         es3fFloatStateQueryTests.PolygonOffsetFactorCase = function(name, description) {
113                 es3fApiCase.ApiCase.call(this, name, description, gl);
114         };
116         es3fFloatStateQueryTests.PolygonOffsetFactorCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
117         es3fFloatStateQueryTests.PolygonOffsetFactorCase.prototype.constructor = es3fFloatStateQueryTests.PolygonOffsetFactorCase;
119         es3fFloatStateQueryTests.PolygonOffsetFactorCase.prototype.test = function() {
120                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
122                 this.check(glsStateQuery.verify(gl.POLYGON_OFFSET_FACTOR, 0.0));
124                 /** @type {Array<number>} */ var fixedTests = [0.0, 0.5, -0.5, 1.5];
126                 for (var ndx = 0; ndx < fixedTests.length; ++ndx) {
127                         gl.polygonOffset(fixedTests[ndx], 0);
128                         this.check(glsStateQuery.verify(gl.POLYGON_OFFSET_FACTOR, fixedTests[ndx]));
129                 }
131                 /** @type {number} */ var numIterations = 120;
132                 for (var i = 0; i < numIterations; ++i) {
133                         /** @type {number} */ var reference = rnd.getFloat(-64000, 64000);
135                         gl.polygonOffset(reference, 0);
136                         this.check(glsStateQuery.verify(gl.POLYGON_OFFSET_FACTOR, reference));
137                 }
138         };
140         /**
141          * @constructor
142          * @extends {es3fApiCase.ApiCase}
143          * @param {string} name
144          * @param {string} description
145          */
146         es3fFloatStateQueryTests.PolygonOffsetUnitsCase = function(name, description) {
147                 es3fApiCase.ApiCase.call(this, name, description, gl);
148         };
150         es3fFloatStateQueryTests.PolygonOffsetUnitsCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
151         es3fFloatStateQueryTests.PolygonOffsetUnitsCase.prototype.constructor = es3fFloatStateQueryTests.PolygonOffsetUnitsCase;
153         es3fFloatStateQueryTests.PolygonOffsetUnitsCase.prototype.test = function() {
154                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
156                 this.check(glsStateQuery.verify(gl.POLYGON_OFFSET_UNITS, 0.0));
158                 /** @type {Array<number>} */ var fixedTests = [0.0, 0.5, -0.5, 1.5];
160                 for (var ndx = 0; ndx < fixedTests.length; ++ndx) {
161                         gl.polygonOffset(0, fixedTests[ndx]);
162                         this.check(glsStateQuery.verify(gl.POLYGON_OFFSET_UNITS, fixedTests[ndx]));
163                 }
165                 /** @type {number} */ var numIterations = 120;
166                 for (var i = 0; i < numIterations; ++i) {
167                         /** @type {number} */ var reference = rnd.getFloat(-64000, 64000);
169                         gl.polygonOffset(0, reference);
170                         this.check(glsStateQuery.verify(gl.POLYGON_OFFSET_UNITS, reference));
171                 }
172         };
174         /**
175          * @constructor
176          * @extends {es3fApiCase.ApiCase}
177          * @param {string} name
178          * @param {string} description
179          */
180         es3fFloatStateQueryTests.SampleCoverageCase = function(name, description) {
181                 es3fApiCase.ApiCase.call(this, name, description, gl);
182         };
184         es3fFloatStateQueryTests.SampleCoverageCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
185         es3fFloatStateQueryTests.SampleCoverageCase.prototype.constructor = es3fFloatStateQueryTests.SampleCoverageCase;
187         es3fFloatStateQueryTests.SampleCoverageCase.prototype.test = function() {
188                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
190                 this.check(glsStateQuery.verify(gl.SAMPLE_COVERAGE_VALUE, 1.0));
192                 /** @type {Array<number>} */ var fixedTests = [0.0, 0.5, 0.45, 0.55];
194                 for (var ndx = 0; ndx < fixedTests.length; ++ndx) {
195                         gl.sampleCoverage(fixedTests[ndx], false);
196                         this.check(glsStateQuery.verify(gl.SAMPLE_COVERAGE_VALUE, fixedTests[ndx]));
197                 }
199                 /** @type {Array<number>} */ var clampTests = [-1.0, -1.5, 1.45, 3.55];
201                 for (var ndx = 0; ndx < clampTests.length; ++ndx) {
202                         gl.sampleCoverage(clampTests[ndx], false);
203                         this.check(glsStateQuery.verify(gl.SAMPLE_COVERAGE_VALUE, deMath.clamp(clampTests[ndx], 0.0, 1.0)));
204                 }
206                 /** @type {number} */ var numIterations = 120;
207                 for (var i = 0; i < numIterations; ++i) {
208                         /** @type {number} */ var reference     = rnd.getFloat(0, 1);
209                         /** @type {boolean} */ var invert = rnd.getBool() ? true : false;
211                         gl.sampleCoverage(reference, invert);
212                         this.check(glsStateQuery.verify(gl.SAMPLE_COVERAGE_VALUE, reference));
213                 }
214         };
216         /**
217          * @constructor
218          * @extends {es3fApiCase.ApiCase}
219          * @param {string} name
220          * @param {string} description
221          */
222         es3fFloatStateQueryTests.BlendColorCase = function(name, description) {
223                 es3fApiCase.ApiCase.call(this, name, description, gl);
224         };
226         es3fFloatStateQueryTests.BlendColorCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
227         es3fFloatStateQueryTests.BlendColorCase.prototype.constructor = es3fFloatStateQueryTests.BlendColorCase;
229         es3fFloatStateQueryTests.BlendColorCase.prototype.test = function() {
230                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
232                 this.check(glsStateQuery.verify(gl.BLEND_COLOR, new Float32Array([0, 0, 0, 0])));
234                 /** @type {Array<Float32Array>} */ var fixedTests = [
235                         new Float32Array([0.5, 1.0, 0.5, 1.0]),
236                         new Float32Array([0.0, 0.5, 0.0, 0.5]),
237                         new Float32Array([0.0, 0.0, 0.0, 0.0]),
238                         new Float32Array([1.0, 1.0, 1.0, 1.0])
239                 ];
240                 for (var ndx = 0; ndx < fixedTests.length; ++ndx) {
241                         gl.blendColor(fixedTests[ndx][0], fixedTests[ndx][1], fixedTests[ndx][2], fixedTests[ndx][3]);
242                         this.check(glsStateQuery.verify(gl.BLEND_COLOR, fixedTests[ndx]));
243                 }
245                 /** @type {number} */ var numIterations = 120;
246                 for (var i = 0; i < numIterations; ++i) {
247                         /** @type {number} */ var r = rnd.getFloat(0, 1);
248                         /** @type {number} */ var g = rnd.getFloat(0, 1);
249                         /** @type {number} */ var b = rnd.getFloat(0, 1);
250                         /** @type {number} */ var a = rnd.getFloat(0, 1);
252                         gl.blendColor(r, g, b, a);
253                         this.check(glsStateQuery.verify(gl.BLEND_COLOR, new Float32Array([r, g, b, a])));
254                 }
255         };
257         /**
258          * @constructor
259          * @extends {es3fApiCase.ApiCase}
260          * @param {string} name
261          * @param {string} description
262          */
263         es3fFloatStateQueryTests.ColorClearCase = function(name, description) {
264                 es3fApiCase.ApiCase.call(this, name, description, gl);
265         };
267         es3fFloatStateQueryTests.ColorClearCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
268         es3fFloatStateQueryTests.ColorClearCase.prototype.constructor = es3fFloatStateQueryTests.ColorClearCase;
270         es3fFloatStateQueryTests.ColorClearCase.prototype.test = function() {
271                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
273                 // [dag] In the C++ dEQP code, initial color clear value check is temorarily removed. (until the framework does not alter it)
274                 this.check(glsStateQuery.verify(gl.COLOR_CLEAR_VALUE, new Float32Array([0, 0, 0, 0])));
276                 /** @type {Array<Float32Array>} */ var fixedTests = [
277                         new Float32Array([0.5, 1.0, 0.5, 1.0]),
278                         new Float32Array([0.0, 0.5, 0.0, 0.5]),
279                         new Float32Array([0.0, 0.0, 0.0, 0.0]),
280                         new Float32Array([1.0, 1.0, 1.0, 1.0])
281                 ];
282                 for (var ndx = 0; ndx < fixedTests.length; ++ndx) {
283                         gl.clearColor(fixedTests[ndx][0], fixedTests[ndx][1], fixedTests[ndx][2], fixedTests[ndx][3]);
284                         this.check(glsStateQuery.verify(gl.COLOR_CLEAR_VALUE, fixedTests[ndx]));
285                 }
287                 /** @type {number} */ var numIterations = 120;
288                 for (var i = 0; i < numIterations; ++i) {
289                         /** @type {number} */ var r = rnd.getFloat(0, 1);
290                         /** @type {number} */ var g = rnd.getFloat(0, 1);
291                         /** @type {number} */ var b = rnd.getFloat(0, 1);
292                         /** @type {number} */ var a = rnd.getFloat(0, 1);
294                         gl.clearColor(r, g, b, a);
295                         this.check(glsStateQuery.verify(gl.COLOR_CLEAR_VALUE, new Float32Array([r, g, b, a])));
296                 }
297         };
299         /**
300          * @constructor
301          * @extends {es3fApiCase.ApiCase}
302          * @param {string} name
303          * @param {string} description
304          */
305         es3fFloatStateQueryTests.DepthClearCase = function(name, description) {
306                 es3fApiCase.ApiCase.call(this, name, description, gl);
307         };
309         es3fFloatStateQueryTests.DepthClearCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
310         es3fFloatStateQueryTests.DepthClearCase.prototype.constructor = es3fFloatStateQueryTests.DepthClearCase;
312         es3fFloatStateQueryTests.DepthClearCase.prototype.test = function() {
313                 /** @type {deRandom.Random} */ var rnd = new deRandom.Random(0xabcdef);
315                 this.check(glsStateQuery.verify(gl.DEPTH_CLEAR_VALUE, 1));
317                 /** @type {number} */ var numIterations = 120;
318                 for (var i = 0; i < numIterations; ++i) {
319                         /** @type {number} */ var ref = rnd.getFloat(0, 1);
321                         gl.clearDepth(ref);
322                         this.check(glsStateQuery.verify(gl.DEPTH_CLEAR_VALUE, ref));
323                 }
324         };
326         /**
327          * @constructor
328          * @extends {es3fApiCase.ApiCase}
329          * @param {string} name
330          * @param {string} description
331          */
332         es3fFloatStateQueryTests.MaxTextureLODBiasCase = function(name, description) {
333                 es3fApiCase.ApiCase.call(this, name, description, gl);
334         };
336         es3fFloatStateQueryTests.MaxTextureLODBiasCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
337         es3fFloatStateQueryTests.MaxTextureLODBiasCase.prototype.constructor = es3fFloatStateQueryTests.MaxTextureLODBiasCase;
339         es3fFloatStateQueryTests.MaxTextureLODBiasCase.prototype.test = function() {
340                 this.check(glsStateQuery.verifyGreaterOrEqual(gl.MAX_TEXTURE_LOD_BIAS, 2.0));
341         };
343         /**
344          * @constructor
345          * @extends {es3fApiCase.ApiCase}
346          * @param {string} name
347          * @param {string} description
348          */
349         es3fFloatStateQueryTests.AliasedPointSizeRangeCase = function(name, description) {
350                 es3fApiCase.ApiCase.call(this, name, description, gl);
351         };
353         es3fFloatStateQueryTests.AliasedPointSizeRangeCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
354         es3fFloatStateQueryTests.AliasedPointSizeRangeCase.prototype.constructor = es3fFloatStateQueryTests.AliasedPointSizeRangeCase;
356         es3fFloatStateQueryTests.AliasedPointSizeRangeCase.prototype.test = function() {
357                 var pointSizeRange = /** @type {Float32Array} */ (gl.getParameter(gl.ALIASED_POINT_SIZE_RANGE));
358                 /** @type {Float32Array} */ var reference = new Float32Array([1, 1]);
359                 this.check(pointSizeRange[0] <= reference[0] && pointSizeRange[1] >= reference[1]);
360         };
362         /**
363          * @constructor
364          * @extends {es3fApiCase.ApiCase}
365          * @param {string} name
366          * @param {string} description
367          */
368         es3fFloatStateQueryTests.AliasedLineWidthRangeCase = function(name, description) {
369                 es3fApiCase.ApiCase.call(this, name, description, gl);
370         };
372         es3fFloatStateQueryTests.AliasedLineWidthRangeCase.prototype = Object.create(es3fApiCase.ApiCase.prototype);
373         es3fFloatStateQueryTests.AliasedLineWidthRangeCase.prototype.constructor = es3fFloatStateQueryTests.AliasedLineWidthRangeCase;
375         es3fFloatStateQueryTests.AliasedLineWidthRangeCase.prototype.test = function() {
376                 var lineWidthRange = /** @type {Float32Array} */ (gl.getParameter(gl.ALIASED_LINE_WIDTH_RANGE));
377                 /** @type {Float32Array} */ var reference = new Float32Array([1, 1]);
378                 this.check(lineWidthRange[0] <= reference[0] && lineWidthRange[1] >= reference[1]);
379         };
381     /**
382     * @constructor
383     * @extends {tcuTestCase.DeqpTest}
384     */
385     es3fFloatStateQueryTests.FloatStateQueryTests = function() {
386         tcuTestCase.DeqpTest.call(this, 'floats', 'Float Values');
387     };
389     es3fFloatStateQueryTests.FloatStateQueryTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
390     es3fFloatStateQueryTests.FloatStateQueryTests.prototype.constructor = es3fFloatStateQueryTests.FloatStateQueryTests;
392     es3fFloatStateQueryTests.FloatStateQueryTests.prototype.init = function() {
393                 this.addChild(new es3fFloatStateQueryTests.DepthRangeCase('depth_range', 'DEPTH_RANGE'));
394                 this.addChild(new es3fFloatStateQueryTests.LineWidthCase('line_width', 'LINE_WIDTH'));
395                 this.addChild(new es3fFloatStateQueryTests.PolygonOffsetFactorCase('polygon_offset_factor', 'POLYGON_OFFSET_FACTOR'));
396                 this.addChild(new es3fFloatStateQueryTests.PolygonOffsetUnitsCase('polygon_offset_units', 'POLYGON_OFFSET_UNITS'));
397                 this.addChild(new es3fFloatStateQueryTests.SampleCoverageCase('sample_coverage_value', 'SAMPLE_COVERAGE_VALUE'));
398                 this.addChild(new es3fFloatStateQueryTests.BlendColorCase('blend_color', 'BLEND_COLOR'));
399                 this.addChild(new es3fFloatStateQueryTests.ColorClearCase('color_clear_value', 'COLOR_CLEAR_VALUE'));
400                 this.addChild(new es3fFloatStateQueryTests.DepthClearCase('depth_clear_value', 'DEPTH_CLEAR_VALUE'));
401                 this.addChild(new es3fFloatStateQueryTests.MaxTextureLODBiasCase('max_texture_lod_bias', 'MAX_TEXTURE_LOD_BIAS'));
402                 this.addChild(new es3fFloatStateQueryTests.AliasedPointSizeRangeCase('aliased_point_size_range', 'ALIASED_POINT_SIZE_RANGE'));
403                 this.addChild(new es3fFloatStateQueryTests.AliasedLineWidthRangeCase('aliased_line_width_range', 'ALIASED_LINE_WIDTH_RANGE'));
405     };
407     /**
408     * Run test
409     * @param {WebGL2RenderingContext} context
410     */
411     es3fFloatStateQueryTests.run = function(context) {
412         gl = context;
413         //Set up Test Root parameters
414         var state = tcuTestCase.runner;
415         state.setRoot(new es3fFloatStateQueryTests.FloatStateQueryTests());
417         //Set up name and description of this test series.
418         setCurrentTestName(state.testCases.fullName());
419         description(state.testCases.getDescription());
421         try {
422                 //Run test cases
423                 tcuTestCase.runTestCases();
424         }
425         catch (err) {
426                 testFailedOptions('Failed to es3fFloatStateQueryTests.run tests', false);
427                 tcuTestCase.runner.terminate();
428         }
429     };