1 #ifndef _GLSFBOUTIL_HPP
2 #define _GLSFBOUTIL_HPP
4 /*-------------------------------------------------------------------------
5 * drawElements Quality Program OpenGL (ES) Module
6 * -----------------------------------------------
8 * Copyright 2014 The Android Open Source Project
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
14 * http://www.apache.org/licenses/LICENSE-2.0
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
24 * \brief Utilities for framebuffer objects.
25 *//*--------------------------------------------------------------------*/
27 #include "gluRenderContext.hpp"
28 #include "gluContextInfo.hpp"
29 #include "glwDefs.hpp"
30 #include "glwEnums.hpp"
31 #include "glwFunctions.hpp"
32 #include "gluTextureUtil.hpp"
33 #include "tcuTestLog.hpp"
34 #include "tcuDefs.hpp"
47 //! A pair of iterators to present a range.
48 //! \note This must be POD to allow static initialization.
49 //! \todo [2013-12-03 lauri] Move this to decpp?
53 typedef const T* const_iterator;
58 const T* begin (void) const { return m_begin; }
59 const T* end (void) const { return m_end; }
62 #define GLS_ARRAY_RANGE(ARR) { DE_ARRAY_BEGIN(ARR), DE_ARRAY_END(ARR) }
64 #define GLS_NULL_RANGE { DE_NULL, DE_NULL }
67 //! A pair type that, unlike stl::pair, is POD so it can be statically initialized.
68 template <typename T1, typename T2>
71 typedef T1 first_type;
72 typedef T2 second_type;
80 //! Configurations for framebuffer objects and their attachments.
85 typedef deUint32 FormatKey;
87 #define GLS_UNSIZED_FORMATKEY(FORMAT, TYPE) \
88 (deUint32(TYPE) << 16 | deUint32(FORMAT))
90 typedef Range<FormatKey> FormatKeys;
96 //! Type if format is unsized, GL_NONE if sized.
97 glw::GLenum unsizedType;
99 bool operator< (const ImageFormat& other) const
101 return (format < other.format ||
102 (format == other.format && unsizedType < other.unsizedType));
105 static ImageFormat none (void)
107 ImageFormat fmt = { GL_NONE, GL_NONE };
112 std::ostream& operator<< (std::ostream& stream, const ImageFormat& format);
114 static inline ImageFormat formatKeyInfo(FormatKey key)
116 ImageFormat fmt = { key & 0xffff, key >> 16 };
123 COLOR_RENDERABLE = 1 << 0,
124 DEPTH_RENDERABLE = 1 << 1,
125 STENCIL_RENDERABLE = 1 << 2,
126 RENDERBUFFER_VALID = 1 << 3,
127 TEXTURE_VALID = 1 << 4,
128 REQUIRED_RENDERABLE = 1 << 5, //< Without this, renderability is allowed, not required.
131 static inline FormatFlags operator|(FormatFlags f1, FormatFlags f2)
133 return FormatFlags(deUint32(f1) | deUint32(f2));
136 FormatFlags formatFlag(glw::GLenum context);
138 typedef std::set<ImageFormat> Formats;
143 void addCoreFormat (ImageFormat format, FormatFlags flags);
144 void addExtensionFormat (ImageFormat format, FormatFlags flags, const std::set<std::string>& requiredExtensions);
146 Formats getFormats (FormatFlags requirements) const;
147 bool isKnownFormat (ImageFormat format) const;
148 FormatFlags getFormatInfo (ImageFormat format) const;
149 std::set<std::set<std::string> > getFormatFeatureExtensions (ImageFormat format, FormatFlags requirements) const;
155 std::set<std::string> requiredExtensions;
157 bool operator< (const ExtensionInfo& other) const;
160 typedef std::map<ImageFormat, FormatFlags> FormatMap;
161 typedef std::map<ImageFormat, std::set<ExtensionInfo> > FormatExtensionMap;
163 FormatMap m_formatFlags;
164 FormatExtensionMap m_formatExtensions;
167 typedef Pair<FormatFlags, FormatKeys> FormatEntry;
168 typedef Range<FormatEntry> FormatEntries;
170 // \todo [2013-12-20 lauri] It turns out that format properties in extensions
171 // are actually far too fine-grained for this bundling to be reasonable,
172 // especially given the syntactic cumbersomeness of static arrays. It's better
173 // to list each entry separately.
175 struct FormatExtEntry
177 const char* extensions;
179 Range<FormatKey> formats;
182 typedef Range<FormatExtEntry> FormatExtEntries;
184 // Check support for GL_* and DEQP_* extensions
185 bool checkExtensionSupport (const glu::RenderContext& ctx, const std::string& extension);
187 // Accepts GL_* and DEQP_* extension strings and converts DEQP_* strings to a human readable string
188 std::string getExtensionDescription (const std::string& extensionName);
190 void addFormats (FormatDB& db, FormatEntries stdFmts);
191 void addExtFormats (FormatDB& db, FormatExtEntries extFmts, const glu::RenderContext* ctx);
192 glu::TransferFormat transferImageFormat (const ImageFormat& imgFormat);
199 virtual ~Config (void) {};
202 struct Image : public Config
204 ImageFormat internalFormat;
210 : internalFormat (ImageFormat::none())
215 struct Renderbuffer : public Image
217 Renderbuffer (void) : numSamples(0) {}
219 glw::GLsizei numSamples;
222 struct Texture : public Image
224 Texture (void) : numLevels(1) {}
226 glw::GLint numLevels;
229 struct TextureFlat : public Texture
233 struct Texture2D : public TextureFlat
237 struct TextureCubeMap : public TextureFlat
241 struct TextureLayered : public Texture
243 TextureLayered (void) : numLayers(1) {}
244 glw::GLsizei numLayers;
247 struct Texture3D : public TextureLayered
251 struct Texture2DArray : public TextureLayered
255 struct Attachment : public Config
257 Attachment (void) : target(GL_FRAMEBUFFER), imageName(0) {}
260 glw::GLuint imageName;
262 //! Returns `true` iff this attachment is "framebuffer attachment
263 //! complete" when bound to attachment point `attPoint`, and the current
264 //! image with name `imageName` is `image`, using `vfr` to check format
266 bool isComplete (glw::GLenum attPoint, const Image* image,
267 const FboVerifier& vfr) const;
270 struct RenderbufferAttachment : public Attachment
272 RenderbufferAttachment (void)
273 : renderbufferTarget(GL_RENDERBUFFER) {}
275 glw::GLenum renderbufferTarget;
278 struct TextureAttachment : public Attachment
280 TextureAttachment (void) : level(0) {}
285 struct TextureFlatAttachment : public TextureAttachment
287 TextureFlatAttachment (void) : texTarget(GL_NONE) {}
289 glw::GLenum texTarget;
292 struct TextureLayerAttachment : public TextureAttachment
294 TextureLayerAttachment (void) : layer(0) {}
299 glw::GLenum attachmentType (const Attachment& att);
300 glw::GLsizei imageNumSamples (const Image& img);
302 //! Mapping from attachment points to attachment configurations.
303 typedef std::map<glw::GLenum, const Attachment*> AttachmentMap;
305 //! Mapping from object names to texture configurations.
306 typedef std::map<glw::GLuint, const Texture*> TextureMap;
308 //! Mapping from object names to renderbuffer configurations.
309 typedef std::map<glw::GLuint, const Renderbuffer*> RboMap;
311 //! A framebuffer configuration.
314 AttachmentMap attachments;
318 void attach (glw::GLenum attPoint, const Attachment* att);
319 void setTexture (glw::GLuint texName, const Texture& texCfg);
320 void setRbo (glw::GLuint rbName, const Renderbuffer& rbCfg);
321 const Image* getImage (glw::GLenum type, glw::GLuint imgName) const;
326 class FboBuilder : public config::Framebuffer
329 void glAttach (glw::GLenum attPoint,
330 const config::Attachment* att);
331 glw::GLuint glCreateTexture (const config::Texture& texCfg);
332 glw::GLuint glCreateRbo (const config::Renderbuffer& rbCfg);
333 FboBuilder (glw::GLuint fbo, glw::GLenum target,
334 const glw::Functions& gl);
336 glw::GLenum getError (void) { return m_error; }
338 //! Allocate a new configuration of type `Config` (which must be a
339 //! subclass of `config::Config`), and return a referenc to it. The newly
340 //! allocated object will be freed when this builder object is destroyed.
341 template<typename Config>
342 Config& makeConfig (void)
344 Config* cfg = new Config();
345 m_configs.insert(cfg);
350 typedef std::set<config::Config*> Configs;
352 void checkError (void);
354 glw::GLenum m_error; //< The first GL error encountered.
355 glw::GLenum m_target;
356 const glw::Functions& m_gl;
360 struct ValidStatusCodes
362 ValidStatusCodes (void);
364 bool isFBOStatusValid (glw::GLenum fboStatus) const;
365 bool isFBOStatusRequired (glw::GLenum fboStatus) const;
366 bool isErrorCodeValid (glw::GLenum errorCode) const;
367 bool isErrorCodeRequired (glw::GLenum errorCode) const;
369 void addErrorCode (glw::GLenum error, const char* description);
370 void addFBOErrorStatus (glw::GLenum status, const char* description);
371 void setAllowComplete (bool);
373 void logLegalResults (tcu::TestLog& log) const;
374 void logRules (tcu::TestLog& log) const;
379 glw::GLenum errorCode;
380 std::set<std::string> rules;
383 void logRule (tcu::TestLog& log, const std::string& ruleName, const std::set<std::string>& rules) const;
384 void addViolation (std::vector<RuleViolation>& dst, glw::GLenum code, const char* description) const;
386 std::vector<RuleViolation> m_errorCodes; //!< Allowed GL errors, GL_NO_ERROR is not allowed
387 std::vector<RuleViolation> m_errorStatuses; //!< Allowed FBO error statuses, GL_FRAMEBUFFER_COMPLETE is not allowed
388 bool m_allowComplete; //!< true if (GL_NO_ERROR && GL_FRAMEBUFFER_COMPLETE) is allowed
391 void logFramebufferConfig (const config::Framebuffer& cfg, tcu::TestLog& log);
396 Checker (const glu::RenderContext&);
397 virtual ~Checker (void) {}
399 void addGLError (glw::GLenum error, const char* description);
400 void addPotentialGLError (glw::GLenum error, const char* description);
401 void addFBOStatus (glw::GLenum status, const char* description);
402 void addPotentialFBOStatus (glw::GLenum status, const char* description);
404 ValidStatusCodes getStatusCodes (void) { return m_statusCodes; }
406 virtual void check (glw::GLenum attPoint,
407 const config::Attachment& att,
408 const config::Image* image) = 0;
411 const glu::RenderContext& m_renderCtx;
414 ValidStatusCodes m_statusCodes; //< Allowed return values for glCheckFramebufferStatus.
420 virtual Checker* createChecker (const glu::RenderContext&) = 0;
423 typedef std::set<glw::GLenum> AttachmentPoints;
424 typedef std::set<ImageFormat> Formats;
429 FboVerifier (const FormatDB& formats,
430 CheckerFactory& factory,
431 const glu::RenderContext& renderCtx);
433 ValidStatusCodes validStatusCodes (const config::Framebuffer& cfg) const;
436 const FormatDB& m_formats;
437 CheckerFactory& m_factory;
438 const glu::RenderContext& m_renderCtx;
445 #endif // _GLSFBOUTIL_HPP