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.es3fRboStateQueryTests');
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 es3fRboStateQueryTests = functional.gles3.es3fRboStateQueryTests;
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;
41 * @this {es3fApiCase.ApiCase}
43 var checkRenderbufferComponentSize = function(r, g, b, a, d, s) {
44 var referenceSizes = [r, g, b, a, d, s];
46 gl.RENDERBUFFER_RED_SIZE,
47 gl.RENDERBUFFER_GREEN_SIZE,
48 gl.RENDERBUFFER_BLUE_SIZE,
49 gl.RENDERBUFFER_ALPHA_SIZE,
50 gl.RENDERBUFFER_DEPTH_SIZE,
51 gl.RENDERBUFFER_STENCIL_SIZE
54 for (var ndx = 0; ndx < referenceSizes.length; ++ndx) {
55 if (referenceSizes[ndx] == -1)
57 var value = /** @type {number} */ (gl.getRenderbufferParameter(gl.RENDERBUFFER, paramNames[ndx]));
59 this.check(value >= referenceSizes[ndx], 'Expected greater or equal to ' + referenceSizes[ndx] + ' got ' + value);
65 * @extends {es3fApiCase.ApiCase}
66 * @param {string} name
67 * @param {string} description
69 es3fRboStateQueryTests.RboSizeCase = function(name, description) {
70 es3fApiCase.ApiCase.call(this, name, description, gl);
73 setParentClass(es3fRboStateQueryTests.RboSizeCase, es3fApiCase.ApiCase);
75 es3fRboStateQueryTests.RboSizeCase.prototype.test = function() {
76 var rnd = new deRandom.Random(0xabcdef);
78 var renderbufferID = gl.createRenderbuffer();
79 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbufferID);
81 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_WIDTH, 0));
82 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_HEIGHT, 0));
84 var numIterations = 60;
85 for (var i = 0; i < numIterations; ++i) {
86 var w = rnd.getInt(0, 128);
87 var h = rnd.getInt(0, 128);
89 gl.renderbufferStorage(gl.RENDERBUFFER, gl.RGB8, w, h);
91 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_WIDTH, w));
92 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_HEIGHT, h));
94 gl.deleteRenderbuffer(renderbufferID);
99 * @extends {es3fApiCase.ApiCase}
100 * @param {string} name
101 * @param {string} description
103 es3fRboStateQueryTests.RboInternalFormatCase = function(name, description) {
104 es3fApiCase.ApiCase.call(this, name, description, gl);
107 setParentClass(es3fRboStateQueryTests.RboInternalFormatCase, es3fApiCase.ApiCase);
109 es3fRboStateQueryTests.RboInternalFormatCase.prototype.test = function() {
110 var renderbufferID = gl.createRenderbuffer();
111 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbufferID);
113 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_INTERNAL_FORMAT, gl.RGBA4));
115 var requiredColorformats = [
116 gl.R8, gl.RG8, gl.RGB8, gl.RGB565, gl.RGBA4, gl.RGB5_A1, gl.RGBA8, gl.RGB10_A2,
117 gl.RGB10_A2UI, gl.SRGB8_ALPHA8, gl.R8I, gl.R8UI, gl.R16I, gl.R16UI, gl.R32I, gl.R32UI,
118 gl.RG8I, gl.RG8UI, gl.RG16I, gl.RG16UI, gl.RG32I, gl.RG32UI, gl.RGBA8I, gl.RGBA8UI,
119 gl.RGBA16I, gl.RGBA16UI, gl.RGBA32I, gl.RGBA32UI
122 for (var ndx = 0; ndx < requiredColorformats.length; ++ndx) {
123 gl.renderbufferStorage(gl.RENDERBUFFER, requiredColorformats[ndx], 128, 128);
125 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_INTERNAL_FORMAT, requiredColorformats[ndx]));
127 gl.deleteRenderbuffer(renderbufferID);
132 * @extends {es3fApiCase.ApiCase}
133 * @param {string} name
134 * @param {string} description
136 es3fRboStateQueryTests.RboComponentSizeColorCase = function(name, description) {
137 es3fApiCase.ApiCase.call(this, name, description, gl);
140 setParentClass(es3fRboStateQueryTests.RboComponentSizeColorCase, es3fApiCase.ApiCase);
142 es3fRboStateQueryTests.RboComponentSizeColorCase.prototype.test = function() {
143 var renderbufferID = gl.createRenderbuffer();
144 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbufferID);
146 checkRenderbufferComponentSize.bind(this, 0, 0, 0, 0, 0, 0);
148 var requiredColorFormats = [
149 // format, r, g, b, a
151 [gl.RG8, 8, 8, 0, 0],
152 [gl.RGB8, 8, 8, 8, 0],
153 [gl.RGB565, 5, 6, 5, 0],
154 [gl.RGBA4, 4, 4, 4, 4],
155 [gl.RGB5_A1, 5, 5, 5, 1],
156 [gl.RGBA8, 8, 8, 8, 8],
157 [gl.RGB10_A2, 10, 10, 10, 2],
158 [gl.RGB10_A2UI, 10, 10, 10, 2],
159 [gl.SRGB8_ALPHA8, 8, 8, 8, 8],
160 [gl.R8I, 8, 0, 0, 0],
161 [gl.R8UI, 8, 0, 0, 0],
162 [gl.R16I, 16, 0, 0, 0],
163 [gl.R16UI, 16, 0, 0, 0],
164 [gl.R32I, 32, 0, 0, 0],
165 [gl.R32UI, 32, 0, 0, 0],
166 [gl.RG8I, 8, 8, 0, 0],
167 [gl.RG8UI, 8, 8, 0, 0],
168 [gl.RG16I, 16, 16, 0, 0],
169 [gl.RG16UI, 16, 16, 0, 0],
170 [gl.RG32I, 32, 32, 0, 0],
171 [gl.RG32UI, 32, 32, 0, 0],
172 [gl.RGBA8I, 8, 8, 8, 8],
173 [gl.RGBA8UI, 8, 8, 8, 8],
174 [gl.RGBA16I, 16, 16, 16, 16],
175 [gl.RGBA16UI, 16, 16, 16, 16],
176 [gl.RGBA32I, 32, 32, 32, 32],
177 [gl.RGBA32UI, 32, 32, 32, 32]
180 for (var ndx = 0; ndx < requiredColorFormats.length; ++ndx) {
181 gl.renderbufferStorage(gl.RENDERBUFFER, requiredColorFormats[ndx][0], 128, 128);
183 checkRenderbufferComponentSize.bind(this, requiredColorFormats[ndx][1], requiredColorFormats[ndx][2], requiredColorFormats[ndx][3], requiredColorFormats[ndx][4], -1, -1);
185 gl.deleteRenderbuffer(renderbufferID);
190 * @extends {es3fApiCase.ApiCase}
191 * @param {string} name
192 * @param {string} description
194 es3fRboStateQueryTests.RboComponentSizeDepthCase = function(name, description) {
195 es3fApiCase.ApiCase.call(this, name, description, gl);
198 setParentClass(es3fRboStateQueryTests.RboComponentSizeDepthCase, es3fApiCase.ApiCase);
200 es3fRboStateQueryTests.RboComponentSizeDepthCase.prototype.test = function() {
201 var renderbufferID = gl.createRenderbuffer();
202 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbufferID);
204 var requiredDepthFormats = [
205 // format, depth, stencil
206 [gl.DEPTH_COMPONENT16, 16, 0],
207 [gl.DEPTH_COMPONENT24, 24, 0],
208 [gl.DEPTH_COMPONENT32F, 32, 0],
209 [gl.DEPTH24_STENCIL8, 24, 8],
210 [gl.DEPTH32F_STENCIL8, 32, 8]
213 for (var ndx = 0; ndx < requiredDepthFormats.length; ++ndx) {
214 gl.renderbufferStorage(gl.RENDERBUFFER, requiredDepthFormats[ndx][0], 128, 128);
216 checkRenderbufferComponentSize.bind(this, -1, -1, -1, -1, requiredDepthFormats[ndx][1], requiredDepthFormats[ndx][2]);
219 // STENCIL_INDEX8 is required, in that case sBits >= 8
220 gl.renderbufferStorage(gl.RENDERBUFFER, gl.STENCIL_INDEX8, 128, 128);
222 var value = /** @type {number} */ (gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_STENCIL_SIZE));
223 this.check(value >= 8, 'Expected greater or equal to 8; got ' + value);
225 gl.deleteRenderbuffer(renderbufferID);
230 * @extends {es3fApiCase.ApiCase}
231 * @param {string} name
232 * @param {string} description
234 es3fRboStateQueryTests.RboSamplesCase = function(name, description) {
235 es3fApiCase.ApiCase.call(this, name, description, gl);
238 setParentClass(es3fRboStateQueryTests.RboSamplesCase, es3fApiCase.ApiCase);
240 es3fRboStateQueryTests.RboSamplesCase.prototype.test = function() {
241 var rnd = new deRandom.Random(0xabcdef);
243 var renderbufferID = gl.createRenderbuffer();
244 gl.bindRenderbuffer(gl.RENDERBUFFER, renderbufferID);
246 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_SAMPLES, 0));
248 var max_samples = /** @type {number} */ (gl.getParameter(gl.MAX_SAMPLES));
250 // 0 samples is a special case
251 gl.renderbufferStorageMultisample(gl.RENDERBUFFER, 0, gl.RGBA8, 128, 128);
253 this.check(glsStateQuery.verifyRenderbuffer(gl.RENDERBUFFER_SAMPLES, 0));
255 // test [1, n] samples
256 for (var samples = 1; samples <= max_samples; ++samples) {
257 gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples, gl.RGBA8, 128, 128);
258 var value = /** @type {number} */ (gl.getRenderbufferParameter(gl.RENDERBUFFER, gl.RENDERBUFFER_SAMPLES));
259 this.check(value >= samples, 'Expected greater or equal to ' + samples + ' got ' + value);
262 gl.deleteRenderbuffer(renderbufferID);
267 * @extends {tcuTestCase.DeqpTest}
269 es3fRboStateQueryTests.RboStateQueryTests = function() {
270 tcuTestCase.DeqpTest.call(this, 'rbo', 'Rbo State Query tests');
273 es3fRboStateQueryTests.RboStateQueryTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
274 es3fRboStateQueryTests.RboStateQueryTests.prototype.constructor = es3fRboStateQueryTests.RboStateQueryTests;
276 es3fRboStateQueryTests.RboStateQueryTests.prototype.init = function() {
277 this.addChild(new es3fRboStateQueryTests.RboSizeCase('renderbuffer_size', 'RENDERBUFFER_WIDTH and RENDERBUFFER_HEIGHT'));
278 this.addChild(new es3fRboStateQueryTests.RboInternalFormatCase('renderbuffer_internal_format', 'RENDERBUFFER_INTERNAL_FORMAT'));
279 this.addChild(new es3fRboStateQueryTests.RboComponentSizeColorCase('renderbuffer_component_size_color', 'RENDERBUFFER_x_SIZE'));
280 this.addChild(new es3fRboStateQueryTests.RboComponentSizeDepthCase('renderbuffer_component_size_depth', 'RENDERBUFFER_x_SIZE'));
281 this.addChild(new es3fRboStateQueryTests.RboSamplesCase('renderbuffer_samples', 'RENDERBUFFER_SAMPLES'));
286 * @param {WebGL2RenderingContext} context
288 es3fRboStateQueryTests.run = function(context) {
290 //Set up Test Root parameters
291 var state = tcuTestCase.runner;
292 state.setRoot(new es3fRboStateQueryTests.RboStateQueryTests());
294 //Set up name and description of this test series.
295 setCurrentTestName(state.testCases.fullName());
296 description(state.testCases.getDescription());
300 tcuTestCase.runTestCases();
303 testFailedOptions('Failed to es3fRboStateQueryTests.run tests', false);
304 tcuTestCase.runner.terminate();