Overte C++ Documentation
GLHelpers.h
1 //
2 // Created by Bradley Austin Davis 2015/05/29
3 // Copyright 2014 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #pragma once
10 #ifndef hifi_GLHelpers_h
11 #define hifi_GLHelpers_h
12 
13 #include <functional>
14 #include <QJsonObject>
15 
16 #include "GLLogging.h"
17 
18 // 16 bits of depth precision
19 #define DEFAULT_GL_DEPTH_BUFFER_BITS 16
20 // 8 bits of stencil buffer (typically you really only need 1 bit for functionality
21 // but GL implementations usually just come with buffer sizes in multiples of 8)
22 #define DEFAULT_GL_STENCIL_BUFFER_BITS 8
23 
24 class QObject;
25 class QOpenGLDebugMessage;
26 class QSurfaceFormat;
27 class QGLFormat;
28 
29 size_t evalGLFormatSwapchainPixelSize(const QSurfaceFormat& format);
30 
31 const QSurfaceFormat& getDefaultOpenGLSurfaceFormat();
32 int glVersionToInteger(QString glVersion);
33 
34 bool isRenderThread();
35 
36 #define GL_MAKE_VERSION(major, minor) ((major << 8) | minor)
37 #define GL_GET_MINOR_VERSION(glversion) (glversion & 0x00FF)
38 #define GL_GET_MAJOR_VERSION(glversion) ((glversion & 0xFF00) >> 8)
39 
40 namespace gl {
41  struct ContextInfo {
42  std::string version;
43  std::string shadingLanguageVersion;
44  std::string vendor;
45  std::string renderer;
46  std::vector<std::string> extensions;
47 
48  ContextInfo& init();
49  operator bool() const { return !version.empty(); }
50 
51  static const ContextInfo& get(bool init = false);
52  };
53 
54 #define LOG_GL_CONTEXT_INFO(category, contextInfo) \
55  qCDebug(category) << "GL Version: " << contextInfo.version.c_str(); \
56  qCDebug(category) << "GL Shader Language Version: " << contextInfo.shadingLanguageVersion.c_str(); \
57  qCDebug(category) << "GL Vendor: " << contextInfo.vendor.c_str(); \
58  qCDebug(category) << "GL Renderer: " << contextInfo.renderer.c_str();
59 
60 
61  void globalLock();
62  void globalRelease(bool finish = true);
63 
64  bool debugContextEnabled();
65 
66  bool khrDebugEnabled();
67 
68  bool extDebugMarkerEnabled();
69 
70  void withSavedContext(const std::function<void()>& f);
71 
72  bool checkGLError(const char* name);
73 
74  bool checkGLErrorDebug(const char* name);
75 
76  bool disableGl45();
77  void setDisableGl45(bool disable);
78 
79  uint16_t getTargetVersion();
80 
81  uint16_t getAvailableVersion();
82 
83  uint16_t getRequiredVersion();
84 } // namespace gl
85 
86 #define CHECK_GL_ERROR() ::gl::checkGLErrorDebug(__FUNCTION__)
87 
88 #endif