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