Merge "Use invalid sample count in renderbuffer_storage_multisample negative case...
[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::getPixelFormatName;
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 namespace deqp::gls::FboUtil;
49 using namespace deqp::gls::FboUtil::config;
50 typedef TestCase::IterateResult IterateResult;
51
52 namespace deqp
53 {
54 namespace gls
55 {
56 namespace fboc
57 {
58
59 namespace details
60 {
61 // \todo [2013-12-04 lauri] Place in deStrUtil.hpp?
62
63 string toLower (const string& str)
64 {
65         string ret;
66         std::transform(str.begin(), str.end(), std::inserter(ret, ret.begin()), ::tolower);
67         return ret;
68 }
69
70 // The following extensions are applicable both to ES2 and ES3.
71
72 // GL_OES_depth_texture
73 static const FormatKey s_oesDepthTextureFormats[] =
74 {
75         GLS_UNSIZED_FORMATKEY(GL_DEPTH_COMPONENT,       GL_UNSIGNED_SHORT),
76         GLS_UNSIZED_FORMATKEY(GL_DEPTH_COMPONENT,       GL_UNSIGNED_INT),
77 };
78
79 // GL_OES_packed_depth_stencil
80 static const FormatKey s_oesPackedDepthStencilSizedFormats[] =
81 {
82         GL_DEPTH24_STENCIL8,
83 };
84
85 static const FormatKey s_oesPackedDepthStencilTexFormats[] =
86 {
87         GLS_UNSIZED_FORMATKEY(GL_DEPTH_STENCIL, GL_UNSIGNED_INT_24_8),
88 };
89
90 // GL_OES_required_internalformat
91 static const FormatKey s_oesRequiredInternalFormatColorFormats[] =
92 {
93         // Same as ES2 RBO formats, plus RGBA8 (even without OES_rgb8_rgba8)
94         GL_RGB5_A1, GL_RGBA8, GL_RGBA4, GL_RGB565
95 };
96
97 static const FormatKey s_oesRequiredInternalFormatDepthFormats[] =
98 {
99         GL_DEPTH_COMPONENT16,
100 };
101
102 // GL_EXT_color_buffer_half_float
103 static const FormatKey s_extColorBufferHalfFloatFormats[] =
104 {
105         GL_RGBA16F, GL_RGB16F, GL_RG16F, GL_R16F,
106 };
107
108 static const FormatKey s_oesDepth24SizedFormats[] =
109 {
110         GL_DEPTH_COMPONENT24
111 };
112
113 static const FormatKey s_oesDepth32SizedFormats[] =
114 {
115         GL_DEPTH_COMPONENT32
116 };
117
118 static const FormatKey s_oesRgb8Rgba8RboFormats[] =
119 {
120         GL_RGB8,
121         GL_RGBA8,
122 };
123
124 static const FormatKey s_oesRequiredInternalFormatRgb8ColorFormat[] =
125 {
126         GL_RGB8,
127 };
128
129 static const FormatKey s_extTextureType2101010RevFormats[] =
130 {
131         GLS_UNSIZED_FORMATKEY(GL_RGBA,  GL_UNSIGNED_INT_2_10_10_10_REV),
132         GLS_UNSIZED_FORMATKEY(GL_RGB,   GL_UNSIGNED_INT_2_10_10_10_REV),
133 };
134
135 static const FormatKey s_oesRequiredInternalFormat10bitColorFormats[] =
136 {
137         GL_RGB10_A2, GL_RGB10,
138 };
139
140 static const FormatKey s_extTextureRgRboFormats[] =
141 {
142         GL_R8, GL_RG8,
143 };
144
145 static const FormatKey s_extTextureRgTexFormats[] =
146 {
147         GLS_UNSIZED_FORMATKEY(GL_RED,   GL_UNSIGNED_BYTE),
148         GLS_UNSIZED_FORMATKEY(GL_RG,    GL_UNSIGNED_BYTE),
149 };
150
151 static const FormatKey s_extTextureRgFloatTexFormats[] =
152 {
153         GLS_UNSIZED_FORMATKEY(GL_RED,   GL_FLOAT),
154         GLS_UNSIZED_FORMATKEY(GL_RG,    GL_FLOAT),
155 };
156
157 static const FormatKey s_extTextureRgHalfFloatTexFormats[] =
158 {
159         GLS_UNSIZED_FORMATKEY(GL_RED,   GL_HALF_FLOAT_OES),
160         GLS_UNSIZED_FORMATKEY(GL_RG,    GL_HALF_FLOAT_OES),
161 };
162
163 static const FormatKey s_nvPackedFloatRboFormats[] =
164 {
165         GL_R11F_G11F_B10F,
166 };
167
168 static const FormatKey s_nvPackedFloatTexFormats[] =
169 {
170         GLS_UNSIZED_FORMATKEY(GL_RGB,   GL_UNSIGNED_INT_10F_11F_11F_REV),
171 };
172
173 static const FormatKey s_extSrgbRboFormats[] =
174 {
175         GL_SRGB8_ALPHA8,
176 };
177
178 static const FormatKey s_extSrgbRenderableTexFormats[] =
179 {
180         GLS_UNSIZED_FORMATKEY(GL_SRGB_ALPHA,    GL_UNSIGNED_BYTE),
181 };
182
183 static const FormatKey s_extSrgbNonRenderableTexFormats[] =
184 {
185         GLS_UNSIZED_FORMATKEY(GL_SRGB,                  GL_UNSIGNED_BYTE),
186         GL_SRGB8,
187 };
188
189 static const FormatKey s_nvSrgbFormatsFormats[] =
190 {
191         GL_SRGB8,
192 };
193
194 static const FormatKey s_oesRgb8Rgba8TexFormats[] =
195 {
196         GLS_UNSIZED_FORMATKEY(GL_RGB,           GL_UNSIGNED_BYTE),
197         GLS_UNSIZED_FORMATKEY(GL_RGBA,          GL_UNSIGNED_BYTE),
198 };
199
200 static const FormatExtEntry s_esExtFormats[] =
201 {
202         {
203                 "GL_OES_depth_texture",
204                 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | TEXTURE_VALID,
205                 GLS_ARRAY_RANGE(s_oesDepthTextureFormats),
206         },
207         {
208                 "GL_OES_packed_depth_stencil",
209                 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | STENCIL_RENDERABLE | RENDERBUFFER_VALID,
210                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
211         },
212         {
213                 "GL_OES_packed_depth_stencil GL_OES_required_internalformat",
214                 TEXTURE_VALID,
215                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilSizedFormats)
216         },
217         {
218                 "GL_OES_packed_depth_stencil",
219                 DEPTH_RENDERABLE | STENCIL_RENDERABLE | TEXTURE_VALID,
220                 GLS_ARRAY_RANGE(s_oesPackedDepthStencilTexFormats)
221         },
222         // \todo [2013-12-10 lauri] Find out if OES_texture_half_float is really a
223         // requirement on ES3 also. Or is color_buffer_half_float applicatble at
224         // all on ES3, since there's also EXT_color_buffer_float?
225         {
226                 "GL_OES_texture_half_float GL_EXT_color_buffer_half_float",
227                 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
228                 GLS_ARRAY_RANGE(s_extColorBufferHalfFloatFormats)
229         },
230
231         // OES_required_internalformat doesn't actually specify that these are renderable,
232         // since it was written against ES 1.1.
233         {
234                 "GL_OES_required_internalformat",
235                  // Allow but don't require RGBA8 to be color-renderable if
236                  // OES_rgb8_rgba8 is not present.
237                 COLOR_RENDERABLE | TEXTURE_VALID,
238                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatColorFormats)
239         },
240         {
241                 "GL_OES_required_internalformat",
242                 DEPTH_RENDERABLE | TEXTURE_VALID,
243                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatDepthFormats)
244         },
245         {
246                 "GL_EXT_texture_rg",
247                 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
248                 GLS_ARRAY_RANGE(s_extTextureRgRboFormats)
249         },
250         // These are not specified to be color-renderable, but the wording is
251         // exactly as ambiguous as the wording in the ES2 spec.
252         {
253                 "GL_EXT_texture_rg",
254                 COLOR_RENDERABLE | TEXTURE_VALID,
255                 GLS_ARRAY_RANGE(s_extTextureRgTexFormats)
256         },
257         {
258                 "GL_EXT_texture_rg GL_OES_texture_float",
259                 COLOR_RENDERABLE | TEXTURE_VALID,
260                 GLS_ARRAY_RANGE(s_extTextureRgFloatTexFormats)
261         },
262         {
263                 "GL_EXT_texture_rg GL_OES_texture_half_float",
264                 COLOR_RENDERABLE | TEXTURE_VALID,
265                 GLS_ARRAY_RANGE(s_extTextureRgHalfFloatTexFormats)
266         },
267
268         {
269                 "GL_NV_packed_float",
270                 COLOR_RENDERABLE | TEXTURE_VALID,
271                 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
272         },
273         {
274                 "GL_NV_packed_float GL_EXT_color_buffer_half_float",
275                 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
276                 GLS_ARRAY_RANGE(s_nvPackedFloatRboFormats)
277         },
278
279         // Some Tegra drivers report GL_EXT_packed_float even for ES. Treat it as
280         // a synonym for the NV_ version.
281         {
282                 "GL_EXT_packed_float",
283                 COLOR_RENDERABLE | TEXTURE_VALID,
284                 GLS_ARRAY_RANGE(s_nvPackedFloatTexFormats)
285         },
286         {
287                 "GL_EXT_packed_float GL_EXT_color_buffer_half_float",
288                 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
289                 GLS_ARRAY_RANGE(s_nvPackedFloatRboFormats)
290         },
291
292         {
293                 "GL_EXT_sRGB",
294                 COLOR_RENDERABLE | TEXTURE_VALID,
295                 GLS_ARRAY_RANGE(s_extSrgbRenderableTexFormats)
296         },
297         {
298                 "GL_EXT_sRGB",
299                 TEXTURE_VALID,
300                 GLS_ARRAY_RANGE(s_extSrgbNonRenderableTexFormats)
301         },
302         {
303                 "GL_EXT_sRGB",
304                 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
305                 GLS_ARRAY_RANGE(s_extSrgbRboFormats)
306         },
307         {
308                 "GL_NV_sRGB_formats",
309                 REQUIRED_RENDERABLE | COLOR_RENDERABLE | TEXTURE_VALID | RENDERBUFFER_VALID,
310                 GLS_ARRAY_RANGE(s_nvSrgbFormatsFormats)
311         },
312
313          // In Khronos bug 7333 discussion, the consensus is that these texture
314          // formats, at least, should be color-renderable. Still, that cannot be
315          // found in any extension specs, so only allow it, not require it.
316         {
317                 "GL_OES_rgb8_rgba8",
318                 COLOR_RENDERABLE | TEXTURE_VALID,
319                 GLS_ARRAY_RANGE(s_oesRgb8Rgba8TexFormats)
320         },
321         {
322                 "GL_OES_rgb8_rgba8",
323                 REQUIRED_RENDERABLE | COLOR_RENDERABLE | RENDERBUFFER_VALID,
324                 GLS_ARRAY_RANGE(s_oesRgb8Rgba8RboFormats)
325         },
326         {
327                 "GL_OES_rgb8_rgba8 GL_OES_required_internalformat",
328                 TEXTURE_VALID,
329                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormatRgb8ColorFormat)
330         },
331
332         // The depth-renderability of the depth RBO formats is not explicitly
333         // spelled out, but all renderbuffer formats are meant to be renderable.
334         {
335                 "GL_OES_depth24",
336                 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID,
337                 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
338         },
339         {
340                 "GL_OES_depth24 GL_OES_required_internalformat GL_OES_depth_texture",
341                 TEXTURE_VALID,
342                 GLS_ARRAY_RANGE(s_oesDepth24SizedFormats)
343         },
344
345         {
346                 "GL_OES_depth32",
347                 REQUIRED_RENDERABLE | DEPTH_RENDERABLE | RENDERBUFFER_VALID,
348                 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
349         },
350         {
351                 "GL_OES_depth32 GL_OES_required_internalformat GL_OES_depth_texture",
352                 TEXTURE_VALID,
353                 GLS_ARRAY_RANGE(s_oesDepth32SizedFormats)
354         },
355
356         {
357                 "GL_EXT_texture_type_2_10_10_10_REV",
358                 TEXTURE_VALID, // explicitly unrenderable
359                 GLS_ARRAY_RANGE(s_extTextureType2101010RevFormats)
360         },
361         {
362                 "GL_EXT_texture_type_2_10_10_10_REV GL_OES_required_internalformat",
363                 TEXTURE_VALID, // explicitly unrenderable
364                 GLS_ARRAY_RANGE(s_oesRequiredInternalFormat10bitColorFormats)
365         },
366 };
367
368 Context::Context (TestContext& testCtx,
369                                   RenderContext& renderCtx,
370                                   CheckerFactory& factory)
371         : m_testCtx                             (testCtx)
372         , m_renderCtx                   (renderCtx)
373         , m_verifier                    (m_ctxFormats, factory)
374         , m_haveMultiColorAtts  (false)
375 {
376         FormatExtEntries extRange = GLS_ARRAY_RANGE(s_esExtFormats);
377         addExtFormats(extRange);
378 }
379
380 void Context::addFormats (FormatEntries fmtRange)
381 {
382         FboUtil::addFormats(m_minFormats, fmtRange);
383         FboUtil::addFormats(m_ctxFormats, fmtRange);
384         FboUtil::addFormats(m_maxFormats, fmtRange);
385 }
386
387 void Context::addExtFormats (FormatExtEntries extRange)
388 {
389         FboUtil::addExtFormats(m_ctxFormats, extRange, &m_renderCtx);
390         FboUtil::addExtFormats(m_maxFormats, extRange, DE_NULL);
391 }
392
393 void TestBase::pass (void)
394 {
395         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
396 }
397
398 void TestBase::qualityWarning (const char* msg)
399 {
400         m_testCtx.setTestResult(QP_TEST_RESULT_QUALITY_WARNING, msg);
401 }
402
403 void TestBase::fail (const char* msg)
404 {
405         m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, msg);
406 }
407
408 static string statusName (GLenum status)
409 {
410         const char* errorName = getErrorName(status);
411         if (status != GL_NO_ERROR && errorName != DE_NULL)
412                 return string(errorName) + " (during FBO initialization)";
413
414         const char* fbStatusName = getFramebufferStatusName(status);
415         if (fbStatusName != DE_NULL)
416                 return fbStatusName;
417
418         return "unknown value (" + toString(status) + ")";
419 }
420
421 const glw::Functions& gl (const TestBase& test)
422 {
423         return test.getContext().getRenderContext().getFunctions();
424 }
425
426 IterateResult TestBase::iterate (void)
427 {
428         glu::Framebuffer fbo(m_ctx.getRenderContext());
429         FboBuilder builder(*fbo, GL_FRAMEBUFFER, gl(*this));
430         const IterateResult ret = build(builder);
431         const StatusCodes statuses = m_ctx.getVerifier().validStatusCodes(builder);
432
433         GLenum glStatus = builder.getError();
434         if (glStatus == GL_NO_ERROR)
435                 glStatus = gl(*this).checkFramebufferStatus(GL_FRAMEBUFFER);
436
437         // \todo [2013-12-04 lauri] Check if drawing operations succeed.
438
439         StatusCodes::const_iterator it = statuses.begin();
440         GLenum err = *it++;
441         logFramebufferConfig(builder, m_testCtx.getLog());
442
443         MessageBuilder msg(&m_testCtx.getLog());
444
445         msg << "Expected ";
446         if (it != statuses.end())
447         {
448                 msg << "one of ";
449                 while (it != statuses.end())
450                 {
451                         msg << statusName(err);
452                         err = *it++;
453                         msg << (it == statuses.end() ? " or " : ", ");
454                 }
455         }
456         msg << statusName(err) << "." << TestLog::EndMessage;
457         m_testCtx.getLog() << TestLog::Message << "Received " << statusName(glStatus)
458                          << "." << TestLog::EndMessage;
459
460         if (!contains(statuses, glStatus))
461         {
462                 // The returned status value was not acceptable.
463                 if (glStatus == GL_FRAMEBUFFER_COMPLETE)
464                         fail("Framebuffer checked as complete, expected incomplete");
465                 else if (statuses.size() == 1 && contains(statuses, GL_FRAMEBUFFER_COMPLETE))
466                         fail("Framebuffer checked is incomplete, expected complete");
467                 else
468                         // An incomplete status is allowed, but not _this_ incomplete status.
469                         fail("Framebuffer checked as incomplete, but with wrong status");
470         }
471         else if (glStatus != GL_FRAMEBUFFER_COMPLETE &&
472                          contains(statuses, GL_FRAMEBUFFER_COMPLETE))
473         {
474                 qualityWarning("Framebuffer object could have checked as complete but did not.");
475         }
476         else
477                 pass();
478
479         return ret;
480 }
481
482 IterateResult TestBase::build (FboBuilder& builder)
483 {
484         DE_UNREF(builder);
485         return STOP;
486 }
487
488 ImageFormat TestBase::getDefaultFormat (GLenum attPoint, GLenum bufType) const
489 {
490         if (bufType == GL_NONE)
491         {
492                 return ImageFormat::none();
493         }
494
495         // Prefer a standard format, if there is one, but if not, use a format
496         // provided by an extension.
497         Formats formats = m_ctx.getMinFormats().getFormats(formatFlag(attPoint) |
498                                                                                                                  formatFlag(bufType));
499         Formats::const_iterator it = formats.begin();
500         if (it == formats.end())
501         {
502                 formats = m_ctx.getCtxFormats().getFormats(formatFlag(attPoint) |
503                                                                                                          formatFlag(bufType));
504                 it = formats.begin();
505         }
506         if (it == formats.end())
507                 throw tcu::NotSupportedError("Unsupported attachment kind for attachment point",
508                                                                          "", __FILE__, __LINE__);
509         return *it;
510 };
511
512 Image* makeImage (GLenum bufType, ImageFormat format,
513                                   GLsizei width, GLsizei height, FboBuilder& builder)
514 {
515         Image* image = DE_NULL;
516         switch (bufType)
517         {
518                 case GL_NONE:
519                         return DE_NULL;
520                 case GL_RENDERBUFFER:
521                         image = &builder.makeConfig<Renderbuffer>();
522                         break;
523                 case GL_TEXTURE:
524                         image = &builder.makeConfig<Texture2D>();
525                         break;
526                 default:
527                         DE_ASSERT(!"Impossible case");
528         }
529         image->internalFormat = format;
530         image->width = width;
531         image->height = height;
532         return image;
533 }
534
535 Attachment* makeAttachment (GLenum bufType, ImageFormat format,
536                                                         GLsizei width, GLsizei height, FboBuilder& builder)
537 {
538         Image* const imgCfg = makeImage (bufType, format, width, height, builder);
539         Attachment* att = DE_NULL;
540         GLuint img = 0;
541
542         if (Renderbuffer* rboCfg = dynamic_cast<Renderbuffer*>(imgCfg))
543         {
544                 img = builder.glCreateRbo(*rboCfg);
545                 att = &builder.makeConfig<RenderbufferAttachment>();
546         }
547         else if (Texture2D* texCfg = dynamic_cast<Texture2D*>(imgCfg))
548         {
549                 img = builder.glCreateTexture(*texCfg);
550                 TextureFlatAttachment& texAtt = builder.makeConfig<TextureFlatAttachment>();
551                 texAtt.texTarget = GL_TEXTURE_2D;
552                 att = &texAtt;
553         }
554         else
555         {
556                 DE_ASSERT(imgCfg == DE_NULL);
557                 return DE_NULL;
558         }
559         att->imageName = img;
560         return att;
561 }
562
563 void TestBase::attachTargetToNew (GLenum target, GLenum bufType, ImageFormat format,
564                                                                   GLsizei width, GLsizei height, FboBuilder& builder)
565 {
566         ImageFormat imgFmt = format;
567         if (imgFmt.format == GL_NONE)
568                 imgFmt = getDefaultFormat(target, bufType);
569
570         const Attachment* const att = makeAttachment(bufType, imgFmt, width, height, builder);
571         builder.glAttach(target, att);
572 }
573
574 static string formatName (ImageFormat format)
575 {
576         const string s = getPixelFormatName(format.format);
577         const string fmtStr = toLower(s.substr(3));
578
579         if (format.unsizedType != GL_NONE)
580         {
581                 const string typeStr = getTypeName(format.unsizedType);
582                 return fmtStr + "_" + toLower(typeStr.substr(3));
583         }
584
585         return fmtStr;
586 }
587
588 static string formatDesc (ImageFormat format)
589 {
590         const string fmtStr = getPixelFormatName(format.format);
591
592         if (format.unsizedType != GL_NONE)
593         {
594                 const string typeStr = getTypeName(format.unsizedType);
595                 return fmtStr + " with type " + typeStr;
596         }
597
598         return fmtStr;
599 }
600
601 struct RenderableParams
602 {
603         GLenum                          attPoint;
604         GLenum                          bufType;
605         ImageFormat             format;
606         static string           getName                         (const RenderableParams& params)
607         {
608                 return formatName(params.format);
609         }
610         static string           getDescription          (const RenderableParams& params)
611         {
612                 return formatDesc(params.format);
613         }
614 };
615
616 class RenderableTest : public ParamTest<RenderableParams>
617 {
618 public:
619                                         RenderableTest          (Context& group, const Params& params)
620                                                 : ParamTest<RenderableParams> (group, params) {}
621         IterateResult   build                           (FboBuilder& builder);
622 };
623
624 IterateResult RenderableTest::build (FboBuilder& builder)
625 {
626         attachTargetToNew(m_params.attPoint, m_params.bufType, m_params.format, 64, 64, builder);
627         return STOP;
628 }
629
630 string attTypeName (GLenum bufType)
631 {
632         switch (bufType)
633         {
634                 case GL_NONE:
635                         return "none";
636                 case GL_RENDERBUFFER:
637                         return "rbo";
638                 case GL_TEXTURE:
639                         return "tex";
640                 default:
641                         DE_ASSERT(!"Impossible case");
642         }
643         return ""; // Shut up compiler
644 }
645
646 struct AttachmentParams
647 {
648         GLenum                                          color0Kind;
649         GLenum                                          colornKind;
650         GLenum                                          depthKind;
651         GLenum                                          stencilKind;
652
653         static string           getName                 (const AttachmentParams& params);
654         static string           getDescription  (const AttachmentParams& params)
655         {
656                 return getName(params);
657         }
658 };
659
660 string AttachmentParams::getName (const AttachmentParams& params)
661 {
662         return (attTypeName(params.color0Kind) + "_" +
663                         attTypeName(params.colornKind) + "_" +
664                         attTypeName(params.depthKind) + "_" +
665                         attTypeName(params.stencilKind));
666 }
667
668 //! Test for combinations of different kinds of attachments
669 class AttachmentTest : public ParamTest<AttachmentParams>
670 {
671 public:
672                                         AttachmentTest          (Context& group, Params& params)
673                                                 : ParamTest<AttachmentParams> (group, params) {}
674
675 protected:
676         IterateResult   build                           (FboBuilder& builder);
677         void                    makeDepthAndStencil     (FboBuilder& builder);
678 };
679
680
681 void AttachmentTest::makeDepthAndStencil (FboBuilder& builder)
682 {
683         if (m_params.stencilKind == m_params.depthKind)
684         {
685                 // If there is a common stencil+depth -format, try to use a common
686                 // image for both attachments.
687                 const FormatFlags flags =
688                         DEPTH_RENDERABLE | STENCIL_RENDERABLE | formatFlag(m_params.stencilKind);
689                 const Formats& formats = m_ctx.getMinFormats().getFormats(flags);
690                 Formats::const_iterator it = formats.begin();
691                 if (it != formats.end())
692                 {
693                         const ImageFormat format = *it;
694                         Attachment* att = makeAttachment(m_params.depthKind, format, 64, 64, builder);
695                         builder.glAttach(GL_DEPTH_ATTACHMENT, att);
696                         builder.glAttach(GL_STENCIL_ATTACHMENT, att);
697                         return;
698                 }
699         }
700         // Either the kinds were separate, or a suitable format was not found.
701         // Create separate images.
702         attachTargetToNew(GL_STENCIL_ATTACHMENT, m_params.stencilKind, ImageFormat::none(),
703                                           64, 64, builder);
704         attachTargetToNew(GL_DEPTH_ATTACHMENT, m_params.depthKind, ImageFormat::none(),
705                                           64, 64, builder);
706 }
707
708 IterateResult AttachmentTest::build (FboBuilder& builder)
709 {
710         attachTargetToNew(GL_COLOR_ATTACHMENT0, m_params.color0Kind, ImageFormat::none(),
711                                           64, 64, builder);
712
713         if (m_params.colornKind != GL_NONE)
714         {
715                 TCU_CHECK_AND_THROW(NotSupportedError, m_ctx.haveMultiColorAtts(),
716                                                         "Multiple attachments not supported");
717                 GLint maxAttachments = 1;
718                 gl(*this).getIntegerv(GL_MAX_COLOR_ATTACHMENTS, &maxAttachments);
719                 GLU_EXPECT_NO_ERROR(
720                         gl(*this).getError(), "Couldn't read GL_MAX_COLOR_ATTACHMENTS");
721
722                 for (int i = 1; i < maxAttachments; i++)
723                 {
724                         attachTargetToNew(GL_COLOR_ATTACHMENT0 + i, m_params.colornKind,
725                                                           ImageFormat::none(), 64, 64, builder);
726                 }
727         }
728
729         makeDepthAndStencil(builder);
730
731         return STOP;
732 }
733
734 class EmptyImageTest : public TestBase
735 {
736 public:
737                                         EmptyImageTest  (Context& group,
738                                                                          const char* name, const char* desc)
739                                                 : TestBase      (group, name, desc) {}
740
741         IterateResult   build                   (FboBuilder& builder);
742 };
743
744 IterateResult EmptyImageTest::build (FboBuilder& builder)
745 {
746         attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
747                                           0, 0, builder);
748         return STOP;
749 }
750
751
752 class DistinctSizeTest : public TestBase
753 {
754 public:
755                                         DistinctSizeTest        (Context& group,
756                                                                                  const char* name, const char* desc)
757                                                 : TestBase              (group, name, desc) {}
758
759         IterateResult   build                           (FboBuilder& builder);
760 };
761
762 IterateResult DistinctSizeTest::build (FboBuilder& builder)
763 {
764         attachTargetToNew(GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ImageFormat::none(),
765                                           64, 64, builder);
766         attachTargetToNew(GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, ImageFormat::none(),
767                                           128, 128, builder);
768         return STOP;
769 }
770
771 TestCaseGroup* Context::createRenderableTests (void)
772 {
773         TestCaseGroup* const renderableTests = new TestCaseGroup(
774                 m_testCtx, "renderable", "Tests for support of renderable image formats");
775
776         TestCaseGroup* const rbRenderableTests = new TestCaseGroup(
777                 m_testCtx, "renderbuffer", "Tests for renderbuffer formats");
778
779         TestCaseGroup* const texRenderableTests = new TestCaseGroup(
780                 m_testCtx, "texture", "Tests for texture formats");
781
782         static const struct AttPoint {
783                 GLenum                  attPoint;
784                 const char*     name;
785                 const char*     desc;
786         } attPoints[] =
787         {
788                 { GL_COLOR_ATTACHMENT0,         "color0",       "Tests for color attachments"   },
789                 { GL_STENCIL_ATTACHMENT,        "stencil",      "Tests for stencil attachments" },
790                 { GL_DEPTH_ATTACHMENT,          "depth",        "Tests for depth attachments"   },
791         };
792
793         // At each attachment point, iterate through all the possible formats to
794         // detect both false positives and false negatives.
795         const Formats rboFmts = m_maxFormats.getFormats(ANY_FORMAT);
796         const Formats texFmts = m_maxFormats.getFormats(ANY_FORMAT);
797
798         for (const AttPoint* it = DE_ARRAY_BEGIN(attPoints); it != DE_ARRAY_END(attPoints); it++)
799         {
800                 TestCaseGroup* const rbAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
801                 TestCaseGroup* const texAttTests = new TestCaseGroup(m_testCtx, it->name, it->desc);
802
803                 for (Formats::const_iterator it2 = rboFmts.begin(); it2 != rboFmts.end(); it2++)
804                 {
805                         const RenderableParams params = { it->attPoint, GL_RENDERBUFFER, *it2 };
806                         rbAttTests->addChild(new RenderableTest(*this, params));
807                 }
808                 rbRenderableTests->addChild(rbAttTests);
809
810                 for (Formats::const_iterator it2 = texFmts.begin(); it2 != texFmts.end(); it2++)
811                 {
812                         const RenderableParams params = { it->attPoint, GL_TEXTURE, *it2 };
813                         texAttTests->addChild(new RenderableTest(*this, params));
814                 }
815                 texRenderableTests->addChild(texAttTests);
816         }
817         renderableTests->addChild(rbRenderableTests);
818         renderableTests->addChild(texRenderableTests);
819
820         return renderableTests;
821 }
822
823 TestCaseGroup* Context::createAttachmentTests (void)
824 {
825         TestCaseGroup* const attCombTests = new TestCaseGroup(
826                 m_testCtx, "attachment_combinations", "Tests for attachment combinations");
827
828         static const GLenum s_bufTypes[] = { GL_NONE, GL_RENDERBUFFER, GL_TEXTURE };
829         static const Range<GLenum> s_kinds = GLS_ARRAY_RANGE(s_bufTypes);
830
831         for (const GLenum* col0 = s_kinds.begin(); col0 != s_kinds.end(); ++col0)
832                 for (const GLenum* coln = s_kinds.begin(); coln != s_kinds.end(); ++coln)
833                         for (const GLenum* dep = s_kinds.begin(); dep != s_kinds.end(); ++dep)
834                                 for (const GLenum* stc = s_kinds.begin(); stc != s_kinds.end(); ++stc)
835                                 {
836                                         AttachmentParams params = { *col0, *coln, *dep, *stc };
837                                         attCombTests->addChild(new AttachmentTest(*this, params));
838                                 }
839
840         return attCombTests;
841 }
842
843 TestCaseGroup* Context::createSizeTests (void)
844 {
845         TestCaseGroup* const sizeTests = new TestCaseGroup(
846                 m_testCtx, "size", "Tests for attachment sizes");
847         sizeTests->addChild(new EmptyImageTest(
848                                                         *this, "zero",
849                                                         "Test for zero-sized image attachment"));
850         sizeTests->addChild(new DistinctSizeTest(
851                                                         *this, "distinct",
852                                                         "Test for attachments with different sizes"));
853
854         return sizeTests;
855 }
856
857 } // details
858
859 } // fboc
860 } // gls
861 } // deqp