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.es3fFboDepthbufferTests');
23 goog.require('framework.common.tcuSurface');
24 goog.require('framework.common.tcuTestCase');
25 goog.require('framework.common.tcuTexture');
26 goog.require('framework.opengl.gluTextureUtil');
27 goog.require('functional.gles3.es3fFboTestCase');
28 goog.require('functional.gles3.es3fFboTestUtil');
29 goog.require('framework.common.tcuRGBA');
30 goog.require('framework.delibs.debase.deRandom');
31 goog.require('framework.common.tcuImageCompare');
32 goog.require('framework.common.tcuTextureUtil');
33 goog.require('framework.referencerenderer.rrUtil');
34 goog.require('framework.delibs.debase.deMath');
35 goog.require('framework.opengl.gluShaderUtil');
37 goog.scope(function() {
38 var es3fFboDepthbufferTests = functional.gles3.es3fFboDepthbufferTests;
39 var es3fFboTestCase = functional.gles3.es3fFboTestCase;
40 var es3fFboTestUtil = functional.gles3.es3fFboTestUtil;
41 var tcuTestCase = framework.common.tcuTestCase;
42 var tcuSurface = framework.common.tcuSurface;
43 var tcuTexture = framework.common.tcuTexture;
44 var gluTextureUtil = framework.opengl.gluTextureUtil;
45 var tcuRGBA = framework.common.tcuRGBA;
46 var deRandom = framework.delibs.debase.deRandom;
47 var tcuImageCompare = framework.common.tcuImageCompare;
48 var tcuTextureUtil = framework.common.tcuTextureUtil;
49 var rrUtil = framework.referencerenderer.rrUtil;
50 var deMath = framework.delibs.debase.deMath;
51 var gluShaderUtil = framework.opengl.gluShaderUtil;
53 /** @type {WebGL2RenderingContext} */ var gl;
55 var setParentClass = function(child, parent) {
56 child.prototype = Object.create(parent.prototype);
57 child.prototype.constructor = child;
62 * @extends {es3fFboTestCase.FboTestCase}
63 * @param {string} name
64 * @param {string} desc
65 * @param {number} format
66 * @param {number} width
67 * @param {number} height
69 es3fFboDepthbufferTests.BasicFboDepthCase = function(name, desc, format, width, height) {
70 es3fFboTestCase.FboTestCase.call(this, name, desc);
71 this.m_format = format;
73 this.m_height = height;
76 setParentClass(es3fFboDepthbufferTests.BasicFboDepthCase, es3fFboTestCase.FboTestCase);
78 es3fFboDepthbufferTests.BasicFboDepthCase.prototype.preCheck = function() {
79 this.checkFormatSupport(this.m_format);
80 return true; // No exception thrown
83 es3fFboDepthbufferTests.BasicFboDepthCase.prototype.render = function(dst) {
84 var ctx = this.getCurrentContext();
85 var colorFormat = gl.RGBA8;
86 /** @type {es3fFboTestUtil.GradientShader} */
87 var gradShader = new es3fFboTestUtil.GradientShader(gluShaderUtil.DataType.FLOAT_VEC4);
89 /** @type {es3fFboTestUtil.Texture2DShader} */
90 var texShader = new es3fFboTestUtil.Texture2DShader(
91 [gluShaderUtil.DataType.SAMPLER_2D], gluShaderUtil.DataType.FLOAT_VEC4);
92 var texShaderID = ctx.createProgram(texShader);
93 var gradShaderID = ctx.createProgram(gradShader);
97 gradShader.setGradient(ctx, gradShaderID, [0, 0, 0, 0], [1, 1, 1, 1]);
98 texShader.setUniforms(ctx, texShaderID);
102 var fbo = ctx.createFramebuffer();
103 var colorRbo = ctx.createRenderbuffer();
104 var depthRbo = ctx.createRenderbuffer();
106 ctx.bindRenderbuffer(gl.RENDERBUFFER, colorRbo);
107 ctx.renderbufferStorage(gl.RENDERBUFFER, colorFormat, this.m_width, this.m_height);
109 ctx.bindRenderbuffer(gl.RENDERBUFFER, depthRbo);
110 ctx.renderbufferStorage(gl.RENDERBUFFER, this.m_format, this.m_width, this.m_height);
112 ctx.bindFramebuffer(gl.FRAMEBUFFER, fbo);
113 ctx.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorRbo);
114 ctx.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, depthRbo);
116 this.checkFramebufferStatus(gl.FRAMEBUFFER);
118 ctx.viewport(0, 0, this.m_width, this.m_height);
121 ctx.clearBufferfv(gl.DEPTH, 0, [clearDepth]);
123 // Render gradient with depth = [-1..1]
124 ctx.enable(gl.DEPTH_TEST);
125 rrUtil.drawQuad(ctx, gradShaderID, [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]);
127 // Render grid pattern with depth = 0
128 var format = gl.RGBA;
129 var dataType = gl.UNSIGNED_BYTE;
132 var data = new tcuTexture.TextureLevel(gluTextureUtil.mapGLTransferFormat(format, dataType), texW, texH, 1);
134 tcuTextureUtil.fillWithGrid(data.getAccess(), 8, [0.2, 0.7, 0.1, 1.0], [0.7, 0.1, 0.5, 0.8]);
136 var gridTex = ctx.createTexture();
137 ctx.bindTexture(gl.TEXTURE_2D, gridTex);
138 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
139 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
140 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
141 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
142 ctx.texImage2D(gl.TEXTURE_2D, 0, format, texW, texH, 0, format, dataType, data.getAccess().getDataPtr());
144 rrUtil.drawQuad(ctx, texShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]);
148 this.readPixelsUsingFormat(dst, 0, 0, this.m_width, this.m_height,
149 gluTextureUtil.mapGLInternalFormat(colorFormat),
150 [1, 1, 1, 1], [0, 0, 0, 0]);
155 * @extends {es3fFboTestCase.FboTestCase}
156 * @param {string} name
157 * @param {string} desc
158 * @param {number} format
159 * @param {number} width
160 * @param {number} height
162 es3fFboDepthbufferTests.DepthWriteClampCase = function(name, desc, format, width, height) {
163 es3fFboTestCase.FboTestCase.call(this, name, desc);
164 this.m_format = format;
165 this.m_width = width;
166 this.m_height = height;
169 setParentClass(es3fFboDepthbufferTests.DepthWriteClampCase, es3fFboTestCase.FboTestCase);
171 es3fFboDepthbufferTests.DepthWriteClampCase.prototype.preCheck = function() {
172 this.checkFormatSupport(this.m_format);
173 return true; // No exception thrown
176 es3fFboDepthbufferTests.DepthWriteClampCase.prototype.render = function(dst) {
177 var ctx = this.getCurrentContext();
178 var colorFormat = gl.RGBA8;
179 var transferFmt = gluTextureUtil.getTransferFormat(gluTextureUtil.mapGLInternalFormat(this.m_format));
180 /** @type {es3fFboTestUtil.DepthGradientShader} */
181 var gradShader = new es3fFboTestUtil.DepthGradientShader(gluShaderUtil.DataType.FLOAT_VEC4);
183 var gradShaderID = ctx.createProgram(gradShader);
185 var red = [1, 0, 0, 1];
186 var green = [0, 1, 0, 1];
190 var fbo = ctx.createFramebuffer();
191 var colorRbo = ctx.createRenderbuffer();
192 var depthTexture = ctx.createTexture();
194 ctx.bindRenderbuffer(gl.RENDERBUFFER, colorRbo);
195 ctx.renderbufferStorage(gl.RENDERBUFFER, colorFormat, this.m_width, this.m_height);
197 ctx.bindTexture(gl.TEXTURE_2D, depthTexture);
198 ctx.texImage2D(gl.TEXTURE_2D, 0, this.m_format, this.m_width, this.m_height, 0, transferFmt.format, transferFmt.dataType, null);
199 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
200 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
202 ctx.bindFramebuffer(gl.FRAMEBUFFER, fbo);
203 ctx.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorRbo);
204 ctx.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture, 0);
206 this.checkFramebufferStatus(gl.FRAMEBUFFER);
208 ctx.viewport(0, 0, this.m_width, this.m_height);
211 ctx.clearBufferfv(gl.DEPTH, 0, [clearDepth]);
213 // Render gradient with depth = [-1..1]
214 ctx.enable(gl.DEPTH_TEST);
215 ctx.depthFunc(gl.ALWAYS);
216 gradShader.setUniforms(ctx, gradShaderID, -1, 2, green);
217 rrUtil.drawQuad(ctx, gradShaderID, [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]);
218 ctx.depthMask(false);
220 // Test if any fragment has greater depth than 1; there should be none
221 ctx.depthFunc(gl.LESS); // (1 < depth) ?
222 gradShader.setUniforms(ctx, gradShaderID, 1, 1, red);
223 rrUtil.drawQuad(ctx, gradShaderID, [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]);
225 // Test if any fragment has smaller depth than 0; there should be none
226 ctx.depthFunc(gl.GREATER); // (0 > depth) ?
227 gradShader.setUniforms(ctx, gradShaderID, 0, 0, red);
228 rrUtil.drawQuad(ctx, gradShaderID, [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]);
231 this.readPixelsUsingFormat(dst, 0, 0, this.m_width, this.m_height,
232 gluTextureUtil.mapGLInternalFormat(colorFormat),
233 [1, 1, 1, 1], [0, 0, 0, 0]);
240 * @extends {es3fFboTestCase.FboTestCase}
241 * @param {string} name
242 * @param {string} desc
243 * @param {number} format
244 * @param {number} width
245 * @param {number} height
247 es3fFboDepthbufferTests.DepthTestClampCase = function(name, desc, format, width, height) {
248 es3fFboTestCase.FboTestCase.call(this, name, desc);
249 this.m_format = format;
250 this.m_width = width;
251 this.m_height = height;
254 setParentClass(es3fFboDepthbufferTests.DepthTestClampCase, es3fFboTestCase.FboTestCase);
256 es3fFboDepthbufferTests.DepthTestClampCase.prototype.preCheck = function() {
257 this.checkFormatSupport(this.m_format);
258 return true; // No exception thrown
261 es3fFboDepthbufferTests.DepthTestClampCase.prototype.render = function(dst) {
262 var ctx = this.getCurrentContext();
263 var colorFormat = gl.RGBA8;
264 var transferFmt = gluTextureUtil.getTransferFormat(gluTextureUtil.mapGLInternalFormat(this.m_format));
265 /** @type {es3fFboTestUtil.DepthGradientShader} */
266 var gradShader = new es3fFboTestUtil.DepthGradientShader(gluShaderUtil.DataType.FLOAT_VEC4);
268 var gradShaderID = ctx.createProgram(gradShader);
270 var yellow = [1, 1, 0, 1];
271 var green = [0, 1, 0, 1];
275 var fbo = ctx.createFramebuffer();
276 var colorRbo = ctx.createRenderbuffer();
277 var depthTexture = ctx.createTexture();
279 ctx.bindRenderbuffer(gl.RENDERBUFFER, colorRbo);
280 ctx.renderbufferStorage(gl.RENDERBUFFER, colorFormat, this.m_width, this.m_height);
282 ctx.bindTexture(gl.TEXTURE_2D, depthTexture);
283 ctx.texImage2D(gl.TEXTURE_2D, 0, this.m_format, this.m_width, this.m_height, 0, transferFmt.format, transferFmt.dataType, null);
284 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
285 ctx.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
287 ctx.bindFramebuffer(gl.FRAMEBUFFER, fbo);
288 ctx.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, colorRbo);
289 ctx.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.TEXTURE_2D, depthTexture, 0);
291 this.checkFramebufferStatus(gl.FRAMEBUFFER);
293 ctx.viewport(0, 0, this.m_width, this.m_height);
296 ctx.clearBufferfv(gl.DEPTH, 0, [clearDepth]);
298 // Test values used in depth test are clamped
300 // Render green quad, depth gradient = [-1..2]
301 ctx.enable(gl.DEPTH_TEST);
302 ctx.depthFunc(gl.ALWAYS);
304 gradShader.setUniforms(ctx, gradShaderID, -1, 2, green);
305 rrUtil.drawQuad(ctx, gradShaderID, [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]);
307 // Render yellow quad, depth gradient = [-0.5..3]. Gradients have equal values only outside [0, 1] range due to clamping
308 ctx.depthFunc(gl.EQUAL);
310 gradShader.setUniforms(ctx, gradShaderID, -0.5, 3, yellow);
311 rrUtil.drawQuad(ctx, gradShaderID, [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]);
314 this.readPixelsUsingFormat(dst, 0, 0, this.m_width, this.m_height,
315 gluTextureUtil.mapGLInternalFormat(colorFormat),
316 [1, 1, 1, 1], [0, 0, 0, 0]);
321 * @extends {tcuTestCase.DeqpTest}
323 es3fFboDepthbufferTests.FboDepthbufferTests = function() {
324 tcuTestCase.DeqpTest.call(this, 'depth', 'depth tests');
327 setParentClass(es3fFboDepthbufferTests.FboDepthbufferTests, tcuTestCase.DeqpTest);
329 es3fFboDepthbufferTests.FboDepthbufferTests.prototype.init = function() {
331 gl.DEPTH_COMPONENT32F,
332 gl.DEPTH_COMPONENT24,
333 gl.DEPTH_COMPONENT16,
334 gl.DEPTH32F_STENCIL8,
339 var basicGroup = tcuTestCase.newTest('basic', 'Basic depth tests');
340 this.addChild(basicGroup);
342 for (var ndx = 0; ndx < depthFormats.length; ndx++)
343 basicGroup.addChild(new es3fFboDepthbufferTests.BasicFboDepthCase(es3fFboTestUtil.getFormatName(depthFormats[ndx]), '', depthFormats[ndx], 119, 127));
345 // .depth_write_clamp
346 var depthClampGroup = tcuTestCase.newTest('depth_write_clamp', 'Depth write clamping tests');
347 this.addChild(depthClampGroup);
349 for (var ndx = 0; ndx < depthFormats.length; ndx++)
350 depthClampGroup.addChild(new es3fFboDepthbufferTests.DepthWriteClampCase(es3fFboTestUtil.getFormatName(depthFormats[ndx]), '', depthFormats[ndx], 119, 127));
353 var depthTestGroup = tcuTestCase.newTest('depth_test_clamp', 'Depth test value clamping tests');
354 this.addChild(depthTestGroup);
356 for (var ndx = 0; ndx < depthFormats.length; ndx++)
357 depthTestGroup.addChild(new es3fFboDepthbufferTests.DepthTestClampCase(es3fFboTestUtil.getFormatName(depthFormats[ndx]), '', depthFormats[ndx], 119, 127));
363 * @param {WebGL2RenderingContext} context
365 es3fFboDepthbufferTests.run = function(context) {
367 //Set up Test Root parameters
368 var state = tcuTestCase.runner;
369 state.setRoot(new es3fFboDepthbufferTests.FboDepthbufferTests());
371 //Set up name and description of this test series.
372 setCurrentTestName(state.testCases.fullName());
373 description(state.testCases.getDescription());
377 tcuTestCase.runTestCases();
380 testFailedOptions('Failed to es3fFboDepthbufferTests.run tests', false);
381 tcuTestCase.runner.terminate();