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::getTextureFormatName;
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 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
218 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
221 "GL_OES_packed_depth_stencil",
222 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID),
223 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
226 "GL_OES_packed_depth_stencil GL_OES_required_internalformat",
227 (deUint32)TEXTURE_VALID,
228 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
231 "GL_OES_packed_depth_stencil GL_OES_depth_texture",
232 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
233 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats)
235 // The ANGLE extension incorporates GL_OES_depth_texture/GL_OES_packed_depth_stencil.
237 "GL_ANGLE_depth_texture",
238 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
239 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
242 "GL_OES_packed_depth_stencil GL_ANGLE_depth_texture",
243 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
244 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats),
246 // \todo [2013-12-10 lauri] Find out if OES_texture_half_float is really a
247 // requirement on ES3 also. Or is color_buffer_half_float applicatble at
248 // all on ES3, since there's also EXT_color_buffer_float?
250 "GL_OES_texture_half_float GL_EXT_color_buffer_half_float",
251 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
252 GLS_ARRAY_RANGE(s_extColorBufferHalfFloatFormats)
255 // OES_required_internalformat doesn't actually specify that these are renderable,
256 // since it was written against ES 1.1.
258 "GL_OES_required_internalformat",
259 // Allow but don't require RGBA8 to be color-renderable if
260 // OES_rgb8_rgba8 is not present.
261 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
262 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatColorFormats)
265 "GL_OES_required_internalformat",
266 (deUint32)(DEPTH_RENDERABLE | TEXTURE_VALID),
267 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatDepthFormats)
271 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
272 GLS_ARRAY_RANGE(s_extTextureRgRboFormats)
274 // These are not specified to be color-renderable, but the wording is
275 // exactly as ambiguous as the wording in the ES2 spec.
278 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
279 GLS_ARRAY_RANGE(s_extTextureRgTexFormats)
282 "GL_EXT_texture_rg GL_OES_texture_float",
283 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
284 GLS_ARRAY_RANGE(s_extTextureRgFloatTexFormats)
287 "GL_EXT_texture_rg GL_OES_texture_half_float",
288 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
289 GLS_ARRAY_RANGE(s_extTextureRgHalfFloatTexFormats)
293 "GL_NV_packed_float",
294 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
295 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
298 "GL_NV_packed_float GL_EXT_color_buffer_half_float",
299 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
300 GLS_ARRAY_RANGE(s_nvPackedFloatRboFormats)
305 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
306 GLS_ARRAY_RANGE(s_extSrgbRenderableTexFormats)
310 (deUint32)TEXTURE_VALID,
311 GLS_ARRAY_RANGE(s_extSrgbNonRenderableTexFormats)
315 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
316 GLS_ARRAY_RANGE(s_extSrgbRboFormats)
319 "GL_NV_sRGB_formats",
320 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
321 GLS_ARRAY_RANGE(s_nvSrgbFormatsRboFormats)
324 "GL_NV_sRGB_formats",
325 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID),
326 GLS_ARRAY_RANGE(s_nvSrgbFormatsTextureFormats)
329 // In Khronos bug 7333 discussion, the consensus is that these texture
330 // formats, at least, should be color-renderable. Still, that cannot be
331 // found in any extension specs, so only allow it, not require it.
334 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
335 GLS_ARRAY_RANGE(s_oesRgb8Rgba8TexFormats)
339 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
340 GLS_ARRAY_RANGE(s_oesRgb8Rgba8RboFormats)
343 "GL_OES_rgb8_rgba8 GL_OES_required_internalformat",
344 (deUint32)TEXTURE_VALID,
345 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatRgb8ColorFormat)
348 // The depth-renderability of the depth RBO formats is not explicitly
349 // spelled out, but all renderbuffer formats are meant to be renderable.
352 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
353 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
356 "GL_OES_depth24 GL_OES_required_internalformat GL_OES_depth_texture",
357 (deUint32)TEXTURE_VALID,
358 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
363 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
364 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
367 "GL_OES_depth32 GL_OES_required_internalformat GL_OES_depth_texture",
368 (deUint32)TEXTURE_VALID,
369 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
373 "GL_EXT_texture_type_2_10_10_10_REV",
374 (deUint32)TEXTURE_VALID, // explicitly unrenderable
375 GLS_ARRAY_RANGE(s_extTextureType2101010RevFormats)
378 "GL_EXT_texture_type_2_10_10_10_REV GL_OES_required_internalformat",
379 (deUint32)TEXTURE_VALID, // explicitly unrenderable
380 GLS_ARRAY_RANGE(s_oesRequiredInternalFormat10bitColorFormats)
384 "GL_EXT_texture_sRGB_R8",
385 (deUint32)TEXTURE_VALID,
386 GLS_ARRAY_RANGE(s_extTextureSRGBR8Formats)
389 "GL_EXT_texture_sRGB_RG8",
390 (deUint32)TEXTURE_VALID,
391 GLS_ARRAY_RANGE(s_extTextureSRGBRG8Formats)
395 Context::Context (TestContext& testCtx,
396 RenderContext& renderCtx,
397 CheckerFactory& factory)
398 : m_testCtx (testCtx)
399 , m_renderCtx (renderCtx)
400 , m_verifier (m_ctxFormats, factory, renderCtx)
401 , m_haveMultiColorAtts (false)
403 FormatExtEntries extRange = GLS_ARRAY_RANGE(s_esExtFormats);
404 addExtFormats(extRange);
407 void Context::addFormats (FormatEntries fmtRange)
409 FboUtil::addFormats(m_coreFormats, fmtRange);
410 FboUtil::addFormats(m_ctxFormats, fmtRange);
411 FboUtil::addFormats(m_allFormats, fmtRange);
414 void Context::addExtFormats (FormatExtEntries extRange)
416 FboUtil::addExtFormats(m_ctxFormats, extRange, &m_renderCtx);
417 FboUtil::addExtFormats(m_allFormats, extRange, DE_NULL);
420 void TestBase::pass (void)
422 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
425 void TestBase::qualityWarning (const char* msg)
427 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, msg);
430 void TestBase::fail (const char* msg)
432 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg);
435 const glw::Functions& gl (const TestBase& test)
437 return test.getContext().getRenderContext().getFunctions();
440 static bool isFormatFeatureSupported (const FormatDB& db, const ImageFormat& format, FormatFlags feature)
442 return db.isKnownFormat(format) && ((db.getFormatInfo(format) & feature) == feature);
445 static void logAffectingExtensions (const char* prefix, const FormatDB& db, const ImageFormat& format, FormatFlags feature, tcu::MessageBuilder& msg)
447 const std::set<std::set<std::string> > rows = db.getFormatFeatureExtensions(format, feature);
449 for (std::set<std::set<std::string> >::const_iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt)
451 const std::set<std::string>& requiredExtensions = *rowIt;
452 std::set<std::string>::const_iterator it = requiredExtensions.begin();
458 while (it != requiredExtensions.end())
460 msg << getExtensionDescription(extName);
462 msg << (it == requiredExtensions.end() ? " and " : ", ");
465 msg << getExtensionDescription(extName) << '\n';
469 static void logFormatInfo (const config::Framebuffer& fbo, const FormatDB& ctxFormats, const FormatDB& coreFormats, const FormatDB& allFormats, tcu::TestLog& log)
474 const FormatFlags flag;
475 } s_renderability[] =
477 { "color-renderable", COLOR_RENDERABLE },
478 { "depth-renderable", DEPTH_RENDERABLE },
479 { "stencil-renderable", STENCIL_RENDERABLE },
482 std::set<ImageFormat> formats;
484 for (config::TextureMap::const_iterator it = fbo.textures.begin(); it != fbo.textures.end(); ++it)
485 formats.insert(it->second->internalFormat);
486 for (config::RboMap::const_iterator it = fbo.rbos.begin(); it != fbo.rbos.end(); ++it)
487 formats.insert(it->second->internalFormat);
489 if (!formats.empty())
491 const tcu::ScopedLogSection supersection(log, "Format", "Format info");
493 for (std::set<ImageFormat>::const_iterator it = formats.begin(); it != formats.end(); ++it)
495 const tcu::ScopedLogSection section(log, "FormatInfo", de::toString(*it));
498 if (isFormatFeatureSupported(ctxFormats, *it, TEXTURE_VALID))
500 tcu::MessageBuilder msg(&log);
501 msg << "* Valid texture format\n";
503 if (isFormatFeatureSupported(coreFormats, *it, TEXTURE_VALID))
504 msg << "\t* core feature";
507 msg << "\t* defined in supported extension(s):\n";
508 logAffectingExtensions("\t\t- ", ctxFormats, *it, TEXTURE_VALID, msg);
511 msg << tcu::TestLog::EndMessage;
515 tcu::MessageBuilder msg(&log);
516 msg << "* Unsupported texture format\n";
518 if (isFormatFeatureSupported(allFormats, *it, TEXTURE_VALID))
520 msg << "\t* requires any of the extensions or combinations:\n";
521 logAffectingExtensions("\t\t- ", allFormats, *it, TEXTURE_VALID, msg);
524 msg << "\t* no extension can make this format valid";
526 msg << tcu::TestLog::EndMessage;
530 if (isFormatFeatureSupported(ctxFormats, *it, RENDERBUFFER_VALID))
532 tcu::MessageBuilder msg(&log);
533 msg << "* Valid renderbuffer format\n";
535 if (isFormatFeatureSupported(coreFormats, *it, RENDERBUFFER_VALID))
536 msg << "\t* core feature";
539 msg << "\t* defined in supported extension(s):\n";
540 logAffectingExtensions("\t\t- ", ctxFormats, *it, RENDERBUFFER_VALID, msg);
543 msg << tcu::TestLog::EndMessage;
547 tcu::MessageBuilder msg(&log);
548 msg << "* Unsupported renderbuffer format\n";
550 if (isFormatFeatureSupported(allFormats, *it, RENDERBUFFER_VALID))
552 msg << "\t* requires any of the extensions or combinations:\n";
553 logAffectingExtensions("\t\t- ", allFormats, *it, RENDERBUFFER_VALID, msg);
556 msg << "\t* no extension can make this format valid";
558 msg << tcu::TestLog::EndMessage;
562 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderability); ++ndx)
564 if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
566 tcu::MessageBuilder msg(&log);
567 msg << "* Format is " << s_renderability[ndx].name << "\n";
569 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
570 msg << "\t* core feature";
573 msg << "\t* defined in supported extension(s):\n";
574 logAffectingExtensions("\t\t- ", ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
577 msg << tcu::TestLog::EndMessage;
579 else if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag))
581 tcu::MessageBuilder msg(&log);
582 msg << "* Format is allowed to be " << s_renderability[ndx].name << " but not required\n";
584 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag))
585 msg << "\t* core feature";
586 else if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
588 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
589 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
592 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
594 msg << tcu::TestLog::EndMessage;
598 tcu::MessageBuilder msg(&log);
599 msg << "* Format is NOT " << s_renderability[ndx].name << "\n";
601 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
603 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
605 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
606 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
610 msg << "\t* extensions that are allowed to make format " << s_renderability[ndx].name << ":\n";
611 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
615 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
617 msg << tcu::TestLog::EndMessage;
624 IterateResult TestBase::iterate (void)
626 glu::Framebuffer fbo (m_ctx.getRenderContext());
627 FboBuilder builder (*fbo, GL_FRAMEBUFFER, gl(*this));
628 const IterateResult ret = build(builder);
629 const ValidStatusCodes reference = m_ctx.getVerifier().validStatusCodes(builder);
630 const GLenum errorCode = builder.getError();
632 logFramebufferConfig(builder, m_testCtx.getLog());
633 logFormatInfo(builder, m_ctx.getCtxFormats(), m_ctx.getCoreFormats(), m_ctx.getAllFormats(), m_testCtx.getLog());
634 reference.logRules(m_testCtx.getLog());
635 reference.logLegalResults(m_testCtx.getLog());
637 // \todo [2013-12-04 lauri] Check if drawing operations succeed.
639 if (errorCode != GL_NO_ERROR)
643 << "Received " << glu::getErrorStr(errorCode) << " (during FBO initialization)."
644 << TestLog::EndMessage;
646 if (reference.isErrorCodeValid(errorCode))
648 else if (reference.isErrorCodeRequired(GL_NO_ERROR))
649 fail(("Expected no error but got " + de::toString(glu::getErrorStr(errorCode))).c_str());
651 fail("Got wrong error code");
655 const GLenum fboStatus = gl(*this).checkFramebufferStatus(GL_FRAMEBUFFER);
656 const bool validStatus = reference.isFBOStatusValid(fboStatus);
660 << "Received " << glu::getFramebufferStatusStr(fboStatus) << "."
661 << TestLog::EndMessage;
665 if (fboStatus == GL_FRAMEBUFFER_COMPLETE)
666 fail("Framebuffer checked as complete, expected incomplete");
667 else if (reference.isFBOStatusRequired(GL_FRAMEBUFFER_COMPLETE))
668 fail("Framebuffer checked is incomplete, expected complete");
670 // An incomplete status is allowed, but not _this_ incomplete status.
671 fail("Framebuffer checked as incomplete, but with wrong status");
673 else if (fboStatus != GL_FRAMEBUFFER_COMPLETE && reference.isFBOStatusValid(GL_FRAMEBUFFER_COMPLETE))
674 qualityWarning("Framebuffer object could have checked as complete but did not.");
682 IterateResult TestBase::build (FboBuilder& builder)
688 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
690 if (bufType == GL_NONE)
692 return ImageFormat::none();
695 // Prefer a standard format, if there is one, but if not, use a format
696 // provided by an extension.
697 Formats formats = m_ctx.getCoreFormats().getFormats(formatFlag(attPoint) |
698 formatFlag(bufType));
699 Formats::const_iterator it = formats.begin();
700 if (it == formats.end())
702 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
703 formatFlag(bufType));
704 it = formats.begin();
706 if (it == formats.end())
707 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
708 "", __FILE__, __LINE__);
712 Image* makeImage (GLenum bufType, ImageFormat format,
713 GLsizei width, GLsizei height, FboBuilder& builder)
715 Image* image = DE_NULL;
720 case GL_RENDERBUFFER:
721 image = &builder.makeConfig<Renderbuffer>();
724 image = &builder.makeConfig<Texture2D>();
727 DE_FATAL("Impossible case");
729 image->internalFormat = format;
730 image->width = width;
731 image->height = height;
735 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
736 GLsizei width, GLsizei height, FboBuilder& builder)
738 Image* const imgCfg = makeImage (bufType, format, width, height, builder);
739 Attachment* att = DE_NULL;
742 if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
744 img = builder.glCreateRbo(*rboCfg);
745 att = &builder.makeConfig<RenderbufferAttachment>();
747 else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
749 img = builder.glCreateTexture(*texCfg);
750 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
751 texAtt.texTarget = GL_TEXTURE_2D;
756 DE_ASSERT(imgCfg == DE_NULL);
759 att->imageName = img;
763 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
764 GLsizei width, GLsizei height, FboBuilder& builder)
766 ImageFormat imgFmt = format;
767 if (imgFmt.format == GL_NONE)
768 imgFmt = getDefaultFormat(target, bufType);
770 const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
771 builder.glAttach(target, att);
774 static string formatName (ImageFormat format)
776 const string s = getTextureFormatName(format.format);
777 const string fmtStr = toLower(s.substr(3));
779 if (format.unsizedType != GL_NONE)
781 const string typeStr = getTypeName(format.unsizedType);
782 return fmtStr + "_" + toLower(typeStr.substr(3));
788 static string formatDesc (ImageFormat format)
790 const string fmtStr = getTextureFormatName(format.format);
792 if (format.unsizedType != GL_NONE)
794 const string typeStr = getTypeName(format.unsizedType);
795 return fmtStr + " with type " + typeStr;
801 struct RenderableParams
806 static string getName (const RenderableParams& params)
808 return formatName(params.format);
810 static string getDescription (const RenderableParams& params)
812 return formatDesc(params.format);
816 class RenderableTest : public ParamTest<RenderableParams>
819 RenderableTest (Context& group, const Params& params)
820 : ParamTest<RenderableParams> (group, params) {}
821 IterateResult build (FboBuilder& builder);
824 IterateResult RenderableTest::build (FboBuilder& builder)
826 attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
830 string attTypeName (GLenum bufType)
836 case GL_RENDERBUFFER:
841 DE_FATAL("Impossible case");
843 return ""; // Shut up compiler
846 struct AttachmentParams
853 static string getName (const AttachmentParams& params);
854 static string getDescription (const AttachmentParams& params)
856 return getName(params);
860 string AttachmentParams::getName (const AttachmentParams& params)
862 return (attTypeName(params.color0Kind) + "_" +
863 attTypeName(params.colornKind) + "_" +
864 attTypeName(params.depthKind) + "_" +
865 attTypeName(params.stencilKind));
868 //! Test for combinations of different kinds of attachments
869 class AttachmentTest : public ParamTest<AttachmentParams>
872 AttachmentTest (Context& group, Params& params)
873 : ParamTest<AttachmentParams> (group, params) {}
876 IterateResult build (FboBuilder& builder);
877 void makeDepthAndStencil (FboBuilder& builder);
881 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
883 if (m_params.stencilKind == m_params.depthKind)
885 // If there is a common stencil+depth -format, try to use a common
886 // image for both attachments.
887 const FormatFlags flags =
888 DEPTH_RENDERABLE | STENCIL_RENDERABLE | formatFlag(m_params.stencilKind);
889 const Formats& formats = m_ctx.getCoreFormats().getFormats(flags);
890 Formats::const_iterator it = formats.begin();
891 if (it != formats.end())
893 const ImageFormat format = *it;
894 Attachment* att = makeAttachment(m_params.depthKind, format, 64, 64, builder);
895 builder.glAttach(GL_DEPTH_ATTACHMENT, att);
896 builder.glAttach(GL_STENCIL_ATTACHMENT, att);
900 // Either the kinds were separate, or a suitable format was not found.
901 // Create separate images.
902 attachTargetToNew(GL_STENCIL_ATTACHMENT, m_params.stencilKind, ImageFormat::none(),
904 attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
908 IterateResult AttachmentTest::build (FboBuilder& builder)
910 attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
913 if (m_params.colornKind != GL_NONE)
915 TCU_CHECK_AND_THROW(NotSupportedError, m_ctx.haveMultiColorAtts(),
916 "Multiple attachments not supported");
917 GLint maxAttachments = 1;
918 gl(*this).getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments);
920 gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
922 for (int i = 1; i < maxAttachments; i++)
924 attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
925 ImageFormat::none(), 64, 64, builder);
929 makeDepthAndStencil(builder);
934 class EmptyImageTest : public TestBase
937 EmptyImageTest (Context& group,
938 const char* name, const char* desc)
939 : TestBase (group, name, desc) {}
941 IterateResult build (FboBuilder& builder);
944 IterateResult EmptyImageTest::build (FboBuilder& builder)
946 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
952 class DistinctSizeTest : public TestBase
955 DistinctSizeTest (Context& group,
956 const char* name, const char* desc)
957 : TestBase (group, name, desc) {}
959 IterateResult build (FboBuilder& builder);
962 IterateResult DistinctSizeTest::build (FboBuilder& builder)
964 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
966 attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
971 TestCaseGroup* Context::createRenderableTests (void)
973 TestCaseGroup* const renderableTests = new TestCaseGroup(
974 m_testCtx, "renderable", "Tests for support of renderable image formats");
976 TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
977 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
979 TestCaseGroup* const texRenderableTests = new TestCaseGroup(
980 m_testCtx, "texture", "Tests for texture formats");
982 static const struct AttPoint {
988 { GL_COLOR_ATTACHMENT0, "color0", "Tests for color attachments" },
989 { GL_STENCIL_ATTACHMENT, "stencil", "Tests for stencil attachments" },
990 { GL_DEPTH_ATTACHMENT, "depth", "Tests for depth attachments" },
993 // At each attachment point, iterate through all the possible formats to
994 // detect both false positives and false negatives.
995 const Formats rboFmts = m_allFormats.getFormats(ANY_FORMAT);
996 const Formats texFmts = m_allFormats.getFormats(ANY_FORMAT);
998 for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
1000 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1001 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1003 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
1005 const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
1006 rbAttTests->addChild(new RenderableTest(*this, params));
1008 rbRenderableTests->addChild(rbAttTests);
1010 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
1012 const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
1013 texAttTests->addChild(new RenderableTest(*this, params));
1015 texRenderableTests->addChild(texAttTests);
1017 renderableTests->addChild(rbRenderableTests);
1018 renderableTests->addChild(texRenderableTests);
1020 return renderableTests;
1023 TestCaseGroup* Context::createAttachmentTests (void)
1025 TestCaseGroup* const attCombTests = new TestCaseGroup(
1026 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
1028 static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
1029 static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
1031 for (const GLenum* col0 = s_kinds.begin(); col0 != s_kinds.end(); ++col0)
1032 for (const GLenum* coln = s_kinds.begin(); coln != s_kinds.end(); ++coln)
1033 for (const GLenum* dep = s_kinds.begin(); dep != s_kinds.end(); ++dep)
1034 for (const GLenum* stc = s_kinds.begin(); stc != s_kinds.end(); ++stc)
1036 AttachmentParams params = { *col0, *coln, *dep, *stc };
1037 attCombTests->addChild(new AttachmentTest(*this, params));
1040 return attCombTests;
1043 TestCaseGroup* Context::createSizeTests (void)
1045 TestCaseGroup* const sizeTests = new TestCaseGroup(
1046 m_testCtx, "size", "Tests for attachment sizes");
1047 sizeTests->addChild(new EmptyImageTest(
1049 "Test for zero-sized image attachment"));
1050 sizeTests->addChild(new DistinctSizeTest(
1052 "Test for attachments with different sizes"));