Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / deqp / functional / gles3 / es3fFboRenderTest.js
blob78229de447b127d230aadaa611d4352b915f04a7
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.
21 'use strict';
22 goog.provide('functional.gles3.es3fFboRenderTest');
23 goog.require('framework.common.tcuImageCompare');
24 goog.require('framework.common.tcuLogImage');
25 goog.require('framework.common.tcuPixelFormat');
26 goog.require('framework.common.tcuRGBA');
27 goog.require('framework.common.tcuSurface');
28 goog.require('framework.common.tcuTestCase');
29 goog.require('framework.common.tcuTexture');
30 goog.require('framework.common.tcuTextureUtil');
31 goog.require('framework.delibs.debase.deMath');
32 goog.require('framework.delibs.debase.deRandom');
33 goog.require('framework.delibs.debase.deString');
34 goog.require('framework.delibs.debase.deUtil');
35 goog.require('framework.opengl.gluShaderUtil');
36 goog.require('framework.opengl.gluTextureUtil');
37 goog.require('framework.opengl.simplereference.sglrGLContext');
38 goog.require('framework.opengl.simplereference.sglrReferenceContext');
39 goog.require('framework.referencerenderer.rrUtil');
40 goog.require('functional.gles3.es3fFboTestUtil');
42 goog.scope(function() {
44 var es3fFboRenderTest = functional.gles3.es3fFboRenderTest;
45 var es3fFboTestUtil = functional.gles3.es3fFboTestUtil;
46 var gluShaderUtil = framework.opengl.gluShaderUtil;
47 var gluTextureUtil = framework.opengl.gluTextureUtil;
48 var tcuImageCompare = framework.common.tcuImageCompare;
49 var tcuLogImage = framework.common.tcuLogImage;
50 var tcuPixelFormat = framework.common.tcuPixelFormat;
51 var tcuRGBA = framework.common.tcuRGBA;
52 var tcuTestCase = framework.common.tcuTestCase;
53 var tcuSurface = framework.common.tcuSurface;
54 var tcuTexture = framework.common.tcuTexture;
55 var tcuTextureUtil = framework.common.tcuTextureUtil;
56 var deMath = framework.delibs.debase.deMath;
57 var deRandom = framework.delibs.debase.deRandom;
58 var deString = framework.delibs.debase.deString;
59 var deUtil = framework.delibs.debase.deUtil;
60 var sglrGLContext = framework.opengl.simplereference.sglrGLContext;
61 var sglrReferenceContext =
62 framework.opengl.simplereference.sglrReferenceContext;
63 var rrUtil = framework.referencerenderer.rrUtil;
65 /** @type {WebGL2RenderingContext} */ var gl;
67 /**
68 * @constructor
69 * @param {number=} buffers_
70 * @param {number=} colorType_
71 * @param {number=} colorFormat_
72 * @param {number=} depthStencilType_
73 * @param {number=} depthStencilFormat_
74 * @param {number=} width_
75 * @param {number=} height_
76 * @param {number=} samples_
78 es3fFboRenderTest.FboConfig = function(
79 buffers_, colorType_, colorFormat_, depthStencilType_,
80 depthStencilFormat_, width_, height_, samples_
81 ) {
82 // Buffer bit mask (gl.COLOR_BUFFER_BIT|gl.DEPTH_BUFFER_BIT|...)
83 this.buffers = buffers_ ? buffers_ : 0;
84 // gl.TEXTURE_2D, gl.TEXTURE_CUBE_MAP, gl.RENDERBUFFER
85 this.colorType = colorType_ ? colorType_ : gl.NONE;
86 // Internal format for color buffer texture or renderbuffer
87 this.colorFormat = colorFormat_ ? colorFormat_ : gl.NONE;
88 this.depthStencilType = depthStencilType_?
89 depthStencilType_ : gl.NONE;
90 this.depthStencilFormat = depthStencilFormat_ ?
91 depthStencilFormat_ : gl.NONE;
92 this.width = width_ ? width_ : 0;
93 this.height = height_ ? height_ : 0;
94 this.samples = samples_? samples_ : 0;
97 /**
98 * @param {number} type
99 * @return {string}
101 es3fFboRenderTest.getTypeName = function(type) {
102 switch (type) {
103 case gl.TEXTURE_2D: return 'tex2d';
104 case gl.RENDERBUFFER: return 'rbo';
105 default:
106 testFailed('Unknown type');
108 return 'Should not get to this point';
112 * @return {string}
114 es3fFboRenderTest.FboConfig.prototype.getName = function() {
115 var name = '';
117 assertMsgOptions((this.buffers & gl.COLOR_BUFFER_BIT) != 0,
118 'Color buffer is not specified', false, true);
120 name += es3fFboRenderTest.getTypeName(this.colorType) + '_' +
121 es3fFboTestUtil.getFormatName(this.colorFormat);
123 if (this.buffers & gl.DEPTH_BUFFER_BIT)
124 name += '_depth';
125 if (this.buffers & gl.STENCIL_BUFFER_BIT)
126 name += '_stencil';
128 if (this.buffers & (gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT))
129 name += '_' + es3fFboRenderTest.getTypeName(this.depthStencilType) +
130 '_' + es3fFboTestUtil.getFormatName(this.depthStencilFormat);
132 return name;
136 * @param {number} format
137 * @return {Array<string>}
139 es3fFboRenderTest.getEnablingExtensions = function(format) {
140 /** @type {Array<string>} */ var out = [];
142 switch (format) {
143 case gl.RGB16F:
144 assertMsgOptions(false, "Not part of the tested formats", false, true);
145 break;
147 case gl.RGBA16F:
148 case gl.RG16F:
149 case gl.R16F:
150 case gl.RGBA32F:
151 case gl.RGB32F:
152 case gl.R11F_G11F_B10F:
153 case gl.RG32F:
154 case gl.R32F:
155 out.push('EXT_color_buffer_float');
157 default:
158 break;
161 return out;
165 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
166 * context
167 * @param {string} name
168 * @return {*}
170 es3fFboRenderTest.isExtensionSupported = function(context, name) {
171 return context.getExtension(name);
175 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
176 * context
177 * @param {Array<string>} requiredExts
178 * @return {boolean}
180 es3fFboRenderTest.isAnyExtensionSupported = function(
181 context, requiredExts) {
183 if (!requiredExts || requiredExts.length == 0)
184 return true;
186 for (var extNdx = 0; extNdx < requiredExts.length; extNdx++) {
187 var extension = requiredExts[extNdx];
189 if (es3fFboRenderTest.isExtensionSupported(context, extension))
190 return true;
193 return false;
197 * @param {Array} list
198 * @param {string} sep
199 * @return {string}
201 es3fFboRenderTest.join = function(list, sep) {
202 var out = '';
204 for (var elemNdx = 0; elemNdx < list.length; elemNdx++) {
205 if (elemNdx != 0)
206 out += sep;
207 out += list[elemNdx];
210 return out;
214 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
215 * context
216 * @param {number} sizedFormat
218 es3fFboRenderTest.checkColorFormatSupport = function(context, sizedFormat) {
219 /** @type {Array<string>} */ var requiredExts =
220 es3fFboRenderTest.getEnablingExtensions(sizedFormat);
222 if (!es3fFboRenderTest.isAnyExtensionSupported(context, requiredExts)) {
223 var errMsg = 'Format not supported, requires ' + (
224 (requiredExts.length == 1) ? requiredExts[0] :
225 ' one of the following: ' +
226 requiredExts.join(', ')
228 checkMessage(false, errMsg);
230 throw new TestFailedException(errMsg);
235 * @constructor
236 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
237 * context
238 * @param {es3fFboRenderTest.FboConfig} config
239 * @param {number} width
240 * @param {number} height
241 * @param {sglrReferenceContext.AnyFramebuffer=} fbo
242 * @param {sglrReferenceContext.AnyRenderbuffer=} colorBufferName
243 * @param {sglrReferenceContext.AnyRenderbuffer=} depthStencilBufferName
245 es3fFboRenderTest.Framebuffer = function(
246 context, config, width, height, fbo,
247 colorBufferName, depthStencilBufferName) {
249 this.m_config = config;
250 this.m_context = context;
251 this.m_framebuffer = fbo ? fbo : null;
252 this.m_colorBuffer = colorBufferName ? colorBufferName : null;
253 this.m_depthStencilBuffer = depthStencilBufferName ?
254 depthStencilBufferName : null;
256 // Verify that color format is supported
257 es3fFboRenderTest.checkColorFormatSupport(context, config.colorFormat);
259 if (!this.m_framebuffer)
260 this.m_framebuffer = context.createFramebuffer();
261 context.bindFramebuffer(gl.FRAMEBUFFER, this.m_framebuffer);
263 if (this.m_config.buffers & (gl.COLOR_BUFFER_BIT)) {
264 switch (this.m_config.colorType) {
265 case gl.TEXTURE_2D:
266 this.m_colorBuffer = this.createTex2D(
267 /** @type {WebGLTexture} */ (colorBufferName),
268 this.m_config.colorFormat, width, height
271 context.framebufferTexture2D(
272 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
273 gl.TEXTURE_2D, this.m_colorBuffer, 0
276 break;
278 case gl.RENDERBUFFER:
279 this.m_colorBuffer = this.createRbo(
280 /** @type {WebGLRenderbuffer} */ (colorBufferName),
281 this.m_config.colorFormat, width, height
284 context.framebufferRenderbuffer(
285 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
286 gl.RENDERBUFFER, this.m_colorBuffer
289 break;
291 default:
292 testFailed('Unsupported type');
296 if (this.m_config.buffers &
297 (gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT)) {
299 switch (this.m_config.depthStencilType) {
300 case gl.TEXTURE_2D:
301 this.m_depthStencilBuffer = this.createTex2D(
302 /** @type {WebGLTexture} */
303 (depthStencilBufferName),
304 this.m_config.depthStencilFormat, width, height
306 break;
307 case gl.RENDERBUFFER:
308 this.m_depthStencilBuffer = this.createRbo(
309 /** @type {WebGLRenderbuffer} */
310 (depthStencilBufferName),
311 this.m_config.depthStencilFormat, width, height
313 break;
315 default:
316 testFailed('Unsupported type');
320 for (var ndx = 0; ndx < 2; ndx++) {
321 var bit = ndx ? gl.STENCIL_BUFFER_BIT : gl.DEPTH_BUFFER_BIT;
322 var point = ndx ? gl.STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
324 if ((this.m_config.buffers & bit) == 0)
325 continue; /* Not used. */
327 switch (this.m_config.depthStencilType) {
328 case gl.TEXTURE_2D:
329 context.framebufferTexture2D(
330 gl.FRAMEBUFFER, point, gl.TEXTURE_2D,
331 this.m_depthStencilBuffer, 0
333 break;
334 case gl.RENDERBUFFER:
335 context.framebufferRenderbuffer(
336 gl.FRAMEBUFFER, point,
337 gl.RENDERBUFFER, this.m_depthStencilBuffer
339 break;
340 default:
341 throw new Error('Invalid depth stencil type');
345 context.bindFramebuffer(gl.FRAMEBUFFER, null);
349 * @return {es3fFboRenderTest.FboConfig}
351 es3fFboRenderTest.Framebuffer.prototype.getConfig = function() {
352 return this.m_config;
356 * @return {?sglrReferenceContext.AnyFramebuffer}
358 es3fFboRenderTest.Framebuffer.prototype.getFramebuffer = function() {
359 return this.m_framebuffer;
363 * @return {?sglrReferenceContext.AnyRenderbuffer}
365 es3fFboRenderTest.Framebuffer.prototype.getColorBuffer = function() {
366 return this.m_colorBuffer;
370 * @return {?sglrReferenceContext.AnyRenderbuffer}
372 es3fFboRenderTest.Framebuffer.prototype.getDepthStencilBuffer = function() {
373 return this.m_depthStencilBuffer;
377 * deinit
379 es3fFboRenderTest.Framebuffer.prototype.deinit = function() {
380 this.m_context.deleteFramebuffer(
381 /** @type {WebGLFramebuffer} */ (this.m_framebuffer)
383 this.destroyBuffer(this.m_colorBuffer, this.m_config.colorType);
384 this.destroyBuffer(
385 this.m_depthStencilBuffer, this.m_config.depthStencilType
390 * checkCompleteness
392 es3fFboRenderTest.Framebuffer.prototype.checkCompleteness = function() {
393 this.m_context.bindFramebuffer(gl.FRAMEBUFFER, this.m_framebuffer);
394 var status = this.m_context.checkFramebufferStatus(gl.FRAMEBUFFER);
395 this.m_context.bindFramebuffer(gl.FRAMEBUFFER, null);
396 if (status != gl.FRAMEBUFFER_COMPLETE)
397 throw new es3fFboTestUtil.FboIncompleteException(status);
401 * @param {?WebGLTexture|sglrReferenceContext.TextureContainer} name
402 * @param {number} format
403 * @param {number} width
404 * @param {number} height
405 * @return {?WebGLTexture|sglrReferenceContext.TextureContainer}
407 es3fFboRenderTest.Framebuffer.prototype.createTex2D = function(
408 name, format, width, height) {
410 if (!name)
411 name = this.m_context.createTexture();
413 this.m_context.bindTexture(gl.TEXTURE_2D, name);
414 this.m_context.texImage2DDelegate(
415 gl.TEXTURE_2D, 0, format, width, height
418 if (!deMath.deIsPowerOfTwo32(width) ||
419 !deMath.deIsPowerOfTwo32(height)) {
421 // Set wrap mode to clamp for NPOT FBOs
422 this.m_context.texParameteri(
423 gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE
425 this.m_context.texParameteri(
426 gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE
430 this.m_context.texParameteri(
431 gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST
433 this.m_context.texParameteri(
434 gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST
437 return name;
441 * @param {?WebGLRenderbuffer|sglrReferenceContext.Renderbuffer} name
442 * @param {number} format
443 * @param {number} width
444 * @param {number} height
445 * @return {?WebGLRenderbuffer|sglrReferenceContext.Renderbuffer}
447 es3fFboRenderTest.Framebuffer.prototype.createRbo = function(
448 name, format, width, height) {
450 if (!name)
451 name = this.m_context.createRenderbuffer();
453 this.m_context.bindRenderbuffer(gl.RENDERBUFFER, name);
454 this.m_context.renderbufferStorage(
455 gl.RENDERBUFFER, format, width, height
458 return name;
462 * @param {?sglrReferenceContext.AnyRenderbuffer} name
463 * @param {number} type
465 es3fFboRenderTest.Framebuffer.prototype.destroyBuffer = function(
466 name, type) {
468 if (type == gl.TEXTURE_2D || type == gl.TEXTURE_CUBE_MAP)
469 this.m_context.deleteTexture(/** @type {?WebGLTexture} */ (name));
470 else if (type == gl.RENDERBUFFER)
471 this.m_context.deleteRenderbuffer(
472 /** @type {?WebGLRenderbuffer} */ (name)
474 else
475 assertMsgOptions(
476 type == gl.NONE, 'Invalid buffer type', false, true
481 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
482 * context
483 * @param {WebGLTexture|sglrReferenceContext.TextureContainer} name
484 * @param {number} format
485 * @param {number} dataType
486 * @param {number} width
487 * @param {number} height
489 es3fFboRenderTest.createMetaballsTex2D = function(
490 context, name, format, dataType, width, height) {
492 /** @type {tcuTexture.TextureFormat} */ var texFormat =
493 gluTextureUtil.mapGLTransferFormat(format, dataType);
494 /** @type {tcuTexture.TextureLevel} */ var level =
495 new tcuTexture.TextureLevel(texFormat, width, height);
497 tcuTextureUtil.fillWithMetaballs(
498 level.getAccess(), 5, /*name ^*/ width ^ height
501 context.bindTexture(gl.TEXTURE_2D, name);
502 context.texImage2D(
503 gl.TEXTURE_2D, 0, format, width, height, 0, format,
504 dataType, level.getAccess().getDataPtr()
506 context.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
510 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
511 * context
512 * @param {WebGLTexture|sglrReferenceContext.TextureContainer} name
513 * @param {number} format
514 * @param {number} dataType
515 * @param {number} width
516 * @param {number} height
518 es3fFboRenderTest.createQuadsTex2D = function(
519 context, name, format, dataType, width, height) {
521 /** @type {tcuTexture.TextureFormat} */
522 var texFormat = gluTextureUtil.mapGLTransferFormat(format, dataType);
523 /** @type {tcuTexture.TextureLevel} */
524 var level = new tcuTexture.TextureLevel(texFormat, width, height);
526 tcuTextureUtil.fillWithRGBAQuads(level.getAccess());
528 context.bindTexture(gl.TEXTURE_2D, name);
529 context.texImage2D(
530 gl.TEXTURE_2D, 0, format, width, height, 0,
531 format, dataType, level.getAccess().getDataPtr()
533 context.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
537 * @constructor
538 * @extends {tcuTestCase.DeqpTest}
539 * @param {string} name
540 * @param {string} description
541 * @param {es3fFboRenderTest.FboConfig} config
543 es3fFboRenderTest.FboRenderCase = function(name, description, config) {
544 tcuTestCase.DeqpTest.call(this, name, description);
545 this.m_config = config;
548 es3fFboRenderTest.FboRenderCase.prototype =
549 Object.create(tcuTestCase.DeqpTest.prototype);
551 es3fFboRenderTest.FboRenderCase.prototype.constructor =
552 es3fFboRenderTest.FboRenderCase;
555 * Must be overridden
556 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
557 * fboContext
558 * @param {tcuSurface.Surface} dst
560 es3fFboRenderTest.FboRenderCase.prototype.render = function(
561 fboContext, dst) {
562 throw new Error('Must override');
566 * @return {tcuTestCase.IterateResult}
568 es3fFboRenderTest.FboRenderCase.prototype.iterate = function() {
569 var clearColor = [0.125, 0.25, 0.5, 1.0];
570 /** @type {?string} */ var failReason = "";
572 // Position & size for context
573 var rnd = new deRandom.deRandom();
574 deRandom.deRandom_init(rnd, deString.deStringHash(this.fullName()));
576 var width = Math.min(gl.canvas.width, 128);
577 var height = Math.min(gl.canvas.height, 128);
578 var xMax = gl.canvas.width - width + 1;
579 var yMax = gl.canvas.height - height + 1;
580 var x = Math.abs(deRandom.deRandom_getInt(rnd)) % xMax;
581 var y = Math.abs(deRandom.deRandom_getInt(rnd)) % yMax;
583 /** @type {tcuSurface.Surface} */
584 var gles3Frame = new tcuSurface.Surface(width, height);
585 /** @type {tcuSurface.Surface} */
586 var refFrame = new tcuSurface.Surface(width, height);
588 /** @type {number} */ var gles3Error = 0;
589 /** @type {number} */ var refError = 0;
591 // Render using GLES3
593 * @type {sglrGLContext.GLContext|
594 * sglrReferenceContext.ReferenceContext}
596 var context;
598 try {
599 context = new sglrGLContext.GLContext(gl, [x, y, width, height]);
601 context.clearColor(
602 clearColor[0], clearColor[1], clearColor[2], clearColor[3]
605 context.clear(
606 gl.COLOR_BUFFER_BIT |
607 gl.DEPTH_BUFFER_BIT |
608 gl.STENCIL_BUFFER_BIT
611 this.render(context, gles3Frame); // Call actual render func
612 gles3Error = context.getError();
614 catch (e) {
615 if (e instanceof es3fFboTestUtil.FboIncompleteException) {
616 e.message = WebGLTestUtils.glEnumToString(gl, e.getReason());
617 if(e.getReason() == gl.FRAMEBUFFER_UNSUPPORTED) {
618 // Mark test case as unsupported
619 bufferedLogToConsole(e + ': ' + e.message);
620 testFailed('Not supported');
621 return tcuTestCase.IterateResult.STOP;
625 // Propagate error
626 throw e;
629 // Render reference image
631 /** @type {sglrReferenceContext.ReferenceContextBuffers} */
632 var buffers = new sglrReferenceContext.ReferenceContextBuffers(
633 new tcuPixelFormat.PixelFormat(
634 8, 8, 8,
635 gl.getParameter(gl.ALPHA_BITS) ? 8 : 0
637 /** @type {number} */ (gl.getParameter(gl.DEPTH_BITS)),
638 /** @type {number} */ (gl.getParameter(gl.STENCIL_BITS)),
639 width,
640 height
642 context = new sglrReferenceContext.ReferenceContext(
643 new sglrReferenceContext.ReferenceContextLimits(gl),
644 buffers.getColorbuffer(),
645 buffers.getDepthbuffer(),
646 buffers.getStencilbuffer()
649 context.clearColor(
650 clearColor[0], clearColor[1], clearColor[2], clearColor[3]
653 context.clear(
654 gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT
657 this.render(context, refFrame);
658 refError = context.getError();
660 // Compare error codes
661 var errorCodesOk = (gles3Error == refError);
663 if (!errorCodesOk) {
664 bufferedLogToConsole (
665 'Error code mismatch: got ' +
666 WebGLTestUtils.glEnumToString(gl, gles3Error) + ', expected ' +
667 WebGLTestUtils.glEnumToString(gl, refError)
669 failReason = 'Got unexpected error';
672 // Compare images
673 var imagesOk = this.compare(refFrame, gles3Frame);
675 if (!imagesOk && !failReason)
676 failReason = 'Image comparison failed';
678 // Store test result
679 var isOk = errorCodesOk && imagesOk;
680 assertMsgOptions(isOk, failReason, true, true);
682 return tcuTestCase.IterateResult.STOP;
686 * @param {tcuSurface.Surface} reference
687 * @param {tcuSurface.Surface} result
688 * @return {boolean}
690 es3fFboRenderTest.FboRenderCase.prototype.compare = function(
691 reference, result) {
693 var threshold = new tcuRGBA.RGBA(
694 /* TODO: tcu::max(getFormatThreshold(this.m_config.colorFormat),*/
695 [12, 12, 12, 12]
698 return tcuImageCompare.bilinearCompare(
699 'ComparisonResult', 'Image comparison result',
700 reference.getAccess(), result.getAccess(),
701 threshold, tcuImageCompare.CompareLogMode.RESULT
706 * deinit
708 es3fFboRenderTest.FboRenderCase.prototype.deinit = function() {
709 gl.clearColor(0.0, 0.0, 0.0, 0.0);
710 gl.clearDepth(1.0);
711 gl.clearStencil(0);
713 gl.disable(gl.STENCIL_TEST);
714 gl.disable(gl.DEPTH_TEST);
715 gl.disable(gl.BLEND);
717 gl.bindFramebuffer(gl.FRAMEBUFFER, null);
718 gl.bindRenderbuffer(gl.RENDERBUFFER, null);
721 // FboCases
724 * @constructor
725 * @extends {es3fFboRenderTest.FboRenderCase}
726 * @param {es3fFboRenderTest.FboConfig} config
728 es3fFboRenderTest.StencilClearsTest = function(config) {
729 es3fFboRenderTest.FboRenderCase.call(
730 this, config.getName(), 'Stencil clears', config
734 es3fFboRenderTest.StencilClearsTest.prototype =
735 Object.create(es3fFboRenderTest.FboRenderCase.prototype);
737 es3fFboRenderTest.StencilClearsTest.prototype.constructor =
738 es3fFboRenderTest.StencilClearsTest;
741 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
742 * context
743 * @param {tcuSurface.Surface} dst
745 es3fFboRenderTest.StencilClearsTest.prototype.render = function(
746 context, dst) {
748 /** @type {tcuTexture.TextureFormat} */
749 var colorFormat = gluTextureUtil.mapGLInternalFormat(
750 this.m_config.colorFormat
753 /** @type {gluShaderUtil.DataType} */
754 var fboSamplerType = /** @type {gluShaderUtil.DataType} */ (
755 gluTextureUtil.getSampler2DType(colorFormat)
758 /** @type {gluShaderUtil.DataType} */
759 var fboOutputType = es3fFboTestUtil.getFragmentOutputType(colorFormat);
761 /** @type {tcuTextureUtil.TextureFormatInfo} */
762 var fboRangeInfo = tcuTextureUtil.getTextureFormatInfo(colorFormat);
764 var fboOutScale = deMath.subtract(
765 fboRangeInfo.valueMax, fboRangeInfo.valueMin
768 var fboOutBias = fboRangeInfo.valueMin;
770 /** @type {es3fFboTestUtil.Texture2DShader} */
771 var texToFboShader = new es3fFboTestUtil.Texture2DShader(
772 [gluShaderUtil.DataType.SAMPLER_2D], fboOutputType
775 /** @type {es3fFboTestUtil.Texture2DShader} */
776 var texFromFboShader = new es3fFboTestUtil.Texture2DShader(
777 [fboSamplerType], gluShaderUtil.DataType.FLOAT_VEC4);
779 /** @type {number} */ var texToFboShaderID =
780 context.createProgram(texToFboShader);
782 /** @type {number} */ var texFromFboShaderID =
783 context.createProgram(texFromFboShader);
785 /** @type {?WebGLTexture|sglrReferenceContext.TextureContainer} */
786 var metaballsTex = context.createTexture();
788 /** @type {?WebGLTexture|sglrReferenceContext.TextureContainer} */
789 var quadsTex = context.createTexture();
791 /** @type {number} */ var width = 128;
792 /** @type {number} */ var height = 128;
794 texToFboShader.setOutScaleBias(fboOutScale, fboOutBias);
795 texFromFboShader.setTexScaleBias(
796 0, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias
799 es3fFboRenderTest.createQuadsTex2D(
800 context, quadsTex, gl.RGBA, gl.UNSIGNED_BYTE, width, height
803 es3fFboRenderTest.createMetaballsTex2D(
804 context, metaballsTex, gl.RGBA, gl.UNSIGNED_BYTE, width, height
807 /** @type {es3fFboRenderTest.Framebuffer} */
808 var fbo = new es3fFboRenderTest.Framebuffer(
809 context, this.m_config, width, height
811 fbo.checkCompleteness();
813 // Bind framebuffer and clear
814 context.bindFramebuffer(gl.FRAMEBUFFER, fbo.getFramebuffer());
815 context.viewport(0, 0, width, height);
816 context.clearColor(0.0, 0.0, 0.0, 1.0);
817 context.clear(
818 gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT
821 // Do stencil clears
822 context.enable(gl.SCISSOR_TEST);
823 context.scissor(10, 16, 32, 120);
824 context.clearStencil(1);
825 context.clear(gl.STENCIL_BUFFER_BIT);
826 context.scissor(16, 32, 100, 64);
827 context.clearStencil(2);
828 context.clear(gl.STENCIL_BUFFER_BIT);
829 context.disable(gl.SCISSOR_TEST);
831 // Draw 2 textures with stecil tests
832 context.enable(gl.STENCIL_TEST);
834 context.bindTexture(gl.TEXTURE_2D, quadsTex);
835 context.stencilFunc(gl.EQUAL, 1, 0xff);
837 texToFboShader.setUniforms(context, texToFboShaderID);
838 rrUtil.drawQuad(
839 context, texToFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
842 context.bindTexture(gl.TEXTURE_2D, metaballsTex);
843 context.stencilFunc(gl.EQUAL, 2, 0xff);
845 texToFboShader.setUniforms(context, texToFboShaderID);
846 rrUtil.drawQuad(
847 context, texToFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
850 context.disable(gl.STENCIL_TEST);
852 if (fbo.getConfig().colorType == gl.TEXTURE_2D) {
853 context.bindFramebuffer(gl.FRAMEBUFFER, null);
854 context.bindTexture(gl.TEXTURE_2D, fbo.getColorBuffer());
855 context.viewport(0, 0, context.getWidth(), context.getHeight());
857 texFromFboShader.setUniforms(context, texFromFboShaderID);
858 rrUtil.drawQuad(
859 context, texFromFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
862 dst.readViewport(
863 context, [0, 0, context.getWidth(), context.getHeight()]
865 } else
866 es3fFboTestUtil.readPixels(
867 context, dst, 0, 0, width, height, colorFormat,
868 fboRangeInfo.lookupScale, fboRangeInfo.lookupBias
873 * @constructor
874 * @extends {es3fFboRenderTest.FboRenderCase}
875 * @param {es3fFboRenderTest.FboConfig} config
877 es3fFboRenderTest.SharedColorbufferTest = function(config) {
878 es3fFboRenderTest.FboRenderCase.call(
879 this, config.getName(), 'Shared colorbuffer', config
883 es3fFboRenderTest.SharedColorbufferTest.prototype =
884 Object.create(es3fFboRenderTest.FboRenderCase.prototype);
886 es3fFboRenderTest.SharedColorbufferTest.prototype.constructor =
887 es3fFboRenderTest.SharedColorbufferTest;
890 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
891 * context
892 * @param {tcuSurface.Surface} dst
894 es3fFboRenderTest.SharedColorbufferTest.prototype.render = function(
895 context, dst) {
897 /** @type {es3fFboTestUtil.Texture2DShader} */
898 var texShader = new es3fFboTestUtil.Texture2DShader(
899 [gluShaderUtil.DataType.SAMPLER_2D],
900 gluShaderUtil.DataType.FLOAT_VEC4
903 /** @type {es3fFboTestUtil.FlatColorShader} */
904 var flatShader = new es3fFboTestUtil.FlatColorShader(
905 gluShaderUtil.DataType.FLOAT_VEC4
908 /** @type {number} */
909 var texShaderID = context.createProgram(texShader);
910 /** @type {number} */
911 var flatShaderID = context.createProgram(flatShader);
913 /** @type {number} */ var width = 128;
914 /** @type {number} */ var height = 128;
916 /** @type {?WebGLTexture|sglrReferenceContext.TextureContainer} */
917 var quadsTex = context.createTexture();
919 /** @type {?WebGLTexture|sglrReferenceContext.TextureContainer} */
920 var metaballsTex = context.createTexture();
922 /** @type {boolean} */ var stencil =
923 (this.m_config.buffers & gl.STENCIL_BUFFER_BIT) != 0;
925 context.disable(gl.DITHER);
927 // Textures
928 es3fFboRenderTest.createQuadsTex2D(
929 context, quadsTex, gl.RGB, gl.UNSIGNED_BYTE, 64, 64
931 es3fFboRenderTest.createMetaballsTex2D(
932 context, metaballsTex, gl.RGBA, gl.UNSIGNED_BYTE, 64, 64
935 context.viewport(0, 0, width, height);
937 // Fbo A
938 /** @type {es3fFboRenderTest.Framebuffer} */
939 var fboA = new es3fFboRenderTest.Framebuffer(
940 context, this.m_config, width, height
942 fboA.checkCompleteness();
944 // Fbo B - don't create colorbuffer
946 /** @type {es3fFboRenderTest.FboConfig} */
947 var cfg = /** @type {es3fFboRenderTest.FboConfig} */
948 (deUtil.clone(this.m_config));
950 cfg.buffers = deMath.binaryOp(
951 cfg.buffers,
952 deMath.binaryNot(gl.COLOR_BUFFER_BIT),
953 deMath.BinaryOp.AND
955 cfg.colorType = gl.NONE;
956 cfg.colorFormat = gl.NONE;
958 /** @type {es3fFboRenderTest.Framebuffer} */
959 var fboB = new es3fFboRenderTest.Framebuffer(
960 context, cfg, width, height
963 // Attach color buffer from fbo A
964 context.bindFramebuffer(gl.FRAMEBUFFER, fboB.getFramebuffer());
965 switch (this.m_config.colorType) {
966 case gl.TEXTURE_2D:
967 context.framebufferTexture2D(
968 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
969 gl.TEXTURE_2D, fboA.getColorBuffer(), 0
971 break;
973 case gl.RENDERBUFFER:
974 context.framebufferRenderbuffer(
975 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
976 gl.RENDERBUFFER, fboA.getColorBuffer()
978 break;
980 default:
981 throw new Error('Invalid color type');
984 // Clear depth and stencil in fbo B
985 context.clear(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
987 // Render quads to fbo 1, with depth 0.0
988 context.bindFramebuffer(gl.FRAMEBUFFER, fboA.getFramebuffer());
989 context.bindTexture(gl.TEXTURE_2D, quadsTex);
990 context.clearColor(0.0, 0.0, 0.0, 1.0);
991 context.clear(
992 gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT
995 if (stencil) {
996 // Stencil to 1 in fbo A
997 context.clearStencil(1);
998 context.clear(gl.STENCIL_BUFFER_BIT);
1001 texShader.setUniforms(context, texShaderID);
1003 context.enable(gl.DEPTH_TEST);
1004 rrUtil.drawQuad(
1005 context, texShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1007 context.disable(gl.DEPTH_TEST);
1009 // Blend metaballs to fbo 2
1010 context.bindFramebuffer(gl.FRAMEBUFFER, fboB.getFramebuffer());
1011 context.bindTexture(gl.TEXTURE_2D, metaballsTex);
1012 context.enable(gl.BLEND);
1013 context.blendFuncSeparate(
1014 gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ZERO, gl.ONE
1016 rrUtil.drawQuad(
1017 context, texShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1020 // Render small quad that is only visible if depth buffer
1021 // is not shared with fbo A - or there is no depth bits
1022 context.bindTexture(gl.TEXTURE_2D, quadsTex);
1023 context.enable(gl.DEPTH_TEST);
1024 rrUtil.drawQuad(context, texShaderID, [0.5, 0.5, 0.5], [1.0, 1.0, 0.5]);
1025 context.disable(gl.DEPTH_TEST);
1027 if (stencil) {
1028 flatShader.setColor(context, flatShaderID, [0.0, 1.0, 0.0, 1.0]);
1030 // Clear subset of stencil buffer to 1
1031 context.enable(gl.SCISSOR_TEST);
1032 context.scissor(10, 10, 12, 25);
1033 context.clearStencil(1);
1034 context.clear(gl.STENCIL_BUFFER_BIT);
1035 context.disable(gl.SCISSOR_TEST);
1037 // Render quad with stencil mask == 1
1038 context.enable(gl.STENCIL_TEST);
1039 context.stencilFunc(gl.EQUAL, 1, 0xff);
1040 rrUtil.drawQuad(
1041 context, flatShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1043 context.disable(gl.STENCIL_TEST);
1046 // Get results
1047 if (fboA.getConfig().colorType == gl.TEXTURE_2D) {
1048 texShader.setUniforms(context, texShaderID);
1050 context.bindFramebuffer(gl.FRAMEBUFFER, null);
1051 context.bindTexture(gl.TEXTURE_2D, fboA.getColorBuffer());
1052 context.viewport(0, 0, context.getWidth(), context.getHeight());
1053 rrUtil.drawQuad(
1054 context, texShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1056 dst.readViewport(
1057 context, [0, 0, context.getWidth(), context.getHeight()]
1059 } else
1060 es3fFboTestUtil.readPixels(
1061 context, dst, 0, 0, width, height,
1062 gluTextureUtil.mapGLInternalFormat(
1063 fboA.getConfig().colorFormat
1064 ), [1.0, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.0]
1069 * @constructor
1070 * @extends {es3fFboRenderTest.FboRenderCase}
1071 * @param {es3fFboRenderTest.FboConfig} config
1073 es3fFboRenderTest.SharedColorbufferClearsTest = function(config) {
1074 es3fFboRenderTest.FboRenderCase.call(
1075 this, config.getName(), 'Shared colorbuffer clears', config
1079 es3fFboRenderTest.SharedColorbufferClearsTest.prototype =
1080 Object.create(es3fFboRenderTest.FboRenderCase.prototype);
1082 es3fFboRenderTest.SharedColorbufferClearsTest.prototype.constructor =
1083 es3fFboRenderTest.SharedColorbufferClearsTest;
1086 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
1087 * context
1088 * @param {tcuSurface.Surface} dst
1090 es3fFboRenderTest.SharedColorbufferClearsTest.prototype.render = function(
1091 context, dst) {
1093 /** @type {tcuTexture.TextureFormat} */
1094 var colorFormat = gluTextureUtil.mapGLInternalFormat(
1095 this.m_config.colorFormat
1098 /** @type {gluShaderUtil.DataType} */
1099 var fboSamplerType = gluTextureUtil.getSampler2DType(colorFormat);
1101 var width = 128;
1102 var height = 128;
1103 var colorbuffer = this.m_config.colorType == gl.TEXTURE_2D?
1104 context.createTexture() :
1105 context.createRenderbuffer();
1107 // Check for format support.
1108 es3fFboRenderTest.checkColorFormatSupport(
1109 context, this.m_config.colorFormat
1112 // Single colorbuffer
1113 if (this.m_config.colorType == gl.TEXTURE_2D) {
1114 context.bindTexture(gl.TEXTURE_2D, colorbuffer);
1115 context.texImage2DDelegate(
1116 gl.TEXTURE_2D, 0, this.m_config.colorFormat, width, height
1118 context.texParameteri(
1119 gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST
1121 context.texParameteri(
1122 gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST
1124 } else {
1125 assertMsgOptions(
1126 this.m_config.colorType == gl.RENDERBUFFER,
1127 'Not a render buffer type', false, true
1129 context.bindRenderbuffer(gl.RENDERBUFFER, colorbuffer);
1130 context.renderbufferStorage(
1131 gl.RENDERBUFFER, this.m_config.colorFormat, width, height
1135 // Multiple framebuffers sharing the colorbuffer
1136 var fbo = [
1137 context.createFramebuffer(),
1138 context.createFramebuffer(),
1139 context.createFramebuffer()
1142 for (var fboi = 0; fboi < fbo.length; fboi++) {
1143 context.bindFramebuffer(gl.FRAMEBUFFER, fbo[fboi]);
1145 if (this.m_config.colorType == gl.TEXTURE_2D)
1146 context.framebufferTexture2D(
1147 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
1148 gl.TEXTURE_2D, colorbuffer, 0
1150 else
1151 context.framebufferRenderbuffer(
1152 gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
1153 gl.RENDERBUFFER, colorbuffer
1157 context.bindFramebuffer(gl.FRAMEBUFFER, fbo[0]);
1159 // Check completeness
1161 var status = context.checkFramebufferStatus(gl.FRAMEBUFFER);
1162 if (status != gl.FRAMEBUFFER_COMPLETE)
1163 throw new es3fFboTestUtil.FboIncompleteException(status);
1165 // Render to them
1166 context.viewport(0, 0, width, height);
1167 context.clearColor(0.0, 0.0, 1.0, 1.0);
1168 context.clear(gl.COLOR_BUFFER_BIT);
1170 context.enable(gl.SCISSOR_TEST);
1172 context.bindFramebuffer(gl.FRAMEBUFFER, fbo[1]);
1173 context.clearColor(0.6, 0.0, 0.0, 1.0);
1174 context.scissor(10, 10, 64, 64);
1175 context.clear(gl.COLOR_BUFFER_BIT);
1176 context.clearColor(0.0, 0.6, 0.0, 1.0);
1177 context.scissor(60, 60, 40, 20);
1178 context.clear(gl.COLOR_BUFFER_BIT);
1180 context.bindFramebuffer(gl.FRAMEBUFFER, fbo[2]);
1181 context.clearColor(0.0, 0.0, 0.6, 1.0);
1182 context.scissor(20, 20, 100, 10);
1183 context.clear(gl.COLOR_BUFFER_BIT);
1185 context.bindFramebuffer(gl.FRAMEBUFFER, fbo[0]);
1186 context.clearColor(0.6, 0.0, 0.6, 1.0);
1187 context.scissor(20, 20, 5, 100);
1188 context.clear(gl.COLOR_BUFFER_BIT);
1190 context.disable(gl.SCISSOR_TEST);
1192 if (this.m_config.colorType == gl.TEXTURE_2D) {
1193 /** @type {es3fFboTestUtil.Texture2DShader} */
1194 var shader = new es3fFboTestUtil.Texture2DShader(
1195 [fboSamplerType], gluShaderUtil.DataType.FLOAT_VEC4
1197 var shaderID = context.createProgram(shader);
1199 shader.setUniforms(context, shaderID);
1201 context.bindFramebuffer(gl.FRAMEBUFFER, null);
1202 context.viewport(0, 0, context.getWidth(), context.getHeight());
1203 rrUtil.drawQuad(
1204 context, shaderID, [-0.9, -0.9, 0.0], [0.9, 0.9, 0.0]
1206 dst.readViewport(
1207 context, [0, 0, context.getWidth(), context.getHeight()]
1209 } else
1210 es3fFboTestUtil.readPixels(
1211 context, dst, 0, 0, width, height, colorFormat,
1212 [1.0, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.0]
1215 //delete FBOs
1216 for (fboi = 0; fboi < fbo.length; fboi++)
1217 context.deleteFramebuffer(fbo[fboi]);
1219 //delete Texture/Renderbuffer
1220 if (this.m_config.colorType == gl.TEXTURE_2D)
1221 context.deleteTexture(colorbuffer);
1222 else
1223 context.deleteRenderbuffer(colorbuffer);
1227 * @constructor
1228 * @extends {es3fFboRenderTest.FboRenderCase}
1229 * @param {es3fFboRenderTest.FboConfig} config
1231 es3fFboRenderTest.SharedDepthStencilTest = function(config) {
1232 es3fFboRenderTest.FboRenderCase.call(
1233 this, config.getName(), 'Shared depth/stencilbuffer', config
1237 es3fFboRenderTest.SharedDepthStencilTest.prototype =
1238 Object.create(es3fFboRenderTest.FboRenderCase.prototype);
1240 es3fFboRenderTest.SharedDepthStencilTest.prototype.constructor =
1241 es3fFboRenderTest.SharedDepthStencilTest;
1244 * @param {es3fFboRenderTest.FboConfig} config
1245 * @return {boolean}
1247 es3fFboRenderTest.SharedDepthStencilTest.prototype.isConfigSupported =
1248 function(config) {
1249 return deMath.binaryOp(
1250 config.buffers,
1251 deMath.binaryOp(
1252 gl.DEPTH_BUFFER_BIT, gl.STENCIL_BUFFER_BIT, deMath.BinaryOp.OR
1253 ), deMath.BinaryOp.AND
1254 ) != 0;
1258 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
1259 * context
1260 * @param {tcuSurface.Surface} dst
1262 es3fFboRenderTest.SharedDepthStencilTest.prototype.render = function(
1263 context, dst) {
1265 /** @type {es3fFboTestUtil.Texture2DShader} */
1266 var texShader = new es3fFboTestUtil.Texture2DShader(
1267 [gluShaderUtil.DataType.SAMPLER_2D],
1268 gluShaderUtil.DataType.FLOAT_VEC4
1271 /** @type {es3fFboTestUtil.FlatColorShader} */
1272 var flatShader = new es3fFboTestUtil.FlatColorShader(
1273 gluShaderUtil.DataType.FLOAT_VEC4
1276 var texShaderID = context.createProgram(texShader);
1277 var flatShaderID = context.createProgram(flatShader);
1278 var width = 128;
1279 var height = 128;
1280 // bool depth = (this.m_config.buffers & gl.DEPTH_BUFFER_BIT) != 0;
1281 /**@type {boolean} */ var stencil =
1282 (this.m_config.buffers & gl.STENCIL_BUFFER_BIT) != 0;
1284 // Textures
1285 var metaballsTex = context.createTexture();
1286 var quadsTex = context.createTexture();
1287 es3fFboRenderTest.createMetaballsTex2D(
1288 context, metaballsTex, gl.RGB, gl.UNSIGNED_BYTE, 64, 64
1290 es3fFboRenderTest.createQuadsTex2D(
1291 context, quadsTex, gl.RGB, gl.UNSIGNED_BYTE, 64, 64
1294 context.viewport(0, 0, width, height);
1296 // Fbo A
1297 /** @type {es3fFboRenderTest.Framebuffer} */
1298 var fboA = new es3fFboRenderTest.Framebuffer(
1299 context, this.m_config, width, height
1302 fboA.checkCompleteness();
1304 // Fbo B
1305 /** @type {es3fFboRenderTest.FboConfig} */
1306 var cfg = /** @type {es3fFboRenderTest.FboConfig} */
1307 (deUtil.clone(this.m_config));
1309 cfg.buffers = deMath.binaryOp(
1310 cfg.buffers,
1311 deMath.binaryNot(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT),
1312 deMath.BinaryOp.AND
1314 cfg.depthStencilType = gl.NONE;
1315 cfg.depthStencilFormat = gl.NONE;
1317 /** @type {es3fFboRenderTest.Framebuffer} */
1318 var fboB = new es3fFboRenderTest.Framebuffer(
1319 context, cfg, width, height
1322 // Bind depth/stencil buffers from fbo A to fbo B
1323 context.bindFramebuffer(gl.FRAMEBUFFER, fboB.getFramebuffer());
1324 for (var ndx = 0; ndx < 2; ndx++) {
1325 var bit = ndx ? gl.STENCIL_BUFFER_BIT : gl.DEPTH_BUFFER_BIT;
1326 var point = ndx ? gl.STENCIL_ATTACHMENT : gl.DEPTH_ATTACHMENT;
1328 if (
1329 deMath.binaryOp(
1330 this.m_config.buffers, bit, deMath.BinaryOp.AND
1331 ) == 0
1333 continue;
1335 switch (this.m_config.depthStencilType) {
1336 case gl.TEXTURE_2D:
1337 context.framebufferTexture2D(
1338 gl.FRAMEBUFFER, point, gl.TEXTURE_2D,
1339 fboA.getDepthStencilBuffer(), 0
1341 break;
1342 case gl.RENDERBUFFER:
1343 context.framebufferRenderbuffer(
1344 gl.FRAMEBUFFER, point, gl.RENDERBUFFER,
1345 fboA.getDepthStencilBuffer()
1347 break;
1348 default:
1349 testFailed('Not implemented');
1353 // Setup uniforms
1354 texShader.setUniforms(context, texShaderID);
1356 // Clear color to red and stencil to 1 in fbo B.
1357 context.clearColor(1.0, 0.0, 0.0, 1.0);
1358 context.clearStencil(1);
1359 context.clear(
1360 gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT
1363 context.enable(gl.DEPTH_TEST);
1365 // Render quad to fbo A
1366 context.bindFramebuffer(gl.FRAMEBUFFER, fboA.getFramebuffer());
1367 context.bindTexture(gl.TEXTURE_2D, quadsTex);
1368 rrUtil.drawQuad(
1369 context, texShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1372 if (stencil) {
1373 // Clear subset of stencil buffer to 0 in fbo A
1374 context.enable(gl.SCISSOR_TEST);
1375 context.scissor(10, 10, 12, 25);
1376 context.clearStencil(0);
1377 context.clear(gl.STENCIL_BUFFER_BIT);
1378 context.disable(gl.SCISSOR_TEST);
1381 // Render metaballs to fbo B
1382 context.bindFramebuffer(gl.FRAMEBUFFER, fboB.getFramebuffer());
1383 context.bindTexture(gl.TEXTURE_2D, metaballsTex);
1384 rrUtil.drawQuad(
1385 context, texShaderID, [-1.0, -1.0, -1.0], [1.0, 1.0, 1.0]
1388 context.disable(gl.DEPTH_TEST);
1390 if (stencil) {
1391 // Render quad with stencil mask == 0
1392 context.enable(gl.STENCIL_TEST);
1393 context.stencilFunc(gl.EQUAL, 0, 0xff);
1394 context.useProgram(flatShaderID);
1395 flatShader.setColor(context, flatShaderID, [0.0, 1.0, 0.0, 1.0]);
1396 rrUtil.drawQuad(
1397 context, flatShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1399 context.disable(gl.STENCIL_TEST);
1402 if (this.m_config.colorType == gl.TEXTURE_2D) {
1403 // Render both to screen
1404 context.bindFramebuffer(gl.FRAMEBUFFER, null);
1405 context.viewport(0, 0, context.getWidth(), context.getHeight());
1406 context.bindTexture(gl.TEXTURE_2D, fboA.getColorBuffer());
1407 rrUtil.drawQuad(
1408 context, texShaderID, [-1.0, -1.0, 0.0], [0.0, 1.0, 0.0]
1410 context.bindTexture(gl.TEXTURE_2D, fboB.getColorBuffer());
1411 rrUtil.drawQuad(
1412 context, texShaderID, [0.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1415 dst.readViewport(
1416 context, [0, 0, context.getWidth(), context.getHeight()]
1418 } else {
1419 // Read results from fbo B
1420 es3fFboTestUtil.readPixels(
1421 context, dst, 0, 0, width, height,
1422 gluTextureUtil.mapGLInternalFormat(this.m_config.colorFormat),
1423 [1.0, 1.0, 1.0, 1.0], [0.0, 0.0, 0.0, 0.0]
1429 * @constructor
1430 * @extends {es3fFboRenderTest.FboRenderCase}
1431 * @param {es3fFboRenderTest.FboConfig} config
1433 es3fFboRenderTest.ResizeTest = function(config) {
1434 es3fFboRenderTest.FboRenderCase.call(
1435 this, config.getName(), 'Resize framebuffer', config
1439 es3fFboRenderTest.ResizeTest.prototype =
1440 Object.create(es3fFboRenderTest.FboRenderCase.prototype);
1442 es3fFboRenderTest.ResizeTest.prototype.constructor =
1443 es3fFboRenderTest.ResizeTest;
1446 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
1447 * context
1448 * @param {tcuSurface.Surface} dst
1450 es3fFboRenderTest.ResizeTest.prototype.render = function(context, dst) {
1451 /** @type {tcuTexture.TextureFormat} */
1452 var colorFormat = gluTextureUtil.mapGLInternalFormat(
1453 this.m_config.colorFormat
1455 /** @type {gluShaderUtil.DataType} */
1456 var fboSamplerType = gluTextureUtil.getSampler2DType(colorFormat);
1457 /** @type {gluShaderUtil.DataType} */
1458 var fboOutputType = es3fFboTestUtil.getFragmentOutputType(colorFormat);
1459 /** @type {tcuTextureUtil.TextureFormatInfo} */
1460 var fboRangeInfo = tcuTextureUtil.getTextureFormatInfo(colorFormat);
1461 var fboOutScale = deMath.subtract(
1462 fboRangeInfo.valueMax, fboRangeInfo.valueMin
1464 var fboOutBias = fboRangeInfo.valueMin;
1466 /** @type {es3fFboTestUtil.Texture2DShader} */
1467 var texToFboShader = new es3fFboTestUtil.Texture2DShader(
1468 [gluShaderUtil.DataType.SAMPLER_2D], fboOutputType
1471 /** @type {es3fFboTestUtil.Texture2DShader} */
1472 var texFromFboShader = new es3fFboTestUtil.Texture2DShader(
1473 [fboSamplerType], gluShaderUtil.DataType.FLOAT_VEC4
1476 /** @type {es3fFboTestUtil.FlatColorShader} */
1477 var flatShader = new es3fFboTestUtil.FlatColorShader(fboOutputType);
1478 /** @type {WebGLProgram} */
1479 var texToFboShaderID = context.createProgram(texToFboShader);
1480 /** @type {WebGLProgram} */
1481 var texFromFboShaderID = context.createProgram(texFromFboShader);
1482 /** @type {WebGLProgram} */
1483 var flatShaderID = context.createProgram(flatShader);
1485 var quadsTex = context.createTexture();
1486 var metaballsTex = context.createTexture();
1488 var depth = deMath.binaryOp(
1489 this.m_config.buffers, gl.DEPTH_BUFFER_BIT, deMath.BinaryOp.AND
1490 ) != 0;
1491 var stencil = deMath.binaryOp(
1492 this.m_config.buffers, gl.STENCIL_BUFFER_BIT, deMath.BinaryOp.AND
1493 ) != 0;
1495 var initialWidth = 128;
1496 var initialHeight = 128;
1497 var newWidth = 64;
1498 var newHeight = 32;
1500 texToFboShader.setOutScaleBias(fboOutScale, fboOutBias);
1501 texFromFboShader.setTexScaleBias(
1502 0, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias
1505 es3fFboRenderTest.createQuadsTex2D(
1506 context, quadsTex, gl.RGB, gl.UNSIGNED_BYTE, 64, 64
1508 es3fFboRenderTest.createMetaballsTex2D(
1509 context, metaballsTex, gl.RGB, gl.UNSIGNED_BYTE, 32, 32
1512 /** @type {es3fFboRenderTest.Framebuffer} */
1513 var fbo = new es3fFboRenderTest.Framebuffer(
1514 context, this.m_config, initialWidth, initialHeight
1516 fbo.checkCompleteness();
1518 // Setup shaders
1519 texToFboShader.setUniforms(context, texToFboShaderID);
1520 texFromFboShader.setUniforms(context, texFromFboShaderID);
1521 flatShader.setColor(
1522 context, flatShaderID, deMath.add(
1523 deMath.multiply([0.0, 1.0, 0.0, 1.0], fboOutScale), fboOutBias
1527 // Render quads
1528 context.bindFramebuffer(gl.FRAMEBUFFER, fbo.getFramebuffer());
1529 context.viewport(0, 0, initialWidth, initialHeight);
1530 es3fFboTestUtil.clearColorBuffer(
1531 context, colorFormat, [0.0, 0.0, 0.0, 1.0]
1533 context.clear(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
1534 context.bindTexture(gl.TEXTURE_2D, quadsTex);
1535 rrUtil.drawQuad(
1536 context, texToFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1539 if (fbo.getConfig().colorType == gl.TEXTURE_2D) {
1540 // Render fbo to screen
1541 context.bindFramebuffer(gl.FRAMEBUFFER, null);
1542 context.viewport(0, 0, context.getWidth(), context.getHeight());
1543 context.bindTexture(gl.TEXTURE_2D, fbo.getColorBuffer());
1544 rrUtil.drawQuad(
1545 context, texFromFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1547 // Restore binding
1548 context.bindFramebuffer(gl.FRAMEBUFFER, fbo.getFramebuffer());
1551 // Resize buffers
1552 switch (fbo.getConfig().colorType) {
1553 case gl.TEXTURE_2D:
1554 context.bindTexture(gl.TEXTURE_2D, fbo.getColorBuffer());
1555 context.texImage2DDelegate(
1556 gl.TEXTURE_2D, 0, fbo.getConfig().colorFormat,
1557 newWidth, newHeight
1559 break;
1561 case gl.RENDERBUFFER:
1562 context.bindRenderbuffer(gl.RENDERBUFFER, fbo.getColorBuffer());
1563 context.renderbufferStorage(
1564 gl.RENDERBUFFER, fbo.getConfig().colorFormat,
1565 newWidth, newHeight
1567 break;
1569 default:
1570 throw new Error('Color type unsupported');
1573 if (depth || stencil) {
1574 switch (fbo.getConfig().depthStencilType) {
1575 case gl.TEXTURE_2D:
1576 context.bindTexture(
1577 gl.TEXTURE_2D, fbo.getDepthStencilBuffer()
1579 context.texImage2DDelegate(
1580 gl.TEXTURE_2D, 0, fbo.getConfig().depthStencilFormat,
1581 newWidth, newHeight
1583 break;
1585 case gl.RENDERBUFFER:
1586 context.bindRenderbuffer(
1587 gl.RENDERBUFFER, fbo.getDepthStencilBuffer()
1589 context.renderbufferStorage(
1590 gl.RENDERBUFFER, fbo.getConfig().depthStencilFormat,
1591 newWidth, newHeight
1593 break;
1595 default:
1596 throw new Error('Depth / stencil type unsupported');
1600 // Render to resized fbo
1601 context.viewport(0, 0, newWidth, newHeight);
1602 es3fFboTestUtil.clearColorBuffer(
1603 context, colorFormat, [1.0, 0.0, 0.0, 1.0]
1605 context.clear(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
1607 context.enable(gl.DEPTH_TEST);
1609 context.bindTexture(gl.TEXTURE_2D, metaballsTex);
1610 rrUtil.drawQuad(
1611 context, texToFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1614 context.bindTexture(gl.TEXTURE_2D, quadsTex);
1615 rrUtil.drawQuad(
1616 context, texToFboShaderID, [0.0, 0.0, -1.0], [1.0, 1.0, 1.0]
1619 context.disable(gl.DEPTH_TEST);
1621 if (stencil) {
1622 context.enable(gl.SCISSOR_TEST);
1623 context.clearStencil(1);
1624 context.scissor(10, 10, 5, 15);
1625 context.clear(gl.STENCIL_BUFFER_BIT);
1626 context.disable(gl.SCISSOR_TEST);
1628 context.enable(gl.STENCIL_TEST);
1629 context.stencilFunc(gl.EQUAL, 1, 0xff);
1630 rrUtil.drawQuad(
1631 context, flatShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1633 context.disable(gl.STENCIL_TEST);
1636 if (this.m_config.colorType == gl.TEXTURE_2D) {
1637 context.bindFramebuffer(gl.FRAMEBUFFER, null);
1638 context.viewport(0, 0, context.getWidth(), context.getHeight());
1639 context.bindTexture(gl.TEXTURE_2D, fbo.getColorBuffer());
1640 rrUtil.drawQuad(
1641 context, texFromFboShaderID, [-0.5, -0.5, 0.0], [0.5, 0.5, 0.0]
1643 dst.readViewport(
1644 context, [0, 0, context.getWidth(), context.getHeight()]
1646 } else
1647 es3fFboTestUtil.readPixels(
1648 context, dst, 0, 0, newWidth, newHeight, colorFormat,
1649 fboRangeInfo.lookupScale, fboRangeInfo.lookupBias
1654 * @constructor
1655 * @extends {es3fFboRenderTest.FboRenderCase}
1656 * @param {es3fFboRenderTest.FboConfig} config
1657 * @param {number} buffers
1658 * @param {boolean} rebind
1660 es3fFboRenderTest.RecreateBuffersTest = function(config, buffers, rebind) {
1661 es3fFboRenderTest.FboRenderCase.call(
1662 this, config.getName() +
1663 (rebind ? '' : '_no_rebind'),
1664 'Recreate buffers', config
1666 this.m_buffers = buffers;
1667 this.m_rebind = rebind;
1670 es3fFboRenderTest.RecreateBuffersTest.prototype =
1671 Object.create(es3fFboRenderTest.FboRenderCase.prototype);
1673 es3fFboRenderTest.RecreateBuffersTest.prototype.construtor =
1674 es3fFboRenderTest.RecreateBuffersTest;
1677 * @param {?sglrGLContext.GLContext|sglrReferenceContext.ReferenceContext}
1678 * ctx
1679 * @param {tcuSurface.Surface} dst
1681 es3fFboRenderTest.RecreateBuffersTest.prototype.render = function(
1682 ctx, dst) {
1684 /** @type {tcuTexture.TextureFormat} */
1685 var colorFormat = gluTextureUtil.mapGLInternalFormat(
1686 this.m_config.colorFormat
1688 /** @type {gluShaderUtil.DataType} */
1689 var fboSamplerType = gluTextureUtil.getSampler2DType(colorFormat);
1690 /** @type {gluShaderUtil.DataType} */
1691 var fboOutputType = es3fFboTestUtil.getFragmentOutputType(colorFormat);
1692 /** @type {tcuTextureUtil.TextureFormatInfo} */
1693 var fboRangeInfo = tcuTextureUtil.getTextureFormatInfo(colorFormat);
1694 var fboOutScale = deMath.subtract(
1695 fboRangeInfo.valueMax, fboRangeInfo.valueMin
1697 var fboOutBias = fboRangeInfo.valueMin;
1699 /** @type {es3fFboTestUtil.Texture2DShader} */
1700 var texToFboShader = new es3fFboTestUtil.Texture2DShader(
1701 [gluShaderUtil.DataType.SAMPLER_2D], fboOutputType
1703 /** @type {es3fFboTestUtil.Texture2DShader} */
1704 var texFromFboShader = new es3fFboTestUtil.Texture2DShader(
1705 [fboSamplerType], gluShaderUtil.DataType.FLOAT_VEC4
1708 /** @type {es3fFboTestUtil.FlatColorShader} */
1709 var flatShader = new es3fFboTestUtil.FlatColorShader(fboOutputType);
1710 /** @type {number} */
1711 var texToFboShaderID = ctx.createProgram(texToFboShader);
1712 /** @type {number} */
1713 var texFromFboShaderID = ctx.createProgram(texFromFboShader);
1714 /** @type {number} */
1715 var flatShaderID = ctx.createProgram(flatShader);
1717 var width = 128;
1718 var height = 128;
1719 var metaballsTex = ctx.createTexture();
1720 var quadsTex = ctx.createTexture();
1721 var stencil = deMath.binaryOp(
1722 this.m_config.buffers, gl.STENCIL_BUFFER_BIT, deMath.BinaryOp.AND
1723 ) != 0;
1725 es3fFboRenderTest.createQuadsTex2D(
1726 ctx, quadsTex, gl.RGB, gl.UNSIGNED_BYTE, 64, 64
1728 es3fFboRenderTest.createMetaballsTex2D(
1729 ctx, metaballsTex, gl.RGB, gl.UNSIGNED_BYTE, 64, 64
1732 /** @type {es3fFboRenderTest.Framebuffer} */
1733 var fbo = new es3fFboRenderTest.Framebuffer(
1734 ctx, this.m_config, width, height
1736 fbo.checkCompleteness();
1738 // Setup shaders
1739 texToFboShader.setOutScaleBias(fboOutScale, fboOutBias);
1740 texFromFboShader.setTexScaleBias(
1741 0, fboRangeInfo.lookupScale, fboRangeInfo.lookupBias
1743 texToFboShader.setUniforms(ctx, texToFboShaderID);
1744 texFromFboShader.setUniforms(ctx, texFromFboShaderID);
1745 flatShader.setColor(
1746 ctx, flatShaderID, deMath.add(
1747 deMath.multiply([0.0, 0.0, 1.0, 1.0], fboOutScale
1748 ), fboOutBias)
1751 // Draw scene
1752 ctx.bindFramebuffer(gl.FRAMEBUFFER, fbo.getFramebuffer());
1753 ctx.viewport(0, 0, width, height);
1754 es3fFboTestUtil.clearColorBuffer(
1755 ctx, colorFormat, [1.0, 0.0, 0.0, 1.0]
1757 ctx.clear(gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
1759 ctx.enable(gl.DEPTH_TEST);
1761 ctx.bindTexture(gl.TEXTURE_2D, quadsTex);
1762 rrUtil.drawQuad(
1763 ctx, texToFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1766 ctx.disable(gl.DEPTH_TEST);
1768 if (stencil) {
1769 ctx.enable(gl.SCISSOR_TEST);
1770 ctx.scissor(
1771 Math.floor(width / 4), Math.floor(height / 4),
1772 Math.floor(width / 2), Math.floor(height / 2)
1774 ctx.clearStencil(1);
1775 ctx.clear(gl.STENCIL_BUFFER_BIT);
1776 ctx.disable(gl.SCISSOR_TEST);
1779 // Recreate buffers
1780 if (!this.m_rebind)
1781 ctx.bindFramebuffer(gl.FRAMEBUFFER, null);
1783 assertMsgOptions(
1784 deMath.binaryOp(
1785 this.m_buffers, deMath.binaryOp(
1786 gl.DEPTH_BUFFER_BIT,
1787 gl.STENCIL_BUFFER_BIT,
1788 deMath.BinaryOp.OR
1789 ), deMath.BinaryOp.AND
1790 ) == 0 || deMath.binaryOp(
1791 this.m_buffers, deMath.binaryOp(
1792 gl.DEPTH_BUFFER_BIT,
1793 gl.STENCIL_BUFFER_BIT,
1794 deMath.BinaryOp.OR
1795 ), deMath.BinaryOp.AND
1796 ) == deMath.binaryOp(
1797 this.m_config.buffers, deMath.binaryOp(
1798 gl.DEPTH_BUFFER_BIT,
1799 gl.STENCIL_BUFFER_BIT,
1800 deMath.BinaryOp.OR
1801 ), deMath.BinaryOp.AND
1802 ), 'Depth/stencil buffers are not disabled or not ' +
1803 'equal to the config\'s depth/stencil buffer state',
1804 false, true
1807 // Recreate.
1808 for (var ndx = 0; ndx < 2; ndx++) {
1809 var bit = ndx == 0 ? gl.COLOR_BUFFER_BIT :
1810 (gl.DEPTH_BUFFER_BIT | gl.STENCIL_BUFFER_BIT);
1811 var type = ndx == 0 ? fbo.getConfig().colorType :
1812 fbo.getConfig().depthStencilType;
1813 var format = ndx == 0 ? fbo.getConfig().colorFormat :
1814 fbo.getConfig().depthStencilFormat;
1815 var buf = ndx == 0 ? fbo.getColorBuffer() :
1816 fbo.getDepthStencilBuffer();
1818 if (deMath.binaryOp(this.m_buffers, bit, deMath.BinaryOp.AND) == 0)
1819 continue;
1821 switch (type) {
1822 case gl.TEXTURE_2D:
1823 ctx.deleteTexture(/** @type {WebGLTexture} */ (buf));
1824 buf = ctx.createTexture();
1825 ctx.bindTexture(gl.TEXTURE_2D, buf);
1826 ctx.texImage2DDelegate(
1827 gl.TEXTURE_2D, 0, format, width, height
1829 ctx.texParameteri(
1830 gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST
1832 ctx.texParameteri(
1833 gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST
1835 break;
1837 case gl.RENDERBUFFER:
1838 ctx.deleteRenderbuffer(
1839 /** @type {WebGLRenderbuffer} */ (buf)
1841 buf = ctx.createRenderbuffer();
1842 ctx.bindRenderbuffer(gl.RENDERBUFFER, buf);
1843 ctx.renderbufferStorage(
1844 gl.RENDERBUFFER, format, width, height
1846 break;
1848 default:
1849 throw new Error('Unsupported buffer type');
1852 if (ndx == 0) {
1853 fbo.m_colorBuffer = buf;
1854 } else {
1855 fbo.m_depthStencilBuffer = buf;
1859 // Rebind.
1860 if (this.m_rebind) {
1861 for (var ndx = 0; ndx < 3; ndx++) {
1862 var bit = ndx == 0 ? gl.COLOR_BUFFER_BIT :
1863 ndx == 1 ? gl.DEPTH_BUFFER_BIT :
1864 ndx == 2 ? gl.STENCIL_BUFFER_BIT : 0;
1865 var point = ndx == 0 ? gl.COLOR_ATTACHMENT0 :
1866 ndx == 1 ? gl.DEPTH_ATTACHMENT :
1867 ndx == 2 ? gl.STENCIL_ATTACHMENT : 0;
1868 var type = ndx == 0 ? fbo.getConfig().colorType :
1869 fbo.getConfig().depthStencilType;
1870 var buf = ndx == 0 ? fbo.getColorBuffer() :
1871 fbo.getDepthStencilBuffer();
1873 if (deMath.binaryOp(
1874 this.m_buffers, bit, deMath.BinaryOp.AND) == 0)
1875 continue;
1877 switch (type) {
1878 case gl.TEXTURE_2D:
1879 ctx.framebufferTexture2D(
1880 gl.FRAMEBUFFER, point, gl.TEXTURE_2D, buf, 0
1882 break;
1884 case gl.RENDERBUFFER:
1885 ctx.framebufferRenderbuffer(
1886 gl.FRAMEBUFFER, point, gl.RENDERBUFFER, buf
1888 break;
1890 default:
1891 throw new Error('Invalid buffer type');
1896 if (!this.m_rebind)
1897 ctx.bindFramebuffer(gl.FRAMEBUFFER, fbo.getFramebuffer());
1899 ctx.clearStencil(0);
1901 // \note Clear only buffers that were re-created
1902 ctx.clear(
1903 deMath.binaryOp(
1904 this.m_buffers,
1905 deMath.binaryOp(
1906 gl.DEPTH_BUFFER_BIT,
1907 gl.STENCIL_BUFFER_BIT,
1908 deMath.BinaryOp.OR
1909 ), deMath.BinaryOp.AND
1913 if (deMath.binaryOp(
1914 this.m_buffers, gl.COLOR_BUFFER_BIT, deMath.BinaryOp.AND)) {
1915 // Clearing of integer buffers is undefined
1916 // so do clearing by rendering flat color.
1917 rrUtil.drawQuad(
1918 ctx, flatShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1922 ctx.enable(gl.DEPTH_TEST);
1924 if (stencil) {
1925 // \note Stencil test enabled only if we have stencil buffer
1926 ctx.enable(gl.STENCIL_TEST);
1927 ctx.stencilFunc(gl.EQUAL, 0, 0xff);
1929 ctx.bindTexture(gl.TEXTURE_2D, metaballsTex);
1930 rrUtil.drawQuad(
1931 ctx, texToFboShaderID, [-1.0, -1.0, 1.0], [1.0, 1.0, -1.0]
1933 if (stencil)
1934 ctx.disable(gl.STENCIL_TEST);
1936 ctx.disable(gl.DEPTH_TEST);
1938 if (fbo.getConfig().colorType == gl.TEXTURE_2D) {
1939 // Unbind fbo
1940 ctx.bindFramebuffer(gl.FRAMEBUFFER, null);
1942 // Draw to screen
1943 ctx.bindTexture(gl.TEXTURE_2D, fbo.getColorBuffer());
1944 ctx.viewport(0, 0, ctx.getWidth(), ctx.getHeight());
1945 rrUtil.drawQuad(
1946 ctx, texFromFboShaderID, [-1.0, -1.0, 0.0], [1.0, 1.0, 0.0]
1949 // Read from screen
1950 dst.readViewport(ctx, [0, 0, ctx.getWidth(), ctx.getHeight()]);
1951 } else {
1952 // Read from fbo
1953 es3fFboTestUtil.readPixels(
1954 ctx, dst, 0, 0, width, height, colorFormat,
1955 fboRangeInfo.lookupScale, fboRangeInfo.lookupBias
1960 // FboGroups
1963 * @constructor
1964 * @extends {tcuTestCase.DeqpTest}
1966 es3fFboRenderTest.FboRenderTestGroup = function() {
1967 tcuTestCase.DeqpTest.call(this, 'render', 'Rendering Tests');
1970 es3fFboRenderTest.FboRenderTestGroup.prototype =
1971 Object.create(tcuTestCase.DeqpTest.prototype);
1973 es3fFboRenderTest.FboRenderTestGroup.prototype.constructor =
1974 es3fFboRenderTest.FboRenderTestGroup;
1977 * @enum {number}
1979 var FormatType = {
1980 FLOAT: 0,
1981 INT: 1,
1982 UINT: 2
1985 // Required by specification.
1987 * @typedef {{format: number, type: FormatType}}
1989 var ColorFormatStruct;
1992 * @typedef {{format: number, depth: boolean, stencil: boolean}}
1994 var DepthStencilFormatStruct;
1997 * init
1999 es3fFboRenderTest.FboRenderTestGroup.prototype.init = function() {
2000 var objectTypes = [
2001 gl.TEXTURE_2D,
2002 gl.RENDERBUFFER
2005 /** @type {Array<ColorFormatStruct>} */ var colorFormats = [{
2006 format: gl.RGBA32F, type: FormatType.FLOAT
2008 format: gl.RGBA32I, type: FormatType.INT
2010 format: gl.RGBA32UI, type: FormatType.UINT
2012 format: gl.RGBA16F, type: FormatType.FLOAT
2014 format: gl.RGBA16I, type: FormatType.INT
2016 format: gl.RGBA16UI, type: FormatType.UINT
2017 },/*{
2018 // RGB16F isn't made color-renderable through WebGL's EXT_color_buffer_float
2019 format: gl.RGB16F, type: FormatType.FLOAT
2020 },*/{
2021 format: gl.RGBA8I, type: FormatType.INT
2023 format: gl.RGBA8UI, type: FormatType.UINT
2025 format: gl.RGB10_A2UI, type: FormatType.UINT
2027 format: gl.R11F_G11F_B10F, type: FormatType.FLOAT
2029 format: gl.RG32F, type: FormatType.FLOAT
2031 format: gl.RG32I, type: FormatType.INT
2033 format: gl.RG32UI, type: FormatType.UINT
2035 format: gl.RG16F, type: FormatType.FLOAT
2037 format: gl.RG16I, type: FormatType.INT
2039 format: gl.RG16UI, type: FormatType.UINT
2041 format: gl.RG8, type: FormatType.FLOAT
2043 format: gl.RG8I, type: FormatType.INT
2045 format: gl.RG8UI, type: FormatType.UINT
2047 format: gl.R32F, type: FormatType.FLOAT
2049 format: gl.R32I, type: FormatType.INT
2051 format: gl.R32UI, type: FormatType.UINT
2053 format: gl.R16F, type: FormatType.FLOAT
2055 format: gl.R16I, type: FormatType.INT
2057 format: gl.R16UI, type: FormatType.UINT
2059 format: gl.R8, type: FormatType.FLOAT
2061 format: gl.R8I, type: FormatType.INT
2063 format: gl.R8UI, type: FormatType.UINT
2066 /** @type {Array<DepthStencilFormatStruct>} */
2067 var depthStencilFormats = [{
2068 format: gl.DEPTH_COMPONENT32F, depth: true, stencil: false
2070 format: gl.DEPTH_COMPONENT24, depth: true, stencil: false
2072 format: gl.DEPTH_COMPONENT16, depth: true, stencil: false
2074 format: gl.DEPTH32F_STENCIL8, depth: true, stencil: true
2076 format: gl.DEPTH24_STENCIL8, depth: true, stencil: true
2078 format: gl.STENCIL_INDEX8, depth: false, stencil: true
2081 /** @type {es3fFboRenderTest.FboConfig} */ var config;
2082 var colorType;
2083 var stencilType;
2084 var colorFmt;
2085 var depth;
2086 var stencil;
2087 var depthStencilType;
2088 var depthStencilFormat;
2090 // .stencil_clear
2091 /** @type {tcuTestCase.DeqpTest} */
2092 var stencilClearGroup = new tcuTestCase.DeqpTest(
2093 'stencil_clear', 'Stencil buffer clears'
2096 this.addChild(stencilClearGroup);
2098 for (var fmtNdx = 0; fmtNdx < depthStencilFormats.length; fmtNdx++) {
2099 colorType = gl.TEXTURE_2D;
2100 stencilType = gl.RENDERBUFFER;
2101 colorFmt = gl.RGBA8;
2103 if (!depthStencilFormats[fmtNdx].stencil)
2104 continue;
2106 config = new es3fFboRenderTest.FboConfig(
2107 gl.COLOR_BUFFER_BIT | gl.STENCIL_BUFFER_BIT,
2108 colorType, colorFmt, stencilType,
2109 depthStencilFormats[fmtNdx].format
2111 stencilClearGroup.addChild(
2112 new es3fFboRenderTest.StencilClearsTest(config)
2116 // .shared_colorbuffer_clear
2117 /** @type {tcuTestCase.DeqpTest} */
2118 var sharedColorbufferClearGroup = new tcuTestCase.DeqpTest(
2119 'shared_colorbuffer_clear', 'Shader colorbuffer clears'
2122 this.addChild(sharedColorbufferClearGroup);
2124 for (var colorFmtNdx = 0;
2125 colorFmtNdx < colorFormats.length;
2126 colorFmtNdx++) {
2128 // Clearing of integer buffers is undefined.
2129 if (colorFormats[colorFmtNdx].type == FormatType.INT ||
2130 colorFormats[colorFmtNdx].type == FormatType.UINT)
2131 continue;
2133 for (var typeNdx = 0; typeNdx < objectTypes.length; typeNdx++) {
2134 config = new es3fFboRenderTest.FboConfig(
2135 gl.COLOR_BUFFER_BIT, objectTypes[typeNdx],
2136 colorFormats[colorFmtNdx].format, gl.NONE, gl.NONE
2138 sharedColorbufferClearGroup.addChild(
2139 new es3fFboRenderTest.SharedColorbufferClearsTest(config)
2144 // .shared_colorbuffer
2145 /** @type {Array<tcuTestCase.DeqpTest>} */ var sharedColorbufferGroup = [];
2146 var numSharedColorbufferGroups = 3;
2147 for (var ii = 0; ii < numSharedColorbufferGroups; ++ii) {
2148 sharedColorbufferGroup[ii] = new tcuTestCase.DeqpTest(
2149 'shared_colorbuffer', 'Shared colorbuffer tests'
2151 this.addChild(sharedColorbufferGroup[ii]);
2154 for (var colorFmtNdx = 0; colorFmtNdx < colorFormats.length; colorFmtNdx++) {
2156 depthStencilType = gl.RENDERBUFFER;
2157 depthStencilFormat = gl.DEPTH24_STENCIL8;
2159 // Blending with integer buffers and fp32 targets is not supported.
2160 if (colorFormats[colorFmtNdx].type == FormatType.INT ||
2161 colorFormats[colorFmtNdx].type == FormatType.UINT ||
2162 colorFormats[colorFmtNdx].format == gl.RGBA32F ||
2163 colorFormats[colorFmtNdx].format == gl.RGB32F ||
2164 colorFormats[colorFmtNdx].format == gl.RG32F ||
2165 colorFormats[colorFmtNdx].format == gl.R32F)
2166 continue;
2168 for (var typeNdx = 0; typeNdx < objectTypes.length; typeNdx++) {
2169 /** @type {es3fFboRenderTest.FboConfig} */
2170 var colorOnlyConfig = new es3fFboRenderTest.FboConfig(
2171 gl.COLOR_BUFFER_BIT, objectTypes[typeNdx],
2172 colorFormats[colorFmtNdx].format, gl.NONE, gl.NONE
2174 /** @type {es3fFboRenderTest.FboConfig} */
2175 var colorDepthConfig = new es3fFboRenderTest.FboConfig(
2176 gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT,
2177 objectTypes[typeNdx], colorFormats[colorFmtNdx].format,
2178 depthStencilType, depthStencilFormat
2180 /** @type {es3fFboRenderTest.FboConfig} */
2181 var colorDepthStencilConfig =
2182 new es3fFboRenderTest.FboConfig(
2183 gl.COLOR_BUFFER_BIT |
2184 gl.DEPTH_BUFFER_BIT |
2185 gl.STENCIL_BUFFER_BIT,
2186 objectTypes[typeNdx], colorFormats[colorFmtNdx].format,
2187 depthStencilType, depthStencilFormat
2190 sharedColorbufferGroup[0].addChild(
2191 new es3fFboRenderTest.SharedColorbufferTest(colorOnlyConfig)
2194 sharedColorbufferGroup[1].addChild(
2195 new es3fFboRenderTest.SharedColorbufferTest(
2196 colorDepthConfig
2200 sharedColorbufferGroup[2].addChild(
2201 new es3fFboRenderTest.SharedColorbufferTest(
2202 colorDepthStencilConfig
2208 // .shared_depth_stencil
2209 /** @type {tcuTestCase.DeqpTest} */
2210 var sharedDepthStencilGroup = new tcuTestCase.DeqpTest(
2211 'shared_depth_stencil', 'Shared depth and stencil buffers'
2214 this.addChild(sharedDepthStencilGroup);
2216 for (var fmtNdx = 0; fmtNdx < depthStencilFormats.length; fmtNdx++) {
2217 colorType = gl.TEXTURE_2D;
2218 colorFmt = gl.RGBA8;
2219 depth = depthStencilFormats[fmtNdx].depth;
2220 stencil = depthStencilFormats[fmtNdx].stencil;
2222 if (!depth)
2223 continue; // Not verified.
2225 // Depth and stencil: both rbo and textures
2226 for (var typeNdx = 0; typeNdx < objectTypes.length; typeNdx++) {
2227 config = new es3fFboRenderTest.FboConfig(
2228 gl.COLOR_BUFFER_BIT |
2229 (depth ? gl.DEPTH_BUFFER_BIT : 0) |
2230 (stencil ? gl.STENCIL_BUFFER_BIT : 0),
2231 colorType, colorFmt, objectTypes[typeNdx],
2232 depthStencilFormats[fmtNdx].format
2235 sharedDepthStencilGroup.addChild(
2236 new es3fFboRenderTest.SharedDepthStencilTest(config)
2241 // .resize
2242 /** @type {Array<tcuTestCase.DeqpTest>} */ var resizeGroup = [];
2243 var numResizeGroups = 4;
2244 for (var ii = 0; ii < numResizeGroups; ++ii) {
2245 resizeGroup[ii] = new tcuTestCase.DeqpTest('resize', 'FBO resize tests');
2246 this.addChild(resizeGroup[ii]);
2249 for (var colorFmtNdx = 0; colorFmtNdx < colorFormats.length; colorFmtNdx++) {
2251 var colorFormat = colorFormats[colorFmtNdx].format;
2253 // Color-only.
2254 for (var typeNdx = 0; typeNdx < objectTypes.length; typeNdx++) {
2255 config = new es3fFboRenderTest.FboConfig(
2256 gl.COLOR_BUFFER_BIT, objectTypes[typeNdx],
2257 colorFormat, gl.NONE, gl.NONE
2259 resizeGroup[colorFmtNdx % numResizeGroups].addChild(new es3fFboRenderTest.ResizeTest(config));
2262 // For selected color formats tests depth & stencil variants.
2263 if (colorFormat == gl.RGBA8 || colorFormat == gl.RGBA16F) {
2264 for (var depthStencilFmtNdx = 0; depthStencilFmtNdx < depthStencilFormats.length; depthStencilFmtNdx++) {
2266 colorType = gl.TEXTURE_2D;
2267 depth = depthStencilFormats[depthStencilFmtNdx].depth;
2268 stencil = depthStencilFormats[depthStencilFmtNdx].stencil;
2270 // Depth and stencil: both rbo and textures
2271 for (var typeNdx = 0; typeNdx < objectTypes.length; typeNdx++) {
2273 if (!depth && objectTypes[typeNdx] != gl.RENDERBUFFER)
2274 continue; // Not supported.
2276 config = new es3fFboRenderTest.FboConfig(
2277 gl.COLOR_BUFFER_BIT |
2278 (depth ? gl.DEPTH_BUFFER_BIT : 0) |
2279 (stencil ? gl.STENCIL_BUFFER_BIT : 0),
2280 colorType, colorFormat, objectTypes[typeNdx],
2281 depthStencilFormats[depthStencilFmtNdx].format
2284 resizeGroup[colorFmtNdx % numResizeGroups].addChild(
2285 new es3fFboRenderTest.ResizeTest(config)
2292 // .recreate_color
2293 /** @type {Array<tcuTestCase.DeqpTest>} */ var recreateColorGroup = [];
2294 var numRecreateColorGroups = 7;
2295 for (var ii = 0; ii < numRecreateColorGroups; ++ii) {
2296 recreateColorGroup[ii] = new tcuTestCase.DeqpTest('recreate_color', 'Recreate colorbuffer tests');
2297 this.addChild(recreateColorGroup[ii]);
2300 for (var colorFmtNdx = 0; colorFmtNdx < colorFormats.length; colorFmtNdx++) {
2302 colorFormat = colorFormats[colorFmtNdx].format;
2303 depthStencilFormat = gl.DEPTH24_STENCIL8;
2304 depthStencilType = gl.RENDERBUFFER;
2306 // Color-only.
2307 for (var typeNdx = 0; typeNdx < objectTypes.length; typeNdx++) {
2308 config = new es3fFboRenderTest.FboConfig(
2309 gl.COLOR_BUFFER_BIT |
2310 gl.DEPTH_BUFFER_BIT |
2311 gl.STENCIL_BUFFER_BIT,
2312 objectTypes[typeNdx], colorFormat,
2313 depthStencilType, depthStencilFormat
2316 recreateColorGroup[colorFmtNdx % numRecreateColorGroups].addChild(
2317 new es3fFboRenderTest.RecreateBuffersTest(
2318 config, gl.COLOR_BUFFER_BIT, true /* rebind */
2324 // .recreate_depth_stencil
2325 /** @type {tcuTestCase.DeqpTest} */
2326 var recreateDepthStencilGroup = new tcuTestCase.DeqpTest(
2327 'recreate_depth_stencil', 'Recreate depth and stencil buffers'
2330 this.addChild(recreateDepthStencilGroup);
2332 for (var fmtNdx = 0; fmtNdx < depthStencilFormats.length; fmtNdx++) {
2333 colorType = gl.TEXTURE_2D;
2334 colorFmt = gl.RGBA8;
2335 depth = depthStencilFormats[fmtNdx].depth;
2336 stencil = depthStencilFormats[fmtNdx].stencil;
2338 // Depth and stencil: both rbo and textures
2339 for (var typeNdx = 0; typeNdx < objectTypes.length; typeNdx++) {
2340 if (!depth && objectTypes[typeNdx] != gl.RENDERBUFFER)
2341 continue;
2343 config = new es3fFboRenderTest.FboConfig(
2344 gl.COLOR_BUFFER_BIT |
2345 (depth ? gl.DEPTH_BUFFER_BIT : 0) |
2346 (stencil ? gl.STENCIL_BUFFER_BIT : 0),
2347 colorType, colorFmt, objectTypes[typeNdx],
2348 depthStencilFormats[fmtNdx].format
2351 recreateDepthStencilGroup.addChild(
2352 new es3fFboRenderTest.RecreateBuffersTest(
2353 config,
2354 (depth ? gl.DEPTH_BUFFER_BIT : 0) |
2355 (stencil ? gl.STENCIL_BUFFER_BIT : 0),
2356 true /* rebind */
2364 * Create and execute the test cases
2365 * @param {WebGL2RenderingContext} context
2367 es3fFboRenderTest.run = function(context, range) {
2368 gl = context;
2369 //Set up Test Root parameters
2370 var state = tcuTestCase.runner;
2372 state.setRoot(new es3fFboRenderTest.FboRenderTestGroup());
2374 //Set up name and description of this test series.
2375 setCurrentTestName(state.testCases.fullName());
2376 description(state.testCases.getDescription());
2378 try {
2379 if (range)
2380 state.setRange(range);
2381 //Run test cases
2382 tcuTestCase.runTestCases();
2384 catch (err) {
2385 testFailedOptions('Failed to run tests', false);
2386 tcuTestCase.runner.terminate();