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.es3fBufferObjectQueryTests');
23 goog.require('framework.common.tcuTestCase');
24 goog.require('framework.delibs.debase.deRandom');
25 goog.require('functional.gles3.es3fApiCase');
27 goog.scope(function() {
28 var es3fBufferObjectQueryTests = functional.gles3.es3fBufferObjectQueryTests;
29 var tcuTestCase = framework.common.tcuTestCase;
30 var es3fApiCase = functional.gles3.es3fApiCase;
31 var deRandom = framework.delibs.debase.deRandom;
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
44 es3fBufferObjectQueryTests.BufferCase = function(name, description) {
45 es3fApiCase.ApiCase.call(this, name, description, gl);
48 setParentClass(es3fBufferObjectQueryTests.BufferCase, es3fApiCase.ApiCase);
50 es3fBufferObjectQueryTests.BufferCase.prototype.test = function() {
52 gl.ARRAY_BUFFER, gl.COPY_READ_BUFFER,
53 gl.TRANSFORM_FEEDBACK_BUFFER, gl.UNIFORM_BUFFER,
55 gl.COPY_WRITE_BUFFER, gl.ELEMENT_ARRAY_BUFFER,
56 gl.PIXEL_PACK_BUFFER, gl.PIXEL_UNPACK_BUFFER
59 // most test need only to be run with a subset of targets
60 var targets = this.m_testAllTargets ? bufferTargets.length : 4;
62 for (var ndx = 0; ndx < targets; ++ndx) {
63 this.m_bufferTarget = bufferTargets[ndx];
65 var bufferId = gl.createBuffer();
66 gl.bindBuffer(this.m_bufferTarget, bufferId);
70 gl.bindBuffer(this.m_bufferTarget, null);
71 gl.deleteBuffer(bufferId);
77 * @extends {es3fBufferObjectQueryTests.BufferCase}
78 * @param {string} name
79 * @param {string} description
81 es3fBufferObjectQueryTests.BufferSizeCase = function(name, description) {
82 es3fBufferObjectQueryTests.BufferCase.call(this, name, description);
83 this.m_testAllTargets = true;
86 setParentClass(es3fBufferObjectQueryTests.BufferSizeCase, es3fBufferObjectQueryTests.BufferCase);
88 es3fBufferObjectQueryTests.BufferSizeCase.prototype.testBuffer = function() {
89 var rnd = new deRandom.Random(0xabcdef);
91 var size = /** type {number} */ (gl.getBufferParameter(this.m_bufferTarget, gl.BUFFER_SIZE));
92 this.check(size == 0, 'Initial size should be 0; got ' + size);
94 var numIterations = 16;
95 for (var i = 0; i < numIterations; ++i) {
96 var len = rnd.getInt(0, 1024);
97 gl.bufferData(this.m_bufferTarget, len, gl.STREAM_DRAW);
99 size = /** type {number} */ (gl.getBufferParameter(this.m_bufferTarget, gl.BUFFER_SIZE));
100 this.check(size == len, 'Buffer size should be ' + len + ' ; got ' + size);
106 * @extends {es3fBufferObjectQueryTests.BufferCase}
107 * @param {string} name
108 * @param {string} description
110 es3fBufferObjectQueryTests.BufferUsageCase = function(name, description) {
111 es3fBufferObjectQueryTests.BufferCase.call(this, name, description);
112 this.m_testAllTargets = false;
115 setParentClass(es3fBufferObjectQueryTests.BufferUsageCase, es3fBufferObjectQueryTests.BufferCase);
117 es3fBufferObjectQueryTests.BufferUsageCase.prototype.testBuffer = function() {
118 var usage = /** type {number} */ (gl.getBufferParameter(this.m_bufferTarget, gl.BUFFER_USAGE));
119 this.check(usage == gl.STATIC_DRAW, 'Initial usage should be STATIC_DRAW; got ' + wtu.glEnumToString(gl, usage));
122 gl.STREAM_DRAW, gl.STREAM_READ,
123 gl.STREAM_COPY, gl.STATIC_DRAW,
124 gl.STATIC_READ, gl.STATIC_COPY,
125 gl.DYNAMIC_DRAW, gl.DYNAMIC_READ,
129 for (var ndx = 0; ndx < usages.length; ++ndx) {
130 gl.bufferData(this.m_bufferTarget, 16, usages[ndx]);
132 usage = /** type {number} */ (gl.getBufferParameter(this.m_bufferTarget, gl.BUFFER_USAGE));
133 this.check(usage == usages[ndx], 'Buffer usage should be ' + wtu.glEnumToString(gl, usages[ndx]) + ' ; got ' + wtu.glEnumToString(gl, usage));
139 * @extends {tcuTestCase.DeqpTest}
141 es3fBufferObjectQueryTests.BufferObjectQueryTests = function() {
142 tcuTestCase.DeqpTest.call(this, 'buffer_object', 'Buffer Object Query tests');
145 es3fBufferObjectQueryTests.BufferObjectQueryTests.prototype = Object.create(tcuTestCase.DeqpTest.prototype);
146 es3fBufferObjectQueryTests.BufferObjectQueryTests.prototype.constructor = es3fBufferObjectQueryTests.BufferObjectQueryTests;
148 es3fBufferObjectQueryTests.BufferObjectQueryTests.prototype.init = function() {
149 this.addChild(new es3fBufferObjectQueryTests.BufferSizeCase('buffer_size' , 'BUFFER_SIZE'));
150 this.addChild(new es3fBufferObjectQueryTests.BufferUsageCase('buffer_usage' , 'BUFFER_USAGE'));
155 * @param {WebGL2RenderingContext} context
157 es3fBufferObjectQueryTests.run = function(context) {
159 //Set up Test Root parameters
160 var state = tcuTestCase.runner;
161 state.setRoot(new es3fBufferObjectQueryTests.BufferObjectQueryTests());
163 //Set up name and description of this test series.
164 setCurrentTestName(state.testCases.fullName());
165 description(state.testCases.getDescription());
169 tcuTestCase.runTestCases();
172 testFailedOptions('Failed to es3fBufferObjectQueryTests.run tests', false);
173 tcuTestCase.runner.terminate();