Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
WindowQt.hpp
1// This file si picked and slightly adapted from
2// globjects/source/examples/qtexample/WindowQt.h
3// so that update in globjects is easy
4// Radium Viewer derive this class
5
6#pragma once
7#include <Gui/RaGui.hpp>
8
9#include <QScopedPointer>
10#include <QWindow>
11
12#include <glbinding/ProcAddress.h>
13
14#include <atomic>
15#include <memory>
16
17class QSurfaceFormat;
18class QOpenGLContext;
19class QEvent;
20class QResizeEvent;
21class QScreen;
22
23namespace Ra {
24namespace Gui {
25
31class RA_GUI_API WindowQt : public QWindow
32{
33 Q_OBJECT
34 private:
35 class ScopedGLContext;
36
37 public:
38 explicit WindowQt( QScreen* screen );
39 virtual ~WindowQt();
40
41 void resizeEvent( QResizeEvent* event ) override;
42 void showEvent( QShowEvent* event ) override;
43 void exposeEvent( QExposeEvent* event ) override;
44 // bool event( QEvent* event ) override;
45
46 virtual void enterEvent( QEvent* event );
47 virtual void leaveEvent( QEvent* event );
48
57 void makeCurrent();
58
66 void doneCurrent();
67
86 inline ScopedGLContext activateScopedContext();
87
89 QOpenGLContext* context();
90
91 // note when updating from globjets
92 // updateGL done by base app rendering loop
93
94 bool isOpenGlInitialized() const { return m_glInitialized.load(); }
95
96 signals:
98 void dpiChanged();
99
100 public slots:
102 void cleanupGL();
103 void screenChanged();
104
105 private slots:
106 void physicalDpiChanged( qreal dpi );
107
108 protected:
109 // OpenglContext used with this widget
111
112 bool m_updatePending;
113 std::atomic_bool m_glInitialized;
114
115 void initialize();
116 void resizeInternal( QResizeEvent* event );
117
118 //
119 // OpenGL related methods
120 // Not inherited, defined here in the same way QOpenGLWidget define them.
121 //
123 virtual bool initializeGL();
125 virtual void deinitializeGL();
127 virtual void resizeGL( QResizeEvent* event );
128
129 // note when updating from globjets
130 // paintGL done by base app rendering loop
131
132 protected:
133 static glbinding::ProcAddress getProcAddress( const char* name );
134
135 private:
138 using QWindow::create;
139
140 static WindowQt* s_getProcAddressHelper;
141 int m_contextActivationCount { 0 };
142
143 QMetaObject::Connection m_screenObserver;
144};
145
146class WindowQt::ScopedGLContext
147{
148 public:
149 explicit ScopedGLContext( WindowQt* window ) : m_window( window ) { window->makeCurrent(); }
150 ~ScopedGLContext() { m_window->doneCurrent(); }
151 ScopedGLContext( const ScopedGLContext& ) = delete;
152 ScopedGLContext& operator=( ScopedGLContext const& ) = delete;
153
154 private:
155 WindowQt* m_window;
156};
157
158inline WindowQt::ScopedGLContext WindowQt::activateScopedContext() {
159 return ScopedGLContext { this };
160}
161
162} // namespace Gui
163} // namespace Ra
Base class for OpenGL widgets, compatble with Qt and globjects/glbindings.
Definition WindowQt.hpp:32
void dpiChanged()
Emitted when physical device changes. Useful for tracking devicePixelRatio() change.
ScopedGLContext activateScopedContext()
Definition WindowQt.hpp:158
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4