From 3ef9e4502753715ff8af8b8220f635731f1a2463 Mon Sep 17 00:00:00 2001 From: Dmitry Kunin Date: Fri, 27 Dec 2013 17:28:26 +0300 Subject: [PATCH] DrapeSurface updated. --- drape_frontend/drape_frontend.pro | 3 +- drape_head/drape_head.pro | 9 +- drape_head/drape_surface.cpp | 144 +++--------------------------- drape_head/drape_surface.hpp | 18 ++-- 4 files changed, 27 insertions(+), 147 deletions(-) diff --git a/drape_frontend/drape_frontend.pro b/drape_frontend/drape_frontend.pro index 41481068bf..93be432a66 100644 --- a/drape_frontend/drape_frontend.pro +++ b/drape_frontend/drape_frontend.pro @@ -18,11 +18,11 @@ SOURCES += \ read_mwm_task.cpp \ batchers_pool.cpp \ frontend_renderer.cpp \ + drape_engine.cpp \ area_shape.cpp HEADERS += \ backend_renderer.hpp \ - render_thread.hpp \ engine_context.hpp \ memory_feature_index.hpp \ tile_info.hpp \ @@ -36,4 +36,5 @@ HEADERS += \ map_shape.hpp \ batchers_pool.hpp \ frontend_renderer.hpp \ + drape_engine.hpp \ area_shape.hpp diff --git a/drape_head/drape_head.pro b/drape_head/drape_head.pro index b108789673..fd2f2ce6cf 100644 --- a/drape_head/drape_head.pro +++ b/drape_head/drape_head.pro @@ -1,6 +1,6 @@ # Head project for drape develop and debuging ROOT_DIR = .. -DEPENDENCIES = drape base +DEPENDENCIES = drape_frontend drape map indexer platform geometry base include($$ROOT_DIR/common.pri) @@ -20,6 +20,11 @@ win32*|linux* { QT *= network } +macx-* { + LIBS *= "-framework CoreLocation" "-framework Foundation" "-framework CoreWLAN" \ + "-framework QuartzCore" "-framework IOKit" +} + HEADERS += \ mainwindow.hpp \ qtoglcontext.hpp \ @@ -30,5 +35,5 @@ SOURCES += \ mainwindow.cpp \ main.cpp \ qtoglcontext.cpp \ - qtoglcontextfactory.cpp \ + qtoglcontextfactory.cpp \ drape_surface.cpp \ diff --git a/drape_head/drape_surface.cpp b/drape_head/drape_surface.cpp index be3e5d8983..8aec497169 100644 --- a/drape_head/drape_surface.cpp +++ b/drape_head/drape_surface.cpp @@ -9,34 +9,19 @@ #include "../std/bind.hpp" #include "../std/cmath.hpp" -namespace -{ - struct Deleter - { - void operator()(pair > > & value) - { - GetRangeDeletor(value.second, MasterPointerDeleter())(); - } - }; -} DrapeSurface::DrapeSurface() : m_contextFactory(NULL) { setSurfaceType(QSurface::OpenGLSurface); - m_batcher = new Batcher(); - m_programManager = new GpuProgramManager(); - QObject::connect(this, SIGNAL(heightChanged(int)), this, SLOT(RefreshProjector(int))); - QObject::connect(this, SIGNAL(widthChanged(int)), this, SLOT(RefreshProjector(int))); + QObject::connect(this, SIGNAL(heightChanged(int)), this, SLOT(sizeChanged(int))); + QObject::connect(this, SIGNAL(widthChanged(int)), this, SLOT(sizeChanged(int))); } DrapeSurface::~DrapeSurface() { - GetRangeDeletor(m_frames, Deleter())(); - delete m_batcher; - delete m_programManager; - delete m_contextFactory; + m_contextFactory.Destroy(); } void DrapeSurface::exposeEvent(QExposeEvent *e) @@ -45,15 +30,11 @@ void DrapeSurface::exposeEvent(QExposeEvent *e) if (isExposed()) { - if (m_contextFactory == NULL) + if (m_contextFactory.IsNull()) { - m_contextFactory = new QtOGLContextFactory(this); - m_contextFactory->getDrawContext()->makeCurrent(); + m_contextFactory = MasterPointer(new QtOGLContextFactory(this)); CreateEngine(); } - - Render(); - m_contextFactory->getDrawContext()->present(); } } @@ -66,123 +47,24 @@ void DrapeSurface::timerEvent(QTimerEvent * e) angle += 0.035; if (angle > _2pi) angle -= _2pi; - RefreshMVUniform(angle); - Render(); - m_contextFactory->getDrawContext()->present(); - } -} -namespace -{ - void OrthoMatrix(float * m, float left, float right, float bottom, float top, float near, float far) - { - memset(m, 0, 16 * sizeof(float)); - m[0] = 2.0f / (right - left); - m[4] = - (right + left) / (right - left); - m[5] = 2.0f / (top - bottom); - m[9] = - (top + bottom) / (top - bottom); - m[10] = -2.0f / (far - near); - m[14] = - (far + near) / (far - near); - m[15] = 1.0; + // TODO this is test + m_drapeEngine->SetAngle(angle); } } void DrapeSurface::CreateEngine() { - glClearColor(0.8, 0.8, 0.8, 1.0); + RefPointer f(m_contextFactory.GetRefPointer()); - GLFunctions::Init(); - glEnable(GL_DEPTH_TEST); - glDepthMask(GL_TRUE); - glDepthFunc(GL_LEQUAL); - glClearDepth(0.0); - - RefreshMVUniform(0.0); - RefreshProjector(0); - - UniformValuesStorage uniforms; - float color[4] = { 0.6, 0.8, 0.3, 1.0 }; - uniforms.SetFloatValue("color", color[0], color[1], color[2], color[3]); - - m_batcher->StartSession(bind(&DrapeSurface::FlushFullBucket, this, _1, _2)); - ListGenerator gen; - gen.SetDepth(0.5); - gen.SetProgram(gpu::SOLID_AREA_PROGRAM); - gen.SetViewport(-1.0f, -1.0f, 2.0f, 2.0f); - gen.SetUniforms(uniforms); - gen.Generate(31, *m_batcher); - m_batcher->EndSession(); + m_drapeEngine = MasterPointer( + new df::DrapeEngine(f , devicePixelRatio(), width(), height())); m_timerID = startTimer(1000 / 30); } -void DrapeSurface::Render() +void DrapeSurface::sizeChanged(int) { - const qreal retinaScale = devicePixelRatio(); - glViewport(0, 0, width() * retinaScale, height() * retinaScale); - glClearDepth(1.0); - glDepthFunc(GL_LEQUAL); - glDepthMask(GL_TRUE); - glEnable(GL_DEPTH_TEST); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - if (!m_frames.empty()) - { - frames_t::iterator it = m_frames.begin(); - for (; it != m_frames.end(); ++it) - { - for (size_t i = 0; i < it->second.size(); ++i) - { - RenderBucket(it->first, it->second[i].GetRefPointer()); - } - } - } -} - -void DrapeSurface::RefreshProjector(int ) -{ - int w = width(); - int h = height(); - if (w == 0) - w = 1; - float aspect = h / (float)w; - float m[16]; - if (w > h) - OrthoMatrix(m, -2.0f / aspect, 2.0f / aspect, -2.0f, 2.0f, -2.0f, 2.0f); - else - OrthoMatrix(m, -2.0f, 2.0f, -2.0f * aspect, 2.0f * aspect, -2.0f, 2.0f); - - m_generalUniforms.SetMatrix4x4Value("projection", m); -} - -void DrapeSurface::RefreshMVUniform(float angle) -{ - float c = cos(angle); - float s = sin(angle); - float model[16] = - { - c, -s, 0.0, 0.0, - s, c, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0, - 0.0, 0.0, 0.0, 1.0 - }; - - m_generalUniforms.SetMatrix4x4Value("modelView", model); -} - -void DrapeSurface::RenderBucket(const GLState & state, RefPointer bucket) -{ - RefPointer program = m_programManager->GetProgram(state.GetProgramIndex()); - ApplyState(state, program); - ApplyUniforms(m_generalUniforms, program); - bucket->Render(); -} - -void DrapeSurface::FlushFullBucket(const GLState & state, TransferPointer bucket) -{ - RefPointer program = m_programManager->GetProgram(state.GetProgramIndex()); - MasterPointer masterBucket(bucket); - masterBucket->Build(program); - m_frames[state].push_back(masterBucket); - Render(); + if (!m_drapeEngine.IsNull()) + m_drapeEngine->OnSizeChanged(0, 0, width(), height()); } diff --git a/drape_head/drape_surface.hpp b/drape_head/drape_surface.hpp index 569bc62e58..fdad3857ce 100644 --- a/drape_head/drape_surface.hpp +++ b/drape_head/drape_surface.hpp @@ -5,6 +5,7 @@ #include "../drape/batcher.hpp" #include "../drape/gpu_program_manager.hpp" #include "../drape/uniform_values_storage.hpp" +#include "../drape_frontend/drape_engine.hpp" #include #include @@ -22,24 +23,15 @@ protected: void timerEvent(QTimerEvent * e); private: - void RefreshMVUniform(float angle); - Q_SLOT void RefreshProjector(int); void CreateEngine(); - void Render(); - void RenderBucket(const GLState & state, RefPointer bucket); - void FlushFullBucket(const GLState & state, TransferPointer bucket); + + Q_SLOT void sizeChanged(int); private: - typedef map > > frames_t; - frames_t m_frames; - -private: - Batcher * m_batcher; - GpuProgramManager * m_programManager; - UniformValuesStorage m_generalUniforms; int m_timerID; private: - QtOGLContextFactory * m_contextFactory; + MasterPointer m_contextFactory; + MasterPointer m_drapeEngine; };