1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL ES Utilities
3 * ------------------------------------------------
5 * Copyright 2014 The Android Open Source Project
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 goog.provide('functional.gles3.es3fBooleanStateQuery');
23 goog.require('framework.common.tcuTestCase');
24 goog.require('functional.gles3.es3fApiCase');
25 goog.require('modules.shared.glsStateQuery');
27 goog.scope(function() {
28 var es3fBooleanStateQuery = functional.gles3.es3fBooleanStateQuery;
29 var tcuTestCase = framework.common.tcuTestCase;
30 var glsStateQuery = modules.shared.glsStateQuery;
31 var es3fApiCase = functional.gles3.es3fApiCase;
33 var setParentClass = function(child, parent) {
34 child.prototype = Object.create(parent.prototype);
35 child.prototype.constructor = child;
40 * @extends {es3fApiCase.ApiCase}
41 * @param {string} name
42 * @param {string} description
43 * @param {number} targetName
44 * @param {boolean} value
46 es3fBooleanStateQuery.IsEnabledStateTestCase = function(name, description, targetName, value) {
47 es3fApiCase.ApiCase.call(this, name, description, gl);
48 this.m_targetName = targetName;
49 this.m_initial = value;
52 setParentClass(es3fBooleanStateQuery.IsEnabledStateTestCase, es3fApiCase.ApiCase);
54 es3fBooleanStateQuery.IsEnabledStateTestCase.prototype.test = function() {
56 this.m_pass &= glsStateQuery.verify(this.m_targetName, this.m_initial);
60 gl.enable(this.m_targetName);
62 this.m_pass &= glsStateQuery.verify(this.m_targetName, true);
64 gl.disable(this.m_targetName);
66 this.m_pass &= glsStateQuery.verify(this.m_targetName, false);
71 * @extends {es3fApiCase.ApiCase}
72 * @param {string} name
73 * @param {string} description
75 es3fBooleanStateQuery.DepthWriteMaskTestCase = function(name, description) {
76 es3fApiCase.ApiCase.call(this, name, description, gl);
79 setParentClass(es3fBooleanStateQuery.DepthWriteMaskTestCase, es3fApiCase.ApiCase);
81 es3fBooleanStateQuery.DepthWriteMaskTestCase.prototype.test = function() {
82 this.m_pass &= glsStateQuery.verify(gl.DEPTH_WRITEMASK, true);
85 this.m_pass &= glsStateQuery.verify(gl.DEPTH_WRITEMASK, false);
88 this.m_pass &= glsStateQuery.verify(gl.DEPTH_WRITEMASK, true);
93 * @extends {es3fApiCase.ApiCase}
94 * @param {string} name
95 * @param {string} description
97 es3fBooleanStateQuery.SampleCoverageInvertTestCase = function(name, description) {
98 es3fApiCase.ApiCase.call(this, name, description, gl);
101 setParentClass(es3fBooleanStateQuery.SampleCoverageInvertTestCase, es3fApiCase.ApiCase);
103 es3fBooleanStateQuery.SampleCoverageInvertTestCase.prototype.test = function() {
104 this.m_pass &= glsStateQuery.verify(gl.SAMPLE_COVERAGE_INVERT, false);
106 gl.sampleCoverage(1, true);
107 this.m_pass &= glsStateQuery.verify(gl.SAMPLE_COVERAGE_INVERT, true);
109 gl.sampleCoverage(1, false);
110 this.m_pass &= glsStateQuery.verify(gl.SAMPLE_COVERAGE_INVERT, false);
115 * @extends {es3fApiCase.ApiCase}
116 * @param {string} name
117 * @param {string} description
118 * @param {number} targetName
119 * @param {boolean} value
121 es3fBooleanStateQuery.InitialBooleanTestCase = function(name, description, targetName, value) {
122 es3fApiCase.ApiCase.call(this, name, description, gl);
123 this.m_targetName = targetName;
124 this.m_initial = value;
127 setParentClass(es3fBooleanStateQuery.InitialBooleanTestCase, es3fApiCase.ApiCase);
129 es3fBooleanStateQuery.InitialBooleanTestCase.prototype.test = function() {
130 // check inital value
131 this.m_pass &= glsStateQuery.verify(this.m_targetName, this.m_initial);
136 * @extends {es3fApiCase.ApiCase}
137 * @param {string} name
138 * @param {string} description
140 es3fBooleanStateQuery.ColorMaskTestCase = function(name, description) {
141 es3fApiCase.ApiCase.call(this, name, description, gl);
144 setParentClass(es3fBooleanStateQuery.ColorMaskTestCase, es3fApiCase.ApiCase);
146 es3fBooleanStateQuery.ColorMaskTestCase.prototype.test = function() {
147 this.m_pass &= glsStateQuery.verify(gl.COLOR_WRITEMASK, [true, true, true, true]);
150 [true, true, true, true],
151 [true, true, true, false],
152 [true, true, false, true],
153 [true, true, false, false],
154 [true, false, true, true],
155 [true, false, true, false],
156 [true, false, false, true],
157 [true, false, false, false],
158 [false, true, true, true],
159 [false, true, true, false],
160 [false, true, false, true],
161 [false, true, false, false],
162 [false, false, true, true],
163 [false, false, true, false],
164 [false, false, false, true],
165 [false, false, false, false]
168 for (var ndx = 0; ndx < testMasks.length; ndx++) {
169 var mask = testMasks[ndx];
170 gl.colorMask(mask[0], mask[1], mask[2], mask[3]);
171 this.m_pass &= glsStateQuery.verify(gl.COLOR_WRITEMASK, mask);
177 * @extends {es3fApiCase.ApiCase}
178 * @param {string} name
179 * @param {string} description
181 es3fBooleanStateQuery.TransformFeedbackTestCase = function(name, description) {
182 es3fApiCase.ApiCase.call(this, name, description, gl);
183 /** @type {WebGLTransformFeedback} */ this.m_transformfeedback = null;
186 setParentClass(es3fBooleanStateQuery.TransformFeedbackTestCase, es3fApiCase.ApiCase);
188 es3fBooleanStateQuery.TransformFeedbackTestCase.prototype.testTransformFeedback = function() {
189 throw new Error('Virtual function.');
192 es3fBooleanStateQuery.TransformFeedbackTestCase.prototype.test = function() {
193 var transformFeedbackTestVertSource = '#version 300 es\n' +
194 'void main (void)\n' +
196 ' gl_Position = vec4(0.0);\n' +
198 var transformFeedbackTestFragSource = '#version 300 es\n' +
199 'layout(location = 0) out mediump vec4 fragColor;' +
200 'void main (void)\n' +
202 ' fragColor = vec4(0.0);\n' +
205 this.m_transformfeedback = gl.createTransformFeedback();
207 var shaderVert = gl.createShader(gl.VERTEX_SHADER);
208 gl.shaderSource(shaderVert, transformFeedbackTestVertSource);
209 gl.compileShader(shaderVert);
210 this.m_pass &= glsStateQuery.verifyShader(shaderVert, gl.COMPILE_STATUS, true);
212 var shaderFrag = gl.createShader(gl.FRAGMENT_SHADER);
213 gl.shaderSource(shaderFrag, transformFeedbackTestFragSource);
214 gl.compileShader(shaderFrag);
215 this.m_pass &= glsStateQuery.verifyShader(shaderFrag, gl.COMPILE_STATUS, true);
217 var shaderProg = gl.createProgram();
218 gl.attachShader(shaderProg, shaderVert);
219 gl.attachShader(shaderProg, shaderFrag);
220 var transform_feedback_outputs = ['gl_Position'];
221 gl.transformFeedbackVaryings(shaderProg, transform_feedback_outputs, gl.INTERLEAVED_ATTRIBS);
222 gl.linkProgram(shaderProg);
223 this.m_pass &= glsStateQuery.verifyProgram(shaderProg, gl.LINK_STATUS, true);
225 gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, this.m_transformfeedback);
227 var buffer = gl.createBuffer();
228 gl.bindBuffer(gl.TRANSFORM_FEEDBACK_BUFFER, buffer);
229 gl.bufferData(gl.TRANSFORM_FEEDBACK_BUFFER, 16, gl.DYNAMIC_READ);
230 gl.bindBufferBase(gl.TRANSFORM_FEEDBACK_BUFFER, 0, buffer);
232 gl.useProgram(shaderProg);
234 this.testTransformFeedback();
237 gl.bindTransformFeedback(gl.TRANSFORM_FEEDBACK, null);
238 gl.deleteTransformFeedback(this.m_transformfeedback);
239 gl.deleteBuffer(buffer);
240 gl.deleteShader(shaderVert);
241 gl.deleteShader(shaderFrag);
242 gl.deleteProgram(shaderProg);
247 * @extends {es3fBooleanStateQuery.TransformFeedbackTestCase}
248 * @param {string} name
250 es3fBooleanStateQuery.TransformFeedbackBasicTestCase = function(name) {
251 es3fBooleanStateQuery.TransformFeedbackTestCase.call(this, name, 'Test TRANSFORM_FEEDBACK_ACTIVE and TRANSFORM_FEEDBACK_PAUSED');
254 setParentClass(es3fBooleanStateQuery.TransformFeedbackBasicTestCase, es3fBooleanStateQuery.TransformFeedbackTestCase);
256 es3fBooleanStateQuery.TransformFeedbackBasicTestCase.prototype.testTransformFeedback = function() {
257 gl.beginTransformFeedback(gl.POINTS);
259 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_ACTIVE, true);
260 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_PAUSED, false);
262 gl.pauseTransformFeedback();
264 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_ACTIVE, true);
265 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_PAUSED, true);
267 gl.resumeTransformFeedback();
269 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_ACTIVE, true);
270 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_PAUSED, false);
272 gl.endTransformFeedback();
274 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_ACTIVE, false);
275 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_PAUSED, false);
280 * @extends {es3fBooleanStateQuery.TransformFeedbackTestCase}
281 * @param {string} name
283 es3fBooleanStateQuery.TransformFeedbackImplicitResumeTestCase = function(name) {
284 es3fBooleanStateQuery.TransformFeedbackTestCase.call(this, name, 'EndTransformFeedback performs an implicit ResumeTransformFeedback.');
287 setParentClass(es3fBooleanStateQuery.TransformFeedbackImplicitResumeTestCase, es3fBooleanStateQuery.TransformFeedbackTestCase);
289 es3fBooleanStateQuery.TransformFeedbackImplicitResumeTestCase.prototype.testTransformFeedback = function() {
290 gl.beginTransformFeedback(gl.POINTS);
292 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_ACTIVE, true);
293 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_PAUSED, false);
295 gl.pauseTransformFeedback();
297 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_ACTIVE, true);
298 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_PAUSED, true);
300 gl.endTransformFeedback();
302 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_ACTIVE, false);
303 this.m_pass &= glsStateQuery.verify(gl.TRANSFORM_FEEDBACK_PAUSED, false);
308 * @extends {tcuTestCase.DeqpTest}
310 es3fBooleanStateQuery.BooleanStateQuery = function() {
311 tcuTestCase.DeqpTest.call(this, 'boolean', 'Boolean State Query tests');
314 es3fBooleanStateQuery.BooleanStateQuery.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
315 es3fBooleanStateQuery.BooleanStateQuery.prototype.constructor = es3fBooleanStateQuery.BooleanStateQuery;
317 es3fBooleanStateQuery.BooleanStateQuery.prototype.init = function() {
320 ['rasterizer_discard', 'RASTERIZER_DISCARD', gl.RASTERIZER_DISCARD, false],
321 ['cull_face', 'CULL_FACE', gl.CULL_FACE, false],
322 ['polygon_offset_fill', 'POLYGON_OFFSET_FILL', gl.POLYGON_OFFSET_FILL, false],
323 ['sample_alpha_to_coverage', 'SAMPLE_ALPHA_TO_COVERAGE', gl.SAMPLE_ALPHA_TO_COVERAGE, false],
324 ['sample_coverage', 'SAMPLE_COVERAGE', gl.SAMPLE_COVERAGE, false],
325 ['scissor_test', 'SCISSOR_TEST', gl.SCISSOR_TEST, false],
326 ['stencil_test', 'STENCIL_TEST', gl.STENCIL_TEST, false],
327 ['depth_test', 'DEPTH_TEST', gl.DEPTH_TEST, false],
328 ['blend', 'BLEND', gl.BLEND, false],
329 ['dither', 'DITHER', gl.DITHER, true]
331 isEnableds.forEach(function(elem) {
333 var description = elem[1];
334 var targetName = elem[2];
336 testRoot.addChild(new es3fBooleanStateQuery.IsEnabledStateTestCase(name, description, targetName, value));
339 testRoot.addChild(new es3fBooleanStateQuery.ColorMaskTestCase('color_writemask', 'COLOR_WRITEMASK'));
340 testRoot.addChild(new es3fBooleanStateQuery.DepthWriteMaskTestCase('depth_writemask', 'DEPTH_WRITEMASK'));
341 testRoot.addChild(new es3fBooleanStateQuery.SampleCoverageInvertTestCase('sample_coverage_invert', 'SAMPLE_COVERAGE_INVERT'));
342 testRoot.addChild(new es3fBooleanStateQuery.InitialBooleanTestCase('transform_feedback_active_initial', 'initial TRANSFORM_FEEDBACK_ACTIVE', gl.TRANSFORM_FEEDBACK_ACTIVE, false));
343 testRoot.addChild(new es3fBooleanStateQuery.InitialBooleanTestCase('transform_feedback_paused_initial', 'initial TRANSFORM_FEEDBACK_PAUSED', gl.TRANSFORM_FEEDBACK_PAUSED, false));
344 testRoot.addChild(new es3fBooleanStateQuery.TransformFeedbackBasicTestCase('transform_feedback'));
345 testRoot.addChild(new es3fBooleanStateQuery.TransformFeedbackImplicitResumeTestCase('transform_feedback_implicit_resume'));
350 * @param {WebGL2RenderingContext} context
352 es3fBooleanStateQuery.run = function(context) {
354 //Set up Test Root parameters
355 var state = tcuTestCase.runner;
356 state.setRoot(new es3fBooleanStateQuery.BooleanStateQuery());
358 //Set up name and description of this test series.
359 setCurrentTestName(state.testCases.fullName());
360 description(state.testCases.getDescription());
364 tcuTestCase.runTestCases();
367 testFailedOptions('Failed to es3fBooleanStateQuery.run tests', false);
368 tcuTestCase.runner.terminate();