Overte C++ Documentation
OffscreenGLCanvas.h
1 //
2 // OffscreenGLCanvas.h
3 // interface/src/renderer
4 //
5 // Created by Bradley Austin Davis on 2014/04/09.
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 #pragma once
12 #ifndef hifi_OffscreenGLCanvas_h
13 #define hifi_OffscreenGLCanvas_h
14 
15 #include <mutex>
16 #include <QObject>
17 
18 class QOpenGLContext;
19 class QOffscreenSurface;
20 class QOpenGLDebugMessage;
21 class QSurfaceFormat;
22 
23 class OffscreenGLCanvas : public QObject {
24 public:
25  OffscreenGLCanvas();
26  ~OffscreenGLCanvas();
27  void setFormat(const QSurfaceFormat& format);
28  bool create(QOpenGLContext* sharedContext = nullptr);
29  bool makeCurrent();
30  void doneCurrent();
31  void moveToThreadWithContext(QThread* thread);
32  QOpenGLContext* getContext() {
33  return _context;
34  }
35  QObject* getContextObject();
36 
37  void setThreadContext();
38  static bool restoreThreadContext();
39 
40 protected:
41  void clearThreadContext();
42 
43  std::once_flag _reportOnce;
44  QOpenGLContext* _context{ nullptr };
45  QOffscreenSurface* _offscreenSurface{ nullptr };
46 };
47 
48 #endif // hifi_OffscreenGLCanvas_h