From 6476b1cfea7c450f9b61ec5aa0a92f8e6ba525a5 Mon Sep 17 00:00:00 2001 From: Dmitry Kunin Date: Wed, 25 Dec 2013 15:10:50 +0300 Subject: [PATCH] OGLContextFactory + Qt impl. --- drape/drape.pro | 3 +++ drape/oglcontextfactory.hpp | 9 +++++++++ drape_head/drape_head.pro | 2 ++ drape_head/qtoglcontext.cpp | 12 +++--------- drape_head/qtoglcontext.hpp | 1 - drape_head/qtoglcontextfactory.cpp | 25 +++++++++++++++++++++++++ drape_head/qtoglcontextfactory.hpp | 20 ++++++++++++++++++++ 7 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 drape/oglcontextfactory.hpp create mode 100644 drape_head/qtoglcontextfactory.cpp create mode 100644 drape_head/qtoglcontextfactory.hpp diff --git a/drape/drape.pro b/drape/drape.pro index f40fcae4f8..054732c9b4 100644 --- a/drape/drape.pro +++ b/drape/drape.pro @@ -25,3 +25,6 @@ OTHER_FILES += \ shaders/texturing_vertex_shader.vsh \ shaders/shader_index.txt \ shaders/texturing_fragment_shader.fsh + +HEADERS += \ + oglcontextfactory.hpp diff --git a/drape/oglcontextfactory.hpp b/drape/oglcontextfactory.hpp new file mode 100644 index 0000000000..753b037da4 --- /dev/null +++ b/drape/oglcontextfactory.hpp @@ -0,0 +1,9 @@ +#pragma once + +#include "oglcontext.hpp" + +class OGLContextFactory +{ + virtual OGLContext * getDrawContext() = 0; + virtual OGLContext * getResourcesUploadContext() = 0; +}; diff --git a/drape_head/drape_head.pro b/drape_head/drape_head.pro index 3f90e8f1dc..cca1d81aa7 100644 --- a/drape_head/drape_head.pro +++ b/drape_head/drape_head.pro @@ -24,12 +24,14 @@ HEADERS += \ mainwindow.hpp \ glwidget.hpp \ qtoglcontext.hpp \ + qtoglcontextfactory.hpp SOURCES += \ mainwindow.cpp \ main.cpp \ glwidget.cpp \ qtoglcontext.cpp \ + qtoglcontextfactory.cpp FORMS += \ mainwindow.ui diff --git a/drape_head/qtoglcontext.cpp b/drape_head/qtoglcontext.cpp index 7eed7eb065..a93b7fcac1 100644 --- a/drape_head/qtoglcontext.cpp +++ b/drape_head/qtoglcontext.cpp @@ -2,21 +2,15 @@ #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); + + if (contextToShareWith != NULL) + m_nativeContext->setShareContext(contextToShareWith->m_nativeContext); } void QtOGLContext::makeCurrent() diff --git a/drape_head/qtoglcontext.hpp b/drape_head/qtoglcontext.hpp index 64da92e4b6..0889028af5 100644 --- a/drape_head/qtoglcontext.hpp +++ b/drape_head/qtoglcontext.hpp @@ -8,7 +8,6 @@ class QtOGLContext: public OGLContext { public: - QtOGLContext(QWindow * surface); QtOGLContext(QWindow *surface, QtOGLContext * contextToShareWith); virtual void present(); diff --git a/drape_head/qtoglcontextfactory.cpp b/drape_head/qtoglcontextfactory.cpp new file mode 100644 index 0000000000..89885c23c3 --- /dev/null +++ b/drape_head/qtoglcontextfactory.cpp @@ -0,0 +1,25 @@ +#include "qtoglcontextfactory.hpp" + +#include "../base/assert.hpp" + +QtOGLContextFactory::QtOGLContextFactory(QWindow * surface) + : m_surface(surface) + , m_drawContext(NULL) + , m_uploadContext(NULL) +{} + +OGLContext * QtOGLContextFactory::getDrawContext() +{ + if (m_drawContext == NULL) + m_drawContext = new QtOGLContext(m_surface, m_uploadContext); + + return m_drawContext; +} + +OGLContext * QtOGLContextFactory::getResourcesUploadContext() +{ + if (m_uploadContext != NULL) + m_uploadContext = new QtOGLContext(m_surface, m_drawContext); + + return m_uploadContext; +} diff --git a/drape_head/qtoglcontextfactory.hpp b/drape_head/qtoglcontextfactory.hpp new file mode 100644 index 0000000000..2a756bfe28 --- /dev/null +++ b/drape_head/qtoglcontextfactory.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include "../../drape/oglcontextfactory.hpp" +#include "qtoglcontext.hpp" + +#include + +class QtOGLContextFactory +{ +public: + QtOGLContextFactory(QWindow * surface); + + virtual OGLContext * getDrawContext(); + virtual OGLContext * getResourcesUploadContext(); + +private: + QWindow * m_surface; + QtOGLContext * m_drawContext; + QtOGLContext * m_uploadContext; +};