From 9db943b8201e06c2e0cc6397bd94303754ae36cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Kapu=C5=9Bci=C5=84ski?= Date: Sat, 30 Jan 2016 17:41:11 +0100 Subject: [PATCH] Optimized matrix operations in CGLDevice --- src/graphics/opengl/gldevice.cpp | 29 ++++++++++++++++++----------- src/graphics/opengl/gldevice.h | 4 ++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/graphics/opengl/gldevice.cpp b/src/graphics/opengl/gldevice.cpp index f0c7e137..5bef6f4b 100644 --- a/src/graphics/opengl/gldevice.cpp +++ b/src/graphics/opengl/gldevice.cpp @@ -323,8 +323,15 @@ bool CGLDevice::Create() m_framebufferSupport = DetectFramebufferSupport(); if (m_framebufferSupport != FBS_NONE) + { + glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &m_maxRenderbufferSize); GetLogger()->Info("Framebuffer supported\n"); - + GetLogger()->Info("Maximum renderbuffer size: %d\n", m_maxRenderbufferSize); + } + else + { + GetLogger()->Info("Framebuffer not supported\n"); + } GetLogger()->Info("CDevice created successfully\n"); return true; @@ -395,17 +402,23 @@ void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix) { m_worldMat = matrix; UpdateModelviewMatrix(); + + m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat); } else if (type == TRANSFORM_VIEW) { m_viewMat = matrix; UpdateModelviewMatrix(); + + m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat); } else if (type == TRANSFORM_PROJECTION) { m_projectionMat = matrix; glMatrixMode(GL_PROJECTION); glLoadMatrixf(m_projectionMat.Array()); + + m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat); } else if (type == TRANSFORM_SHADOW) { @@ -425,12 +438,12 @@ void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix) void CGLDevice::UpdateModelviewMatrix() { - m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat); - glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glScalef(1.0f, 1.0f, -1.0f); - glMultMatrixf(m_modelviewMat.Array()); + glMultMatrixf(m_viewMat.Array()); + glMultMatrixf(m_worldMat.Array()); + glGetFloatv(GL_MODELVIEW_MATRIX, m_modelviewMat.Array()); if (m_lighting) { @@ -1751,13 +1764,7 @@ void CGLDevice::DestroyStaticBuffer(unsigned int bufferId) int CGLDevice::ComputeSphereVisibility(const Math::Vector ¢er, float radius) { - Math::Matrix m; - m = Math::MultiplyMatrices(m_worldMat, m); - m = Math::MultiplyMatrices(m_viewMat, m); - Math::Matrix sc; - Math::LoadScaleMatrix(sc, Math::Vector(1.0f, 1.0f, -1.0f)); - m = Math::MultiplyMatrices(sc, m); - m = Math::MultiplyMatrices(m_projectionMat, m); + Math::Matrix &m = m_combinedMatrix; Math::Vector vec[6]; float originPlane[6]; diff --git a/src/graphics/opengl/gldevice.h b/src/graphics/opengl/gldevice.h index 061c2638..696e6d6b 100644 --- a/src/graphics/opengl/gldevice.h +++ b/src/graphics/opengl/gldevice.h @@ -210,6 +210,8 @@ private: Math::Matrix m_modelviewMat; //! Current projection matrix Math::Matrix m_projectionMat; + //! Combined world-view-projection matrix + Math::Matrix m_combinedMatrix; //! The current material Material m_material; @@ -268,6 +270,8 @@ private: int m_maxAnisotropy = 1; //! Maximum samples int m_maxSamples = 1; + //! Maximum renderbuffer size + int m_maxRenderbufferSize = 0; //! glMultiDrawArrays() available bool m_multiDrawArrays = false; //! Framebuffer support