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),
181 static const FormatKey s_nvSrgbFormatsRboFormats[] =
186 static const FormatKey s_nvSrgbFormatsTextureFormats[] =
190 // The extension does not actually require any unsized format
191 // to be renderable. However, the renderablility of unsized
192 // SRGB,UBYTE internalformat-type pair is implied.
193 GLS_UNSIZED_FORMATKEY(GL_SRGB, GL_UNSIGNED_BYTE),
196 static const FormatKey s_oesRgb8Rgba8TexFormats[] =
198 GLS_UNSIZED_FORMATKEY(GL_RGB, GL_UNSIGNED_BYTE),
199 GLS_UNSIZED_FORMATKEY(GL_RGBA, GL_UNSIGNED_BYTE),
202 static const FormatKey s_extTextureSRGBR8Formats[] =
207 static const FormatKey s_extTextureSRGBRG8Formats[] =
212 static const FormatExtEntry s_esExtFormats[] =
215 "GL_OES_depth_texture",
216 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
217 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
220 "GL_OES_packed_depth_stencil",
221 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID),
222 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
225 "GL_OES_packed_depth_stencil GL_OES_required_internalformat",
226 (deUint32)TEXTURE_VALID,
227 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
230 "GL_OES_packed_depth_stencil GL_OES_depth_texture",
231 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
232 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats)
234 // The ANGLE extension incorporates GL_OES_depth_texture/GL_OES_packed_depth_stencil.
236 "GL_ANGLE_depth_texture",
237 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
238 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
241 "GL_OES_packed_depth_stencil GL_ANGLE_depth_texture",
242 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
243 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats),
245 // \todo [2013-12-10 lauri] Find out if OES_texture_half_float is really a
246 // requirement on ES3 also. Or is color_buffer_half_float applicatble at
247 // all on ES3, since there's also EXT_color_buffer_float?
249 "GL_OES_texture_half_float GL_EXT_color_buffer_half_float",
250 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
251 GLS_ARRAY_RANGE(s_extColorBufferHalfFloatFormats)
254 // OES_required_internalformat doesn't actually specify that these are renderable,
255 // since it was written against ES 1.1.
257 "GL_OES_required_internalformat",
258 // Allow but don't require RGBA8 to be color-renderable if
259 // OES_rgb8_rgba8 is not present.
260 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
261 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatColorFormats)
264 "GL_OES_required_internalformat",
265 (deUint32)(DEPTH_RENDERABLE | TEXTURE_VALID),
266 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatDepthFormats)
270 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
271 GLS_ARRAY_RANGE(s_extTextureRgRboFormats)
273 // These are not specified to be color-renderable, but the wording is
274 // exactly as ambiguous as the wording in the ES2 spec.
277 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
278 GLS_ARRAY_RANGE(s_extTextureRgTexFormats)
281 "GL_EXT_texture_rg GL_OES_texture_float",
282 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
283 GLS_ARRAY_RANGE(s_extTextureRgFloatTexFormats)
286 "GL_EXT_texture_rg GL_OES_texture_half_float",
287 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
288 GLS_ARRAY_RANGE(s_extTextureRgHalfFloatTexFormats)
292 "GL_NV_packed_float",
293 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
294 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
297 "GL_NV_packed_float GL_EXT_color_buffer_half_float",
298 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
299 GLS_ARRAY_RANGE(s_nvPackedFloatRboFormats)
304 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
305 GLS_ARRAY_RANGE(s_extSrgbRenderableTexFormats)
309 (deUint32)TEXTURE_VALID,
310 GLS_ARRAY_RANGE(s_extSrgbNonRenderableTexFormats)
314 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
315 GLS_ARRAY_RANGE(s_extSrgbRboFormats)
318 "GL_NV_sRGB_formats",
319 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
320 GLS_ARRAY_RANGE(s_nvSrgbFormatsRboFormats)
323 "GL_NV_sRGB_formats",
324 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID),
325 GLS_ARRAY_RANGE(s_nvSrgbFormatsTextureFormats)
328 // In Khronos bug 7333 discussion, the consensus is that these texture
329 // formats, at least, should be color-renderable. Still, that cannot be
330 // found in any extension specs, so only allow it, not require it.
333 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
334 GLS_ARRAY_RANGE(s_oesRgb8Rgba8TexFormats)
338 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
339 GLS_ARRAY_RANGE(s_oesRgb8Rgba8RboFormats)
342 "GL_OES_rgb8_rgba8 GL_OES_required_internalformat",
343 (deUint32)TEXTURE_VALID,
344 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatRgb8ColorFormat)
347 // The depth-renderability of the depth RBO formats is not explicitly
348 // spelled out, but all renderbuffer formats are meant to be renderable.
351 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
352 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
355 "GL_OES_depth24 GL_OES_required_internalformat GL_OES_depth_texture",
356 (deUint32)TEXTURE_VALID,
357 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
362 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
363 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
366 "GL_OES_depth32 GL_OES_required_internalformat GL_OES_depth_texture",
367 (deUint32)TEXTURE_VALID,
368 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
372 "GL_EXT_texture_type_2_10_10_10_REV",
373 (deUint32)TEXTURE_VALID, // explicitly unrenderable
374 GLS_ARRAY_RANGE(s_extTextureType2101010RevFormats)
377 "GL_EXT_texture_type_2_10_10_10_REV GL_OES_required_internalformat",
378 (deUint32)TEXTURE_VALID, // explicitly unrenderable
379 GLS_ARRAY_RANGE(s_oesRequiredInternalFormat10bitColorFormats)
383 "GL_EXT_texture_sRGB_R8",
384 (deUint32)TEXTURE_VALID,
385 GLS_ARRAY_RANGE(s_extTextureSRGBR8Formats)
388 "GL_EXT_texture_sRGB_RG8",
389 (deUint32)TEXTURE_VALID,
390 GLS_ARRAY_RANGE(s_extTextureSRGBRG8Formats)
394 Context::Context (TestContext& testCtx,
395 RenderContext& renderCtx,
396 CheckerFactory& factory)
397 : m_testCtx (testCtx)
398 , m_renderCtx (renderCtx)
399 , m_verifier (m_ctxFormats, factory, renderCtx)
400 , m_haveMultiColorAtts (false)
402 FormatExtEntries extRange = GLS_ARRAY_RANGE(s_esExtFormats);
403 addExtFormats(extRange);
406 void Context::addFormats (FormatEntries fmtRange)
408 FboUtil::addFormats(m_coreFormats, fmtRange);
409 FboUtil::addFormats(m_ctxFormats, fmtRange);
410 FboUtil::addFormats(m_allFormats, fmtRange);
413 void Context::addExtFormats (FormatExtEntries extRange)
415 FboUtil::addExtFormats(m_ctxFormats, extRange, &m_renderCtx);
416 FboUtil::addExtFormats(m_allFormats, extRange, DE_NULL);
419 void TestBase::pass (void)
421 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
424 void TestBase::qualityWarning (const char* msg)
426 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, msg);
429 void TestBase::fail (const char* msg)
431 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg);
434 const glw::Functions& gl (const TestBase& test)
436 return test.getContext().getRenderContext().getFunctions();
439 static bool isFormatFeatureSupported (const FormatDB& db, const ImageFormat& format, FormatFlags feature)
441 return db.isKnownFormat(format) && ((db.getFormatInfo(format) & feature) == feature);
444 static void logAffectingExtensions (const char* prefix, const FormatDB& db, const ImageFormat& format, FormatFlags feature, tcu::MessageBuilder& msg)
446 const std::set<std::set<std::string> > rows = db.getFormatFeatureExtensions(format, feature);
448 for (std::set<std::set<std::string> >::const_iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt)
450 const std::set<std::string>& requiredExtensions = *rowIt;
451 std::set<std::string>::const_iterator it = requiredExtensions.begin();
457 while (it != requiredExtensions.end())
459 msg << getExtensionDescription(extName);
461 msg << (it == requiredExtensions.end() ? " and " : ", ");
464 msg << getExtensionDescription(extName) << '\n';
468 static void logFormatInfo (const config::Framebuffer& fbo, const FormatDB& ctxFormats, const FormatDB& coreFormats, const FormatDB& allFormats, tcu::TestLog& log)
473 const FormatFlags flag;
474 } s_renderability[] =
476 { "color-renderable", COLOR_RENDERABLE },
477 { "depth-renderable", DEPTH_RENDERABLE },
478 { "stencil-renderable", STENCIL_RENDERABLE },
481 std::set<ImageFormat> formats;
483 for (config::TextureMap::const_iterator it = fbo.textures.begin(); it != fbo.textures.end(); ++it)
484 formats.insert(it->second->internalFormat);
485 for (config::RboMap::const_iterator it = fbo.rbos.begin(); it != fbo.rbos.end(); ++it)
486 formats.insert(it->second->internalFormat);
488 if (!formats.empty())
490 const tcu::ScopedLogSection supersection(log, "Format", "Format info");
492 for (std::set<ImageFormat>::const_iterator it = formats.begin(); it != formats.end(); ++it)
494 const tcu::ScopedLogSection section(log, "FormatInfo", de::toString(*it));
497 if (isFormatFeatureSupported(ctxFormats, *it, TEXTURE_VALID))
499 tcu::MessageBuilder msg(&log);
500 msg << "* Valid texture format\n";
502 if (isFormatFeatureSupported(coreFormats, *it, TEXTURE_VALID))
503 msg << "\t* core feature";
506 msg << "\t* defined in supported extension(s):\n";
507 logAffectingExtensions("\t\t- ", ctxFormats, *it, TEXTURE_VALID, msg);
510 msg << tcu::TestLog::EndMessage;
514 tcu::MessageBuilder msg(&log);
515 msg << "* Unsupported texture format\n";
517 if (isFormatFeatureSupported(allFormats, *it, TEXTURE_VALID))
519 msg << "\t* requires any of the extensions or combinations:\n";
520 logAffectingExtensions("\t\t- ", allFormats, *it, TEXTURE_VALID, msg);
523 msg << "\t* no extension can make this format valid";
525 msg << tcu::TestLog::EndMessage;
529 if (isFormatFeatureSupported(ctxFormats, *it, RENDERBUFFER_VALID))
531 tcu::MessageBuilder msg(&log);
532 msg << "* Valid renderbuffer format\n";
534 if (isFormatFeatureSupported(coreFormats, *it, RENDERBUFFER_VALID))
535 msg << "\t* core feature";
538 msg << "\t* defined in supported extension(s):\n";
539 logAffectingExtensions("\t\t- ", ctxFormats, *it, RENDERBUFFER_VALID, msg);
542 msg << tcu::TestLog::EndMessage;
546 tcu::MessageBuilder msg(&log);
547 msg << "* Unsupported renderbuffer format\n";
549 if (isFormatFeatureSupported(allFormats, *it, RENDERBUFFER_VALID))
551 msg << "\t* requires any of the extensions or combinations:\n";
552 logAffectingExtensions("\t\t- ", allFormats, *it, RENDERBUFFER_VALID, msg);
555 msg << "\t* no extension can make this format valid";
557 msg << tcu::TestLog::EndMessage;
561 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderability); ++ndx)
563 if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
565 tcu::MessageBuilder msg(&log);
566 msg << "* Format is " << s_renderability[ndx].name << "\n";
568 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
569 msg << "\t* core feature";
572 msg << "\t* defined in supported extension(s):\n";
573 logAffectingExtensions("\t\t- ", ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
576 msg << tcu::TestLog::EndMessage;
578 else if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag))
580 tcu::MessageBuilder msg(&log);
581 msg << "* Format is allowed to be " << s_renderability[ndx].name << " but not required\n";
583 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag))
584 msg << "\t* core feature";
585 else if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
587 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
588 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
591 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
593 msg << tcu::TestLog::EndMessage;
597 tcu::MessageBuilder msg(&log);
598 msg << "* Format is NOT " << s_renderability[ndx].name << "\n";
600 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
602 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
604 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
605 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
609 msg << "\t* extensions that are allowed to make format " << s_renderability[ndx].name << ":\n";
610 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
614 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
616 msg << tcu::TestLog::EndMessage;
623 IterateResult TestBase::iterate (void)
625 glu::Framebuffer fbo (m_ctx.getRenderContext());
626 FboBuilder builder (*fbo, GL_FRAMEBUFFER, gl(*this));
627 const IterateResult ret = build(builder);
628 const ValidStatusCodes reference = m_ctx.getVerifier().validStatusCodes(builder);
629 const GLenum errorCode = builder.getError();
631 logFramebufferConfig(builder, m_testCtx.getLog());
632 logFormatInfo(builder, m_ctx.getCtxFormats(), m_ctx.getCoreFormats(), m_ctx.getAllFormats(), m_testCtx.getLog());
633 reference.logRules(m_testCtx.getLog());
634 reference.logLegalResults(m_testCtx.getLog());
636 // \todo [2013-12-04 lauri] Check if drawing operations succeed.
638 if (errorCode != GL_NO_ERROR)
642 << "Received " << glu::getErrorStr(errorCode) << " (during FBO initialization)."
643 << TestLog::EndMessage;
645 if (reference.isErrorCodeValid(errorCode))
647 else if (reference.isErrorCodeRequired(GL_NO_ERROR))
648 fail(("Expected no error but got " + de::toString(glu::getErrorStr(errorCode))).c_str());
650 fail("Got wrong error code");
654 const GLenum fboStatus = gl(*this).checkFramebufferStatus(GL_FRAMEBUFFER);
655 const bool validStatus = reference.isFBOStatusValid(fboStatus);
659 << "Received " << glu::getFramebufferStatusStr(fboStatus) << "."
660 << TestLog::EndMessage;
664 if (fboStatus == GL_FRAMEBUFFER_COMPLETE)
665 fail("Framebuffer checked as complete, expected incomplete");
666 else if (reference.isFBOStatusRequired(GL_FRAMEBUFFER_COMPLETE))
667 fail("Framebuffer checked is incomplete, expected complete");
669 // An incomplete status is allowed, but not _this_ incomplete status.
670 fail("Framebuffer checked as incomplete, but with wrong status");
672 else if (fboStatus != GL_FRAMEBUFFER_COMPLETE && reference.isFBOStatusValid(GL_FRAMEBUFFER_COMPLETE))
673 qualityWarning("Framebuffer object could have checked as complete but did not.");
681 IterateResult TestBase::build (FboBuilder& builder)
687 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
689 if (bufType == GL_NONE)
691 return ImageFormat::none();
694 // Prefer a standard format, if there is one, but if not, use a format
695 // provided by an extension.
696 Formats formats = m_ctx.getCoreFormats().getFormats(formatFlag(attPoint) |
697 formatFlag(bufType));
698 Formats::const_iterator it = formats.begin();
699 if (it == formats.end())
701 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
702 formatFlag(bufType));
703 it = formats.begin();
705 if (it == formats.end())
706 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
707 "", __FILE__, __LINE__);
711 Image* makeImage (GLenum bufType, ImageFormat format,
712 GLsizei width, GLsizei height, FboBuilder& builder)
714 Image* image = DE_NULL;
719 case GL_RENDERBUFFER:
720 image = &builder.makeConfig<Renderbuffer>();
723 image = &builder.makeConfig<Texture2D>();
726 DE_FATAL("Impossible case");
728 image->internalFormat = format;
729 image->width = width;
730 image->height = height;
734 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
735 GLsizei width, GLsizei height, FboBuilder& builder)
737 Image* const imgCfg = makeImage (bufType, format, width, height, builder);
738 Attachment* att = DE_NULL;
741 if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
743 img = builder.glCreateRbo(*rboCfg);
744 att = &builder.makeConfig<RenderbufferAttachment>();
746 else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
748 img = builder.glCreateTexture(*texCfg);
749 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
750 texAtt.texTarget = GL_TEXTURE_2D;
755 DE_ASSERT(imgCfg == DE_NULL);
758 att->imageName = img;
762 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
763 GLsizei width, GLsizei height, FboBuilder& builder)
765 ImageFormat imgFmt = format;
766 if (imgFmt.format == GL_NONE)
767 imgFmt = getDefaultFormat(target, bufType);
769 const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
770 builder.glAttach(target, att);
773 static string formatName (ImageFormat format)
775 const string s = getTextureFormatName(format.format);
776 const string fmtStr = toLower(s.substr(3));
778 if (format.unsizedType != GL_NONE)
780 const string typeStr = getTypeName(format.unsizedType);
781 return fmtStr + "_" + toLower(typeStr.substr(3));
787 static string formatDesc (ImageFormat format)
789 const string fmtStr = getTextureFormatName(format.format);
791 if (format.unsizedType != GL_NONE)
793 const string typeStr = getTypeName(format.unsizedType);
794 return fmtStr + " with type " + typeStr;
800 struct RenderableParams
805 static string getName (const RenderableParams& params)
807 return formatName(params.format);
809 static string getDescription (const RenderableParams& params)
811 return formatDesc(params.format);
815 class RenderableTest : public ParamTest<RenderableParams>
818 RenderableTest (Context& group, const Params& params)
819 : ParamTest<RenderableParams> (group, params) {}
820 IterateResult build (FboBuilder& builder);
823 IterateResult RenderableTest::build (FboBuilder& builder)
825 attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
829 string attTypeName (GLenum bufType)
835 case GL_RENDERBUFFER:
840 DE_FATAL("Impossible case");
842 return ""; // Shut up compiler
845 struct AttachmentParams
852 static string getName (const AttachmentParams& params);
853 static string getDescription (const AttachmentParams& params)
855 return getName(params);
859 string AttachmentParams::getName (const AttachmentParams& params)
861 return (attTypeName(params.color0Kind) + "_" +
862 attTypeName(params.colornKind) + "_" +
863 attTypeName(params.depthKind) + "_" +
864 attTypeName(params.stencilKind));
867 //! Test for combinations of different kinds of attachments
868 class AttachmentTest : public ParamTest<AttachmentParams>
871 AttachmentTest (Context& group, Params& params)
872 : ParamTest<AttachmentParams> (group, params) {}
875 IterateResult build (FboBuilder& builder);
876 void makeDepthAndStencil (FboBuilder& builder);
880 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
882 if (m_params.stencilKind == m_params.depthKind)
884 // If there is a common stencil+depth -format, try to use a common
885 // image for both attachments.
886 const FormatFlags flags =
887 DEPTH_RENDERABLE | STENCIL_RENDERABLE | formatFlag(m_params.stencilKind);
888 const Formats& formats = m_ctx.getCoreFormats().getFormats(flags);
889 Formats::const_iterator it = formats.begin();
890 if (it != formats.end())
892 const ImageFormat format = *it;
893 Attachment* att = makeAttachment(m_params.depthKind, format, 64, 64, builder);
894 builder.glAttach(GL_DEPTH_ATTACHMENT, att);
895 builder.glAttach(GL_STENCIL_ATTACHMENT, att);
899 // Either the kinds were separate, or a suitable format was not found.
900 // Create separate images.
901 attachTargetToNew(GL_STENCIL_ATTACHMENT, m_params.stencilKind, ImageFormat::none(),
903 attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
907 IterateResult AttachmentTest::build (FboBuilder& builder)
909 attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
912 if (m_params.colornKind != GL_NONE)
914 TCU_CHECK_AND_THROW(NotSupportedError, m_ctx.haveMultiColorAtts(),
915 "Multiple attachments not supported");
916 GLint maxAttachments = 1;
917 gl(*this).getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments);
919 gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
921 for (int i = 1; i < maxAttachments; i++)
923 attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
924 ImageFormat::none(), 64, 64, builder);
928 makeDepthAndStencil(builder);
933 class EmptyImageTest : public TestBase
936 EmptyImageTest (Context& group,
937 const char* name, const char* desc)
938 : TestBase (group, name, desc) {}
940 IterateResult build (FboBuilder& builder);
943 IterateResult EmptyImageTest::build (FboBuilder& builder)
945 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
951 class DistinctSizeTest : public TestBase
954 DistinctSizeTest (Context& group,
955 const char* name, const char* desc)
956 : TestBase (group, name, desc) {}
958 IterateResult build (FboBuilder& builder);
961 IterateResult DistinctSizeTest::build (FboBuilder& builder)
963 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
965 attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
970 TestCaseGroup* Context::createRenderableTests (void)
972 TestCaseGroup* const renderableTests = new TestCaseGroup(
973 m_testCtx, "renderable", "Tests for support of renderable image formats");
975 TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
976 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
978 TestCaseGroup* const texRenderableTests = new TestCaseGroup(
979 m_testCtx, "texture", "Tests for texture formats");
981 static const struct AttPoint {
987 { GL_COLOR_ATTACHMENT0, "color0", "Tests for color attachments" },
988 { GL_STENCIL_ATTACHMENT, "stencil", "Tests for stencil attachments" },
989 { GL_DEPTH_ATTACHMENT, "depth", "Tests for depth attachments" },
992 // At each attachment point, iterate through all the possible formats to
993 // detect both false positives and false negatives.
994 const Formats rboFmts = m_allFormats.getFormats(ANY_FORMAT);
995 const Formats texFmts = m_allFormats.getFormats(ANY_FORMAT);
997 for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
999 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1000 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1002 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
1004 const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
1005 rbAttTests->addChild(new RenderableTest(*this, params));
1007 rbRenderableTests->addChild(rbAttTests);
1009 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
1011 const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
1012 texAttTests->addChild(new RenderableTest(*this, params));
1014 texRenderableTests->addChild(texAttTests);
1016 renderableTests->addChild(rbRenderableTests);
1017 renderableTests->addChild(texRenderableTests);
1019 return renderableTests;
1022 TestCaseGroup* Context::createAttachmentTests (void)
1024 TestCaseGroup* const attCombTests = new TestCaseGroup(
1025 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
1027 static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
1028 static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
1030 for (const GLenum* col0 = s_kinds.begin(); col0 != s_kinds.end(); ++col0)
1031 for (const GLenum* coln = s_kinds.begin(); coln != s_kinds.end(); ++coln)
1032 for (const GLenum* dep = s_kinds.begin(); dep != s_kinds.end(); ++dep)
1033 for (const GLenum* stc = s_kinds.begin(); stc != s_kinds.end(); ++stc)
1035 AttachmentParams params = { *col0, *coln, *dep, *stc };
1036 attCombTests->addChild(new AttachmentTest(*this, params));
1039 return attCombTests;
1042 TestCaseGroup* Context::createSizeTests (void)
1044 TestCaseGroup* const sizeTests = new TestCaseGroup(
1045 m_testCtx, "size", "Tests for attachment sizes");
1046 sizeTests->addChild(new EmptyImageTest(
1048 "Test for zero-sized image attachment"));
1049 sizeTests->addChild(new DistinctSizeTest(
1051 "Test for attachments with different sizes"));