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",
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),
241 // \todo [2013-12-10 lauri] Find out if OES_texture_half_float is really a
242 // requirement on ES3 also. Or is color_buffer_half_float applicatble at
243 // all on ES3, since there's also EXT_color_buffer_float?
245 "GL_OES_texture_half_float GL_EXT_color_buffer_half_float",
246 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
247 GLS_ARRAY_RANGE(s_extColorBufferHalfFloatFormats)
250 // OES_required_internalformat doesn't actually specify that these are renderable,
251 // since it was written against ES 1.1.
253 "GL_OES_required_internalformat",
254 // Allow but don't require RGBA8 to be color-renderable if
255 // OES_rgb8_rgba8 is not present.
256 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
257 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatColorFormats)
260 "GL_OES_required_internalformat",
261 (deUint32)(DEPTH_RENDERABLE | TEXTURE_VALID),
262 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatDepthFormats)
266 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
267 GLS_ARRAY_RANGE(s_extTextureRgRboFormats)
269 // These are not specified to be color-renderable, but the wording is
270 // exactly as ambiguous as the wording in the ES2 spec.
273 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
274 GLS_ARRAY_RANGE(s_extTextureRgTexFormats)
277 "GL_EXT_texture_rg GL_OES_texture_float",
278 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
279 GLS_ARRAY_RANGE(s_extTextureRgFloatTexFormats)
282 "GL_EXT_texture_rg GL_OES_texture_half_float",
283 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
284 GLS_ARRAY_RANGE(s_extTextureRgHalfFloatTexFormats)
288 "GL_NV_packed_float",
289 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
290 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
293 "GL_NV_packed_float GL_EXT_color_buffer_half_float",
294 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
295 GLS_ARRAY_RANGE(s_nvPackedFloatRboFormats)
300 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
301 GLS_ARRAY_RANGE(s_extSrgbRenderableTexFormats)
305 (deUint32)TEXTURE_VALID,
306 GLS_ARRAY_RANGE(s_extSrgbNonRenderableTexFormats)
310 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
311 GLS_ARRAY_RANGE(s_extSrgbRboFormats)
314 "GL_NV_sRGB_formats",
315 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
316 GLS_ARRAY_RANGE(s_nvSrgbFormatsRboFormats)
319 "GL_NV_sRGB_formats",
320 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID),
321 GLS_ARRAY_RANGE(s_nvSrgbFormatsTextureFormats)
324 // In Khronos bug 7333 discussion, the consensus is that these texture
325 // formats, at least, should be color-renderable. Still, that cannot be
326 // found in any extension specs, so only allow it, not require it.
329 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
330 GLS_ARRAY_RANGE(s_oesRgb8Rgba8TexFormats)
334 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
335 GLS_ARRAY_RANGE(s_oesRgb8Rgba8RboFormats)
338 "GL_OES_rgb8_rgba8 GL_OES_required_internalformat",
339 (deUint32)TEXTURE_VALID,
340 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatRgb8ColorFormat)
343 // The depth-renderability of the depth RBO formats is not explicitly
344 // spelled out, but all renderbuffer formats are meant to be renderable.
347 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
348 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
351 "GL_OES_depth24 GL_OES_required_internalformat GL_OES_depth_texture",
352 (deUint32)TEXTURE_VALID,
353 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
358 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
359 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
362 "GL_OES_depth32 GL_OES_required_internalformat GL_OES_depth_texture",
363 (deUint32)TEXTURE_VALID,
364 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
368 "GL_EXT_texture_type_2_10_10_10_REV",
369 (deUint32)TEXTURE_VALID, // explicitly unrenderable
370 GLS_ARRAY_RANGE(s_extTextureType2101010RevFormats)
373 "GL_EXT_texture_type_2_10_10_10_REV GL_OES_required_internalformat",
374 (deUint32)TEXTURE_VALID, // explicitly unrenderable
375 GLS_ARRAY_RANGE(s_oesRequiredInternalFormat10bitColorFormats)
379 "GL_EXT_texture_sRGB_R8",
380 (deUint32)TEXTURE_VALID,
381 GLS_ARRAY_RANGE(s_extTextureSRGBR8Formats)
384 "GL_EXT_texture_sRGB_RG8",
385 (deUint32)TEXTURE_VALID,
386 GLS_ARRAY_RANGE(s_extTextureSRGBRG8Formats)
390 Context::Context (TestContext& testCtx,
391 RenderContext& renderCtx,
392 CheckerFactory& factory)
393 : m_testCtx (testCtx)
394 , m_renderCtx (renderCtx)
395 , m_verifier (m_ctxFormats, factory, renderCtx)
396 , m_haveMultiColorAtts (false)
398 FormatExtEntries extRange = GLS_ARRAY_RANGE(s_esExtFormats);
399 addExtFormats(extRange);
402 void Context::addFormats (FormatEntries fmtRange)
404 FboUtil::addFormats(m_coreFormats, fmtRange);
405 FboUtil::addFormats(m_ctxFormats, fmtRange);
406 FboUtil::addFormats(m_allFormats, fmtRange);
409 void Context::addExtFormats (FormatExtEntries extRange)
411 FboUtil::addExtFormats(m_ctxFormats, extRange, &m_renderCtx);
412 FboUtil::addExtFormats(m_allFormats, extRange, DE_NULL);
415 void TestBase::pass (void)
417 m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
420 void TestBase::qualityWarning (const char* msg)
422 m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, msg);
425 void TestBase::fail (const char* msg)
427 m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg);
430 const glw::Functions& gl (const TestBase& test)
432 return test.getContext().getRenderContext().getFunctions();
435 static bool isFormatFeatureSupported (const FormatDB& db, const ImageFormat& format, FormatFlags feature)
437 return db.isKnownFormat(format) && ((db.getFormatInfo(format) & feature) == feature);
440 static void logAffectingExtensions (const char* prefix, const FormatDB& db, const ImageFormat& format, FormatFlags feature, tcu::MessageBuilder& msg)
442 const std::set<std::set<std::string> > rows = db.getFormatFeatureExtensions(format, feature);
444 for (std::set<std::set<std::string> >::const_iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt)
446 const std::set<std::string>& requiredExtensions = *rowIt;
447 std::set<std::string>::const_iterator it = requiredExtensions.begin();
453 while (it != requiredExtensions.end())
455 msg << getExtensionDescription(extName);
457 msg << (it == requiredExtensions.end() ? " and " : ", ");
460 msg << getExtensionDescription(extName) << '\n';
464 static void logFormatInfo (const config::Framebuffer& fbo, const FormatDB& ctxFormats, const FormatDB& coreFormats, const FormatDB& allFormats, tcu::TestLog& log)
469 const FormatFlags flag;
470 } s_renderability[] =
472 { "color-renderable", COLOR_RENDERABLE },
473 { "depth-renderable", DEPTH_RENDERABLE },
474 { "stencil-renderable", STENCIL_RENDERABLE },
477 std::set<ImageFormat> formats;
479 for (config::TextureMap::const_iterator it = fbo.textures.begin(); it != fbo.textures.end(); ++it)
480 formats.insert(it->second->internalFormat);
481 for (config::RboMap::const_iterator it = fbo.rbos.begin(); it != fbo.rbos.end(); ++it)
482 formats.insert(it->second->internalFormat);
484 if (!formats.empty())
486 const tcu::ScopedLogSection supersection(log, "Format", "Format info");
488 for (std::set<ImageFormat>::const_iterator it = formats.begin(); it != formats.end(); ++it)
490 const tcu::ScopedLogSection section(log, "FormatInfo", de::toString(*it));
493 if (isFormatFeatureSupported(ctxFormats, *it, TEXTURE_VALID))
495 tcu::MessageBuilder msg(&log);
496 msg << "* Valid texture format\n";
498 if (isFormatFeatureSupported(coreFormats, *it, TEXTURE_VALID))
499 msg << "\t* core feature";
502 msg << "\t* defined in supported extension(s):\n";
503 logAffectingExtensions("\t\t- ", ctxFormats, *it, TEXTURE_VALID, msg);
506 msg << tcu::TestLog::EndMessage;
510 tcu::MessageBuilder msg(&log);
511 msg << "* Unsupported texture format\n";
513 if (isFormatFeatureSupported(allFormats, *it, TEXTURE_VALID))
515 msg << "\t* requires any of the extensions or combinations:\n";
516 logAffectingExtensions("\t\t- ", allFormats, *it, TEXTURE_VALID, msg);
519 msg << "\t* no extension can make this format valid";
521 msg << tcu::TestLog::EndMessage;
525 if (isFormatFeatureSupported(ctxFormats, *it, RENDERBUFFER_VALID))
527 tcu::MessageBuilder msg(&log);
528 msg << "* Valid renderbuffer format\n";
530 if (isFormatFeatureSupported(coreFormats, *it, RENDERBUFFER_VALID))
531 msg << "\t* core feature";
534 msg << "\t* defined in supported extension(s):\n";
535 logAffectingExtensions("\t\t- ", ctxFormats, *it, RENDERBUFFER_VALID, msg);
538 msg << tcu::TestLog::EndMessage;
542 tcu::MessageBuilder msg(&log);
543 msg << "* Unsupported renderbuffer format\n";
545 if (isFormatFeatureSupported(allFormats, *it, RENDERBUFFER_VALID))
547 msg << "\t* requires any of the extensions or combinations:\n";
548 logAffectingExtensions("\t\t- ", allFormats, *it, RENDERBUFFER_VALID, msg);
551 msg << "\t* no extension can make this format valid";
553 msg << tcu::TestLog::EndMessage;
557 for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderability); ++ndx)
559 if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
561 tcu::MessageBuilder msg(&log);
562 msg << "* Format is " << s_renderability[ndx].name << "\n";
564 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
565 msg << "\t* core feature";
568 msg << "\t* defined in supported extension(s):\n";
569 logAffectingExtensions("\t\t- ", ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
572 msg << tcu::TestLog::EndMessage;
574 else if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag))
576 tcu::MessageBuilder msg(&log);
577 msg << "* Format is allowed to be " << s_renderability[ndx].name << " but not required\n";
579 if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag))
580 msg << "\t* core feature";
581 else if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
583 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
584 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
587 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
589 msg << tcu::TestLog::EndMessage;
593 tcu::MessageBuilder msg(&log);
594 msg << "* Format is NOT " << s_renderability[ndx].name << "\n";
596 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
598 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
600 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
601 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
605 msg << "\t* extensions that are allowed to make format " << s_renderability[ndx].name << ":\n";
606 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
610 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
612 msg << tcu::TestLog::EndMessage;
619 IterateResult TestBase::iterate (void)
621 glu::Framebuffer fbo (m_ctx.getRenderContext());
622 FboBuilder builder (*fbo, GL_FRAMEBUFFER, gl(*this));
623 const IterateResult ret = build(builder);
624 const ValidStatusCodes reference = m_ctx.getVerifier().validStatusCodes(builder);
625 const GLenum errorCode = builder.getError();
627 logFramebufferConfig(builder, m_testCtx.getLog());
628 logFormatInfo(builder, m_ctx.getCtxFormats(), m_ctx.getCoreFormats(), m_ctx.getAllFormats(), m_testCtx.getLog());
629 reference.logRules(m_testCtx.getLog());
630 reference.logLegalResults(m_testCtx.getLog());
632 // \todo [2013-12-04 lauri] Check if drawing operations succeed.
634 if (errorCode != GL_NO_ERROR)
638 << "Received " << glu::getErrorStr(errorCode) << " (during FBO initialization)."
639 << TestLog::EndMessage;
641 if (reference.isErrorCodeValid(errorCode))
643 else if (reference.isErrorCodeRequired(GL_NO_ERROR))
644 fail(("Expected no error but got " + de::toString(glu::getErrorStr(errorCode))).c_str());
646 fail("Got wrong error code");
650 const GLenum fboStatus = gl(*this).checkFramebufferStatus(GL_FRAMEBUFFER);
651 const bool validStatus = reference.isFBOStatusValid(fboStatus);
655 << "Received " << glu::getFramebufferStatusStr(fboStatus) << "."
656 << TestLog::EndMessage;
660 if (fboStatus == GL_FRAMEBUFFER_COMPLETE)
661 fail("Framebuffer checked as complete, expected incomplete");
662 else if (reference.isFBOStatusRequired(GL_FRAMEBUFFER_COMPLETE))
663 fail("Framebuffer checked is incomplete, expected complete");
665 // An incomplete status is allowed, but not _this_ incomplete status.
666 fail("Framebuffer checked as incomplete, but with wrong status");
668 else if (fboStatus != GL_FRAMEBUFFER_COMPLETE && reference.isFBOStatusValid(GL_FRAMEBUFFER_COMPLETE))
669 qualityWarning("Framebuffer object could have checked as complete but did not.");
677 IterateResult TestBase::build (FboBuilder& builder)
683 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
685 if (bufType == GL_NONE)
687 return ImageFormat::none();
690 // Prefer a standard format, if there is one, but if not, use a format
691 // provided by an extension.
692 Formats formats = m_ctx.getCoreFormats().getFormats(formatFlag(attPoint) |
693 formatFlag(bufType));
694 Formats::const_iterator it = formats.begin();
695 if (it == formats.end())
697 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
698 formatFlag(bufType));
699 it = formats.begin();
701 if (it == formats.end())
702 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
703 "", __FILE__, __LINE__);
707 Image* makeImage (GLenum bufType, ImageFormat format,
708 GLsizei width, GLsizei height, FboBuilder& builder)
710 Image* image = DE_NULL;
715 case GL_RENDERBUFFER:
716 image = &builder.makeConfig<Renderbuffer>();
719 image = &builder.makeConfig<Texture2D>();
722 DE_FATAL("Impossible case");
724 image->internalFormat = format;
725 image->width = width;
726 image->height = height;
730 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
731 GLsizei width, GLsizei height, FboBuilder& builder)
733 Image* const imgCfg = makeImage (bufType, format, width, height, builder);
734 Attachment* att = DE_NULL;
737 if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
739 img = builder.glCreateRbo(*rboCfg);
740 att = &builder.makeConfig<RenderbufferAttachment>();
742 else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
744 img = builder.glCreateTexture(*texCfg);
745 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
746 texAtt.texTarget = GL_TEXTURE_2D;
751 DE_ASSERT(imgCfg == DE_NULL);
754 att->imageName = img;
758 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
759 GLsizei width, GLsizei height, FboBuilder& builder)
761 ImageFormat imgFmt = format;
762 if (imgFmt.format == GL_NONE)
763 imgFmt = getDefaultFormat(target, bufType);
765 const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
766 builder.glAttach(target, att);
769 static string formatName (ImageFormat format)
771 const string s = getTextureFormatName(format.format);
772 const string fmtStr = toLower(s.substr(3));
774 if (format.unsizedType != GL_NONE)
776 const string typeStr = getTypeName(format.unsizedType);
777 return fmtStr + "_" + toLower(typeStr.substr(3));
783 static string formatDesc (ImageFormat format)
785 const string fmtStr = getTextureFormatName(format.format);
787 if (format.unsizedType != GL_NONE)
789 const string typeStr = getTypeName(format.unsizedType);
790 return fmtStr + " with type " + typeStr;
796 struct RenderableParams
801 static string getName (const RenderableParams& params)
803 return formatName(params.format);
805 static string getDescription (const RenderableParams& params)
807 return formatDesc(params.format);
811 class RenderableTest : public ParamTest<RenderableParams>
814 RenderableTest (Context& group, const Params& params)
815 : ParamTest<RenderableParams> (group, params) {}
816 IterateResult build (FboBuilder& builder);
819 IterateResult RenderableTest::build (FboBuilder& builder)
821 attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
825 string attTypeName (GLenum bufType)
831 case GL_RENDERBUFFER:
836 DE_FATAL("Impossible case");
838 return ""; // Shut up compiler
841 struct AttachmentParams
848 static string getName (const AttachmentParams& params);
849 static string getDescription (const AttachmentParams& params)
851 return getName(params);
855 string AttachmentParams::getName (const AttachmentParams& params)
857 return (attTypeName(params.color0Kind) + "_" +
858 attTypeName(params.colornKind) + "_" +
859 attTypeName(params.depthKind) + "_" +
860 attTypeName(params.stencilKind));
863 //! Test for combinations of different kinds of attachments
864 class AttachmentTest : public ParamTest<AttachmentParams>
867 AttachmentTest (Context& group, Params& params)
868 : ParamTest<AttachmentParams> (group, params) {}
871 IterateResult build (FboBuilder& builder);
872 void makeDepthAndStencil (FboBuilder& builder);
876 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
878 if (m_params.stencilKind == m_params.depthKind)
880 // If there is a common stencil+depth -format, try to use a common
881 // image for both attachments.
882 const FormatFlags flags =
883 DEPTH_RENDERABLE | STENCIL_RENDERABLE | formatFlag(m_params.stencilKind);
884 const Formats& formats = m_ctx.getCoreFormats().getFormats(flags);
885 Formats::const_iterator it = formats.begin();
886 if (it != formats.end())
888 const ImageFormat format = *it;
889 Attachment* att = makeAttachment(m_params.depthKind, format, 64, 64, builder);
890 builder.glAttach(GL_DEPTH_ATTACHMENT, att);
891 builder.glAttach(GL_STENCIL_ATTACHMENT, att);
895 // Either the kinds were separate, or a suitable format was not found.
896 // Create separate images.
897 attachTargetToNew(GL_STENCIL_ATTACHMENT, m_params.stencilKind, ImageFormat::none(),
899 attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
903 IterateResult AttachmentTest::build (FboBuilder& builder)
905 attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
908 if (m_params.colornKind != GL_NONE)
910 TCU_CHECK_AND_THROW(NotSupportedError, m_ctx.haveMultiColorAtts(),
911 "Multiple attachments not supported");
912 GLint maxAttachments = 1;
913 gl(*this).getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments);
915 gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
917 for (int i = 1; i < maxAttachments; i++)
919 attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
920 ImageFormat::none(), 64, 64, builder);
924 makeDepthAndStencil(builder);
929 class EmptyImageTest : public TestBase
932 EmptyImageTest (Context& group,
933 const char* name, const char* desc)
934 : TestBase (group, name, desc) {}
936 IterateResult build (FboBuilder& builder);
939 IterateResult EmptyImageTest::build (FboBuilder& builder)
941 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
947 class DistinctSizeTest : public TestBase
950 DistinctSizeTest (Context& group,
951 const char* name, const char* desc)
952 : TestBase (group, name, desc) {}
954 IterateResult build (FboBuilder& builder);
957 IterateResult DistinctSizeTest::build (FboBuilder& builder)
959 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
961 attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
966 TestCaseGroup* Context::createRenderableTests (void)
968 TestCaseGroup* const renderableTests = new TestCaseGroup(
969 m_testCtx, "renderable", "Tests for support of renderable image formats");
971 TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
972 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
974 TestCaseGroup* const texRenderableTests = new TestCaseGroup(
975 m_testCtx, "texture", "Tests for texture formats");
977 static const struct AttPoint {
983 { GL_COLOR_ATTACHMENT0, "color0", "Tests for color attachments" },
984 { GL_STENCIL_ATTACHMENT, "stencil", "Tests for stencil attachments" },
985 { GL_DEPTH_ATTACHMENT, "depth", "Tests for depth attachments" },
988 // At each attachment point, iterate through all the possible formats to
989 // detect both false positives and false negatives.
990 const Formats rboFmts = m_allFormats.getFormats(ANY_FORMAT);
991 const Formats texFmts = m_allFormats.getFormats(ANY_FORMAT);
993 for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
995 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
996 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
998 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
1000 const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
1001 rbAttTests->addChild(new RenderableTest(*this, params));
1003 rbRenderableTests->addChild(rbAttTests);
1005 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
1007 const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
1008 texAttTests->addChild(new RenderableTest(*this, params));
1010 texRenderableTests->addChild(texAttTests);
1012 renderableTests->addChild(rbRenderableTests);
1013 renderableTests->addChild(texRenderableTests);
1015 return renderableTests;
1018 TestCaseGroup* Context::createAttachmentTests (void)
1020 TestCaseGroup* const attCombTests = new TestCaseGroup(
1021 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
1023 static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
1024 static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
1026 for (const GLenum* col0 = s_kinds.begin(); col0 != s_kinds.end(); ++col0)
1027 for (const GLenum* coln = s_kinds.begin(); coln != s_kinds.end(); ++coln)
1028 for (const GLenum* dep = s_kinds.begin(); dep != s_kinds.end(); ++dep)
1029 for (const GLenum* stc = s_kinds.begin(); stc != s_kinds.end(); ++stc)
1031 AttachmentParams params = { *col0, *coln, *dep, *stc };
1032 attCombTests->addChild(new AttachmentTest(*this, params));
1035 return attCombTests;
1038 TestCaseGroup* Context::createSizeTests (void)
1040 TestCaseGroup* const sizeTests = new TestCaseGroup(
1041 m_testCtx, "size", "Tests for attachment sizes");
1042 sizeTests->addChild(new EmptyImageTest(
1044 "Test for zero-sized image attachment"));
1045 sizeTests->addChild(new DistinctSizeTest(
1047 "Test for attachments with different sizes"));