Remove illegal parameter use in fbo.completeness
[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 };
180
181 static const FormatKey s_nvSrgbFormatsRboFormats[] =
182 {
183         GL_SRGB8,
184 };
185
186 static const FormatKey s_nvSrgbFormatsTextureFormats[] =
187 {
188         GL_SRGB8,
189
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),
194 };
195
196 static const FormatKey s_oesRgb8Rgba8TexFormats[] =
197 {
198         GLS_UNSIZED_FORMATKEY(GL_RGB,           GL_UNSIGNED_BYTE),
199         GLS_UNSIZED_FORMATKEY(GL_RGBA,          GL_UNSIGNED_BYTE),
200 };
201
202 static const FormatKey s_extTextureSRGBR8Formats[] =
203 {
204         GL_SR8_EXT,
205 };
206
207 static const FormatKey s_extTextureSRGBRG8Formats[] =
208 {
209         GL_SRG8_EXT,
210 };
211
212 static const FormatExtEntry s_esExtFormats[] =
213 {
214         {
215                 "GL_OES_depth_texture",
216                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
217                 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
218         },
219         {
220                 "GL_OES_packed_depth_stencil",
221                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID),
222                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
223         },
224         {
225                 "GL_OES_packed_depth_stencil GL_OES_required_internalformat",
226                 (deUint32)TEXTURE_VALID,
227                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
228         },
229         {
230                 "GL_OES_packed_depth_stencil GL_OES_depth_texture",
231                 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
232                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats)
233         },
234         // The ANGLE extension incorporates GL_OES_depth_texture/GL_OES_packed_depth_stencil.
235         {
236                 "GL_ANGLE_depth_texture",
237                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID),
238                 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
239         },
240         {
241                 "GL_OES_packed_depth_stencil GL_ANGLE_depth_texture",
242                 (deUint32)(DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID),
243                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats),
244         },
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?
248         {
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)
252         },
253
254         // OES_required_internalformat doesn't actually specify that these are renderable,
255         // since it was written against ES 1.1.
256         {
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)
262         },
263         {
264                 "GL_OES_required_internalformat",
265                 (deUint32)(DEPTH_RENDERABLE | TEXTURE_VALID),
266                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatDepthFormats)
267         },
268         {
269                 "GL_EXT_texture_rg",
270                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
271                 GLS_ARRAY_RANGE(s_extTextureRgRboFormats)
272         },
273         // These are not specified to be color-renderable, but the wording is
274         // exactly as ambiguous as the wording in the ES2 spec.
275         {
276                 "GL_EXT_texture_rg",
277                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
278                 GLS_ARRAY_RANGE(s_extTextureRgTexFormats)
279         },
280         {
281                 "GL_EXT_texture_rg GL_OES_texture_float",
282                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
283                 GLS_ARRAY_RANGE(s_extTextureRgFloatTexFormats)
284         },
285         {
286                 "GL_EXT_texture_rg GL_OES_texture_half_float",
287                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
288                 GLS_ARRAY_RANGE(s_extTextureRgHalfFloatTexFormats)
289         },
290
291         {
292                 "GL_NV_packed_float",
293                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
294                 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
295         },
296         {
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)
300         },
301
302         {
303                 "GL_EXT_sRGB",
304                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
305                 GLS_ARRAY_RANGE(s_extSrgbRenderableTexFormats)
306         },
307         {
308                 "GL_EXT_sRGB",
309                 (deUint32)TEXTURE_VALID,
310                 GLS_ARRAY_RANGE(s_extSrgbNonRenderableTexFormats)
311         },
312         {
313                 "GL_EXT_sRGB",
314                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
315                 GLS_ARRAY_RANGE(s_extSrgbRboFormats)
316         },
317         {
318                 "GL_NV_sRGB_formats",
319                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
320                 GLS_ARRAY_RANGE(s_nvSrgbFormatsRboFormats)
321         },
322         {
323                 "GL_NV_sRGB_formats",
324                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID),
325                 GLS_ARRAY_RANGE(s_nvSrgbFormatsTextureFormats)
326         },
327
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.
331         {
332                 "GL_OES_rgb8_rgba8",
333                 (deUint32)(COLOR_RENDERABLE | TEXTURE_VALID),
334                 GLS_ARRAY_RANGE(s_oesRgb8Rgba8TexFormats)
335         },
336         {
337                 "GL_OES_rgb8_rgba8",
338                 (deUint32)(REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID),
339                 GLS_ARRAY_RANGE(s_oesRgb8Rgba8RboFormats)
340         },
341         {
342                 "GL_OES_rgb8_rgba8 GL_OES_required_internalformat",
343                 (deUint32)TEXTURE_VALID,
344                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatRgb8ColorFormat)
345         },
346
347         // The depth-renderability of the depth RBO formats is not explicitly
348         // spelled out, but all renderbuffer formats are meant to be renderable.
349         {
350                 "GL_OES_depth24",
351                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
352                 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
353         },
354         {
355                 "GL_OES_depth24 GL_OES_required_internalformat GL_OES_depth_texture",
356                 (deUint32)TEXTURE_VALID,
357                 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
358         },
359
360         {
361                 "GL_OES_depth32",
362                 (deUint32)(REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID),
363                 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
364         },
365         {
366                 "GL_OES_depth32 GL_OES_required_internalformat GL_OES_depth_texture",
367                 (deUint32)TEXTURE_VALID,
368                 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
369         },
370
371         {
372                 "GL_EXT_texture_type_2_10_10_10_REV",
373                 (deUint32)TEXTURE_VALID, // explicitly unrenderable
374                 GLS_ARRAY_RANGE(s_extTextureType2101010RevFormats)
375         },
376         {
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)
380         },
381
382         {
383                 "GL_EXT_texture_sRGB_R8",
384                 (deUint32)TEXTURE_VALID,
385                 GLS_ARRAY_RANGE(s_extTextureSRGBR8Formats)
386         },
387         {
388                 "GL_EXT_texture_sRGB_RG8",
389                 (deUint32)TEXTURE_VALID,
390                 GLS_ARRAY_RANGE(s_extTextureSRGBRG8Formats)
391         },
392 };
393
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)
401 {
402         FormatExtEntries extRange = GLS_ARRAY_RANGE(s_esExtFormats);
403         addExtFormats(extRange);
404 }
405
406 void Context::addFormats (FormatEntries fmtRange)
407 {
408         FboUtil::addFormats(m_coreFormats, fmtRange);
409         FboUtil::addFormats(m_ctxFormats, fmtRange);
410         FboUtil::addFormats(m_allFormats, fmtRange);
411 }
412
413 void Context::addExtFormats (FormatExtEntries extRange)
414 {
415         FboUtil::addExtFormats(m_ctxFormats, extRange, &m_renderCtx);
416         FboUtil::addExtFormats(m_allFormats, extRange, DE_NULL);
417 }
418
419 void TestBase::pass (void)
420 {
421         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
422 }
423
424 void TestBase::qualityWarning (const char* msg)
425 {
426         m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, msg);
427 }
428
429 void TestBase::fail (const char* msg)
430 {
431         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg);
432 }
433
434 const glw::Functions& gl (const TestBase& test)
435 {
436         return test.getContext().getRenderContext().getFunctions();
437 }
438
439 static bool isFormatFeatureSupported (const FormatDB& db, const ImageFormat& format, FormatFlags feature)
440 {
441         return db.isKnownFormat(format) && ((db.getFormatInfo(format) & feature) == feature);
442 }
443
444 static void logAffectingExtensions (const char* prefix, const FormatDB& db, const ImageFormat& format, FormatFlags feature, tcu::MessageBuilder& msg)
445 {
446         const std::set<std::set<std::string> > rows = db.getFormatFeatureExtensions(format, feature);
447
448         for (std::set<std::set<std::string> >::const_iterator rowIt = rows.begin(); rowIt != rows.end(); ++rowIt)
449         {
450                 const std::set<std::string>&                    requiredExtensions      = *rowIt;
451                 std::set<std::string>::const_iterator   it                                      = requiredExtensions.begin();
452                 std::string                                                             extName;
453
454                 msg << prefix;
455
456                 extName = *it++;
457                 while (it != requiredExtensions.end())
458                 {
459                         msg << getExtensionDescription(extName);
460                         extName = *it++;
461                         msg << (it == requiredExtensions.end() ? " and " : ", ");
462                 }
463
464                 msg << getExtensionDescription(extName) << '\n';
465         }
466 }
467
468 static void logFormatInfo (const config::Framebuffer& fbo, const FormatDB& ctxFormats, const FormatDB& coreFormats, const FormatDB& allFormats, tcu::TestLog& log)
469 {
470         static const struct
471         {
472                 const char*                     name;
473                 const FormatFlags       flag;
474         } s_renderability[] =
475         {
476                 { "color-renderable",   COLOR_RENDERABLE        },
477                 { "depth-renderable",   DEPTH_RENDERABLE        },
478                 { "stencil-renderable", STENCIL_RENDERABLE      },
479         };
480
481         std::set<ImageFormat> formats;
482
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);
487
488         if (!formats.empty())
489         {
490                 const tcu::ScopedLogSection supersection(log, "Format", "Format info");
491
492                 for (std::set<ImageFormat>::const_iterator it = formats.begin(); it != formats.end(); ++it)
493                 {
494                         const tcu::ScopedLogSection section(log, "FormatInfo", de::toString(*it));
495
496                         // texture validity
497                         if (isFormatFeatureSupported(ctxFormats, *it, TEXTURE_VALID))
498                         {
499                                 tcu::MessageBuilder msg(&log);
500                                 msg << "* Valid texture format\n";
501
502                                 if (isFormatFeatureSupported(coreFormats, *it, TEXTURE_VALID))
503                                         msg << "\t* core feature";
504                                 else
505                                 {
506                                         msg << "\t* defined in supported extension(s):\n";
507                                         logAffectingExtensions("\t\t- ", ctxFormats, *it, TEXTURE_VALID, msg);
508                                 }
509
510                                 msg << tcu::TestLog::EndMessage;
511                         }
512                         else
513                         {
514                                 tcu::MessageBuilder msg(&log);
515                                 msg << "* Unsupported texture format\n";
516
517                                 if (isFormatFeatureSupported(allFormats, *it, TEXTURE_VALID))
518                                 {
519                                         msg << "\t* requires any of the extensions or combinations:\n";
520                                         logAffectingExtensions("\t\t- ", allFormats, *it, TEXTURE_VALID, msg);
521                                 }
522                                 else
523                                         msg << "\t* no extension can make this format valid";
524
525                                 msg << tcu::TestLog::EndMessage;
526                         }
527
528                         // RBO validity
529                         if (isFormatFeatureSupported(ctxFormats, *it, RENDERBUFFER_VALID))
530                         {
531                                 tcu::MessageBuilder msg(&log);
532                                 msg << "* Valid renderbuffer format\n";
533
534                                 if (isFormatFeatureSupported(coreFormats, *it, RENDERBUFFER_VALID))
535                                         msg << "\t* core feature";
536                                 else
537                                 {
538                                         msg << "\t* defined in supported extension(s):\n";
539                                         logAffectingExtensions("\t\t- ", ctxFormats, *it, RENDERBUFFER_VALID, msg);
540                                 }
541
542                                 msg << tcu::TestLog::EndMessage;
543                         }
544                         else
545                         {
546                                 tcu::MessageBuilder msg(&log);
547                                 msg << "* Unsupported renderbuffer format\n";
548
549                                 if (isFormatFeatureSupported(allFormats, *it, RENDERBUFFER_VALID))
550                                 {
551                                         msg << "\t* requires any of the extensions or combinations:\n";
552                                         logAffectingExtensions("\t\t- ", allFormats, *it, RENDERBUFFER_VALID, msg);
553                                 }
554                                 else
555                                         msg << "\t* no extension can make this format valid";
556
557                                 msg << tcu::TestLog::EndMessage;
558                         }
559
560                         // renderability
561                         for (int ndx = 0; ndx < DE_LENGTH_OF_ARRAY(s_renderability); ++ndx)
562                         {
563                                 if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
564                                 {
565                                         tcu::MessageBuilder msg(&log);
566                                         msg << "* Format is " << s_renderability[ndx].name << "\n";
567
568                                         if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
569                                                 msg << "\t* core feature";
570                                         else
571                                         {
572                                                 msg << "\t* defined in supported extension(s):\n";
573                                                 logAffectingExtensions("\t\t- ", ctxFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE, msg);
574                                         }
575
576                                         msg << tcu::TestLog::EndMessage;
577                                 }
578                                 else if (isFormatFeatureSupported(ctxFormats, *it, s_renderability[ndx].flag))
579                                 {
580                                         tcu::MessageBuilder msg(&log);
581                                         msg << "* Format is allowed to be " << s_renderability[ndx].name << " but not required\n";
582
583                                         if (isFormatFeatureSupported(coreFormats, *it, s_renderability[ndx].flag))
584                                                 msg << "\t* core feature";
585                                         else if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
586                                         {
587                                                 msg << "\t* extensions that would make format " << s_renderability[ndx].name << ":\n";
588                                                 logAffectingExtensions("\t\t- ", allFormats, *it, s_renderability[ndx].flag, msg);
589                                         }
590                                         else
591                                                 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
592
593                                         msg << tcu::TestLog::EndMessage;
594                                 }
595                                 else
596                                 {
597                                         tcu::MessageBuilder msg(&log);
598                                         msg << "* Format is NOT " << s_renderability[ndx].name << "\n";
599
600                                         if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag))
601                                         {
602                                                 if (isFormatFeatureSupported(allFormats, *it, s_renderability[ndx].flag | REQUIRED_RENDERABLE))
603                                                 {
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);
606                                                 }
607                                                 else
608                                                 {
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);
611                                                 }
612                                         }
613                                         else
614                                                 msg << "\t* no extension can make this format " << s_renderability[ndx].name;
615
616                                         msg << tcu::TestLog::EndMessage;
617                                 }
618                         }
619                 }
620         }
621 }
622
623 IterateResult TestBase::iterate (void)
624 {
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();
630
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());
635
636         // \todo [2013-12-04 lauri] Check if drawing operations succeed.
637
638         if (errorCode != GL_NO_ERROR)
639         {
640                 m_testCtx.getLog()
641                         << TestLog::Message
642                         << "Received " << glu::getErrorStr(errorCode) << " (during FBO initialization)."
643                         << TestLog::EndMessage;
644
645                 if (reference.isErrorCodeValid(errorCode))
646                         pass();
647                 else if (reference.isErrorCodeRequired(GL_NO_ERROR))
648                         fail(("Expected no error but got " + de::toString(glu::getErrorStr(errorCode))).c_str());
649                 else
650                         fail("Got wrong error code");
651         }
652         else
653         {
654                 const GLenum    fboStatus       = gl(*this).checkFramebufferStatus(GL_FRAMEBUFFER);
655                 const bool              validStatus     = reference.isFBOStatusValid(fboStatus);
656
657                 m_testCtx.getLog()
658                         << TestLog::Message
659                         << "Received " << glu::getFramebufferStatusStr(fboStatus) << "."
660                         << TestLog::EndMessage;
661
662                 if (!validStatus)
663                 {
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");
668                         else
669                                 // An incomplete status is allowed, but not _this_ incomplete status.
670                                 fail("Framebuffer checked as incomplete, but with wrong status");
671                 }
672                 else if (fboStatus != GL_FRAMEBUFFER_COMPLETE && reference.isFBOStatusValid(GL_FRAMEBUFFER_COMPLETE))
673                         qualityWarning("Framebuffer object could have checked as complete but did not.");
674                 else
675                         pass();
676         }
677
678         return ret;
679 }
680
681 IterateResult TestBase::build (FboBuilder& builder)
682 {
683         DE_UNREF(builder);
684         return STOP;
685 }
686
687 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
688 {
689         if (bufType == GL_NONE)
690         {
691                 return ImageFormat::none();
692         }
693
694         // Prefer a standard format, if there is one, but if not, use a format
695         // provided by an extension.
696         Formats formats = m_ctx.getCoreFormats().getFormats(formatFlag(attPoint) |
697                                                                                                                  formatFlag(bufType));
698         Formats::const_iterator it = formats.begin();
699         if (it == formats.end())
700         {
701                 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
702                                                                                                          formatFlag(bufType));
703                 it = formats.begin();
704         }
705         if (it == formats.end())
706                 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
707                                                                          "", __FILE__, __LINE__);
708         return *it;
709 };
710
711 Image* makeImage (GLenum bufType, ImageFormat format,
712                                   GLsizei width, GLsizei height, FboBuilder& builder)
713 {
714         Image* image = DE_NULL;
715         switch (bufType)
716         {
717                 case GL_NONE:
718                         return DE_NULL;
719                 case GL_RENDERBUFFER:
720                         image = &builder.makeConfig<Renderbuffer>();
721                         break;
722                 case GL_TEXTURE:
723                         image = &builder.makeConfig<Texture2D>();
724                         break;
725                 default:
726                         DE_FATAL("Impossible case");
727         }
728         image->internalFormat = format;
729         image->width = width;
730         image->height = height;
731         return image;
732 }
733
734 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
735                                                         GLsizei width, GLsizei height, FboBuilder& builder)
736 {
737         Image* const imgCfg = makeImage (bufType, format, width, height, builder);
738         Attachment* att = DE_NULL;
739         GLuint img = 0;
740
741         if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
742         {
743                 img = builder.glCreateRbo(*rboCfg);
744                 att = &builder.makeConfig<RenderbufferAttachment>();
745         }
746         else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
747         {
748                 img = builder.glCreateTexture(*texCfg);
749                 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
750                 texAtt.texTarget = GL_TEXTURE_2D;
751                 att = &texAtt;
752         }
753         else
754         {
755                 DE_ASSERT(imgCfg == DE_NULL);
756                 return DE_NULL;
757         }
758         att->imageName = img;
759         return att;
760 }
761
762 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
763                                                                   GLsizei width, GLsizei height, FboBuilder& builder)
764 {
765         ImageFormat imgFmt = format;
766         if (imgFmt.format == GL_NONE)
767                 imgFmt = getDefaultFormat(target, bufType);
768
769         const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
770         builder.glAttach(target, att);
771 }
772
773 static string formatName (ImageFormat format)
774 {
775         const string s = getTextureFormatName(format.format);
776         const string fmtStr = toLower(s.substr(3));
777
778         if (format.unsizedType != GL_NONE)
779         {
780                 const string typeStr = getTypeName(format.unsizedType);
781                 return fmtStr + "_" + toLower(typeStr.substr(3));
782         }
783
784         return fmtStr;
785 }
786
787 static string formatDesc (ImageFormat format)
788 {
789         const string fmtStr = getTextureFormatName(format.format);
790
791         if (format.unsizedType != GL_NONE)
792         {
793                 const string typeStr = getTypeName(format.unsizedType);
794                 return fmtStr + " with type " + typeStr;
795         }
796
797         return fmtStr;
798 }
799
800 struct RenderableParams
801 {
802         GLenum                          attPoint;
803         GLenum                          bufType;
804         ImageFormat                     format;
805         static string           getName                         (const RenderableParams& params)
806         {
807                 return formatName(params.format);
808         }
809         static string           getDescription          (const RenderableParams& params)
810         {
811                 return formatDesc(params.format);
812         }
813 };
814
815 class RenderableTest : public ParamTest<RenderableParams>
816 {
817 public:
818                                         RenderableTest          (Context& group, const Params& params)
819                                                 : ParamTest<RenderableParams> (group, params) {}
820         IterateResult   build                           (FboBuilder& builder);
821 };
822
823 IterateResult RenderableTest::build (FboBuilder& builder)
824 {
825         attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
826         return STOP;
827 }
828
829 string attTypeName (GLenum bufType)
830 {
831         switch (bufType)
832         {
833                 case GL_NONE:
834                         return "none";
835                 case GL_RENDERBUFFER:
836                         return "rbo";
837                 case GL_TEXTURE:
838                         return "tex";
839                 default:
840                         DE_FATAL("Impossible case");
841         }
842         return ""; // Shut up compiler
843 }
844
845 struct AttachmentParams
846 {
847         GLenum                                          color0Kind;
848         GLenum                                          colornKind;
849         GLenum                                          depthKind;
850         GLenum                                          stencilKind;
851
852         static string           getName                 (const AttachmentParams& params);
853         static string           getDescription  (const AttachmentParams& params)
854         {
855                 return getName(params);
856         }
857 };
858
859 string AttachmentParams::getName (const AttachmentParams& params)
860 {
861         return (attTypeName(params.color0Kind) + "_" +
862                         attTypeName(params.colornKind) + "_" +
863                         attTypeName(params.depthKind) + "_" +
864                         attTypeName(params.stencilKind));
865 }
866
867 //! Test for combinations of different kinds of attachments
868 class AttachmentTest : public ParamTest<AttachmentParams>
869 {
870 public:
871                                         AttachmentTest          (Context& group, Params& params)
872                                                 : ParamTest<AttachmentParams> (group, params) {}
873
874 protected:
875         IterateResult   build                           (FboBuilder& builder);
876         void                    makeDepthAndStencil     (FboBuilder& builder);
877 };
878
879
880 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
881 {
882         if (m_params.stencilKind == m_params.depthKind)
883         {
884                 // If there is a common stencil+depth -format, try to use a common
885                 // image for both attachments.
886                 const FormatFlags flags =
887                         DEPTH_RENDERABLE | STENCIL_RENDERABLE | formatFlag(m_params.stencilKind);
888                 const Formats& formats = m_ctx.getCoreFormats().getFormats(flags);
889                 Formats::const_iterator it = formats.begin();
890                 if (it != formats.end())
891                 {
892                         const ImageFormat format = *it;
893                         Attachment* att = makeAttachment(m_params.depthKind, format, 64, 64, builder);
894                         builder.glAttach(GL_DEPTH_ATTACHMENT, att);
895                         builder.glAttach(GL_STENCIL_ATTACHMENT, att);
896                         return;
897                 }
898         }
899         // Either the kinds were separate, or a suitable format was not found.
900         // Create separate images.
901         attachTargetToNew(GL_STENCIL_ATTACHMENT, m_params.stencilKind, ImageFormat::none(),
902                                           64, 64, builder);
903         attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
904                                           64, 64, builder);
905 }
906
907 IterateResult AttachmentTest::build (FboBuilder& builder)
908 {
909         attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
910                                           64, 64, builder);
911
912         if (m_params.colornKind != GL_NONE)
913         {
914                 TCU_CHECK_AND_THROW(NotSupportedError, m_ctx.haveMultiColorAtts(),
915                                                         "Multiple attachments not supported");
916                 GLint maxAttachments = 1;
917                 gl(*this).getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments);
918                 GLU_EXPECT_NO_ERROR(
919                         gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
920
921                 for (int i = 1; i < maxAttachments; i++)
922                 {
923                         attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
924                                                           ImageFormat::none(), 64, 64, builder);
925                 }
926         }
927
928         makeDepthAndStencil(builder);
929
930         return STOP;
931 }
932
933 class EmptyImageTest : public TestBase
934 {
935 public:
936                                         EmptyImageTest  (Context& group,
937                                                                          const char* name, const char* desc)
938                                                 : TestBase      (group, name, desc) {}
939
940         IterateResult   build                   (FboBuilder& builder);
941 };
942
943 IterateResult EmptyImageTest::build (FboBuilder& builder)
944 {
945         attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
946                                           0, 0, builder);
947         return STOP;
948 }
949
950
951 class DistinctSizeTest : public TestBase
952 {
953 public:
954                                         DistinctSizeTest        (Context& group,
955                                                                                  const char* name, const char* desc)
956                                                 : TestBase              (group, name, desc) {}
957
958         IterateResult   build                           (FboBuilder& builder);
959 };
960
961 IterateResult DistinctSizeTest::build (FboBuilder& builder)
962 {
963         attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
964                                           64, 64, builder);
965         attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
966                                           128, 128, builder);
967         return STOP;
968 }
969
970 TestCaseGroup* Context::createRenderableTests (void)
971 {
972         TestCaseGroup* const renderableTests = new TestCaseGroup(
973                 m_testCtx, "renderable", "Tests for support of renderable image formats");
974
975         TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
976                 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
977
978         TestCaseGroup* const texRenderableTests = new TestCaseGroup(
979                 m_testCtx, "texture", "Tests for texture formats");
980
981         static const struct AttPoint {
982                 GLenum                  attPoint;
983                 const char*             name;
984                 const char*             desc;
985         } attPoints[] =
986         {
987                 { GL_COLOR_ATTACHMENT0,         "color0",       "Tests for color attachments"   },
988                 { GL_STENCIL_ATTACHMENT,        "stencil",      "Tests for stencil attachments" },
989                 { GL_DEPTH_ATTACHMENT,          "depth",        "Tests for depth attachments"   },
990         };
991
992         // At each attachment point, iterate through all the possible formats to
993         // detect both false positives and false negatives.
994         const Formats rboFmts = m_allFormats.getFormats(ANY_FORMAT);
995         const Formats texFmts = m_allFormats.getFormats(ANY_FORMAT);
996
997         for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
998         {
999                 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1000                 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
1001
1002                 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
1003                 {
1004                         const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
1005                         rbAttTests->addChild(new RenderableTest(*this, params));
1006                 }
1007                 rbRenderableTests->addChild(rbAttTests);
1008
1009                 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
1010                 {
1011                         const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
1012                         texAttTests->addChild(new RenderableTest(*this, params));
1013                 }
1014                 texRenderableTests->addChild(texAttTests);
1015         }
1016         renderableTests->addChild(rbRenderableTests);
1017         renderableTests->addChild(texRenderableTests);
1018
1019         return renderableTests;
1020 }
1021
1022 TestCaseGroup* Context::createAttachmentTests (void)
1023 {
1024         TestCaseGroup* const attCombTests = new TestCaseGroup(
1025                 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
1026
1027         static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
1028         static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
1029
1030         for (const GLenum* col0 = s_kinds.begin(); col0 != s_kinds.end(); ++col0)
1031                 for (const GLenum* coln = s_kinds.begin(); coln != s_kinds.end(); ++coln)
1032                         for (const GLenum* dep = s_kinds.begin(); dep != s_kinds.end(); ++dep)
1033                                 for (const GLenum* stc = s_kinds.begin(); stc != s_kinds.end(); ++stc)
1034                                 {
1035                                         AttachmentParams params = { *col0, *coln, *dep, *stc };
1036                                         attCombTests->addChild(new AttachmentTest(*this, params));
1037                                 }
1038
1039         return attCombTests;
1040 }
1041
1042 TestCaseGroup* Context::createSizeTests (void)
1043 {
1044         TestCaseGroup* const sizeTests = new TestCaseGroup(
1045                 m_testCtx, "size", "Tests for attachment sizes");
1046         sizeTests->addChild(new EmptyImageTest(
1047                                                         *this, "zero",
1048                                                         "Test for zero-sized image attachment"));
1049         sizeTests->addChild(new DistinctSizeTest(
1050                                                         *this, "distinct",
1051                                                         "Test for attachments with different sizes"));
1052
1053         return sizeTests;
1054 }
1055
1056 } // details
1057
1058 } // fboc
1059 } // gls
1060 } // deqp