diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-11-30 12:05:02 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:47:43 +0300 |
commit | 9ce0961712eb176b2f02b761c6e4e8491270e73b (patch) | |
tree | e0371021e3a62d0c0210335b660251f7dd787956 /graphics | |
parent | bdb3c27342f5e1c1bbf8227f2b541b61eb7fa445 (diff) |
refactored coordinate system setting.
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/coordinates.cpp | 18 | ||||
-rw-r--r-- | graphics/coordinates.hpp | 13 | ||||
-rw-r--r-- | graphics/graphics.pro | 4 | ||||
-rw-r--r-- | graphics/opengl/base_texture.cpp | 1 | ||||
-rw-r--r-- | graphics/opengl/framebuffer.cpp | 8 | ||||
-rw-r--r-- | graphics/opengl/renderbuffer.cpp | 3 | ||||
-rw-r--r-- | graphics/opengl/renderer.cpp | 27 | ||||
-rw-r--r-- | graphics/opengl/renderer.hpp | 9 | ||||
-rw-r--r-- | graphics/render_target.cpp | 14 | ||||
-rw-r--r-- | graphics/render_target.hpp | 7 |
10 files changed, 90 insertions, 14 deletions
diff --git a/graphics/coordinates.cpp b/graphics/coordinates.cpp new file mode 100644 index 0000000000..c26babb775 --- /dev/null +++ b/graphics/coordinates.cpp @@ -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; + } +} diff --git a/graphics/coordinates.hpp b/graphics/coordinates.hpp new file mode 100644 index 0000000000..63d5eff7d3 --- /dev/null +++ b/graphics/coordinates.hpp @@ -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); +} diff --git a/graphics/graphics.pro b/graphics/graphics.pro index 492798e8c5..14bb00d442 100644 --- a/graphics/graphics.pro +++ b/graphics/graphics.pro @@ -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 diff --git a/graphics/opengl/base_texture.cpp b/graphics/opengl/base_texture.cpp index c5a8229411..f68afb26b6 100644 --- a/graphics/opengl/base_texture.cpp +++ b/graphics/opengl/base_texture.cpp @@ -58,7 +58,6 @@ namespace graphics GL_TEXTURE_2D, id(), 0)); - utils::setupCoordinates(width(), height(), false); } void BaseTexture::detachFromFrameBuffer() diff --git a/graphics/opengl/framebuffer.cpp b/graphics/opengl/framebuffer.cpp index a641601cdf..a7bea0cb0a 100644 --- a/graphics/opengl/framebuffer.cpp +++ b/graphics/opengl/framebuffer.cpp @@ -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) diff --git a/graphics/opengl/renderbuffer.cpp b/graphics/opengl/renderbuffer.cpp index 3b6e4e1c90..a91d050568 100644 --- a/graphics/opengl/renderbuffer.cpp +++ b/graphics/opengl/renderbuffer.cpp @@ -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() diff --git a/graphics/opengl/renderer.cpp b/graphics/opengl/renderer.cpp index f524924e25..f8702cd5f0 100644 --- a/graphics/opengl/renderer.cpp +++ b/graphics/opengl/renderer.cpp @@ -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) diff --git a/graphics/opengl/renderer.hpp b/graphics/opengl/renderer.hpp index abd0af9133..18ccb9b3dc 100644 --- a/graphics/opengl/renderer.hpp +++ b/graphics/opengl/renderer.hpp @@ -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; diff --git a/graphics/render_target.cpp b/graphics/render_target.cpp new file mode 100644 index 0000000000..d934f906f2 --- /dev/null +++ b/graphics/render_target.cpp @@ -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); + } +} diff --git a/graphics/render_target.hpp b/graphics/render_target.hpp index 7ef18ce2a0..a145f62ce8 100644 --- a/graphics/render_target.hpp +++ b/graphics/render_target.hpp @@ -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; }; |