forked from organicmaps/organicmaps-tmp
refactored coordinate system setting.
This commit is contained in:
parent
bdb3c27342
commit
9ce0961712
12 changed files with 100 additions and 19 deletions
18
graphics/coordinates.cpp
Normal file
18
graphics/coordinates.cpp
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "coordinates.hpp"
|
||||
|
||||
namespace graphics
|
||||
{
|
||||
void getOrthoMatrix(math::Matrix<float, 4, 4> & m,
|
||||
float l,
|
||||
float r,
|
||||
float b,
|
||||
float t,
|
||||
float n,
|
||||
float f)
|
||||
{
|
||||
m(0, 0) = 2 / (r - l); m(0, 1) = 0; m(0, 2) = 0; m(0, 3) = -(r + l) / (r - l);
|
||||
m(1, 0) = 0; m(1, 1) = 2 / (t - b);m(1, 2) = 0; m(1, 3) = -(t + b) / (t - b);
|
||||
m(2, 0) = 0; m(2, 1) = 0; m(2, 2) = -2 / (f - n); m(2, 3) = - (f + n) / (f - n);
|
||||
m(3, 0) = 0; m(3, 1) = 0; m(3, 2) = 0; m(3, 3) = 1;
|
||||
}
|
||||
}
|
13
graphics/coordinates.hpp
Normal file
13
graphics/coordinates.hpp
Normal file
|
@ -0,0 +1,13 @@
|
|||
#include "../base/matrix.hpp"
|
||||
|
||||
namespace graphics
|
||||
{
|
||||
/// Calculate matrix for orthographic projection
|
||||
void getOrthoMatrix(math::Matrix<float, 4, 4> & m,
|
||||
float left,
|
||||
float right,
|
||||
float bottom,
|
||||
float top,
|
||||
float near,
|
||||
float far);
|
||||
}
|
|
@ -67,6 +67,9 @@ SOURCES += \
|
|||
image_info.cpp \
|
||||
image_renderer.cpp \
|
||||
display_list_renderer.cpp
|
||||
render_context.cpp \
|
||||
coordinates.cpp \
|
||||
render_target.cpp \
|
||||
|
||||
HEADERS += \
|
||||
opengl/opengl.hpp \
|
||||
|
@ -128,6 +131,7 @@ HEADERS += \
|
|||
image_info.hpp \
|
||||
display_list_renderer.hpp
|
||||
render_context.hpp \
|
||||
coordinates.hpp \
|
||||
|
||||
win32* {
|
||||
SOURCES += opengl/opengl_win32.cpp
|
||||
|
|
|
@ -58,7 +58,6 @@ namespace graphics
|
|||
GL_TEXTURE_2D,
|
||||
id(),
|
||||
0));
|
||||
utils::setupCoordinates(width(), height(), false);
|
||||
}
|
||||
|
||||
void BaseTexture::detachFromFrameBuffer()
|
||||
|
|
|
@ -54,15 +54,7 @@ namespace graphics
|
|||
GL_TEXTURE_2D,
|
||||
0,
|
||||
0));
|
||||
|
||||
utils::setupCoordinates(width(), height(), true);
|
||||
}
|
||||
|
||||
/// !!! it's a must for a correct work.
|
||||
/// update: it was necessary for multisampling,
|
||||
/// but without it on KindleFire this function produces bug
|
||||
/* if (m_id != 0)
|
||||
checkStatus();*/
|
||||
}
|
||||
|
||||
void FrameBuffer::setRenderTarget(shared_ptr<RenderTarget> const & renderTarget)
|
||||
|
|
|
@ -48,9 +48,6 @@ namespace graphics
|
|||
isDepthBuffer() ? GL_DEPTH_ATTACHMENT_MWM : GL_COLOR_ATTACHMENT0_MWM,
|
||||
GL_RENDERBUFFER_MWM,
|
||||
id()));
|
||||
|
||||
if (!isDepthBuffer())
|
||||
utils::setupCoordinates(width(), height(), false);
|
||||
}
|
||||
|
||||
void RenderBuffer::detachFromFrameBuffer()
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "../base/logging.hpp"
|
||||
#include "../render_context.hpp"
|
||||
#include "../coordinates.hpp"
|
||||
|
||||
#include "renderer.hpp"
|
||||
#include "data_traits.hpp"
|
||||
|
@ -33,6 +34,7 @@ namespace graphics
|
|||
m_env(0),
|
||||
m_threadSlot(params.m_threadSlot)
|
||||
{
|
||||
m_renderContext = params.m_renderContext;
|
||||
m_frameBuffer = params.m_frameBuffer;
|
||||
m_resourceManager = params.m_resourceManager;
|
||||
|
||||
|
@ -64,6 +66,20 @@ namespace graphics
|
|||
m_frameBuffer->setDepthBuffer(m_depthBuffer);
|
||||
|
||||
processCommand(make_shared_ptr(new ChangeFrameBuffer(m_frameBuffer)));
|
||||
|
||||
math::Matrix<float, 4, 4> coordM;
|
||||
|
||||
if (m_renderTarget != 0)
|
||||
m_renderTarget->coordMatrix(coordM);
|
||||
else
|
||||
getOrthoMatrix(coordM,
|
||||
0, m_frameBuffer->width(),
|
||||
m_frameBuffer->height(), 0,
|
||||
-graphics::maxDepth,
|
||||
graphics::maxDepth);
|
||||
|
||||
processCommand(make_shared_ptr(new ChangeMatrix(EProjection, coordM)));
|
||||
processCommand(make_shared_ptr(new ChangeMatrix(EModelView, math::Identity<float, 4>())));
|
||||
}
|
||||
|
||||
// checkStatus();
|
||||
|
@ -88,6 +104,15 @@ namespace graphics
|
|||
processCommand(make_shared_ptr(new UnbindRenderTarget(m_renderTarget)));
|
||||
}
|
||||
|
||||
Renderer::ChangeMatrix::ChangeMatrix(EMatrix mt, math::Matrix<float, 4, 4> const & m)
|
||||
: m_matrixType(mt), m_matrix(m)
|
||||
{}
|
||||
|
||||
void Renderer::ChangeMatrix::perform()
|
||||
{
|
||||
renderContext()->setMatrix(m_matrixType, m_matrix);
|
||||
}
|
||||
|
||||
Renderer::DiscardFramebuffer::DiscardFramebuffer(bool doDiscardColor, bool doDiscardDepth)
|
||||
: m_doDiscardColor(doDiscardColor), m_doDiscardDepth(doDiscardDepth)
|
||||
{}
|
||||
|
@ -260,6 +285,8 @@ namespace graphics
|
|||
}
|
||||
|
||||
m_frameBuffer->makeCurrent();
|
||||
|
||||
OGLCHECK(glViewport(0, 0, m_frameBuffer->width(), m_frameBuffer->height()));
|
||||
}
|
||||
|
||||
void Renderer::onSize(unsigned int width, unsigned int height)
|
||||
|
|
|
@ -59,6 +59,15 @@ namespace graphics
|
|||
void perform();
|
||||
};
|
||||
|
||||
struct ChangeMatrix : Command
|
||||
{
|
||||
EMatrix m_matrixType;
|
||||
math::Matrix<float, 4, 4> m_matrix;
|
||||
|
||||
ChangeMatrix(EMatrix mt, math::Matrix<float, 4, 4> const & m);
|
||||
void perform();
|
||||
};
|
||||
|
||||
struct UnbindRenderTarget : Command
|
||||
{
|
||||
shared_ptr<RenderTarget> m_renderTarget;
|
||||
|
|
14
graphics/render_target.cpp
Normal file
14
graphics/render_target.cpp
Normal file
|
@ -0,0 +1,14 @@
|
|||
#include "render_target.hpp"
|
||||
#include "coordinates.hpp"
|
||||
#include "defines.hpp"
|
||||
|
||||
namespace graphics
|
||||
{
|
||||
RenderTarget::~RenderTarget()
|
||||
{}
|
||||
|
||||
void RenderTarget::coordMatrix(math::Matrix<float, 4, 4> & m)
|
||||
{
|
||||
getOrthoMatrix(m, 0, width(), 0, height(), -maxDepth, maxDepth);
|
||||
}
|
||||
}
|
|
@ -1,15 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "../base/matrix.hpp"
|
||||
|
||||
namespace graphics
|
||||
{
|
||||
class RenderTarget
|
||||
{
|
||||
public:
|
||||
virtual ~RenderTarget() {}
|
||||
/// attach render target to framebuffer and setup coordinate system
|
||||
virtual ~RenderTarget();
|
||||
virtual unsigned int id() const = 0;
|
||||
/// attach render target to framebuffer and setup coordinate system
|
||||
virtual void attachToFrameBuffer() = 0;
|
||||
virtual void detachFromFrameBuffer() = 0;
|
||||
virtual void coordMatrix(math::Matrix<float, 4, 4> & m);
|
||||
virtual unsigned width() const = 0;
|
||||
virtual unsigned height() const = 0;
|
||||
};
|
||||
|
|
|
@ -33,5 +33,6 @@ namespace iphone
|
|||
|
||||
void attachToFrameBuffer();
|
||||
void detachFromFrameBuffer();
|
||||
void coordMatrix(math::Matrix<float, 4, 4> & m);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
#include "RenderBuffer.hpp"
|
||||
|
||||
#include "../../../graphics/opengl/opengl.hpp"
|
||||
#include "../../../graphics/opengl/utils.hpp"
|
||||
#include "../../../graphics/coordinates.hpp"
|
||||
|
||||
namespace iphone
|
||||
{
|
||||
|
@ -70,14 +70,18 @@ namespace iphone
|
|||
GL_COLOR_ATTACHMENT0_OES,
|
||||
GL_RENDERBUFFER_OES,
|
||||
m_id));
|
||||
graphics::gl::utils::setupCoordinates(width(), height(), true);
|
||||
}
|
||||
|
||||
void RenderBuffer::detachFromFrameBuffer()
|
||||
{
|
||||
OGLCHECK(glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES,
|
||||
GL_COLOR_ATTACHMENT0_OES,
|
||||
GL_RENDERBUFFER_OES,
|
||||
0));
|
||||
GL_RENDERBUFFER_OES,
|
||||
0));
|
||||
}
|
||||
}
|
||||
|
||||
void RenderBuffer::coordMatrix(math::Matrix<float, 4, 4> & m)
|
||||
{
|
||||
graphics::getOrthoMatrix(m, 0, width(), height(), 0, -graphics::maxDepth, graphics::maxDepth);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue