diff options
author | ExMix <rahuba.youri@mapswithme.com> | 2015-07-08 12:36:57 +0300 |
---|---|---|
committer | r.kuznetsov <r.kuznetsov@corp.mail.ru> | 2015-11-30 16:09:31 +0300 |
commit | 425d6bc58416930763e9a74755ff64b6bc9771db (patch) | |
tree | 946a9d2067390bc749fb352b5c7e6ef69b096056 /drape_head | |
parent | 4e8d7d40e78f1fa7ca55b7b107ecab6e19d978e0 (diff) |
[drape] clean up drape_head code. Remove QtOGLContextFactory duplicate
in qt application make rendering according qt widgets composition model
Diffstat (limited to 'drape_head')
-rw-r--r-- | drape_head/drape_head.pro | 4 | ||||
-rw-r--r-- | drape_head/drape_surface.cpp | 43 | ||||
-rw-r--r-- | drape_head/drape_surface.hpp | 19 | ||||
-rw-r--r-- | drape_head/qtoglcontext.cpp | 49 | ||||
-rw-r--r-- | drape_head/qtoglcontext.hpp | 22 | ||||
-rw-r--r-- | drape_head/qtoglcontextfactory.cpp | 31 | ||||
-rw-r--r-- | drape_head/qtoglcontextfactory.hpp | 21 | ||||
-rw-r--r-- | drape_head/testing_engine.cpp | 23 | ||||
-rw-r--r-- | drape_head/testing_engine.hpp | 15 |
9 files changed, 32 insertions, 195 deletions
diff --git a/drape_head/drape_head.pro b/drape_head/drape_head.pro index 6f605377c9..925b12b1ef 100644 --- a/drape_head/drape_head.pro +++ b/drape_head/drape_head.pro @@ -29,15 +29,11 @@ macx-* { HEADERS += \ mainwindow.hpp \ - qtoglcontext.hpp \ - qtoglcontextfactory.hpp \ drape_surface.hpp \ testing_engine.hpp \ SOURCES += \ mainwindow.cpp \ main.cpp \ - qtoglcontext.cpp \ - qtoglcontextfactory.cpp \ drape_surface.cpp \ testing_engine.cpp \ diff --git a/drape_head/drape_surface.cpp b/drape_head/drape_surface.cpp index 8aeca78781..886f3b4eab 100644 --- a/drape_head/drape_surface.cpp +++ b/drape_head/drape_surface.cpp @@ -5,47 +5,44 @@ #include "base/logging.hpp" DrapeSurface::DrapeSurface() - : m_contextFactory(nullptr) { - setSurfaceType(QSurface::OpenGLSurface); - - QObject::connect(this, SIGNAL(heightChanged(int)), this, SLOT(sizeChanged(int))); - QObject::connect(this, SIGNAL(widthChanged(int)), this, SLOT(sizeChanged(int))); } DrapeSurface::~DrapeSurface() { + m_timer.stop(); + m_drapeEngine.reset(); } -void DrapeSurface::exposeEvent(QExposeEvent *e) +void DrapeSurface::initializeGL() { - Q_UNUSED(e); + CreateEngine(); + m_timer.setInterval(1000 / 30); + m_timer.setSingleShot(false); - if (isExposed()) - { - if (m_contextFactory == nullptr) - { - m_contextFactory = make_unique_dp<dp::ThreadSafeFactory>(new QtOGLContextFactory(this), false); - CreateEngine(); - } - } + connect(&m_timer, SIGNAL(timeout()), SLOT(update())); + m_timer.start(); } -void DrapeSurface::CreateEngine() +void DrapeSurface::paintGL() { - float const pixelRatio = devicePixelRatio(); - m_drapeEngine = make_unique_dp<df::TestingEngine>(make_ref(m_contextFactory), - df::Viewport(0, 0, pixelRatio * width(), pixelRatio * height()), - pixelRatio); + m_drapeEngine->Draw(); } -void DrapeSurface::sizeChanged(int) +void DrapeSurface::resizeGL(int width, int height) { if (m_drapeEngine != nullptr) { float const vs = devicePixelRatio(); - int const w = width() * vs; - int const h = height() * vs; + int const w = width * vs; + int const h = height * vs; m_drapeEngine->Resize(w, h); } } + +void DrapeSurface::CreateEngine() +{ + float const pixelRatio = devicePixelRatio(); + m_drapeEngine = make_unique_dp<df::TestingEngine>(df::Viewport(0, 0, pixelRatio * width(), pixelRatio * height()), + pixelRatio); +} diff --git a/drape_head/drape_surface.hpp b/drape_head/drape_surface.hpp index 88d55b4e1e..fd2ceddb97 100644 --- a/drape_head/drape_surface.hpp +++ b/drape_head/drape_surface.hpp @@ -1,11 +1,11 @@ #pragma once -#include "drape_head/qtoglcontextfactory.hpp" #include "drape_head/testing_engine.hpp" -#include <QtGui/QWindow> +#include <QtGui/QOpenGLWindow> +#include <QtCore/QTimer> -class DrapeSurface : public QWindow +class DrapeSurface : public QOpenGLWindow { Q_OBJECT @@ -14,16 +14,13 @@ public: ~DrapeSurface(); protected: - void exposeEvent(QExposeEvent * e); + void initializeGL() override; + void paintGL() override; + void resizeGL(int w, int h) override; private: void CreateEngine(); - Q_SLOT void sizeChanged(int); - -private: - typedef drape_ptr<dp::OGLContextFactory> TContextFactoryPtr; - typedef drape_ptr<df::TestingEngine> TEnginePrt; - TContextFactoryPtr m_contextFactory; - TEnginePrt m_drapeEngine; + drape_ptr<df::TestingEngine> m_drapeEngine; + QTimer m_timer; }; diff --git a/drape_head/qtoglcontext.cpp b/drape_head/qtoglcontext.cpp deleted file mode 100644 index 9d72f9dc12..0000000000 --- a/drape_head/qtoglcontext.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "drape_head/qtoglcontext.hpp" - -#include "base/assert.hpp" -#include "base/logging.hpp" - -#include "drape/glfunctions.hpp" - -QtOGLContext::QtOGLContext(QWindow * surface, QtOGLContext * contextToShareWith) -{ - m_isContextCreated = false; - m_surface = surface; - m_nativeContext = new QOpenGLContext(); - - if (contextToShareWith != NULL) - m_nativeContext->setShareContext(contextToShareWith->m_nativeContext); - - m_nativeContext->setFormat(m_surface->requestedFormat()); - ASSERT(m_surface->isExposed(), ()); - VERIFY(m_nativeContext->create(), ()); -} - -QtOGLContext::~QtOGLContext() -{ - delete m_nativeContext; -} - -void QtOGLContext::makeCurrent() -{ - ASSERT(m_nativeContext->isValid(), ()); - m_nativeContext->makeCurrent(m_surface); - -#ifdef DEBUG - LOG(LDEBUG, ("Current context : ", m_nativeContext)); - QList<QOpenGLContext *> list = QOpenGLContextGroup::currentContextGroup()->shares(); - for (int i = 0; i < list.size(); ++i) - LOG(LDEBUG, ("Share context : ", list[i])); -#endif -} - -void QtOGLContext::present() -{ - m_nativeContext->makeCurrent(m_surface); - m_nativeContext->swapBuffers(m_surface); -} - -void QtOGLContext::setDefaultFramebuffer() -{ - GLFunctions::glBindFramebuffer(GL_FRAMEBUFFER, m_nativeContext->defaultFramebufferObject()); -} diff --git a/drape_head/qtoglcontext.hpp b/drape_head/qtoglcontext.hpp deleted file mode 100644 index 2bc7000de3..0000000000 --- a/drape_head/qtoglcontext.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "drape/oglcontext.hpp" - -#include <QtGui/QWindow> -#include <QtGui/QOpenGLContext> - -class QtOGLContext: public dp::OGLContext -{ -public: - QtOGLContext(QWindow * surface, QtOGLContext * contextToShareWith); - ~QtOGLContext(); - - virtual void present(); - virtual void makeCurrent(); - virtual void setDefaultFramebuffer(); - -private: - QOpenGLContext * m_nativeContext; - QWindow * m_surface; - bool m_isContextCreated; -}; diff --git a/drape_head/qtoglcontextfactory.cpp b/drape_head/qtoglcontextfactory.cpp deleted file mode 100644 index 28ce15cdae..0000000000 --- a/drape_head/qtoglcontextfactory.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include "drape_head/qtoglcontextfactory.hpp" - -#include "base/assert.hpp" - -QtOGLContextFactory::QtOGLContextFactory(QWindow * surface) - : m_surface(surface) - , m_drawContext(NULL) - , m_uploadContext(NULL) -{} - -QtOGLContextFactory::~QtOGLContextFactory() -{ - delete m_drawContext; - delete m_uploadContext; -} - -dp::OGLContext * QtOGLContextFactory::getDrawContext() -{ - if (m_drawContext == NULL) - m_drawContext = new QtOGLContext(m_surface, m_uploadContext); - - return m_drawContext; -} - -dp::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 deleted file mode 100644 index 0ce63d77d5..0000000000 --- a/drape_head/qtoglcontextfactory.hpp +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "drape/oglcontextfactory.hpp" -#include "drape_head/qtoglcontext.hpp" - -#include <QtGui/QWindow> - -class QtOGLContextFactory : public dp::OGLContextFactory -{ -public: - QtOGLContextFactory(QWindow * surface); - ~QtOGLContextFactory(); - - virtual dp::OGLContext * getDrawContext(); - virtual dp::OGLContext * getResourcesUploadContext(); - -private: - QWindow * m_surface; - QtOGLContext * m_drawContext; - QtOGLContext * m_uploadContext; -}; diff --git a/drape_head/testing_engine.cpp b/drape_head/testing_engine.cpp index 79f51fae6f..68159b1842 100644 --- a/drape_head/testing_engine.cpp +++ b/drape_head/testing_engine.cpp @@ -326,13 +326,9 @@ private: TCreatorsMap m_creators; }; -TestingEngine::TestingEngine(ref_ptr<dp::OGLContextFactory> oglcontextfactory, - Viewport const & viewport, - double vs) - : m_contextFactory(oglcontextfactory) - , m_viewport(viewport) +TestingEngine::TestingEngine(Viewport const & viewport, double vs) + : m_viewport(viewport) { - m_contextFactory->getDrawContext()->makeCurrent(); df::VisualParams::Init(vs, df::CalculateTileSize(viewport.GetWidth(), viewport.GetHeight())); GLFunctions::Init(); @@ -352,13 +348,10 @@ TestingEngine::TestingEngine(ref_ptr<dp::OGLContextFactory> oglcontextfactory, ModelViewInit(); ProjectionInit(); - - m_timerId = startTimer(1000 / 30); } TestingEngine::~TestingEngine() { - killTimer(m_timerId); ClearScene(); m_textures->Release(); } @@ -379,9 +372,6 @@ void TestingEngine::Draw() ModelViewInit(); m_angle += 0.005; - dp::OGLContext * context = m_contextFactory->getDrawContext(); - context->setDefaultFramebuffer(); - m_viewport.Apply(); GLFunctions::glClearColor(0.65f, 0.65f, 0.65f, 1.0f); GLFunctions::glClear(); @@ -411,8 +401,6 @@ void TestingEngine::Draw() buckets[i]->Render(m_modelView); tree.EndOverlayPlacing(); } - - context->present(); } void TestingEngine::Resize(int w, int h) @@ -422,13 +410,6 @@ void TestingEngine::Resize(int w, int h) m_viewport.SetViewport(0, 0, w, h); ModelViewInit(); ProjectionInit(); - Draw(); -} - -void TestingEngine::timerEvent(QTimerEvent * e) -{ - if (e->timerId() == m_timerId) - Draw(); } void TestingEngine::DrawImpl() diff --git a/drape_head/testing_engine.hpp b/drape_head/testing_engine.hpp index fa06db5dd7..fb8c175dce 100644 --- a/drape_head/testing_engine.hpp +++ b/drape_head/testing_engine.hpp @@ -12,28 +12,18 @@ #include "std/map.hpp" -#include <QObject> -#include <QEvent> - namespace df { -class TestingEngine : public QObject +class TestingEngine { public: - TestingEngine(ref_ptr<dp::OGLContextFactory> oglcontextfactory, - Viewport const & viewport, - double vs); + TestingEngine(Viewport const & viewport, double vs); ~TestingEngine(); void Draw(); void Resize(int w, int h); -protected: - void timerEvent(QTimerEvent * e); - - int m_timerId; - private: void DrawImpl(); void DrawRects(); @@ -43,7 +33,6 @@ private: void ClearScene(); private: - ref_ptr<dp::OGLContextFactory> m_contextFactory; drape_ptr<dp::Batcher> m_batcher; drape_ptr<dp::GpuProgramManager> m_programManager; drape_ptr<dp::TextureManager> m_textures; |