1 /*-------------------------------------------------------------------------
2 * drawElements Quality Program OpenGL (ES) Module
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 * \brief Framebuffer completeness tests.
22 *//*--------------------------------------------------------------------*/
24 #include "glsFboCompletenessTests.hpp"
26 #include "gluStrUtil.hpp"
27 #include "gluObjectWrapper.hpp"
28 #include "deStringUtil.hpp"
35 using glu::RenderContext;
36 using glu::getFramebufferStatusName;
37 using glu::getPixelFormatName;
38 using glu::getTypeName;
39 using glu::getErrorName;
40 using glu::Framebuffer;
42 using tcu::TestCaseGroup;
44 using tcu::MessageBuilder;
49 using namespace deqp::gls::FboUtil;
50 using namespace deqp::gls::FboUtil::config;
51 typedef TestCase::IterateResult IterateResult;
63 // The following extensions are applicable both to ES2 and ES3.
65 // GL_OES_depth_texture
66 static const FormatKey s_oesDepthTextureFormats[] =
68 GLS_UNSIZED_FORMATKEY(GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT),
69 GLS_UNSIZED_FORMATKEY(GL_DEPTH_COMPONENT, GL_UNSIGNED_INT),
72 // GL_OES_packed_depth_stencil
73 static const FormatKey s_oesPackedDepthStencilSizedFormats[] =
78 static const FormatKey s_oesPackedDepthStencilTexFormats[] =
80 GLS_UNSIZED_FORMATKEY(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8),
83 // GL_OES_required_internalformat
84 static const FormatKey s_oesRequiredInternalFormatColorFormats[] =
86 // Same as ES2 RBO formats, plus RGBA8 (even without OES_rgb8_rgba8)
87 GL_RGB5_A1, GL_RGBA8, GL_RGBA4, GL_RGB565
90 static const FormatKey s_oesRequiredInternalFormatDepthFormats[] =
95 // GL_EXT_color_buffer_half_float
96 static const FormatKey s_extColorBufferHalfFloatFormats[] =
98 GL_RGBA16F, GL_RGB16F, GL_RG16F, GL_R16F,
101 static const FormatKey s_oesDepth24SizedFormats[] =
106 static const FormatKey s_oesDepth32SizedFormats[] =
111 static const FormatKey s_oesRgb8Rgba8RboFormats[] =
117 static const FormatKey s_oesRequiredInternalFormatRgb8ColorFormat[] =
122 static const FormatKey s_extTextureType2101010RevFormats[] =
124 GLS_UNSIZED_FORMATKEY(GL_RGBA, GL_UNSIGNED_INT_2_10_10_10_REV),
125 GLS_UNSIZED_FORMATKEY(GL_RGB, GL_UNSIGNED_INT_2_10_10_10_REV),
128 static const FormatKey s_oesRequiredInternalFormat10bitColorFormats[] =
130 GL_RGB10_A2, GL_RGB10,
133 static const FormatKey s_extTextureRgRboFormats[] =
138 static const FormatKey s_extTextureRgTexFormats[] =
140 GLS_UNSIZED_FORMATKEY(GL_RED, GL_UNSIGNED_BYTE),
141 GLS_UNSIZED_FORMATKEY(GL_RG, GL_UNSIGNED_BYTE),
144 static const FormatKey s_extTextureRgFloatTexFormats[] =
146 GLS_UNSIZED_FORMATKEY(GL_RED, GL_FLOAT),
147 GLS_UNSIZED_FORMATKEY(GL_RG, GL_FLOAT),
150 static const FormatKey s_extTextureRgHalfFloatTexFormats[] =
152 GLS_UNSIZED_FORMATKEY(GL_RED, GL_HALF_FLOAT_OES),
153 GLS_UNSIZED_FORMATKEY(GL_RG, GL_HALF_FLOAT_OES),
156 static const FormatKey s_nvPackedFloatRboFormats[] =
161 static const FormatKey s_nvPackedFloatTexFormats[] =
163 GLS_UNSIZED_FORMATKEY(GL_RGB, GL_UNSIGNED_INT_10F_11F_11F_REV),
166 static const FormatKey s_extSrgbRboFormats[] =
171 static const FormatKey s_extSrgbRenderableTexFormats[] =
173 GLS_UNSIZED_FORMATKEY(GL_SRGB_ALPHA, GL_UNSIGNED_BYTE),
176 static const FormatKey s_extSrgbNonRenderableTexFormats[] =
178 GLS_UNSIZED_FORMATKEY(GL_SRGB, GL_UNSIGNED_BYTE),
182 static const FormatKey s_nvSrgbFormatsRboFormats[] =
187 static const FormatKey s_nvSrgbFormatsTextureFormats[] =
191 // The extension does not actually require any unsized format
192 // to be renderable. However, the renderablility of unsized
193 // SRGB,UBYTE internalformat-type pair is implied.
194 GLS_UNSIZED_FORMATKEY(GL_SRGB, GL_UNSIGNED_BYTE),
197 static const FormatKey s_oesRgb8Rgba8TexFormats[] =
199 GLS_UNSIZED_FORMATKEY(GL_RGB, GL_UNSIGNED_BYTE),
200 GLS_UNSIZED_FORMATKEY(GL_RGBA, GL_UNSIGNED_BYTE),
203 static const FormatKey s_extTextureSRGBR8Formats[] =
208 static const FormatKey s_extTextureSRGBRG8Formats[] =
213 static const FormatExtEntry s_esExtFormats[] =
216 "GL_OES_depth_texture",
217 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID,
218 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
221 "GL_OES_packed_depth_stencil",
222 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID,
223 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
226 "GL_OES_packed_depth_stencil GL_OES_required_internalformat",
228 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
231 "GL_OES_packed_depth_stencil",
232 DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID,
233 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats)
235 // \todo [2013-12-10 lauri] Find out if OES_texture_half_float is really a
236 // requirement on ES3 also. Or is color_buffer_half_float applicatble at
237 // all on ES3, since there's also EXT_color_buffer_float?
239 "GL_OES_texture_half_float GL_EXT_color_buffer_half_float",
240 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
241 GLS_ARRAY_RANGE(s_extColorBufferHalfFloatFormats)
244 // OES_required_internalformat doesn't actually specify that these are renderable,
245 // since it was written against ES 1.1.
247 "GL_OES_required_internalformat",
248 // Allow but don't require RGBA8 to be color-renderable if
249 // OES_rgb8_rgba8 is not present.
250 COLOR_RENDERABLE | TEXTURE_VALID,
251 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatColorFormats)
254 "GL_OES_required_internalformat",
255 DEPTH_RENDERABLE | TEXTURE_VALID,
256 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatDepthFormats)
260 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
261 GLS_ARRAY_RANGE(s_extTextureRgRboFormats)
263 // These are not specified to be color-renderable, but the wording is
264 // exactly as ambiguous as the wording in the ES2 spec.
267 COLOR_RENDERABLE | TEXTURE_VALID,
268 GLS_ARRAY_RANGE(s_extTextureRgTexFormats)
271 "GL_EXT_texture_rg GL_OES_texture_float",
272 COLOR_RENDERABLE | TEXTURE_VALID,
273 GLS_ARRAY_RANGE(s_extTextureRgFloatTexFormats)
276 "GL_EXT_texture_rg GL_OES_texture_half_float",
277 COLOR_RENDERABLE | TEXTURE_VALID,
278 GLS_ARRAY_RANGE(s_extTextureRgHalfFloatTexFormats)
282 "GL_NV_packed_float",
283 COLOR_RENDERABLE | TEXTURE_VALID,
284 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
287 "GL_NV_packed_float GL_EXT_color_buffer_half_float",
288 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
289 GLS_ARRAY_RANGE(s_nvPackedFloatRboFormats)
292 // Some Tegra drivers report GL_EXT_packed_float even for ES. Treat it as
293 // a synonym for the NV_ version.
295 "GL_EXT_packed_float",
296 COLOR_RENDERABLE | TEXTURE_VALID,
297 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
300 "GL_EXT_packed_float GL_EXT_color_buffer_half_float",
301 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
302 GLS_ARRAY_RANGE(s_nvPackedFloatRboFormats)
307 COLOR_RENDERABLE | TEXTURE_VALID,
308 GLS_ARRAY_RANGE(s_extSrgbRenderableTexFormats)
313 GLS_ARRAY_RANGE(s_extSrgbNonRenderableTexFormats)
317 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
318 GLS_ARRAY_RANGE(s_extSrgbRboFormats)
321 "GL_NV_sRGB_formats",
322 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
323 GLS_ARRAY_RANGE(s_nvSrgbFormatsRboFormats)
326 "GL_NV_sRGB_formats",
327 REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID,
328 GLS_ARRAY_RANGE(s_nvSrgbFormatsTextureFormats)
331 // In Khronos bug 7333 discussion, the consensus is that these texture
332 // formats, at least, should be color-renderable. Still, that cannot be
333 // found in any extension specs, so only allow it, not require it.
336 COLOR_RENDERABLE | TEXTURE_VALID,
337 GLS_ARRAY_RANGE(s_oesRgb8Rgba8TexFormats)
341 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
342 GLS_ARRAY_RANGE(s_oesRgb8Rgba8RboFormats)
345 "GL_OES_rgb8_rgba8 GL_OES_required_internalformat",
347 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatRgb8ColorFormat)
350 // The depth-renderability of the depth RBO formats is not explicitly
351 // spelled out, but all renderbuffer formats are meant to be renderable.
354 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID,
355 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
358 "GL_OES_depth24 GL_OES_required_internalformat GL_OES_depth_texture",
360 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
365 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID,
366 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
369 "GL_OES_depth32 GL_OES_required_internalformat GL_OES_depth_texture",
371 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
375 "GL_EXT_texture_type_2_10_10_10_REV",
376 TEXTURE_VALID, // explicitly unrenderable
377 GLS_ARRAY_RANGE(s_extTextureType2101010RevFormats)
380 "GL_EXT_texture_type_2_10_10_10_REV GL_OES_required_internalformat",
381 TEXTURE_VALID, // explicitly unrenderable
382 GLS_ARRAY_RANGE(s_oesRequiredInternalFormat10bitColorFormats)
386 "GL_EXT_texture_sRGB_R8",
388 GLS_ARRAY_RANGE(s_extTextureSRGBR8Formats)
391 "GL_EXT_texture_sRGB_RG8",
393 GLS_ARRAY_RANGE(s_extTextureSRGBRG8Formats)
397 Context::Context (TestContext& testCtx,
398 RenderContext& renderCtx,
399 CheckerFactory& factory)
400 : m_testCtx (testCtx)
401 , m_renderCtx (renderCtx)
402 , m_verifier (m_ctxFormats, factory, renderCtx)
403 , m_haveMultiColorAtts (false)
405 FormatExtEntries extRange = GLS_ARRAY_RANGE(s_esExtFormats);
406 addExtFormats(extRange);
409 void Context::addFormats (FormatEntries fmtRange)
411 FboUtil::addFormats(m_coreFormats, fmtRange);
412 FboUtil::addFormats(m_ctxFormats, fmtRange);
413 FboUtil::addFormats(m_allFormats, fmtRange);
416 void Context::addExtFormats (FormatExtEntries extRange)
418 FboUtil::addExtFormats(m_ctxFormats, extRange, &m_renderCtx);
419 FboUtil::addExtFormats(m_allFormats, extRange, DE_NULL);
422 void TestBase::pass (void)
424 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
427 void TestBase::qualityWarning (const char* msg)
429 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, msg);
432 void TestBase::fail (const char* msg)
434 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg);
437 const glw::Functions& gl (const TestBase& test)
439 return test.getContext().getRenderContext().getFunctions();
442 static bool isFormatFeatureSupported (const FormatDB& db, const ImageFormat& format, FormatFlags feature)
444 return db.isKnownFormat(format) && ((db.getFormatInfo(format) & feature) == feature);
447 static void logAffectingExtensions (const char* prefix, const FormatDB& db, const ImageFormat& format, FormatFlags feature, tcu::MessageBuilder& msg)
449 const std::set<std::set<std::string> > rows = db.getFormatFeatureExtensions(format, feature);
451 for (std::set<std::set<std::string> >::const_iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt)
453 const std::set<std::string>& requiredExtensions = *rowIt;
454 std::set<std::string>::const_iterator it = requiredExtensions.begin();
460 while (it != requiredExtensions.end())
462 msg << getExtensionDescription(extName);
464 msg << (it == requiredExtensions.end() ? " and " : ", ");
467 msg << getExtensionDescription(extName) << '\n';
471 static void logFormatInfo (const config::Framebuffer& fbo, const FormatDB& ctxFormats, const FormatDB& coreFormats, const FormatDB& allFormats, tcu::TestLog& log)
476 const FormatFlags flag;
477 } s_renderability[] =
479 { "color-renderable", COLOR_RENDERABLE },
480 { "depth-renderable", DEPTH_RENDERABLE },
481 { "stencil-renderable", STENCIL_RENDERABLE },
484 std::set<ImageFormat> formats;
486 for (config::TextureMap::const_iterator it = fbo.textures.begin(); it != fbo.textures.end(); ++it)
487 formats.insert(it->second->internalFormat);
488 for (config::RboMap::const_iterator it = fbo.rbos.begin(); it != fbo.rbos.end(); ++it)
489 formats.insert(it->second->internalFormat);
491 if (!formats.empty())
493 const tcu::ScopedLogSection supersection(log, "Format", "Format info");
495 for (std::set<ImageFormat>::const_iterator it = formats.begin(); it != formats.end(); ++it)
497 const tcu::ScopedLogSection section(log, "FormatInfo", de::toString(*it));
500 if (isFormatFeatureSupported(ctxFormats, *it, TEXTURE_VALID))
502 tcu::MessageBuilder msg(&log);
503 msg << "* Valid texture format\n";
505 if (isFormatFeatureSupported(coreFormats, *it, TEXTURE_VALID))
506 msg << "\t* core feature";
509 msg << "\t* defined in supported extension(s):\n";
510 logAffectingExtensions("\t\t- ", ctxFormats, *it, TEXTURE_VALID, msg);
513 msg << tcu::TestLog::EndMessage;
517 tcu::MessageBuilder msg(&log);
518 msg << "* Unsupported texture format\n";
520 if (isFormatFeatureSupported(allFormats, *it, TEXTURE_VALID))
522 msg << "\t* requires any of the extensions or combinations:\n";
523 logAffectingExtensions("\t\t- ", allFormats, *it, TEXTURE_VALID, msg);
526 msg << "\t* no extension can make this format valid";
528 msg << tcu::TestLog::EndMessage;
532 if (isFormatFeatureSupported(ctxFormats, *it, RENDERBUFFER_VALID))
534 tcu::MessageBuilder msg(&log);
535 msg << "* Valid renderbuffer format\n";
537 if (isFormatFeatureSupported(coreFormats, *it, RENDERBUFFER_VALID))
538 msg << "\t* core feature";
541 msg << "\t* defined in supported extension(s):\n";
542 logAffectingExtensions("\t\t- ", ctxFormats, *it, RENDERBUFFER_VALID, msg);
545 msg << tcu::TestLog::EndMessage;
549 tcu::MessageBuilder msg(&log);
550 msg << "* Unsupported renderbuffer format\n";
552 if (isFormatFeatureSupported(allFormats, *it, RENDERBUFFER_VALID))
554 msg << "\t* requires any of the extensions or combinations:\n";
555 logAffectingExtensions("\t\t- ", allFormats, *it, RENDERBUFFER_VALID, msg);
558 msg << "\t* no extension can make this format valid";
560 msg << tcu::TestLog::EndMessage;
564 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderability); ++ndx)
566 if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
568 tcu::MessageBuilder msg(&log);
569 msg << "* Format is " << s_renderability[ndx].name << "\n";
571 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
572 msg << "\t* core feature";
575 msg << "\t* defined in supported extension(s):\n";
576 logAffectingExtensions("\t\t- ", ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
579 msg << tcu::TestLog::EndMessage;
581 else if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag))
583 tcu::MessageBuilder msg(&log);
584 msg << "* Format is allowed to be " << s_renderability[ndx].name << " but not required\n";
586 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag))
587 msg << "\t* core feature";
588 else if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
590 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
591 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
594 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
596 msg << tcu::TestLog::EndMessage;
600 tcu::MessageBuilder msg(&log);
601 msg << "* Format is NOT " << s_renderability[ndx].name << "\n";
603 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
605 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
607 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
608 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
612 msg << "\t* extensions that are allowed to make format " << s_renderability[ndx].name << ":\n";
613 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
617 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
619 msg << tcu::TestLog::EndMessage;
626 IterateResult TestBase::iterate (void)
628 glu::Framebuffer fbo (m_ctx.getRenderContext());
629 FboBuilder builder (*fbo, GL_FRAMEBUFFER, gl(*this));
630 const IterateResult ret = build(builder);
631 const ValidStatusCodes reference = m_ctx.getVerifier().validStatusCodes(builder);
632 const GLenum errorCode = builder.getError();
634 logFramebufferConfig(builder, m_testCtx.getLog());
635 logFormatInfo(builder, m_ctx.getCtxFormats(), m_ctx.getCoreFormats(), m_ctx.getAllFormats(), m_testCtx.getLog());
636 reference.logRules(m_testCtx.getLog());
637 reference.logLegalResults(m_testCtx.getLog());
639 // \todo [2013-12-04 lauri] Check if drawing operations succeed.
641 if (errorCode != GL_NO_ERROR)
645 << "Received " << glu::getErrorStr(errorCode) << " (during FBO initialization)."
646 << TestLog::EndMessage;
648 if (reference.isErrorCodeValid(errorCode))
650 else if (reference.isErrorCodeRequired(GL_NO_ERROR))
651 fail(("Expected no error but got " + de::toString(glu::getErrorStr(errorCode))).c_str());
653 fail("Got wrong error code");
657 const GLenum fboStatus = gl(*this).checkFramebufferStatus(GL_FRAMEBUFFER);
658 const bool validStatus = reference.isFBOStatusValid(fboStatus);
662 << "Received " << glu::getFramebufferStatusStr(fboStatus) << "."
663 << TestLog::EndMessage;
667 if (fboStatus == GL_FRAMEBUFFER_COMPLETE)
668 fail("Framebuffer checked as complete, expected incomplete");
669 else if (reference.isFBOStatusRequired(GL_FRAMEBUFFER_COMPLETE))
670 fail("Framebuffer checked is incomplete, expected complete");
672 // An incomplete status is allowed, but not _this_ incomplete status.
673 fail("Framebuffer checked as incomplete, but with wrong status");
675 else if (fboStatus != GL_FRAMEBUFFER_COMPLETE && reference.isFBOStatusValid(GL_FRAMEBUFFER_COMPLETE))
676 qualityWarning("Framebuffer object could have checked as complete but did not.");
684 IterateResult TestBase::build (FboBuilder& builder)
690 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
692 if (bufType == GL_NONE)
694 return ImageFormat::none();
697 // Prefer a standard format, if there is one, but if not, use a format
698 // provided by an extension.
699 Formats formats = m_ctx.getCoreFormats().getFormats(formatFlag(attPoint) |
700 formatFlag(bufType));
701 Formats::const_iterator it = formats.begin();
702 if (it == formats.end())
704 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
705 formatFlag(bufType));
706 it = formats.begin();
708 if (it == formats.end())
709 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
710 "", __FILE__, __LINE__);
714 Image* makeImage (GLenum bufType, ImageFormat format,
715 GLsizei width, GLsizei height, FboBuilder& builder)
717 Image* image = DE_NULL;
722 case GL_RENDERBUFFER:
723 image = &builder.makeConfig<Renderbuffer>();
726 image = &builder.makeConfig<Texture2D>();
729 DE_ASSERT(!"Impossible case");
731 image->internalFormat = format;
732 image->width = width;
733 image->height = height;
737 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
738 GLsizei width, GLsizei height, FboBuilder& builder)
740 Image* const imgCfg = makeImage (bufType, format, width, height, builder);
741 Attachment* att = DE_NULL;
744 if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
746 img = builder.glCreateRbo(*rboCfg);
747 att = &builder.makeConfig<RenderbufferAttachment>();
749 else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
751 img = builder.glCreateTexture(*texCfg);
752 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
753 texAtt.texTarget = GL_TEXTURE_2D;
758 DE_ASSERT(imgCfg == DE_NULL);
761 att->imageName = img;
765 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
766 GLsizei width, GLsizei height, FboBuilder& builder)
768 ImageFormat imgFmt = format;
769 if (imgFmt.format == GL_NONE)
770 imgFmt = getDefaultFormat(target, bufType);
772 const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
773 builder.glAttach(target, att);
776 static string formatName (ImageFormat format)
778 const string s = getPixelFormatName(format.format);
779 const string fmtStr = toLower(s.substr(3));
781 if (format.unsizedType != GL_NONE)
783 const string typeStr = getTypeName(format.unsizedType);
784 return fmtStr + "_" + toLower(typeStr.substr(3));
790 static string formatDesc (ImageFormat format)
792 const string fmtStr = getPixelFormatName(format.format);
794 if (format.unsizedType != GL_NONE)
796 const string typeStr = getTypeName(format.unsizedType);
797 return fmtStr + " with type " + typeStr;
803 struct RenderableParams
808 static string getName (const RenderableParams& params)
810 return formatName(params.format);
812 static string getDescription (const RenderableParams& params)
814 return formatDesc(params.format);
818 class RenderableTest : public ParamTest<RenderableParams>
821 RenderableTest (Context& group, const Params& params)
822 : ParamTest<RenderableParams> (group, params) {}
823 IterateResult build (FboBuilder& builder);
826 IterateResult RenderableTest::build (FboBuilder& builder)
828 attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
832 string attTypeName (GLenum bufType)
838 case GL_RENDERBUFFER:
843 DE_ASSERT(!"Impossible case");
845 return ""; // Shut up compiler
848 struct AttachmentParams
855 static string getName (const AttachmentParams& params);
856 static string getDescription (const AttachmentParams& params)
858 return getName(params);
862 string AttachmentParams::getName (const AttachmentParams& params)
864 return (attTypeName(params.color0Kind) + "_" +
865 attTypeName(params.colornKind) + "_" +
866 attTypeName(params.depthKind) + "_" +
867 attTypeName(params.stencilKind));
870 //! Test for combinations of different kinds of attachments
871 class AttachmentTest : public ParamTest<AttachmentParams>
874 AttachmentTest (Context& group, Params& params)
875 : ParamTest<AttachmentParams> (group, params) {}
878 IterateResult build (FboBuilder& builder);
879 void makeDepthAndStencil (FboBuilder& builder);
883 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
885 if (m_params.stencilKind == m_params.depthKind)
887 // If there is a common stencil+depth -format, try to use a common
888 // image for both attachments.
889 const FormatFlags flags =
890 DEPTH_RENDERABLE | STENCIL_RENDERABLE | formatFlag(m_params.stencilKind);
891 const Formats& formats = m_ctx.getCoreFormats().getFormats(flags);
892 Formats::const_iterator it = formats.begin();
893 if (it != formats.end())
895 const ImageFormat format = *it;
896 Attachment* att = makeAttachment(m_params.depthKind, format, 64, 64, builder);
897 builder.glAttach(GL_DEPTH_ATTACHMENT, att);
898 builder.glAttach(GL_STENCIL_ATTACHMENT, att);
902 // Either the kinds were separate, or a suitable format was not found.
903 // Create separate images.
904 attachTargetToNew(GL_STENCIL_ATTACHMENT, m_params.stencilKind, ImageFormat::none(),
906 attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
910 IterateResult AttachmentTest::build (FboBuilder& builder)
912 attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
915 if (m_params.colornKind != GL_NONE)
917 TCU_CHECK_AND_THROW(NotSupportedError, m_ctx.haveMultiColorAtts(),
918 "Multiple attachments not supported");
919 GLint maxAttachments = 1;
920 gl(*this).getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments);
922 gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
924 for (int i = 1; i < maxAttachments; i++)
926 attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
927 ImageFormat::none(), 64, 64, builder);
931 makeDepthAndStencil(builder);
936 class EmptyImageTest : public TestBase
939 EmptyImageTest (Context& group,
940 const char* name, const char* desc)
941 : TestBase (group, name, desc) {}
943 IterateResult build (FboBuilder& builder);
946 IterateResult EmptyImageTest::build (FboBuilder& builder)
948 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
954 class DistinctSizeTest : public TestBase
957 DistinctSizeTest (Context& group,
958 const char* name, const char* desc)
959 : TestBase (group, name, desc) {}
961 IterateResult build (FboBuilder& builder);
964 IterateResult DistinctSizeTest::build (FboBuilder& builder)
966 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
968 attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
973 TestCaseGroup* Context::createRenderableTests (void)
975 TestCaseGroup* const renderableTests = new TestCaseGroup(
976 m_testCtx, "renderable", "Tests for support of renderable image formats");
978 TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
979 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
981 TestCaseGroup* const texRenderableTests = new TestCaseGroup(
982 m_testCtx, "texture", "Tests for texture formats");
984 static const struct AttPoint {
990 { GL_COLOR_ATTACHMENT0, "color0", "Tests for color attachments" },
991 { GL_STENCIL_ATTACHMENT, "stencil", "Tests for stencil attachments" },
992 { GL_DEPTH_ATTACHMENT, "depth", "Tests for depth attachments" },
995 // At each attachment point, iterate through all the possible formats to
996 // detect both false positives and false negatives.
997 const Formats rboFmts = m_allFormats.getFormats(ANY_FORMAT);
998 const Formats texFmts = m_allFormats.getFormats(ANY_FORMAT);
1000 for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
1002 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1003 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1005 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
1007 const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
1008 rbAttTests->addChild(new RenderableTest(*this, params));
1010 rbRenderableTests->addChild(rbAttTests);
1012 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
1014 const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
1015 texAttTests->addChild(new RenderableTest(*this, params));
1017 texRenderableTests->addChild(texAttTests);
1019 renderableTests->addChild(rbRenderableTests);
1020 renderableTests->addChild(texRenderableTests);
1022 return renderableTests;
1025 TestCaseGroup* Context::createAttachmentTests (void)
1027 TestCaseGroup* const attCombTests = new TestCaseGroup(
1028 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
1030 static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
1031 static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
1033 for (const GLenum* col0 = s_kinds.begin(); col0 != s_kinds.end(); ++col0)
1034 for (const GLenum* coln = s_kinds.begin(); coln != s_kinds.end(); ++coln)
1035 for (const GLenum* dep = s_kinds.begin(); dep != s_kinds.end(); ++dep)
1036 for (const GLenum* stc = s_kinds.begin(); stc != s_kinds.end(); ++stc)
1038 AttachmentParams params = { *col0, *coln, *dep, *stc };
1039 attCombTests->addChild(new AttachmentTest(*this, params));
1042 return attCombTests;
1045 TestCaseGroup* Context::createSizeTests (void)
1047 TestCaseGroup* const sizeTests = new TestCaseGroup(
1048 m_testCtx, "size", "Tests for attachment sizes");
1049 sizeTests->addChild(new EmptyImageTest(
1051 "Test for zero-sized image attachment"));
1052 sizeTests->addChild(new DistinctSizeTest(
1054 "Test for attachments with different sizes"));