Optimized matrix operations in CGLDevice

dev-time-step
Tomasz Kapuściński 2016-01-30 17:41:11 +01:00
parent 9749419b87
commit 9db943b820
2 changed files with 22 additions and 11 deletions

View File

@ -323,8 +323,15 @@ bool CGLDevice::Create()
m_framebufferSupport = DetectFramebufferSupport(); m_framebufferSupport = DetectFramebufferSupport();
if (m_framebufferSupport != FBS_NONE) if (m_framebufferSupport != FBS_NONE)
{
glGetIntegerv(GL_MAX_RENDERBUFFER_SIZE_EXT, &m_maxRenderbufferSize);
GetLogger()->Info("Framebuffer supported\n"); 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"); GetLogger()->Info("CDevice created successfully\n");
return true; return true;
@ -395,17 +402,23 @@ void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix)
{ {
m_worldMat = matrix; m_worldMat = matrix;
UpdateModelviewMatrix(); UpdateModelviewMatrix();
m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat);
} }
else if (type == TRANSFORM_VIEW) else if (type == TRANSFORM_VIEW)
{ {
m_viewMat = matrix; m_viewMat = matrix;
UpdateModelviewMatrix(); UpdateModelviewMatrix();
m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat);
} }
else if (type == TRANSFORM_PROJECTION) else if (type == TRANSFORM_PROJECTION)
{ {
m_projectionMat = matrix; m_projectionMat = matrix;
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glLoadMatrixf(m_projectionMat.Array()); glLoadMatrixf(m_projectionMat.Array());
m_combinedMatrix = Math::MultiplyMatrices(m_projectionMat, m_modelviewMat);
} }
else if (type == TRANSFORM_SHADOW) else if (type == TRANSFORM_SHADOW)
{ {
@ -425,12 +438,12 @@ void CGLDevice::SetTransform(TransformType type, const Math::Matrix &matrix)
void CGLDevice::UpdateModelviewMatrix() void CGLDevice::UpdateModelviewMatrix()
{ {
m_modelviewMat = Math::MultiplyMatrices(m_viewMat, m_worldMat);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
glScalef(1.0f, 1.0f, -1.0f); 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) if (m_lighting)
{ {
@ -1751,13 +1764,7 @@ void CGLDevice::DestroyStaticBuffer(unsigned int bufferId)
int CGLDevice::ComputeSphereVisibility(const Math::Vector &center, float radius) int CGLDevice::ComputeSphereVisibility(const Math::Vector &center, float radius)
{ {
Math::Matrix m; Math::Matrix &m = m_combinedMatrix;
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::Vector vec[6]; Math::Vector vec[6];
float originPlane[6]; float originPlane[6];

View File

@ -210,6 +210,8 @@ private:
Math::Matrix m_modelviewMat; Math::Matrix m_modelviewMat;
//! Current projection matrix //! Current projection matrix
Math::Matrix m_projectionMat; Math::Matrix m_projectionMat;
//! Combined world-view-projection matrix
Math::Matrix m_combinedMatrix;
//! The current material //! The current material
Material m_material; Material m_material;
@ -268,6 +270,8 @@ private:
int m_maxAnisotropy = 1; int m_maxAnisotropy = 1;
//! Maximum samples //! Maximum samples
int m_maxSamples = 1; int m_maxSamples = 1;
//! Maximum renderbuffer size
int m_maxRenderbufferSize = 0;
//! glMultiDrawArrays() available //! glMultiDrawArrays() available
bool m_multiDrawArrays = false; bool m_multiDrawArrays = false;
//! Framebuffer support //! Framebuffer support