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 | TEXTURE_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_UNSUPPORTED)
675 // "when both depth and stencil attachments are present,implementations are only required
676 // to support framebuffer objects where both attachments refer to the same image."
678 // Thus, it is acceptable for an implementation returning GL_FRAMEBUFFER_UNSUPPORTED,
679 // and the test cannot be marked as failed.
682 else if (fboStatus != GL_FRAMEBUFFER_COMPLETE && reference.isFBOStatusValid(GL_FRAMEBUFFER_COMPLETE))
683 qualityWarning("Framebuffer object could have checked as complete but did not.");
691 IterateResult TestBase::build (FboBuilder& builder)
697 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
699 if (bufType == GL_NONE)
701 return ImageFormat::none();
704 // Prefer a standard format, if there is one, but if not, use a format
705 // provided by an extension.
706 Formats formats = m_ctx.getCoreFormats().getFormats(formatFlag(attPoint) |
707 formatFlag(bufType));
708 Formats::const_iterator it = formats.begin();
709 if (it == formats.end())
711 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
712 formatFlag(bufType));
713 it = formats.begin();
715 if (it == formats.end())
716 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
717 "", __FILE__, __LINE__);
721 Image* makeImage (GLenum bufType, ImageFormat format,
722 GLsizei width, GLsizei height, FboBuilder& builder)
724 Image* image = DE_NULL;
729 case GL_RENDERBUFFER:
730 image = &builder.makeConfig<Renderbuffer>();
733 image = &builder.makeConfig<Texture2D>();
736 DE_FATAL("Impossible case");
738 image->internalFormat = format;
739 image->width = width;
740 image->height = height;
744 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
745 GLsizei width, GLsizei height, FboBuilder& builder)
747 Image* const imgCfg = makeImage (bufType, format, width, height, builder);
748 Attachment* att = DE_NULL;
751 if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
753 img = builder.glCreateRbo(*rboCfg);
754 att = &builder.makeConfig<RenderbufferAttachment>();
756 else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
758 img = builder.glCreateTexture(*texCfg);
759 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
760 texAtt.texTarget = GL_TEXTURE_2D;
765 DE_ASSERT(imgCfg == DE_NULL);
768 att->imageName = img;
772 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
773 GLsizei width, GLsizei height, FboBuilder& builder)
775 ImageFormat imgFmt = format;
776 if (imgFmt.format == GL_NONE)
777 imgFmt = getDefaultFormat(target, bufType);
779 const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
780 builder.glAttach(target, att);
783 static string formatName (ImageFormat format)
785 const string s = getTextureFormatName(format.format);
786 const string fmtStr = toLower(s.substr(3));
788 if (format.unsizedType != GL_NONE)
790 const string typeStr = getTypeName(format.unsizedType);
791 return fmtStr + "_" + toLower(typeStr.substr(3));
797 static string formatDesc (ImageFormat format)
799 const string fmtStr = getTextureFormatName(format.format);
801 if (format.unsizedType != GL_NONE)
803 const string typeStr = getTypeName(format.unsizedType);
804 return fmtStr + " with type " + typeStr;
810 struct RenderableParams
815 static string getName (const RenderableParams& params)
817 return formatName(params.format);
819 static string getDescription (const RenderableParams& params)
821 return formatDesc(params.format);
825 class RenderableTest : public ParamTest<RenderableParams>
828 RenderableTest (Context& group, const Params& params)
829 : ParamTest<RenderableParams> (group, params) {}
830 IterateResult build (FboBuilder& builder);
833 IterateResult RenderableTest::build (FboBuilder& builder)
835 attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
839 string attTypeName (GLenum bufType)
845 case GL_RENDERBUFFER:
850 DE_FATAL("Impossible case");
852 return ""; // Shut up compiler
855 struct AttachmentParams
862 static string getName (const AttachmentParams& params);
863 static string getDescription (const AttachmentParams& params)
865 return getName(params);
869 string AttachmentParams::getName (const AttachmentParams& params)
871 return (attTypeName(params.color0Kind) + "_" +
872 attTypeName(params.colornKind) + "_" +
873 attTypeName(params.depthKind) + "_" +
874 attTypeName(params.stencilKind));
877 //! Test for combinations of different kinds of attachments
878 class AttachmentTest : public ParamTest<AttachmentParams>
881 AttachmentTest (Context& group, Params& params)
882 : ParamTest<AttachmentParams> (group, params) {}
885 IterateResult build (FboBuilder& builder);
886 void makeDepthAndStencil (FboBuilder& builder);
890 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
892 if (m_params.stencilKind == m_params.depthKind)
894 // If there is a common stencil+depth -format, try to use a common
895 // image for both attachments.
896 const FormatFlags flags =
897 DEPTH_RENDERABLE | STENCIL_RENDERABLE | formatFlag(m_params.stencilKind);
898 const Formats& formats = m_ctx.getCoreFormats().getFormats(flags);
899 Formats::const_iterator it = formats.begin();
900 if (it != formats.end())
902 const ImageFormat format = *it;
903 Attachment* att = makeAttachment(m_params.depthKind, format, 64, 64, builder);
904 builder.glAttach(GL_DEPTH_ATTACHMENT, att);
905 builder.glAttach(GL_STENCIL_ATTACHMENT, att);
909 // Either the kinds were separate, or a suitable format was not found.
910 // Create separate images.
911 attachTargetToNew(GL_STENCIL_ATTACHMENT, m_params.stencilKind, ImageFormat::none(),
913 attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
917 IterateResult AttachmentTest::build (FboBuilder& builder)
919 attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
922 if (m_params.colornKind != GL_NONE)
924 TCU_CHECK_AND_THROW(NotSupportedError, m_ctx.haveMultiColorAtts(),
925 "Multiple attachments not supported");
926 GLint maxAttachments = 1;
927 gl(*this).getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments);
929 gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
931 for (int i = 1; i < maxAttachments; i++)
933 attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
934 ImageFormat::none(), 64, 64, builder);
938 makeDepthAndStencil(builder);
943 class EmptyImageTest : public TestBase
946 EmptyImageTest (Context& group,
947 const char* name, const char* desc)
948 : TestBase (group, name, desc) {}
950 IterateResult build (FboBuilder& builder);
953 IterateResult EmptyImageTest::build (FboBuilder& builder)
955 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
961 class DistinctSizeTest : public TestBase
964 DistinctSizeTest (Context& group,
965 const char* name, const char* desc)
966 : TestBase (group, name, desc) {}
968 IterateResult build (FboBuilder& builder);
971 IterateResult DistinctSizeTest::build (FboBuilder& builder)
973 attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
975 attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
980 TestCaseGroup* Context::createRenderableTests (void)
982 TestCaseGroup* const renderableTests = new TestCaseGroup(
983 m_testCtx, "renderable", "Tests for support of renderable image formats");
985 TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
986 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
988 TestCaseGroup* const texRenderableTests = new TestCaseGroup(
989 m_testCtx, "texture", "Tests for texture formats");
991 static const struct AttPoint {
997 { GL_COLOR_ATTACHMENT0, "color0", "Tests for color attachments" },
998 { GL_STENCIL_ATTACHMENT, "stencil", "Tests for stencil attachments" },
999 { GL_DEPTH_ATTACHMENT, "depth", "Tests for depth attachments" },
1002 // At each attachment point, iterate through all the possible formats to
1003 // detect both false positives and false negatives.
1004 const Formats rboFmts = m_allFormats.getFormats(ANY_FORMAT);
1005 const Formats texFmts = m_allFormats.getFormats(ANY_FORMAT);
1007 for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
1009 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1010 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1012 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
1014 const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
1015 rbAttTests->addChild(new RenderableTest(*this, params));
1017 rbRenderableTests->addChild(rbAttTests);
1019 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
1021 const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
1022 texAttTests->addChild(new RenderableTest(*this, params));
1024 texRenderableTests->addChild(texAttTests);
1026 renderableTests->addChild(rbRenderableTests);
1027 renderableTests->addChild(texRenderableTests);
1029 return renderableTests;
1032 TestCaseGroup* Context::createAttachmentTests (void)
1034 TestCaseGroup* const attCombTests = new TestCaseGroup(
1035 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
1037 static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
1038 static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
1040 for (const GLenum* col0 = s_kinds.begin(); col0 != s_kinds.end(); ++col0)
1041 for (const GLenum* coln = s_kinds.begin(); coln != s_kinds.end(); ++coln)
1042 for (const GLenum* dep = s_kinds.begin(); dep != s_kinds.end(); ++dep)
1043 for (const GLenum* stc = s_kinds.begin(); stc != s_kinds.end(); ++stc)
1045 AttachmentParams params = { *col0, *coln, *dep, *stc };
1046 attCombTests->addChild(new AttachmentTest(*this, params));
1049 return attCombTests;
1052 TestCaseGroup* Context::createSizeTests (void)
1054 TestCaseGroup* const sizeTests = new TestCaseGroup(
1055 m_testCtx, "size", "Tests for attachment sizes");
1056 sizeTests->addChild(new EmptyImageTest(
1058 "Test for zero-sized image attachment"));
1059 sizeTests->addChild(new DistinctSizeTest(
1061 "Test for attachments with different sizes"));