[drape] use device-independent viewport

This commit is contained in:
ExMix 2014-01-28 14:06:35 +03:00 committed by Alex Zolotarev
parent 5d9210b272
commit eabf97f6c6
7 changed files with 84 additions and 79 deletions

View file

@ -1,6 +1,7 @@
#include "backend_renderer.hpp"
#include "read_manager.hpp"
#include "batchers_pool.hpp"
#include "vizualization_params.hpp"
#include "threads_commutator.hpp"
#include "message_subclasses.hpp"
@ -12,12 +13,21 @@
namespace df
{
namespace
{
ScalesProcessor CreateScaleProcessor(Viewport const & v)
{
ScalesProcessor p;
int tileSize = ScalesProcessor::CalculateTileSize(v.GetWidth(), v.GetHeight());
p.SetParams(df::VizualizationParams::GetVisualScale(), tileSize);
return p;
}
}
BackendRenderer::BackendRenderer(RefPointer<ThreadsCommutator> commutator,
RefPointer<OGLContextFactory> oglcontextfactory,
double visualScale,
int surfaceWidth,
int surfaceHeight)
: m_engineContext(commutator)
Viewport const & viewport)
: m_engineContext(commutator, CreateScaleProcessor(viewport))
, m_commutator(commutator)
, m_contextFactory(oglcontextfactory)
{
@ -32,7 +42,7 @@ namespace df
m_commutator->RegisterThread(ThreadsCommutator::ResourceUploadThread, this);
m_batchersPool.Reset(new BatchersPool(ReadManager::ReadCount(), bind(&BackendRenderer::PostToRenderThreads, this, _1)));
m_readManager.Reset(new ReadManager(visualScale, surfaceWidth, surfaceHeight, m_engineContext, m_model));
m_readManager.Reset(new ReadManager(m_engineContext, m_model));
StartThread();
}

View file

@ -2,6 +2,7 @@
#include "message_acceptor.hpp"
#include "engine_context.hpp"
#include "viewport.hpp"
#include "../drape/pointers.hpp"
#include "../drape/oglcontextfactory.hpp"
@ -24,9 +25,7 @@ namespace df
public:
BackendRenderer(RefPointer<ThreadsCommutator> commutator,
RefPointer<OGLContextFactory> oglcontextfactory,
double visualScale,
int surfaceWidth,
int surfaceHeight);
Viewport const & viewport);
~BackendRenderer();

View file

@ -1,42 +1,40 @@
#include "drape_engine.hpp"
#include "message_subclasses.hpp"
#include "vizualization_params.hpp"
namespace df
{
DrapeEngine::DrapeEngine(RefPointer<OGLContextFactory> contextfactory, double vs, Viewport const & viewport)
{
GLFunctions::Init();
VizualizationParams::SetVisualScale(vs);
DrapeEngine::DrapeEngine(RefPointer<OGLContextFactory> contextfactory, double vs, int w, int h)
{
GLFunctions::Init();
m_threadCommutator = MasterPointer<ThreadsCommutator>(new ThreadsCommutator());
RefPointer<ThreadsCommutator> commutatorRef = m_threadCommutator.GetRefPointer();
m_threadCommutator = MasterPointer<ThreadsCommutator>(new ThreadsCommutator());
m_frontend = MasterPointer<FrontendRenderer>(new FrontendRenderer(commutatorRef, contextfactory, viewport));
m_backend = MasterPointer<BackendRenderer>(new BackendRenderer(commutatorRef, contextfactory, viewport));
}
m_frontend = MasterPointer<FrontendRenderer>(
new FrontendRenderer(m_threadCommutator.GetRefPointer(), contextfactory, w, h));
m_backend = MasterPointer<BackendRenderer>(
new BackendRenderer(m_threadCommutator.GetRefPointer(), contextfactory, vs, w, h));
}
DrapeEngine::~DrapeEngine()
{
m_backend.Destroy();
m_frontend.Destroy();
m_threadCommutator.Destroy();
}
void DrapeEngine::OnSizeChanged(int x0, int y0, int w, int h)
{
m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
MovePointer<Message>(new ResizeMessage(x0, y0, w, h)));
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
MovePointer<Message>(new ResizeMessage(x0, y0, w, h)));
}
void DrapeEngine::SetAngle(float radians)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
MovePointer<Message>(new RotateMessage(radians)));
}
DrapeEngine::~DrapeEngine()
{
m_backend.Destroy();
m_frontend.Destroy();
m_threadCommutator.Destroy();
}
void DrapeEngine::OnSizeChanged(int x0, int y0, int w, int h)
{
m_threadCommutator->PostMessage(ThreadsCommutator::ResourceUploadThread,
MovePointer<Message>(new ResizeMessage(x0, y0, w, h)));
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
MovePointer<Message>(new ResizeMessage(x0, y0, w, h)));
}
void DrapeEngine::SetAngle(float radians)
{
m_threadCommutator->PostMessage(ThreadsCommutator::RenderThread,
MovePointer<Message>(new RotateMessage(radians)));
}
}

View file

@ -2,27 +2,27 @@
#include "frontend_renderer.hpp"
#include "backend_renderer.hpp"
#include "../drape/pointers.hpp"
#include "threads_commutator.hpp"
#include "../drape/pointers.hpp"
#include "../drape/oglcontextfactory.hpp"
namespace df
{
class Viewport;
class DrapeEngine
{
public:
DrapeEngine(RefPointer<OGLContextFactory> oglcontextfactory, double vs, Viewport const & viewport);
~DrapeEngine();
class DrapeEngine
{
public:
DrapeEngine(RefPointer<OGLContextFactory> oglcontextfactory, double vs, int w, int h);
~DrapeEngine();
void OnSizeChanged(int x0, int y0, int w, int h);
void SetAngle(float radians);
void OnSizeChanged(int x0, int y0, int w, int h);
void SetAngle(float radians);
private:
MasterPointer<FrontendRenderer> m_frontend;
MasterPointer<BackendRenderer> m_backend;
MasterPointer<ThreadsCommutator> m_threadCommutator;
};
private:
MasterPointer<FrontendRenderer> m_frontend;
MasterPointer<BackendRenderer> m_backend;
MasterPointer<ThreadsCommutator> m_threadCommutator;
};
}

View file

@ -13,12 +13,11 @@ namespace df
{
FrontendRenderer::FrontendRenderer(RefPointer<ThreadsCommutator> commutator,
RefPointer<OGLContextFactory> oglcontextfactory,
int w, int h)
Viewport viewport)
: m_commutator(commutator)
, m_gpuProgramManager(new GpuProgramManager())
, m_contextFactory(oglcontextfactory)
, m_width(w)
, m_height(h)
, m_viewport(viewport)
{
#ifdef DRAW_INFO
m_tpf = 0,0;
@ -26,7 +25,7 @@ namespace df
#endif
m_commutator->RegisterThread(ThreadsCommutator::RenderThread, this);
RefreshProjection(w, h);
RefreshProjection(viewport.GetWidth(), viewport.GetHeight());
RefreshModelView(0);
StartThread();
}
@ -67,7 +66,6 @@ namespace df
{
switch (message->GetType())
{
case Message::FlushTile:
{
FlushTileMessage * msg = static_cast<FlushTileMessage *>(message.GetRaw());
@ -81,7 +79,6 @@ namespace df
m_tileData.insert(make_pair(key, renderIterator));
break;
}
case Message::DropTiles:
{
CoverageUpdateDescriptor const & descr = static_cast<DropTilesMessage *>(message.GetRaw())->GetDescriptor();
@ -119,7 +116,7 @@ namespace df
RotateMessage * rtMsg = static_cast<RotateMessage *>(message.GetRaw());
RefreshModelView(rtMsg->GetDstAngle());
ScreenBase screen(m2::RectI(0, 0, m_width, m_height),
ScreenBase screen(m2::RectI(0, 0, m_viewport.GetWidth(), m_viewport.GetHeight()),
m2::AnyRectD(m2::PointD(0, 0), ang::AngleD(rtMsg->GetDstAngle()),
m2::RectD(0 ,0, 50, 50)));
@ -139,11 +136,11 @@ namespace df
{
memset(m, 0, 16 * sizeof(float));
m[0] = 2.0f / (right - left);
m[4] = - (right + left) / (right - left);
m[3] = - (right + left) / (right - left);
m[5] = 2.0f / (top - bottom);
m[9] = - (top + bottom) / (top - bottom);
m[7] = - (top + bottom) / (top - bottom);
m[10] = -2.0f / (far - near);
m[14] = - (far + near) / (far - near);
m[11] = - (far + near) / (far - near);
m[15] = 1.0;
}
}
@ -154,7 +151,7 @@ namespace df
BeforeDrawFrame();
#endif
GLFunctions::glViewport(0, 0, m_width, m_height);
m_viewport.Apply();
GLFunctions::glClearColor(0.65f, 0.65f, 0.65f, 1.f);
GLFunctions::glClear();
@ -167,20 +164,17 @@ namespace df
void FrontendRenderer::RefreshProjection(int w, int h)
{
if (w == 0)
w = 1;
ASSERT(w >= 0, ());
ASSERT(h >= 0, ());
m_height = h;
m_width = w;
if (h < 2) h = 2;
if (w < 2) w = 2;
m_viewport.SetViewport(0, 0, w, h);
float aspect = h / (float)w;
float m[4*4];
if (w >= h)
OrthoMatrix(m, -2.f/aspect, 2.f/aspect, -2.f, 2.f, -2.f, 2.f);
else
OrthoMatrix(m, -2.f, 2.f, -2.f*aspect, 2.f*aspect, -2.f, 2.f);
OrthoMatrix(m, 0.0f, w, h, 0.0f, -2.f, 2.f);
m_generalUniforms.SetMatrix4x4Value("projection", m);
}

View file

@ -12,6 +12,7 @@
#include "threads_commutator.hpp"
#include "tile_info.hpp"
#include "backend_renderer.hpp"
#include "viewport.hpp"
#include "../drape/pointers.hpp"
#include "../drape/glstate.hpp"
@ -31,7 +32,7 @@ namespace df
public:
FrontendRenderer(RefPointer<ThreadsCommutator> commutator,
RefPointer<OGLContextFactory> oglcontextfactory,
int w, int h);
Viewport viewport);
~FrontendRenderer();
@ -85,7 +86,6 @@ namespace df
tile_data_t m_tileData;
UniformValuesStorage m_generalUniforms;
int m_width;
int m_height;
Viewport m_viewport;
};
}

View file

@ -1,5 +1,7 @@
#include "drape_surface.hpp"
#include "../drape_frontend/viewport.hpp"
#include "../drape/utils/list_generator.hpp"
#include "../drape/shader_def.hpp"
@ -60,8 +62,10 @@ void DrapeSurface::CreateEngine()
{
RefPointer<OGLContextFactory> f(m_contextFactory.GetRefPointer());
float pixelRatio = devicePixelRatio();
m_drapeEngine = MasterPointer<df::DrapeEngine>(
new df::DrapeEngine(f , devicePixelRatio(), width(), height()));
new df::DrapeEngine(f , pixelRatio, df::Viewport(pixelRatio, 0, 0, width(), height())));
sizeChanged(0);