3#include <Core/Utils/Log.hpp>
6#include <QOpenGLContext>
9#include <QSurfaceFormat>
13using namespace Ra::Core::Utils;
18WindowQt* WindowQt::s_getProcAddressHelper =
nullptr;
20QSurfaceFormat defaultFormat() {
21 QSurfaceFormat format;
22 format.setProfile( QSurfaceFormat::CoreProfile );
24 format.setOption( QSurfaceFormat::DebugContext );
29WindowQt::WindowQt( QScreen* screen ) :
30 QWindow( screen ), m_context( nullptr ), m_updatePending( false ), m_glInitialized( false ) {
32 setSurfaceType( QWindow::OpenGLSurface );
33 if ( !s_getProcAddressHelper ) { s_getProcAddressHelper =
this; }
38 m_context = std::make_unique<QOpenGLContext>(
this );
39 m_context->setFormat( QSurfaceFormat::defaultFormat() );
41 if ( !m_context->create() ) {
42 LOG( logINFO ) <<
"Could not create OpenGL context.";
46 m_screenObserver = connect(
47 this->screen(), &QScreen::physicalDotsPerInchChanged,
this, &WindowQt::physicalDpiChanged );
48 connect(
this, &QWindow::screenChanged,
this, &WindowQt::screenChanged );
53WindowQt::~WindowQt() {
57void WindowQt::screenChanged() {
58 disconnect( m_screenObserver );
59 m_screenObserver = connect(
60 this->screen(), &QScreen::physicalDotsPerInchChanged,
this, &WindowQt::physicalDpiChanged );
62 QSize s { size().width(), size().height() };
63 QResizeEvent patchEvent { s, s };
64 resizeInternal( &patchEvent );
67void WindowQt::physicalDpiChanged( qreal ) {
71 QSize s { size().width(), size().height() };
72 QResizeEvent patchEvent { s, s };
73 resizeInternal( &patchEvent );
77QOpenGLContext* WindowQt::context() {
78 return m_context.get();
77QOpenGLContext* WindowQt::context() {
…}
81void WindowQt::makeCurrent() {
82 if ( QOpenGLContext::currentContext() != m_context.get() ) {
83 m_context->makeCurrent(
this );
85 m_contextActivationCount = 0;
87 else { ++m_contextActivationCount; }
81void WindowQt::makeCurrent() {
…}
90void WindowQt::doneCurrent() {
91 if ( m_contextActivationCount == 0 ) { m_context->doneCurrent(); }
92 else { --m_contextActivationCount; }
90void WindowQt::doneCurrent() {
…}
95void WindowQt::resizeEvent( QResizeEvent* event ) {
96 resizeInternal( event );
99void WindowQt::exposeEvent( QExposeEvent* ) {
103void WindowQt::initialize() {
104 if ( !m_glInitialized.load() ) {
111void WindowQt::showEvent( QShowEvent* ) {
115void WindowQt::resizeInternal( QResizeEvent* event ) {
118 if ( event->size().width() < minimumSize().width() ||
119 event->size().height() < minimumSize().height() ) {
120 QSize size {
std::max( event->size().width(), minimumSize().width() ),
121 std::max( event->size().height(), minimumSize().height() ) };
122 QResizeEvent* patchEvent =
new QResizeEvent( size, event->oldSize() );
124 QWindow::resize( size );
155bool WindowQt::initializeGL() {
157 m_glInitialized =
false;
158 return m_glInitialized;
155bool WindowQt::initializeGL() {
…}
161void WindowQt::cleanupGL() {
162 if ( m_glInitialized.load() ) {
161void WindowQt::cleanupGL() {
…}
171void WindowQt::deinitializeGL() {}
173void WindowQt::resizeGL( QResizeEvent* ) {}
177void WindowQt::enterEvent( QEvent* ) {}
179void WindowQt::leaveEvent( QEvent* ) {}
181glbinding::ProcAddress WindowQt::getProcAddress(
const char* name ) {
182 if ( !s_getProcAddressHelper || name ==
nullptr ) {
return nullptr; }
186 const auto qtSymbol = QByteArray::fromStdString( symbol );
188 return s_getProcAddressHelper->m_context->getProcAddress( qtSymbol );
Base class for OpenGL widgets, compatble with Qt and globjects/glbindings.
hepler function to manage enum as underlying types in VariableSet