Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / deqp / functional / gles3 / es3fSamplerStateQueryTests.js
blob22cfde12aae0ab36c641a5d5ff1910b70cb3aad8
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.es3fSamplerStateQueryTests');
23 goog.require('framework.common.tcuTestCase');
24 goog.require('framework.delibs.debase.deRandom');
25 goog.require('functional.gles3.es3fApiCase');
26 goog.require('modules.shared.glsStateQuery');
28 goog.scope(function() {
29 var es3fSamplerStateQueryTests = functional.gles3.es3fSamplerStateQueryTests;
30 var tcuTestCase = framework.common.tcuTestCase;
31 var glsStateQuery = modules.shared.glsStateQuery;
32 var es3fApiCase = functional.gles3.es3fApiCase;
33 var deRandom = framework.delibs.debase.deRandom;
35 var setParentClass = function(child, parent) {
36     child.prototype = Object.create(parent.prototype);
37     child.prototype.constructor = child;
40 /**
41  * @constructor
42  * @extends {es3fApiCase.ApiCase}
43  * @param {string} name
44  * @param {string} description
45  */
46 es3fSamplerStateQueryTests.SamplerCase = function(name, description) {
47     es3fApiCase.ApiCase.call(this, name, description, gl);
48     /** @type {WebGLSampler} */ this.m_sampler;
51 setParentClass(es3fSamplerStateQueryTests.SamplerCase, es3fApiCase.ApiCase);
53 es3fSamplerStateQueryTests.SamplerCase.prototype.testSampler = function() {
54     throw new Error('Virtual function. Please override.');
57 es3fSamplerStateQueryTests.SamplerCase.prototype.test = function() {
58     this.m_sampler = gl.createSampler();
60     this.testSampler();
62     gl.deleteSampler(this.m_sampler);
65 /**
66  * @constructor
67  * @extends {es3fSamplerStateQueryTests.SamplerCase}
68  * @param {string} name
69  * @param {string} description
70  * @param {number} valueName
71  * @param {number} initialValue
72  * @param {Array<number>} valueRange
73  */
74 es3fSamplerStateQueryTests.SamplerModeCase = function(name, description, valueName, initialValue, valueRange) {
75     es3fSamplerStateQueryTests.SamplerCase.call(this, name, description);
76     this.m_valueName = valueName;
77     this.m_initialValue = initialValue;
78     this.m_valueRange = valueRange;
81 setParentClass(es3fSamplerStateQueryTests.SamplerModeCase, es3fSamplerStateQueryTests.SamplerCase);
83 es3fSamplerStateQueryTests.SamplerModeCase.prototype.testSampler = function() {
84     this.check(glsStateQuery.verifySampler(this.m_sampler, this.m_valueName, this.m_initialValue));
86     for (var ndx = 0; ndx < this.m_valueRange.length; ++ndx) {
87         gl.samplerParameteri(this.m_sampler, this.m_valueName, this.m_valueRange[ndx]);
89         this.check(glsStateQuery.verifySampler(this.m_sampler, this.m_valueName, this.m_valueRange[ndx]));
90     }
92     //check unit conversions with float
94     for (var ndx = 0; ndx < this.m_valueRange.length; ++ndx) {
95         gl.samplerParameterf(this.m_sampler, this.m_valueName, this.m_valueRange[ndx]);
97         this.check(glsStateQuery.verifySampler(this.m_sampler, this.m_valueName, this.m_valueRange[ndx]));
98     }
102  * @constructor
103  * @extends {es3fSamplerStateQueryTests.SamplerCase}
104  * @param {string} name
105  * @param {string} description
106  * @param {number} lodTarget
107  * @param {number} initialValue
108  */
109 es3fSamplerStateQueryTests.SamplerLODCase = function(name, description, lodTarget, initialValue) {
110     es3fSamplerStateQueryTests.SamplerCase.call(this, name, description);
111     this.m_lodTarget = lodTarget;
112     this.m_initialValue = initialValue;
115 setParentClass(es3fSamplerStateQueryTests.SamplerLODCase, es3fSamplerStateQueryTests.SamplerCase);
117 es3fSamplerStateQueryTests.SamplerLODCase.prototype.testSampler = function() {
118     var rnd = new deRandom.Random(0xabcdef);
120     this.check(glsStateQuery.verifySampler(this.m_sampler, this.m_lodTarget, this.m_initialValue));
121     var numIterations = 60;
122     for (var ndx = 0; ndx < numIterations; ++ndx) {
123         var ref = rnd.getFloat(-64000, 64000);
125         gl.samplerParameterf(this.m_sampler, this.m_lodTarget, ref);
127         this.check(glsStateQuery.verifySampler(this.m_sampler, this.m_lodTarget, ref));
128     }
130     // check unit conversions with int
132     for (var ndx = 0; ndx < numIterations; ++ndx) {
133         var ref = rnd.getInt(-64000, 64000);
135         gl.samplerParameteri(this.m_sampler, this.m_lodTarget, ref);
137         this.check(glsStateQuery.verifySampler(this.m_sampler, this.m_lodTarget, ref));
138     }
142 * @constructor
143 * @extends {tcuTestCase.DeqpTest}
145 es3fSamplerStateQueryTests.SamplerStateQueryTests = function() {
146     tcuTestCase.DeqpTest.call(this, 'sampler', 'Sampler State Query tests');
149 es3fSamplerStateQueryTests.SamplerStateQueryTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
150 es3fSamplerStateQueryTests.SamplerStateQueryTests.prototype.constructor = es3fSamplerStateQueryTests.SamplerStateQueryTests;
152 es3fSamplerStateQueryTests.SamplerStateQueryTests.prototype.init = function() {
153     var wrapValues = [gl.CLAMP_TO_EDGE, gl.REPEAT, gl.MIRRORED_REPEAT];
154     this.addChild(new es3fSamplerStateQueryTests.SamplerModeCase('sampler_texture_wrap_s' , 'TEXTURE_WRAP_S',
155         gl.TEXTURE_WRAP_S, gl.REPEAT, wrapValues));
156     this.addChild(new es3fSamplerStateQueryTests.SamplerModeCase('sampler_texture_wrap_t' , 'TEXTURE_WRAP_T',
157         gl.TEXTURE_WRAP_T, gl.REPEAT, wrapValues));
158     this.addChild(new es3fSamplerStateQueryTests.SamplerModeCase('sampler_texture_wrap_r' , 'TEXTURE_WRAP_R',
159         gl.TEXTURE_WRAP_R, gl.REPEAT, wrapValues));
161     var magValues = [gl.NEAREST, gl.LINEAR];
162     this.addChild(new es3fSamplerStateQueryTests.SamplerModeCase('sampler_texture_mag_filter' , 'TEXTURE_MAG_FILTER',
163         gl.TEXTURE_MAG_FILTER, gl.LINEAR, magValues));
165     var minValues = [gl.NEAREST, gl.LINEAR, gl.NEAREST_MIPMAP_NEAREST, gl.NEAREST_MIPMAP_LINEAR, gl.LINEAR_MIPMAP_NEAREST, gl.LINEAR_MIPMAP_LINEAR];
166     this.addChild(new es3fSamplerStateQueryTests.SamplerModeCase('sampler_texture_min_filter' , 'TEXTURE_MIN_FILTER',
167         gl.TEXTURE_MIN_FILTER, gl.NEAREST_MIPMAP_LINEAR, minValues));
169     this.addChild(new es3fSamplerStateQueryTests.SamplerLODCase('sampler_texture_min_lod' , 'TEXTURE_MIN_LOD', gl.TEXTURE_MIN_LOD, -1000));
170     this.addChild(new es3fSamplerStateQueryTests.SamplerLODCase('sampler_texture_max_lod' , 'TEXTURE_MAX_LOD', gl.TEXTURE_MAX_LOD, 1000));
172     var modes = [gl.COMPARE_REF_TO_TEXTURE, gl.NONE];
173     this.addChild(new es3fSamplerStateQueryTests.SamplerModeCase('sampler_texture_compare_mode' , 'TEXTURE_COMPARE_MODE',
174         gl.TEXTURE_COMPARE_MODE, gl.NONE, modes));
176     var compareFuncs = [gl.LEQUAL, gl.GEQUAL, gl.LESS, gl.GREATER, gl.EQUAL, gl.NOTEQUAL, gl.ALWAYS, gl.NEVER];
177     this.addChild(new es3fSamplerStateQueryTests.SamplerModeCase('sampler_texture_compare_func' , 'TEXTURE_COMPARE_FUNC',
178         gl.TEXTURE_COMPARE_FUNC, gl.LEQUAL, compareFuncs));
182 * Run test
183 * @param {WebGL2RenderingContext} context
185 es3fSamplerStateQueryTests.run = function(context) {
186     gl = context;
187     //Set up Test Root parameters
188     var state = tcuTestCase.runner;
189     state.setRoot(new es3fSamplerStateQueryTests.SamplerStateQueryTests());
191     //Set up name and description of this test series.
192     setCurrentTestName(state.testCases.fullName());
193     description(state.testCases.getDescription());
195     try {
196         //Run test cases
197         tcuTestCase.runTestCases();
198     }
199     catch (err) {
200         testFailedOptions('Failed to es3fSamplerStateQueryTests.run tests', false);
201         tcuTestCase.runner.terminate();
202     }