DrapeSurface updated.

This commit is contained in:
Dmitry Kunin 2013-12-27 17:28:26 +03:00 committed by Alex Zolotarev
parent 1c8a8ad1c0
commit 3ef9e45027
4 changed files with 27 additions and 147 deletions

View file

@ -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

View file

@ -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 \

View file

@ -9,34 +9,19 @@
#include "../std/bind.hpp"
#include "../std/cmath.hpp"
namespace
{
struct Deleter
{
void operator()(pair<const GLState, vector<MasterPointer<VertexArrayBuffer> > > & 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<QtOGLContextFactory>(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<OGLContextFactory> 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<df::DrapeEngine>(
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<VertexArrayBuffer> bucket)
{
RefPointer<GpuProgram> program = m_programManager->GetProgram(state.GetProgramIndex());
ApplyState(state, program);
ApplyUniforms(m_generalUniforms, program);
bucket->Render();
}
void DrapeSurface::FlushFullBucket(const GLState & state, TransferPointer<VertexArrayBuffer> bucket)
{
RefPointer<GpuProgram> program = m_programManager->GetProgram(state.GetProgramIndex());
MasterPointer<VertexArrayBuffer> masterBucket(bucket);
masterBucket->Build(program);
m_frames[state].push_back(masterBucket);
Render();
if (!m_drapeEngine.IsNull())
m_drapeEngine->OnSizeChanged(0, 0, width(), height());
}

View file

@ -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 <QtGui/QWindow>
#include <QtCore/QTimerEvent>
@ -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<VertexArrayBuffer> bucket);
void FlushFullBucket(const GLState & state, TransferPointer<VertexArrayBuffer> bucket);
Q_SLOT void sizeChanged(int);
private:
typedef map<GLState, vector<MasterPointer<VertexArrayBuffer> > > frames_t;
frames_t m_frames;
private:
Batcher * m_batcher;
GpuProgramManager * m_programManager;
UniformValuesStorage m_generalUniforms;
int m_timerID;
private:
QtOGLContextFactory * m_contextFactory;
MasterPointer<QtOGLContextFactory> m_contextFactory;
MasterPointer<df::DrapeEngine> m_drapeEngine;
};