4c71ab9c02d76e32649aa6183a756c7ad278449e
[platform/upstream/VK-GL-CTS.git] / modules / glshared / glsFboCompletenessTests.cpp
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program OpenGL (ES) Module
3  * -----------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  *//*!
20  * \file
21  * \brief Framebuffer completeness tests.
22  *//*--------------------------------------------------------------------*/
23
24 #include "glsFboCompletenessTests.hpp"
25
26 #include "gluStrUtil.hpp"
27 #include "gluObjectWrapper.hpp"
28 #include "deStringUtil.hpp"
29
30 #include <cctype>
31 #include <iterator>
32 #include <algorithm>
33
34 using namespace glw;
35 using glu::RenderContext;
36 using glu::getFramebufferStatusName;
37 using glu::getTextureFormatName;
38 using glu::getTypeName;
39 using glu::getErrorName;
40 using glu::Framebuffer;
41 using tcu::TestCase;
42 using tcu::TestCaseGroup;
43 using tcu::TestLog;
44 using tcu::MessageBuilder;
45 using tcu::TestNode;
46 using std::string;
47 using de::toString;
48 using de::toLower;
49 using namespace deqp::gls::FboUtil;
50 using namespace deqp::gls::FboUtil::config;
51 typedef TestCase::IterateResult IterateResult;
52
53 namespace deqp
54 {
55 namespace gls
56 {
57 namespace fboc
58 {
59
60 namespace details
61 {
62
63 // The following extensions are applicable both to ES2 and ES3.
64
65 // GL_OES_depth_texture
66 static const FormatKey s_oesDepthTextureFormats[] =
67 {
68         GLS_UNSIZED_FORMATKEY(GL_DEPTH_COMPONENT,       GL_UNSIGNED_SHORT),
69         GLS_UNSIZED_FORMATKEY(GL_DEPTH_COMPONENT,       GL_UNSIGNED_INT),
70 };
71
72 // GL_OES_packed_depth_stencil
73 static const FormatKey s_oesPackedDepthStencilSizedFormats[] =
74 {
75         GL_DEPTH24_STENCIL8,
76 };
77
78 static const FormatKey s_oesPackedDepthStencilTexFormats[] =
79 {
80         GLS_UNSIZED_FORMATKEY(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8),
81 };
82
83 // GL_OES_required_internalformat
84 static const FormatKey s_oesRequiredInternalFormatColorFormats[] =
85 {
86         // Same as ES2 RBO formats, plus RGBA8 (even without OES_rgb8_rgba8)
87         GL_RGB5_A1, GL_RGBA8, GL_RGBA4, GL_RGB565
88 };
89
90 static const FormatKey s_oesRequiredInternalFormatDepthFormats[] =
91 {
92         GL_DEPTH_COMPONENT16,
93 };
94
95 // GL_EXT_color_buffer_half_float
96 static const FormatKey s_extColorBufferHalfFloatFormats[] =
97 {
98         GL_RGBA16F, GL_RGB16F, GL_RG16F, GL_R16F,
99 };
100
101 static const FormatKey s_oesDepth24SizedFormats[] =
102 {
103         GL_DEPTH_COMPONENT24
104 };
105
106 static const FormatKey s_oesDepth32SizedFormats[] =
107 {
108         GL_DEPTH_COMPONENT32
109 };
110
111 static const FormatKey s_oesRgb8Rgba8RboFormats[] =
112 {
113         GL_RGB8,
114         GL_RGBA8,
115 };
116
117 static const FormatKey s_oesRequiredInternalFormatRgb8ColorFormat[] =
118 {
119         GL_RGB8,
120 };
121
122 static const FormatKey s_extTextureType2101010RevFormats[] =
123 {
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),
126 };
127
128 static const FormatKey s_oesRequiredInternalFormat10bitColorFormats[] =
129 {
130         GL_RGB10_A2, GL_RGB10,
131 };
132
133 static const FormatKey s_extTextureRgRboFormats[] =
134 {
135         GL_R8, GL_RG8,
136 };
137
138 static const FormatKey s_extTextureRgTexFormats[] =
139 {
140         GLS_UNSIZED_FORMATKEY(GL_RED,   GL_UNSIGNED_BYTE),
141         GLS_UNSIZED_FORMATKEY(GL_RG,    GL_UNSIGNED_BYTE),
142 };
143
144 static const FormatKey s_extTextureRgFloatTexFormats[] =
145 {
146         GLS_UNSIZED_FORMATKEY(GL_RED,   GL_FLOAT),
147         GLS_UNSIZED_FORMATKEY(GL_RG,    GL_FLOAT),
148 };
149
150 static const FormatKey s_extTextureRgHalfFloatTexFormats[] =
151 {
152         GLS_UNSIZED_FORMATKEY(GL_RED,   GL_HALF_FLOAT_OES),
153         GLS_UNSIZED_FORMATKEY(GL_RG,    GL_HALF_FLOAT_OES),
154 };
155
156 static const FormatKey s_nvPackedFloatRboFormats[] =
157 {
158         GL_R11F_G11F_B10F,
159 };
160
161 static const FormatKey s_nvPackedFloatTexFormats[] =
162 {
163         GLS_UNSIZED_FORMATKEY(GL_RGB,   GL_UNSIGNED_INT_10F_11F_11F_REV),
164 };
165
166 static const FormatKey s_extSrgbRboFormats[] =
167 {
168         GL_SRGB8_ALPHA8,
169 };
170
171 static const FormatKey s_extSrgbRenderableTexFormats[] =
172 {
173         GLS_UNSIZED_FORMATKEY(GL_SRGB_ALPHA,    GL_UNSIGNED_BYTE),
174 };
175
176 static const FormatKey s_extSrgbNonRenderableTexFormats[] =
177 {
178         GLS_UNSIZED_FORMATKEY(GL_SRGB,                  GL_UNSIGNED_BYTE),
179         GL_SRGB8,
180 };
181
182 static const FormatKey s_nvSrgbFormatsRboFormats[] =
183 {
184         GL_SRGB8,
185 };
186
187 static const FormatKey s_nvSrgbFormatsTextureFormats[] =
188 {
189         GL_SRGB8,
190
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),
195 };
196
197 static const FormatKey s_oesRgb8Rgba8TexFormats[] =
198 {
199         GLS_UNSIZED_FORMATKEY(GL_RGB,           GL_UNSIGNED_BYTE),
200         GLS_UNSIZED_FORMATKEY(GL_RGBA,          GL_UNSIGNED_BYTE),
201 };
202
203 static const FormatKey s_extTextureSRGBR8Formats[] =
204 {
205         GL_SR8_EXT,
206 };
207
208 static const FormatKey s_extTextureSRGBRG8Formats[] =
209 {
210         GL_SRG8_EXT,
211 };
212
213 static const FormatExtEntry s_esExtFormats[] =
214 {
215         {
216                 "GL_OES_depth_texture",
217                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
218                 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
219         },
220         {
221                 "GL_OES_packed_depth_stencil",
222                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID),
223                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
224         },
225         {
226                 "GL_OES_packed_depth_stencil GL_OES_required_internalformat",
227                 (deUint32)TEXTURE_VALID,
228                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
229         },
230         {
231                 "GL_OES_packed_depth_stencil GL_OES_depth_texture",
232                 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
233                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats)
234         },
235         // The ANGLE extension incorporates GL_OES_depth_texture/GL_OES_packed_depth_stencil.
236         {
237                 "GL_ANGLE_depth_texture",
238                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
239                 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
240         },
241         {
242                 "GL_OES_packed_depth_stencil GL_ANGLE_depth_texture",
243                 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
244                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats),
245         },
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?
249         {
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)
253         },
254
255         // OES_required_internalformat doesn't actually specify that these are renderable,
256         // since it was written against ES 1.1.
257         {
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)
263         },
264         {
265                 "GL_OES_required_internalformat",
266                 (deUint32)(DEPTH_RENDERABLE | TEXTURE_VALID),
267                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatDepthFormats)
268         },
269         {
270                 "GL_EXT_texture_rg",
271                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
272                 GLS_ARRAY_RANGE(s_extTextureRgRboFormats)
273         },
274         // These are not specified to be color-renderable, but the wording is
275         // exactly as ambiguous as the wording in the ES2 spec.
276         {
277                 "GL_EXT_texture_rg",
278                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
279                 GLS_ARRAY_RANGE(s_extTextureRgTexFormats)
280         },
281         {
282                 "GL_EXT_texture_rg GL_OES_texture_float",
283                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
284                 GLS_ARRAY_RANGE(s_extTextureRgFloatTexFormats)
285         },
286         {
287                 "GL_EXT_texture_rg GL_OES_texture_half_float",
288                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
289                 GLS_ARRAY_RANGE(s_extTextureRgHalfFloatTexFormats)
290         },
291
292         {
293                 "GL_NV_packed_float",
294                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
295                 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
296         },
297         {
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)
301         },
302
303         {
304                 "GL_EXT_sRGB",
305                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
306                 GLS_ARRAY_RANGE(s_extSrgbRenderableTexFormats)
307         },
308         {
309                 "GL_EXT_sRGB",
310                 (deUint32)TEXTURE_VALID,
311                 GLS_ARRAY_RANGE(s_extSrgbNonRenderableTexFormats)
312         },
313         {
314                 "GL_EXT_sRGB",
315                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
316                 GLS_ARRAY_RANGE(s_extSrgbRboFormats)
317         },
318         {
319                 "GL_NV_sRGB_formats",
320                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
321                 GLS_ARRAY_RANGE(s_nvSrgbFormatsRboFormats)
322         },
323         {
324                 "GL_NV_sRGB_formats",
325                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID),
326                 GLS_ARRAY_RANGE(s_nvSrgbFormatsTextureFormats)
327         },
328
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.
332         {
333                 "GL_OES_rgb8_rgba8",
334                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
335                 GLS_ARRAY_RANGE(s_oesRgb8Rgba8TexFormats)
336         },
337         {
338                 "GL_OES_rgb8_rgba8",
339                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
340                 GLS_ARRAY_RANGE(s_oesRgb8Rgba8RboFormats)
341         },
342         {
343                 "GL_OES_rgb8_rgba8 GL_OES_required_internalformat",
344                 (deUint32)TEXTURE_VALID,
345                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatRgb8ColorFormat)
346         },
347
348         // The depth-renderability of the depth RBO formats is not explicitly
349         // spelled out, but all renderbuffer formats are meant to be renderable.
350         {
351                 "GL_OES_depth24",
352                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
353                 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
354         },
355         {
356                 "GL_OES_depth24 GL_OES_required_internalformat GL_OES_depth_texture",
357                 (deUint32)TEXTURE_VALID,
358                 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
359         },
360
361         {
362                 "GL_OES_depth32",
363                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
364                 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
365         },
366         {
367                 "GL_OES_depth32 GL_OES_required_internalformat GL_OES_depth_texture",
368                 (deUint32)TEXTURE_VALID,
369                 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
370         },
371
372         {
373                 "GL_EXT_texture_type_2_10_10_10_REV",
374                 (deUint32)TEXTURE_VALID, // explicitly unrenderable
375                 GLS_ARRAY_RANGE(s_extTextureType2101010RevFormats)
376         },
377         {
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)
381         },
382
383         {
384                 "GL_EXT_texture_sRGB_R8",
385                 (deUint32)TEXTURE_VALID,
386                 GLS_ARRAY_RANGE(s_extTextureSRGBR8Formats)
387         },
388         {
389                 "GL_EXT_texture_sRGB_RG8",
390                 (deUint32)TEXTURE_VALID,
391                 GLS_ARRAY_RANGE(s_extTextureSRGBRG8Formats)
392         },
393 };
394
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)
402 {
403         FormatExtEntries extRange = GLS_ARRAY_RANGE(s_esExtFormats);
404         addExtFormats(extRange);
405 }
406
407 void Context::addFormats (FormatEntries fmtRange)
408 {
409         FboUtil::addFormats(m_coreFormats, fmtRange);
410         FboUtil::addFormats(m_ctxFormats, fmtRange);
411         FboUtil::addFormats(m_allFormats, fmtRange);
412 }
413
414 void Context::addExtFormats (FormatExtEntries extRange)
415 {
416         FboUtil::addExtFormats(m_ctxFormats, extRange, &m_renderCtx);
417         FboUtil::addExtFormats(m_allFormats, extRange, DE_NULL);
418 }
419
420 void TestBase::pass (void)
421 {
422         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
423 }
424
425 void TestBase::qualityWarning (const char* msg)
426 {
427         m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, msg);
428 }
429
430 void TestBase::fail (const char* msg)
431 {
432         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg);
433 }
434
435 const glw::Functions& gl (const TestBase& test)
436 {
437         return test.getContext().getRenderContext().getFunctions();
438 }
439
440 static bool isFormatFeatureSupported (const FormatDB& db, const ImageFormat& format, FormatFlags feature)
441 {
442         return db.isKnownFormat(format) && ((db.getFormatInfo(format) & feature) == feature);
443 }
444
445 static void logAffectingExtensions (const char* prefix, const FormatDB& db, const ImageFormat& format, FormatFlags feature, tcu::MessageBuilder& msg)
446 {
447         const std::set<std::set<std::string> > rows = db.getFormatFeatureExtensions(format, feature);
448
449         for (std::set<std::set<std::string> >::const_iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt)
450         {
451                 const std::set<std::string>&                    requiredExtensions      = *rowIt;
452                 std::set<std::string>::const_iterator   it                                      = requiredExtensions.begin();
453                 std::string                                                             extName;
454
455                 msg << prefix;
456
457                 extName = *it++;
458                 while (it != requiredExtensions.end())
459                 {
460                         msg << getExtensionDescription(extName);
461                         extName = *it++;
462                         msg << (it == requiredExtensions.end() ? " and " : ", ");
463                 }
464
465                 msg << getExtensionDescription(extName) << '\n';
466         }
467 }
468
469 static void logFormatInfo (const config::Framebuffer& fbo, const FormatDB& ctxFormats, const FormatDB& coreFormats, const FormatDB& allFormats, tcu::TestLog& log)
470 {
471         static const struct
472         {
473                 const char*                     name;
474                 const FormatFlags       flag;
475         } s_renderability[] =
476         {
477                 { "color-renderable",   COLOR_RENDERABLE        },
478                 { "depth-renderable",   DEPTH_RENDERABLE        },
479                 { "stencil-renderable", STENCIL_RENDERABLE      },
480         };
481
482         std::set<ImageFormat> formats;
483
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);
488
489         if (!formats.empty())
490         {
491                 const tcu::ScopedLogSection supersection(log, "Format", "Format info");
492
493                 for (std::set<ImageFormat>::const_iterator it = formats.begin(); it != formats.end(); ++it)
494                 {
495                         const tcu::ScopedLogSection section(log, "FormatInfo", de::toString(*it));
496
497                         // texture validity
498                         if (isFormatFeatureSupported(ctxFormats, *it, TEXTURE_VALID))
499                         {
500                                 tcu::MessageBuilder msg(&log);
501                                 msg << "* Valid texture format\n";
502
503                                 if (isFormatFeatureSupported(coreFormats, *it, TEXTURE_VALID))
504                                         msg << "\t* core feature";
505                                 else
506                                 {
507                                         msg << "\t* defined in supported extension(s):\n";
508                                         logAffectingExtensions("\t\t- ", ctxFormats, *it, TEXTURE_VALID, msg);
509                                 }
510
511                                 msg << tcu::TestLog::EndMessage;
512                         }
513                         else
514                         {
515                                 tcu::MessageBuilder msg(&log);
516                                 msg << "* Unsupported texture format\n";
517
518                                 if (isFormatFeatureSupported(allFormats, *it, TEXTURE_VALID))
519                                 {
520                                         msg << "\t* requires any of the extensions or combinations:\n";
521                                         logAffectingExtensions("\t\t- ", allFormats, *it, TEXTURE_VALID, msg);
522                                 }
523                                 else
524                                         msg << "\t* no extension can make this format valid";
525
526                                 msg << tcu::TestLog::EndMessage;
527                         }
528
529                         // RBO validity
530                         if (isFormatFeatureSupported(ctxFormats, *it, RENDERBUFFER_VALID))
531                         {
532                                 tcu::MessageBuilder msg(&log);
533                                 msg << "* Valid renderbuffer format\n";
534
535                                 if (isFormatFeatureSupported(coreFormats, *it, RENDERBUFFER_VALID))
536                                         msg << "\t* core feature";
537                                 else
538                                 {
539                                         msg << "\t* defined in supported extension(s):\n";
540                                         logAffectingExtensions("\t\t- ", ctxFormats, *it, RENDERBUFFER_VALID, msg);
541                                 }
542
543                                 msg << tcu::TestLog::EndMessage;
544                         }
545                         else
546                         {
547                                 tcu::MessageBuilder msg(&log);
548                                 msg << "* Unsupported renderbuffer format\n";
549
550                                 if (isFormatFeatureSupported(allFormats, *it, RENDERBUFFER_VALID))
551                                 {
552                                         msg << "\t* requires any of the extensions or combinations:\n";
553                                         logAffectingExtensions("\t\t- ", allFormats, *it, RENDERBUFFER_VALID, msg);
554                                 }
555                                 else
556                                         msg << "\t* no extension can make this format valid";
557
558                                 msg << tcu::TestLog::EndMessage;
559                         }
560
561                         // renderability
562                         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderability); ++ndx)
563                         {
564                                 if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
565                                 {
566                                         tcu::MessageBuilder msg(&log);
567                                         msg << "* Format is " << s_renderability[ndx].name << "\n";
568
569                                         if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
570                                                 msg << "\t* core feature";
571                                         else
572                                         {
573                                                 msg << "\t* defined in supported extension(s):\n";
574                                                 logAffectingExtensions("\t\t- ", ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
575                                         }
576
577                                         msg << tcu::TestLog::EndMessage;
578                                 }
579                                 else if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag))
580                                 {
581                                         tcu::MessageBuilder msg(&log);
582                                         msg << "* Format is allowed to be " << s_renderability[ndx].name << " but not required\n";
583
584                                         if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag))
585                                                 msg << "\t* core feature";
586                                         else if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
587                                         {
588                                                 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
589                                                 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
590                                         }
591                                         else
592                                                 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
593
594                                         msg << tcu::TestLog::EndMessage;
595                                 }
596                                 else
597                                 {
598                                         tcu::MessageBuilder msg(&log);
599                                         msg << "* Format is NOT " << s_renderability[ndx].name << "\n";
600
601                                         if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
602                                         {
603                                                 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
604                                                 {
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);
607                                                 }
608                                                 else
609                                                 {
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);
612                                                 }
613                                         }
614                                         else
615                                                 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
616
617                                         msg << tcu::TestLog::EndMessage;
618                                 }
619                         }
620                 }
621         }
622 }
623
624 IterateResult TestBase::iterate (void)
625 {
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();
631
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());
636
637         // \todo [2013-12-04 lauri] Check if drawing operations succeed.
638
639         if (errorCode != GL_NO_ERROR)
640         {
641                 m_testCtx.getLog()
642                         << TestLog::Message
643                         << "Received " << glu::getErrorStr(errorCode) << " (during FBO initialization)."
644                         << TestLog::EndMessage;
645
646                 if (reference.isErrorCodeValid(errorCode))
647                         pass();
648                 else if (reference.isErrorCodeRequired(GL_NO_ERROR))
649                         fail(("Expected no error but got " + de::toString(glu::getErrorStr(errorCode))).c_str());
650                 else
651                         fail("Got wrong error code");
652         }
653         else
654         {
655                 const GLenum    fboStatus       = gl(*this).checkFramebufferStatus(GL_FRAMEBUFFER);
656                 const bool              validStatus     = reference.isFBOStatusValid(fboStatus);
657
658                 m_testCtx.getLog()
659                         << TestLog::Message
660                         << "Received " << glu::getFramebufferStatusStr(fboStatus) << "."
661                         << TestLog::EndMessage;
662
663                 if (!validStatus)
664                 {
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");
669                         else
670                                 // An incomplete status is allowed, but not _this_ incomplete status.
671                                 fail("Framebuffer checked as incomplete, but with wrong status");
672                 }
673                 else if (fboStatus != GL_FRAMEBUFFER_COMPLETE && reference.isFBOStatusValid(GL_FRAMEBUFFER_COMPLETE))
674                         qualityWarning("Framebuffer object could have checked as complete but did not.");
675                 else
676                         pass();
677         }
678
679         return ret;
680 }
681
682 IterateResult TestBase::build (FboBuilder& builder)
683 {
684         DE_UNREF(builder);
685         return STOP;
686 }
687
688 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
689 {
690         if (bufType == GL_NONE)
691         {
692                 return ImageFormat::none();
693         }
694
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())
701         {
702                 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
703                                                                                                          formatFlag(bufType));
704                 it = formats.begin();
705         }
706         if (it == formats.end())
707                 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
708                                                                          "", __FILE__, __LINE__);
709         return *it;
710 };
711
712 Image* makeImage (GLenum bufType, ImageFormat format,
713                                   GLsizei width, GLsizei height, FboBuilder& builder)
714 {
715         Image* image = DE_NULL;
716         switch (bufType)
717         {
718                 case GL_NONE:
719                         return DE_NULL;
720                 case GL_RENDERBUFFER:
721                         image = &builder.makeConfig<Renderbuffer>();
722                         break;
723                 case GL_TEXTURE:
724                         image = &builder.makeConfig<Texture2D>();
725                         break;
726                 default:
727                         DE_FATAL("Impossible case");
728         }
729         image->internalFormat = format;
730         image->width = width;
731         image->height = height;
732         return image;
733 }
734
735 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
736                                                         GLsizei width, GLsizei height, FboBuilder& builder)
737 {
738         Image* const imgCfg = makeImage (bufType, format, width, height, builder);
739         Attachment* att = DE_NULL;
740         GLuint img = 0;
741
742         if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
743         {
744                 img = builder.glCreateRbo(*rboCfg);
745                 att = &builder.makeConfig<RenderbufferAttachment>();
746         }
747         else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
748         {
749                 img = builder.glCreateTexture(*texCfg);
750                 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
751                 texAtt.texTarget = GL_TEXTURE_2D;
752                 att = &texAtt;
753         }
754         else
755         {
756                 DE_ASSERT(imgCfg == DE_NULL);
757                 return DE_NULL;
758         }
759         att->imageName = img;
760         return att;
761 }
762
763 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
764                                                                   GLsizei width, GLsizei height, FboBuilder& builder)
765 {
766         ImageFormat imgFmt = format;
767         if (imgFmt.format == GL_NONE)
768                 imgFmt = getDefaultFormat(target, bufType);
769
770         const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
771         builder.glAttach(target, att);
772 }
773
774 static string formatName (ImageFormat format)
775 {
776         const string s = getTextureFormatName(format.format);
777         const string fmtStr = toLower(s.substr(3));
778
779         if (format.unsizedType != GL_NONE)
780         {
781                 const string typeStr = getTypeName(format.unsizedType);
782                 return fmtStr + "_" + toLower(typeStr.substr(3));
783         }
784
785         return fmtStr;
786 }
787
788 static string formatDesc (ImageFormat format)
789 {
790         const string fmtStr = getTextureFormatName(format.format);
791
792         if (format.unsizedType != GL_NONE)
793         {
794                 const string typeStr = getTypeName(format.unsizedType);
795                 return fmtStr + " with type " + typeStr;
796         }
797
798         return fmtStr;
799 }
800
801 struct RenderableParams
802 {
803         GLenum                          attPoint;
804         GLenum                          bufType;
805         ImageFormat                     format;
806         static string           getName                         (const RenderableParams& params)
807         {
808                 return formatName(params.format);
809         }
810         static string           getDescription          (const RenderableParams& params)
811         {
812                 return formatDesc(params.format);
813         }
814 };
815
816 class RenderableTest : public ParamTest<RenderableParams>
817 {
818 public:
819                                         RenderableTest          (Context& group, const Params& params)
820                                                 : ParamTest<RenderableParams> (group, params) {}
821         IterateResult   build                           (FboBuilder& builder);
822 };
823
824 IterateResult RenderableTest::build (FboBuilder& builder)
825 {
826         attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
827         return STOP;
828 }
829
830 string attTypeName (GLenum bufType)
831 {
832         switch (bufType)
833         {
834                 case GL_NONE:
835                         return "none";
836                 case GL_RENDERBUFFER:
837                         return "rbo";
838                 case GL_TEXTURE:
839                         return "tex";
840                 default:
841                         DE_FATAL("Impossible case");
842         }
843         return ""; // Shut up compiler
844 }
845
846 struct AttachmentParams
847 {
848         GLenum                                          color0Kind;
849         GLenum                                          colornKind;
850         GLenum                                          depthKind;
851         GLenum                                          stencilKind;
852
853         static string           getName                 (const AttachmentParams& params);
854         static string           getDescription  (const AttachmentParams& params)
855         {
856                 return getName(params);
857         }
858 };
859
860 string AttachmentParams::getName (const AttachmentParams& params)
861 {
862         return (attTypeName(params.color0Kind) + "_" +
863                         attTypeName(params.colornKind) + "_" +
864                         attTypeName(params.depthKind) + "_" +
865                         attTypeName(params.stencilKind));
866 }
867
868 //! Test for combinations of different kinds of attachments
869 class AttachmentTest : public ParamTest<AttachmentParams>
870 {
871 public:
872                                         AttachmentTest          (Context& group, Params& params)
873                                                 : ParamTest<AttachmentParams> (group, params) {}
874
875 protected:
876         IterateResult   build                           (FboBuilder& builder);
877         void                    makeDepthAndStencil     (FboBuilder& builder);
878 };
879
880
881 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
882 {
883         if (m_params.stencilKind == m_params.depthKind)
884         {
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())
892                 {
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);
897                         return;
898                 }
899         }
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(),
903                                           64, 64, builder);
904         attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
905                                           64, 64, builder);
906 }
907
908 IterateResult AttachmentTest::build (FboBuilder& builder)
909 {
910         attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
911                                           64, 64, builder);
912
913         if (m_params.colornKind != GL_NONE)
914         {
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);
919                 GLU_EXPECT_NO_ERROR(
920                         gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
921
922                 for (int i = 1; i < maxAttachments; i++)
923                 {
924                         attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
925                                                           ImageFormat::none(), 64, 64, builder);
926                 }
927         }
928
929         makeDepthAndStencil(builder);
930
931         return STOP;
932 }
933
934 class EmptyImageTest : public TestBase
935 {
936 public:
937                                         EmptyImageTest  (Context& group,
938                                                                          const char* name, const char* desc)
939                                                 : TestBase      (group, name, desc) {}
940
941         IterateResult   build                   (FboBuilder& builder);
942 };
943
944 IterateResult EmptyImageTest::build (FboBuilder& builder)
945 {
946         attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
947                                           0, 0, builder);
948         return STOP;
949 }
950
951
952 class DistinctSizeTest : public TestBase
953 {
954 public:
955                                         DistinctSizeTest        (Context& group,
956                                                                                  const char* name, const char* desc)
957                                                 : TestBase              (group, name, desc) {}
958
959         IterateResult   build                           (FboBuilder& builder);
960 };
961
962 IterateResult DistinctSizeTest::build (FboBuilder& builder)
963 {
964         attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
965                                           64, 64, builder);
966         attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
967                                           128, 128, builder);
968         return STOP;
969 }
970
971 TestCaseGroup* Context::createRenderableTests (void)
972 {
973         TestCaseGroup* const renderableTests = new TestCaseGroup(
974                 m_testCtx, "renderable", "Tests for support of renderable image formats");
975
976         TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
977                 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
978
979         TestCaseGroup* const texRenderableTests = new TestCaseGroup(
980                 m_testCtx, "texture", "Tests for texture formats");
981
982         static const struct AttPoint {
983                 GLenum                  attPoint;
984                 const char*             name;
985                 const char*             desc;
986         } attPoints[] =
987         {
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"   },
991         };
992
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);
997
998         for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
999         {
1000                 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1001                 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1002
1003                 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
1004                 {
1005                         const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
1006                         rbAttTests->addChild(new RenderableTest(*this, params));
1007                 }
1008                 rbRenderableTests->addChild(rbAttTests);
1009
1010                 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
1011                 {
1012                         const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
1013                         texAttTests->addChild(new RenderableTest(*this, params));
1014                 }
1015                 texRenderableTests->addChild(texAttTests);
1016         }
1017         renderableTests->addChild(rbRenderableTests);
1018         renderableTests->addChild(texRenderableTests);
1019
1020         return renderableTests;
1021 }
1022
1023 TestCaseGroup* Context::createAttachmentTests (void)
1024 {
1025         TestCaseGroup* const attCombTests = new TestCaseGroup(
1026                 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
1027
1028         static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
1029         static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
1030
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)
1035                                 {
1036                                         AttachmentParams params = { *col0, *coln, *dep, *stc };
1037                                         attCombTests->addChild(new AttachmentTest(*this, params));
1038                                 }
1039
1040         return attCombTests;
1041 }
1042
1043 TestCaseGroup* Context::createSizeTests (void)
1044 {
1045         TestCaseGroup* const sizeTests = new TestCaseGroup(
1046                 m_testCtx, "size", "Tests for attachment sizes");
1047         sizeTests->addChild(new EmptyImageTest(
1048                                                         *this, "zero",
1049                                                         "Test for zero-sized image attachment"));
1050         sizeTests->addChild(new DistinctSizeTest(
1051                                                         *this, "distinct",
1052                                                         "Test for attachments with different sizes"));
1053
1054         return sizeTests;
1055 }
1056
1057 } // details
1058
1059 } // fboc
1060 } // gls
1061 } // deqp