diff --git a/drape/drape.pro b/drape/drape.pro index b5ee1fe177..f40fcae4f8 100644 --- a/drape/drape.pro +++ b/drape/drape.pro @@ -17,7 +17,7 @@ include($$ROOT_DIR/common.pri) DRAPE_DIR = . include($$DRAPE_DIR/drape_common.pri) -SOURCES += glfunctions.cpp +SOURCES += glfunctions.cpp \ OTHER_FILES += \ shaders/simple_vertex_shader.vsh \ @@ -25,5 +25,3 @@ OTHER_FILES += \ shaders/texturing_vertex_shader.vsh \ shaders/shader_index.txt \ shaders/texturing_fragment_shader.fsh - -HEADERS += diff --git a/drape/drape_common.pri b/drape/drape_common.pri index dac1651731..cb943e9257 100644 --- a/drape/drape_common.pri +++ b/drape/drape_common.pri @@ -41,4 +41,5 @@ HEADERS += \ $$DRAPE_DIR/glbuffer.hpp \ $$DRAPE_DIR/utils/list_generator.hpp \ $$DRAPE_DIR/shader_def.hpp \ - $$DRAPE_DIR/glextensions_list.hpp + $$DRAPE_DIR/glextensions_list.hpp \ + $$DRAPE_DIR/oglcontext.hpp \ diff --git a/drape/oglcontext.hpp b/drape/oglcontext.hpp new file mode 100644 index 0000000000..6d2ef6ed2c --- /dev/null +++ b/drape/oglcontext.hpp @@ -0,0 +1,8 @@ +#pragma once + +class OGLContext +{ +public: + virtual void present() = 0; + virtual void makeCurrent() = 0; +}; diff --git a/drape_head/drape_head.pro b/drape_head/drape_head.pro index 2db081c1f1..3f90e8f1dc 100644 --- a/drape_head/drape_head.pro +++ b/drape_head/drape_head.pro @@ -7,7 +7,7 @@ include($$ROOT_DIR/common.pri) TARGET = DrapeHead TEMPLATE = app CONFIG += warn_on -QT *= core widgets gui opengl +QT *= core widgets gui win32* { LIBS += -lopengl32 -lws2_32 -lshell32 -liphlpapi @@ -22,12 +22,14 @@ win32*|linux* { HEADERS += \ mainwindow.hpp \ - glwidget.hpp + glwidget.hpp \ + qtoglcontext.hpp \ SOURCES += \ mainwindow.cpp \ main.cpp \ - glwidget.cpp + glwidget.cpp \ + qtoglcontext.cpp \ FORMS += \ mainwindow.ui diff --git a/drape_head/qtoglcontext.cpp b/drape_head/qtoglcontext.cpp new file mode 100644 index 0000000000..7eed7eb065 --- /dev/null +++ b/drape_head/qtoglcontext.cpp @@ -0,0 +1,39 @@ +#include "qtoglcontext.hpp" + +#include "../base/assert.hpp" + +QtOGLContext::QtOGLContext(QWindow * surface) +{ + m_isContextCreated = false; + m_surface = surface; + m_nativeContext = new QOpenGLContext(m_surface); + m_nativeContext->setFormat(m_surface->requestedFormat()); +} + +QtOGLContext::QtOGLContext(QWindow * surface, QtOGLContext * contextToShareWith) +{ + m_isContextCreated = false; + m_surface = surface; + m_nativeContext = new QOpenGLContext(m_surface); + m_nativeContext->setFormat(m_surface->requestedFormat()); + m_nativeContext->setShareContext(contextToShareWith->m_nativeContext); +} + +void QtOGLContext::makeCurrent() +{ + if (!m_isContextCreated) + { + ASSERT(m_surface->isExposed(), ()); + m_nativeContext->create(); + m_isContextCreated = true; + } + ASSERT(m_nativeContext->isValid(), ()); + m_nativeContext->makeCurrent(m_surface); +} + +void QtOGLContext::present() +{ + ASSERT(m_isContextCreated, ()); + m_nativeContext->makeCurrent(m_surface); + m_nativeContext->swapBuffers(m_surface); +} diff --git a/drape_head/qtoglcontext.hpp b/drape_head/qtoglcontext.hpp new file mode 100644 index 0000000000..64da92e4b6 --- /dev/null +++ b/drape_head/qtoglcontext.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "../drape/oglcontext.hpp" + +#include +#include + +class QtOGLContext: public OGLContext +{ +public: + QtOGLContext(QWindow * surface); + QtOGLContext(QWindow *surface, QtOGLContext * contextToShareWith); + + virtual void present(); + virtual void makeCurrent(); + +private: + QOpenGLContext * m_nativeContext; + QWindow * m_surface; + bool m_isContextCreated; +};