Overte C++ Documentation
libraries/qml/src/qml/impl/RenderEventHandler.h
1 //
2 // Created by Bradley Austin Davis on 2018-01-04
3 // Copyright 2013-2018 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 #pragma once
9 
10 #ifndef DISABLE_QML
11 
12 #include <QtCore/QObject>
13 #include <QtCore/QThread>
14 #include <QtGui/qevent.h>
15 
16 #include <GLMHelpers.h>
17 #include <gl/OffscreenGLCanvas.h>
18 
19 namespace hifi { namespace qml { namespace impl {
20 
21 class SharedObject;
22 
23 class OffscreenEvent : public QEvent {
24 public:
25  enum Type {
26  Initialize = QEvent::User + 1,
27  Render,
28  RenderSync,
29  Quit
30  };
31 
32  OffscreenEvent(Type type) : QEvent(static_cast<QEvent::Type>(type)) {}
33 };
34 
35 /* The render event handler lives on the QML rendering thread for a given surface
36  * (each surface has a dedicated rendering thread) and handles events of type
37  * OffscreenEvent to do one time initialization or destruction, and to actually
38  * perform the render.
39  */
40 class RenderEventHandler : public QObject {
41 public:
42  RenderEventHandler(SharedObject* shared, QThread* targetThread);
43 
44 private:
45  bool event(QEvent* e) override;
46  void onInitalize();
47  void resize();
48  void onRender();
49  void onRenderSync();
50  void qmlRender(bool sceneGraphSync);
51  void onQuit();
52 
53  SharedObject* const _shared;
54  OffscreenGLCanvas _canvas;
55  QSize _currentSize;
56 
57  uint32_t _fbo{ 0 };
58  uint32_t _depthStencil{ 0 };
59 
60  bool _initialized { false };
61 };
62 
63 }}} // namespace hifi::qml::impl
64 
65 #endif