Overte C++ Documentation
QOpenGLContextWrapper.h
1 //
2 // QOpenGLContextWrapper.h
3 //
4 //
5 // Created by Clement on 12/4/15.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_QOpenGLContextWrapper_h
13 #define hifi_QOpenGLContextWrapper_h
14 
15 #include <QtGlobal>
16 #include <memory>
17 
18 class QOpenGLContext;
19 class QSurface;
20 class QSurfaceFormat;
21 class QThread;
22 
23 #if defined(Q_OS_ANDROID)
24 #include <EGL/egl.h>
25 #include <QtPlatformHeaders/QEGLNativeContext>
26 using QGLNativeContext = QEGLNativeContext;
27 #elif defined(Q_OS_WIN)
28 class QWGLNativeContext;
29 using QGLNativeContext = QWGLNativeContext;
30 #else
31 using QGLNativeContext = void*;
32 #endif
33 
34 class QOpenGLContextWrapper {
35 public:
36  using Pointer = std::shared_ptr<QOpenGLContextWrapper>;
37  using NativeContextPointer = std::shared_ptr<QGLNativeContext>;
38  static Pointer currentContextWrapper();
39 
40 
41  QOpenGLContextWrapper();
42  QOpenGLContextWrapper(QOpenGLContext* context);
43  virtual ~QOpenGLContextWrapper();
44  void setFormat(const QSurfaceFormat& format);
45  bool create();
46  void swapBuffers(QSurface* surface);
47  bool makeCurrent(QSurface* surface);
48  void doneCurrent();
49  void setShareContext(QOpenGLContext* otherContext);
50  void moveToThread(QThread* thread);
51 
52  NativeContextPointer getNativeContext() const;
53 
54  static QOpenGLContext* currentContext();
55  static uint32_t currentContextVersion();
56 
57  QOpenGLContext* getContext() {
58  return _context;
59  }
60 
61 
62 private:
63  bool _ownContext { false };
64  QOpenGLContext* _context { nullptr };
65 };
66 
67 bool isCurrentContext(QOpenGLContext* context);
68 
69 #endif // hifi_QOpenGLContextWrapper_h