aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRainer Hochecker <fernetmenta@online.de>2018-06-11 14:10:44 +0200
committerGitHub <noreply@github.com>2018-06-11 14:10:44 +0200
commit331cead26f2f9b16f8a5bd4903f5b74e404b85d6 (patch)
treef6ab206e0a252ac731e63e0e5d931b3aff21cd58
parent3e7b5690d64f5c64523be9a4f0dbd84958a07dc4 (diff)
parent1c9af67ae1510650a6ef6a0402a555909c665fd0 (diff)
Merge pull request #14014 from MaxKellermann/matrix_optimizations
Various CMatrixGL optimizations
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp2
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp2
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp2
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGL.h6
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGLES.h6
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGL.h6
-rw-r--r--xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGLES.h8
-rw-r--r--xbmc/guilib/CMakeLists.txt4
-rw-r--r--xbmc/guilib/GUIFontTTFGL.cpp2
-rw-r--r--xbmc/rendering/MatrixGL.cpp (renamed from xbmc/guilib/MatrixGLES.cpp)158
-rw-r--r--xbmc/rendering/MatrixGL.h (renamed from xbmc/guilib/MatrixGLES.h)30
-rw-r--r--xbmc/rendering/gl/CMakeLists.txt2
-rw-r--r--xbmc/rendering/gl/GLShader.cpp6
-rw-r--r--xbmc/rendering/gl/GLShader.h4
-rw-r--r--xbmc/rendering/gl/RenderSystemGL.cpp15
-rw-r--r--xbmc/rendering/gles/CMakeLists.txt2
-rw-r--r--xbmc/rendering/gles/GLESShader.cpp6
-rw-r--r--xbmc/rendering/gles/GLESShader.h4
-rw-r--r--xbmc/rendering/gles/RenderSystemGLES.cpp15
19 files changed, 126 insertions, 154 deletions
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp
index 1b48204499..3187f0095b 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGL.cpp
@@ -36,7 +36,7 @@
#include "windowing/WinSystem.h"
#include "guilib/Texture.h"
#include "guilib/LocalizeStrings.h"
-#include "guilib/MatrixGLES.h"
+#include "rendering/MatrixGL.h"
#include "rendering/gl/RenderSystemGL.h"
#include "threads/SingleLock.h"
#include "utils/log.h"
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp
index 8620e01257..cb97de8a04 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/LinuxRendererGLES.cpp
@@ -21,7 +21,6 @@
#include "system_gl.h"
#include <locale.h>
-#include "guilib/MatrixGLES.h"
#include "LinuxRendererGLES.h"
#include "ServiceBroker.h"
#include "utils/MathUtils.h"
@@ -33,6 +32,7 @@
#include "settings/Settings.h"
#include "VideoShaders/YUV2RGBShaderGLES.h"
#include "VideoShaders/VideoFilterShaderGLES.h"
+#include "rendering/MatrixGL.h"
#include "rendering/gles/RenderSystemGLES.h"
#include "guilib/Texture.h"
#include "threads/SingleLock.h"
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp
index a8913c2bea..87c5e59c7c 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/OverlayRendererGL.cpp
@@ -29,7 +29,7 @@
#include "LinuxRendererGLES.h"
#include "rendering/gles/RenderSystemGLES.h"
#endif
-#include "guilib/MatrixGLES.h"
+#include "rendering/MatrixGL.h"
#include "RenderManager.h"
#include "ServiceBroker.h"
#include "cores/VideoPlayer/DVDCodecs/Overlay/DVDOverlayImage.h"
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGL.h b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGL.h
index fa43da8c50..2e6ad551c7 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGL.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGL.h
@@ -43,7 +43,7 @@ namespace Shaders {
GLint GetVertexLoc() { return m_hVertex; }
GLint GetCoordLoc() { return m_hCoord; }
- void SetMatrices(GLfloat *p, GLfloat *m) { m_proj = p; m_model = m; }
+ void SetMatrices(const GLfloat *p, const GLfloat *m) { m_proj = p; m_model = m; }
protected:
int m_width;
@@ -53,8 +53,8 @@ namespace Shaders {
float m_stretch;
GLfloat m_alpha;
GLint m_sourceTexUnit;
- GLfloat *m_proj = nullptr;
- GLfloat *m_model = nullptr;
+ const GLfloat *m_proj = nullptr;
+ const GLfloat *m_model = nullptr;
// shader attribute handles
GLint m_hSourceTex;
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGLES.h b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGLES.h
index 2a0a2c4f66..41355246ce 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGLES.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/VideoFilterShaderGLES.h
@@ -40,7 +40,7 @@ namespace Shaders {
virtual bool GetTextureFilter(GLint& filter) { return false; }
virtual GLint GetVertexLoc() { return m_hVertex; }
virtual GLint GetcoordLoc() { return m_hcoord; }
- virtual void SetMatrices(GLfloat *p, GLfloat *m) { m_proj = p; m_model = m; }
+ virtual void SetMatrices(const GLfloat *p, const GLfloat *m) { m_proj = p; m_model = m; }
virtual void SetAlpha(GLfloat alpha) { m_alpha = alpha; }
protected:
@@ -60,8 +60,8 @@ namespace Shaders {
GLint m_hModel;
GLint m_hAlpha;
- GLfloat *m_proj;
- GLfloat *m_model;
+ const GLfloat *m_proj;
+ const GLfloat *m_model;
GLfloat m_alpha;
};
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGL.h b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGL.h
index c237057d6f..f1e1d9c53e 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGL.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGL.h
@@ -64,7 +64,7 @@ public:
GLint GetUcoordLoc() { return m_hUcoord; }
GLint GetVcoordLoc() { return m_hVcoord; }
- void SetMatrices(GLfloat *p, GLfloat *m) { m_proj = p; m_model = m; }
+ void SetMatrices(const GLfloat *p, const GLfloat *m) { m_proj = p; m_model = m; }
void SetAlpha(GLfloat alpha) { m_alpha = alpha; }
protected:
@@ -90,8 +90,8 @@ protected:
float m_contrast;
float m_stretch;
- GLfloat *m_proj = nullptr;
- GLfloat *m_model = nullptr;
+ const GLfloat *m_proj = nullptr;
+ const GLfloat *m_model = nullptr;
GLfloat m_alpha = 1.0f;
std::string m_defines;
diff --git a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGLES.h b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGLES.h
index edc34827cb..5841839dbf 100644
--- a/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGLES.h
+++ b/xbmc/cores/VideoPlayer/VideoRenderers/VideoShaders/YUV2RGBShaderGLES.h
@@ -50,7 +50,7 @@ namespace Shaders {
virtual GLint GetUcoordLoc() { return 0; };
virtual GLint GetVcoordLoc() { return 0; };
- virtual void SetMatrices(GLfloat *p, GLfloat *m) {};
+ virtual void SetMatrices(const GLfloat *p, const GLfloat *m) {};
virtual void SetAlpha(GLfloat alpha) {};
virtual void SetConvertFullColorRange(bool convertFullRange) {}
@@ -77,7 +77,7 @@ namespace Shaders {
GLint GetUcoordLoc() override { return m_hUcoord; }
GLint GetVcoordLoc() override { return m_hVcoord; }
- void SetMatrices(GLfloat *p, GLfloat *m) override { m_proj = p; m_model = m; }
+ void SetMatrices(const GLfloat *p, const GLfloat *m) override { m_proj = p; m_model = m; }
void SetAlpha(GLfloat alpha) override { m_alpha = alpha; }
protected:
@@ -112,8 +112,8 @@ namespace Shaders {
GLint m_hModel;
GLint m_hAlpha;
- GLfloat *m_proj;
- GLfloat *m_model;
+ const GLfloat *m_proj;
+ const GLfloat *m_model;
GLfloat m_alpha;
bool m_convertFullRange;
diff --git a/xbmc/guilib/CMakeLists.txt b/xbmc/guilib/CMakeLists.txt
index b76ec85d0f..803cbc638c 100644
--- a/xbmc/guilib/CMakeLists.txt
+++ b/xbmc/guilib/CMakeLists.txt
@@ -156,12 +156,10 @@ set(HEADERS DDSImage.h
if(OPENGL_FOUND)
list(APPEND SOURCES GUIFontTTFGL.cpp
GUITextureGL.cpp
- MatrixGLES.cpp
Shader.cpp
TextureGL.cpp)
list(APPEND HEADERS GUIFontTTFGL.h
GUITextureGL.h
- MatrixGLES.h
Shader.h
TextureGL.h)
endif()
@@ -169,12 +167,10 @@ endif()
if(OPENGLES_FOUND)
list(APPEND SOURCES GUIFontTTFGL.cpp
GUITextureGLES.cpp
- MatrixGLES.cpp
Shader.cpp
TextureGL.cpp)
list(APPEND HEADERS GUIFontTTFGL.h
GUITextureGLES.h
- MatrixGLES.h
Shader.h
TextureGL.h)
endif()
diff --git a/xbmc/guilib/GUIFontTTFGL.cpp b/xbmc/guilib/GUIFontTTFGL.cpp
index 26fc3dfb45..298c056952 100644
--- a/xbmc/guilib/GUIFontTTFGL.cpp
+++ b/xbmc/guilib/GUIFontTTFGL.cpp
@@ -33,7 +33,7 @@
#elif HAS_GLES
#include "rendering/gles/RenderSystemGLES.h"
#endif
-#include "guilib/MatrixGLES.h"
+#include "rendering/MatrixGL.h"
// stuff for freetype
#include <ft2build.h>
diff --git a/xbmc/guilib/MatrixGLES.cpp b/xbmc/rendering/MatrixGL.cpp
index 16098da741..1f99f8169f 100644
--- a/xbmc/guilib/MatrixGLES.cpp
+++ b/xbmc/rendering/MatrixGL.cpp
@@ -18,21 +18,31 @@
*
*/
+#include "MatrixGL.h"
+#include "utils/TransformMatrix.h"
-#include "system_gl.h"
-
-#include <cmath>
-#include "MatrixGLES.h"
-#include "utils/log.h"
#if defined(HAS_NEON)
#include "utils/CPUInfo.h"
#endif
+#include <cmath>
CMatrixGLStack glMatrixModview = CMatrixGLStack();
CMatrixGLStack glMatrixProject = CMatrixGLStack();
CMatrixGLStack glMatrixTexture = CMatrixGLStack();
+CMatrixGL::CMatrixGL(const TransformMatrix &src) noexcept
+{
+ for(int i = 0; i < 3; i++)
+ for(int j = 0; j < 4; j++)
+ m_pMatrix[j * 4 + i] = src.m[i][j];
+
+ m_pMatrix[3] = 0.0f;
+ m_pMatrix[7] = 0.0f;
+ m_pMatrix[11] = 0.0f;
+ m_pMatrix[15] = 1.0f;
+}
+
void CMatrixGL::LoadIdentity()
{
m_pMatrix[0] = 1.0f; m_pMatrix[4] = 0.0f; m_pMatrix[8] = 0.0f; m_pMatrix[12] = 0.0f;
@@ -49,10 +59,10 @@ void CMatrixGL::Ortho(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, GLf
GLfloat x = - (r + l) / (r - l);
GLfloat y = - (t + b) / (t - b);
GLfloat z = - (f + n) / (f - n);
- GLfloat matrix[16] = { u, 0.0f, 0.0f, 0.0f,
- 0.0f, v, 0.0f, 0.0f,
- 0.0f, 0.0f, w, 0.0f,
- x, y, z, 1.0f};
+ const CMatrixGL matrix{ u, 0.0f, 0.0f, 0.0f,
+ 0.0f, v, 0.0f, 0.0f,
+ 0.0f, 0.0f, w, 0.0f,
+ x, y, z, 1.0f};
MultMatrixf(matrix);
}
@@ -62,10 +72,10 @@ void CMatrixGL::Ortho2D(GLfloat l, GLfloat r, GLfloat b, GLfloat t)
GLfloat v = 2.0f / (t - b);
GLfloat x = - (r + l) / (r - l);
GLfloat y = - (t + b) / (t - b);
- GLfloat matrix[16] = { u, 0.0f, 0.0f, 0.0f,
- 0.0f, v, 0.0f, 0.0f,
- 0.0f, 0.0f,-1.0f, 0.0f,
- x, y, 0.0f, 1.0f};
+ const CMatrixGL matrix{ u, 0.0f, 0.0f, 0.0f,
+ 0.0f, v, 0.0f, 0.0f,
+ 0.0f, 0.0f,-1.0f, 0.0f,
+ x, y, 0.0f, 1.0f};
MultMatrixf(matrix);
}
@@ -77,42 +87,42 @@ void CMatrixGL::Frustum(GLfloat l, GLfloat r, GLfloat b, GLfloat t, GLfloat n, G
GLfloat x = (t + b) / (t - b);
GLfloat y = - (f + n) / (f - n);
GLfloat z = - (2.0f * f * n) / (f - n);
- GLfloat matrix[16] = { u, 0.0f, 0.0f, 0.0f,
- 0.0f, v, 0.0f, 0.0f,
- w, x, y,-1.0f,
- 0.0f, 0.0f, z, 0.0f};
+ const CMatrixGL matrix{ u, 0.0f, 0.0f, 0.0f,
+ 0.0f, v, 0.0f, 0.0f,
+ w, x, y,-1.0f,
+ 0.0f, 0.0f, z, 0.0f};
MultMatrixf(matrix);
}
void CMatrixGL::Translatef(GLfloat x, GLfloat y, GLfloat z)
{
- GLfloat matrix[16] = {1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- x, y, z, 1.0f};
+ const CMatrixGL matrix{1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ x, y, z, 1.0f};
MultMatrixf(matrix);
}
void CMatrixGL::Scalef(GLfloat x, GLfloat y, GLfloat z)
{
- GLfloat matrix[16] = { x, 0.0f, 0.0f, 0.0f,
- 0.0f, y, 0.0f, 0.0f,
- 0.0f, 0.0f, z, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f};
+ const CMatrixGL matrix{ x, 0.0f, 0.0f, 0.0f,
+ 0.0f, y, 0.0f, 0.0f,
+ 0.0f, 0.0f, z, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f};
MultMatrixf(matrix);
}
void CMatrixGL::Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
- GLfloat modulus = sqrt((x*x)+(y*y)+(z*z));
+ GLfloat modulus = std::sqrt((x*x)+(y*y)+(z*z));
if (modulus != 0.0)
{
x /= modulus;
y /= modulus;
z /= modulus;
}
- GLfloat cosine = cos(angle);
- GLfloat sine = sin(angle);
+ GLfloat cosine = std::cos(angle);
+ GLfloat sine = std::sin(angle);
GLfloat cos1 = 1 - cosine;
GLfloat a = (x*x*cos1) + cosine;
GLfloat b = (x*y*cos1) - (z*sine);
@@ -123,21 +133,21 @@ void CMatrixGL::Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
GLfloat g = (z*x*cos1) - (y*sine);
GLfloat h = (z*y*cos1) + (x*sine);
GLfloat i = (z*z*cos1) + cosine;
- GLfloat matrix[16] = { a, d, g, 0.0f,
- b, e, h, 0.0f,
- c, f, i, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f};
+ const CMatrixGL matrix{ a, d, g, 0.0f,
+ b, e, h, 0.0f,
+ c, f, i, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f};
MultMatrixf(matrix);
}
#if defined(HAS_NEON) && !defined(__LP64__)
-inline void Matrix4Mul(const float* src_mat_1, const float* src_mat_2, float* dst_mat)
+static inline void Matrix4Mul(float* src_mat_1, const float* src_mat_2)
{
asm volatile (
// Store A & B leaving room at top of registers for result (q0-q3)
- "vldmia %1, { q4-q7 } \n\t"
- "vldmia %2, { q8-q11 } \n\t"
+ "vldmia %0, { q4-q7 } \n\t"
+ "vldmia %1, { q8-q11 } \n\t"
// result = first column of B x first row of A
"vmul.f32 q0, q8, d8[0]\n\t"
@@ -164,39 +174,38 @@ inline void Matrix4Mul(const float* src_mat_1, const float* src_mat_2, float* ds
"vmla.f32 q3, q11, d15[1]\n\t"
// output = result registers
- "vstmia %2, { q0-q3 }"
+ "vstmia %1, { q0-q3 }"
: //no output
- : "r" (dst_mat), "r" (src_mat_2), "r" (src_mat_1) // input - note *value* of pointer doesn't change
+ : "r" (src_mat_2), "r" (src_mat_1) // input - note *value* of pointer doesn't change
: "memory", "q0", "q1", "q2", "q3", "q4", "q5", "q6", "q7", "q8", "q9", "q10", "q11" //clobber
);
}
#endif
-void CMatrixGL::MultMatrixf(const GLfloat *matrix)
+void CMatrixGL::MultMatrixf(const CMatrixGL &matrix) noexcept
{
#if defined(HAS_NEON) && !defined(__LP64__)
if ((g_cpuInfo.GetCPUFeatures() & CPU_FEATURE_NEON) == CPU_FEATURE_NEON)
{
- GLfloat m[16];
- Matrix4Mul(m_pMatrix, matrix, m);
+ Matrix4Mul(m_pMatrix, matrix.m_pMatrix);
return;
}
#endif
- GLfloat a = (matrix[0] * m_pMatrix[0]) + (matrix[1] * m_pMatrix[4]) + (matrix[2] * m_pMatrix[8]) + (matrix[3] * m_pMatrix[12]);
- GLfloat b = (matrix[0] * m_pMatrix[1]) + (matrix[1] * m_pMatrix[5]) + (matrix[2] * m_pMatrix[9]) + (matrix[3] * m_pMatrix[13]);
- GLfloat c = (matrix[0] * m_pMatrix[2]) + (matrix[1] * m_pMatrix[6]) + (matrix[2] * m_pMatrix[10]) + (matrix[3] * m_pMatrix[14]);
- GLfloat d = (matrix[0] * m_pMatrix[3]) + (matrix[1] * m_pMatrix[7]) + (matrix[2] * m_pMatrix[11]) + (matrix[3] * m_pMatrix[15]);
- GLfloat e = (matrix[4] * m_pMatrix[0]) + (matrix[5] * m_pMatrix[4]) + (matrix[6] * m_pMatrix[8]) + (matrix[7] * m_pMatrix[12]);
- GLfloat f = (matrix[4] * m_pMatrix[1]) + (matrix[5] * m_pMatrix[5]) + (matrix[6] * m_pMatrix[9]) + (matrix[7] * m_pMatrix[13]);
- GLfloat g = (matrix[4] * m_pMatrix[2]) + (matrix[5] * m_pMatrix[6]) + (matrix[6] * m_pMatrix[10]) + (matrix[7] * m_pMatrix[14]);
- GLfloat h = (matrix[4] * m_pMatrix[3]) + (matrix[5] * m_pMatrix[7]) + (matrix[6] * m_pMatrix[11]) + (matrix[7] * m_pMatrix[15]);
- GLfloat i = (matrix[8] * m_pMatrix[0]) + (matrix[9] * m_pMatrix[4]) + (matrix[10] * m_pMatrix[8]) + (matrix[11] * m_pMatrix[12]);
- GLfloat j = (matrix[8] * m_pMatrix[1]) + (matrix[9] * m_pMatrix[5]) + (matrix[10] * m_pMatrix[9]) + (matrix[11] * m_pMatrix[13]);
- GLfloat k = (matrix[8] * m_pMatrix[2]) + (matrix[9] * m_pMatrix[6]) + (matrix[10] * m_pMatrix[10]) + (matrix[11] * m_pMatrix[14]);
- GLfloat l = (matrix[8] * m_pMatrix[3]) + (matrix[9] * m_pMatrix[7]) + (matrix[10] * m_pMatrix[11]) + (matrix[11] * m_pMatrix[15]);
- GLfloat m = (matrix[12] * m_pMatrix[0]) + (matrix[13] * m_pMatrix[4]) + (matrix[14] * m_pMatrix[8]) + (matrix[15] * m_pMatrix[12]);
- GLfloat n = (matrix[12] * m_pMatrix[1]) + (matrix[13] * m_pMatrix[5]) + (matrix[14] * m_pMatrix[9]) + (matrix[15] * m_pMatrix[13]);
- GLfloat o = (matrix[12] * m_pMatrix[2]) + (matrix[13] * m_pMatrix[6]) + (matrix[14] * m_pMatrix[10]) + (matrix[15] * m_pMatrix[14]);
- GLfloat p = (matrix[12] * m_pMatrix[3]) + (matrix[13] * m_pMatrix[7]) + (matrix[14] * m_pMatrix[11]) + (matrix[15] * m_pMatrix[15]);
+ GLfloat a = (matrix.m_pMatrix[0] * m_pMatrix[0]) + (matrix.m_pMatrix[1] * m_pMatrix[4]) + (matrix.m_pMatrix[2] * m_pMatrix[8]) + (matrix.m_pMatrix[3] * m_pMatrix[12]);
+ GLfloat b = (matrix.m_pMatrix[0] * m_pMatrix[1]) + (matrix.m_pMatrix[1] * m_pMatrix[5]) + (matrix.m_pMatrix[2] * m_pMatrix[9]) + (matrix.m_pMatrix[3] * m_pMatrix[13]);
+ GLfloat c = (matrix.m_pMatrix[0] * m_pMatrix[2]) + (matrix.m_pMatrix[1] * m_pMatrix[6]) + (matrix.m_pMatrix[2] * m_pMatrix[10]) + (matrix.m_pMatrix[3] * m_pMatrix[14]);
+ GLfloat d = (matrix.m_pMatrix[0] * m_pMatrix[3]) + (matrix.m_pMatrix[1] * m_pMatrix[7]) + (matrix.m_pMatrix[2] * m_pMatrix[11]) + (matrix.m_pMatrix[3] * m_pMatrix[15]);
+ GLfloat e = (matrix.m_pMatrix[4] * m_pMatrix[0]) + (matrix.m_pMatrix[5] * m_pMatrix[4]) + (matrix.m_pMatrix[6] * m_pMatrix[8]) + (matrix.m_pMatrix[7] * m_pMatrix[12]);
+ GLfloat f = (matrix.m_pMatrix[4] * m_pMatrix[1]) + (matrix.m_pMatrix[5] * m_pMatrix[5]) + (matrix.m_pMatrix[6] * m_pMatrix[9]) + (matrix.m_pMatrix[7] * m_pMatrix[13]);
+ GLfloat g = (matrix.m_pMatrix[4] * m_pMatrix[2]) + (matrix.m_pMatrix[5] * m_pMatrix[6]) + (matrix.m_pMatrix[6] * m_pMatrix[10]) + (matrix.m_pMatrix[7] * m_pMatrix[14]);
+ GLfloat h = (matrix.m_pMatrix[4] * m_pMatrix[3]) + (matrix.m_pMatrix[5] * m_pMatrix[7]) + (matrix.m_pMatrix[6] * m_pMatrix[11]) + (matrix.m_pMatrix[7] * m_pMatrix[15]);
+ GLfloat i = (matrix.m_pMatrix[8] * m_pMatrix[0]) + (matrix.m_pMatrix[9] * m_pMatrix[4]) + (matrix.m_pMatrix[10] * m_pMatrix[8]) + (matrix.m_pMatrix[11] * m_pMatrix[12]);
+ GLfloat j = (matrix.m_pMatrix[8] * m_pMatrix[1]) + (matrix.m_pMatrix[9] * m_pMatrix[5]) + (matrix.m_pMatrix[10] * m_pMatrix[9]) + (matrix.m_pMatrix[11] * m_pMatrix[13]);
+ GLfloat k = (matrix.m_pMatrix[8] * m_pMatrix[2]) + (matrix.m_pMatrix[9] * m_pMatrix[6]) + (matrix.m_pMatrix[10] * m_pMatrix[10]) + (matrix.m_pMatrix[11] * m_pMatrix[14]);
+ GLfloat l = (matrix.m_pMatrix[8] * m_pMatrix[3]) + (matrix.m_pMatrix[9] * m_pMatrix[7]) + (matrix.m_pMatrix[10] * m_pMatrix[11]) + (matrix.m_pMatrix[11] * m_pMatrix[15]);
+ GLfloat m = (matrix.m_pMatrix[12] * m_pMatrix[0]) + (matrix.m_pMatrix[13] * m_pMatrix[4]) + (matrix.m_pMatrix[14] * m_pMatrix[8]) + (matrix.m_pMatrix[15] * m_pMatrix[12]);
+ GLfloat n = (matrix.m_pMatrix[12] * m_pMatrix[1]) + (matrix.m_pMatrix[13] * m_pMatrix[5]) + (matrix.m_pMatrix[14] * m_pMatrix[9]) + (matrix.m_pMatrix[15] * m_pMatrix[13]);
+ GLfloat o = (matrix.m_pMatrix[12] * m_pMatrix[2]) + (matrix.m_pMatrix[13] * m_pMatrix[6]) + (matrix.m_pMatrix[14] * m_pMatrix[10]) + (matrix.m_pMatrix[15] * m_pMatrix[14]);
+ GLfloat p = (matrix.m_pMatrix[12] * m_pMatrix[3]) + (matrix.m_pMatrix[13] * m_pMatrix[7]) + (matrix.m_pMatrix[14] * m_pMatrix[11]) + (matrix.m_pMatrix[15] * m_pMatrix[15]);
m_pMatrix[0] = a; m_pMatrix[4] = e; m_pMatrix[8] = i; m_pMatrix[12] = m;
m_pMatrix[1] = b; m_pMatrix[5] = f; m_pMatrix[9] = j; m_pMatrix[13] = n;
m_pMatrix[2] = c; m_pMatrix[6] = g; m_pMatrix[10] = k; m_pMatrix[14] = o;
@@ -207,7 +216,6 @@ void CMatrixGL::MultMatrixf(const GLfloat *matrix)
void CMatrixGL::LookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy, GLfloat upz)
{
GLfloat forward[3], side[3], up[3];
- GLfloat m[4][4];
forward[0] = centerx - eyex;
forward[1] = centery - eyey;
@@ -217,7 +225,7 @@ void CMatrixGL::LookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx
up[1] = upy;
up[2] = upz;
- GLfloat tmp = sqrt(forward[0]*forward[0] + forward[1]*forward[1] + forward[2]*forward[2]);
+ GLfloat tmp = std::sqrt(forward[0]*forward[0] + forward[1]*forward[1] + forward[2]*forward[2]);
if (tmp != 0.0)
{
forward[0] /= tmp;
@@ -229,7 +237,7 @@ void CMatrixGL::LookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx
side[1] = forward[2]*up[0] - forward[0]*up[2];
side[2] = forward[0]*up[1] - forward[1]*up[0];
- tmp = sqrt(side[0]*side[0] + side[1]*side[1] + side[2]*side[2]);
+ tmp = std::sqrt(side[0]*side[0] + side[1]*side[1] + side[2]*side[2]);
if (tmp != 0.0)
{
side[0] /= tmp;
@@ -241,24 +249,14 @@ void CMatrixGL::LookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx
up[1] = side[2]*forward[0] - side[0]*forward[2];
up[2] = side[0]*forward[1] - side[1]*forward[0];
- m[0][0] = 1.0f; m[0][1] = 0.0f; m[0][2] = 0.0f; m[0][3] = 0.0f;
- m[1][0] = 0.0f; m[1][1] = 1.0f; m[1][2] = 0.0f; m[1][3] = 0.0f;
- m[2][0] = 0.0f; m[2][1] = 0.0f; m[2][2] = 1.0f; m[2][3] = 0.0f;
- m[3][0] = 0.0f; m[3][1] = 0.0f; m[3][2] = 0.0f; m[3][3] = 1.0f;
-
- m[0][0] = side[0];
- m[1][0] = side[1];
- m[2][0] = side[2];
+ const CMatrixGL matrix{
+ side[0], up[0], -forward[0], 0.0f,
+ side[1], up[1], -forward[1], 0.0f,
+ side[2], up[2], -forward[2], 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f,
+ };
- m[0][1] = up[0];
- m[1][1] = up[1];
- m[2][1] = up[2];
-
- m[0][2] = -forward[0];
- m[1][2] = -forward[1];
- m[2][2] = -forward[2];
-
- MultMatrixf(&m[0][0]);
+ MultMatrixf(matrix);
Translatef(-eyex, -eyey, -eyez);
}
@@ -307,14 +305,6 @@ bool CMatrixGL::Project(GLfloat objx, GLfloat objy, GLfloat objz, const GLfloat
return true;
}
-void CMatrixGL::PrintMatrix(void)
-{
- CLog::Log(LOGDEBUG, "%f %f %f %f", m_pMatrix[0], m_pMatrix[4], m_pMatrix[8], m_pMatrix[12]);
- CLog::Log(LOGDEBUG, "%f %f %f %f", m_pMatrix[1], m_pMatrix[5], m_pMatrix[9], m_pMatrix[13]);
- CLog::Log(LOGDEBUG, "%f %f %f %f", m_pMatrix[2], m_pMatrix[6], m_pMatrix[10], m_pMatrix[14]);
- CLog::Log(LOGDEBUG, "%f %f %f %f", m_pMatrix[3], m_pMatrix[7], m_pMatrix[11], m_pMatrix[15]);
-}
-
void CMatrixGLStack::Load()
{
diff --git a/xbmc/guilib/MatrixGLES.h b/xbmc/rendering/MatrixGL.h
index 67dd6f309e..75a161728e 100644
--- a/xbmc/guilib/MatrixGLES.h
+++ b/xbmc/rendering/MatrixGL.h
@@ -19,20 +19,25 @@
*
*/
+#include "system_gl.h"
-#include <cmath>
-#include <cstring>
#include <stack>
+class TransformMatrix;
+
class CMatrixGL
{
public:
+ CMatrixGL() = default;
+
+ constexpr CMatrixGL(GLfloat x0, GLfloat x1, GLfloat x2, GLfloat x3,
+ GLfloat x4, GLfloat x5, GLfloat x6, GLfloat x7,
+ GLfloat x8, GLfloat x9, GLfloat x10, GLfloat x11,
+ GLfloat x12, GLfloat x13, GLfloat x14, GLfloat x15)
+ :m_pMatrix{x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15} {}
+
+ CMatrixGL(const TransformMatrix &src) noexcept;
- CMatrixGL() { memset(&m_pMatrix, 0, sizeof(m_pMatrix)); };
- explicit CMatrixGL(const float matrix[16]) { memcpy(m_pMatrix, matrix, sizeof(m_pMatrix)); }
- CMatrixGL(const CMatrixGL &rhs ) { memcpy(m_pMatrix, rhs.m_pMatrix, sizeof(m_pMatrix)); }
- CMatrixGL &operator=( const CMatrixGL &rhs ) { memcpy(m_pMatrix, rhs.m_pMatrix, sizeof(m_pMatrix)); return *this;}
- operator float*() { return m_pMatrix; }
operator const float*() const { return m_pMatrix; }
void LoadIdentity();
@@ -42,21 +47,20 @@ public:
void Translatef(GLfloat x, GLfloat y, GLfloat z);
void Scalef(GLfloat x, GLfloat y, GLfloat z);
void Rotatef(GLfloat angle, GLfloat x, GLfloat y, GLfloat z);
- void MultMatrixf(const GLfloat *matrix);
+ void MultMatrixf(const CMatrixGL &matrix) noexcept;
void LookAt(GLfloat eyex, GLfloat eyey, GLfloat eyez, GLfloat centerx, GLfloat centery, GLfloat centerz, GLfloat upx, GLfloat upy, GLfloat upz);
static bool Project(GLfloat objx, GLfloat objy, GLfloat objz, const GLfloat modelMatrix[16], const GLfloat projMatrix[16], const GLint viewport[4], GLfloat* winx, GLfloat* winy, GLfloat* winz);
- void PrintMatrix(void);
-
- GLfloat m_pMatrix[16];
+private:
+ /* alignas(16) allows better SIMD optimizations (e.g. SSE2 benefits
+ a lot from this) */
+ alignas(16) GLfloat m_pMatrix[16];
};
class CMatrixGLStack
{
public:
- explicit CMatrixGLStack() {}
-
void Push()
{
m_stack.push(m_current);
diff --git a/xbmc/rendering/gl/CMakeLists.txt b/xbmc/rendering/gl/CMakeLists.txt
index 5d14fbbf7a..4c4a245fbe 100644
--- a/xbmc/rendering/gl/CMakeLists.txt
+++ b/xbmc/rendering/gl/CMakeLists.txt
@@ -1,9 +1,11 @@
set(SOURCES GUIWindowTestPatternGL.cpp
RenderSystemGL.cpp
+ ../MatrixGL.cpp
GLShader.cpp)
set(HEADERS GUIWindowTestPatternGL.h
RenderSystemGL.h
+ ../MatrixGL.h
GLShader.h)
core_add_library(rendering_gl)
diff --git a/xbmc/rendering/gl/GLShader.cpp b/xbmc/rendering/gl/GLShader.cpp
index 07e4cbacf8..74b538985c 100644
--- a/xbmc/rendering/gl/GLShader.cpp
+++ b/xbmc/rendering/gl/GLShader.cpp
@@ -24,8 +24,8 @@
#include "ServiceBroker.h"
#include "utils/log.h"
#include "rendering/RenderSystem.h"
+#include "rendering/MatrixGL.h"
#include "windowing/GraphicContext.h"
-#include "guilib/MatrixGLES.h"
using namespace Shaders;
@@ -81,8 +81,8 @@ bool CGLShader::OnEnabled()
{
// This is called after glUseProgram()
- GLfloat *projMatrix = glMatrixProject.Get().m_pMatrix;
- GLfloat *modelMatrix = glMatrixModview.Get().m_pMatrix;
+ const GLfloat *projMatrix = glMatrixProject.Get();
+ const GLfloat *modelMatrix = glMatrixModview.Get();
glUniformMatrix4fv(m_hProj, 1, GL_FALSE, projMatrix);
glUniformMatrix4fv(m_hModel, 1, GL_FALSE, modelMatrix);
diff --git a/xbmc/rendering/gl/GLShader.h b/xbmc/rendering/gl/GLShader.h
index ff7d1b6dc2..005b905375 100644
--- a/xbmc/rendering/gl/GLShader.h
+++ b/xbmc/rendering/gl/GLShader.h
@@ -55,8 +55,8 @@ protected:
GLint m_hCord0 = 0;
GLint m_hCord1 = 0;
- GLfloat *m_proj = nullptr;
- GLfloat *m_model = nullptr;
+ const GLfloat *m_proj = nullptr;
+ const GLfloat *m_model = nullptr;
bool m_clipPossible = false;
GLfloat m_clipXFactor;
diff --git a/xbmc/rendering/gl/RenderSystemGL.cpp b/xbmc/rendering/gl/RenderSystemGL.cpp
index df946c079c..c66b7db2ab 100644
--- a/xbmc/rendering/gl/RenderSystemGL.cpp
+++ b/xbmc/rendering/gl/RenderSystemGL.cpp
@@ -20,9 +20,9 @@
#include "RenderSystemGL.h"
#include "filesystem/File.h"
+#include "rendering/MatrixGL.h"
#include "windowing/GraphicContext.h"
#include "settings/AdvancedSettings.h"
-#include "guilib/MatrixGLES.h"
#include "settings/DisplaySettings.h"
#include "utils/log.h"
#include "utils/GLUtils.h"
@@ -402,18 +402,7 @@ void CRenderSystemGL::ApplyHardwareTransform(const TransformMatrix &finalMatrix)
return;
glMatrixModview.Push();
- GLfloat matrix[4][4];
-
- for(int i = 0; i < 3; i++)
- for(int j = 0; j < 4; j++)
- matrix[j][i] = finalMatrix.m[i][j];
-
- matrix[0][3] = 0.0f;
- matrix[1][3] = 0.0f;
- matrix[2][3] = 0.0f;
- matrix[3][3] = 1.0f;
-
- glMatrixModview->MultMatrixf(&matrix[0][0]);
+ glMatrixModview->MultMatrixf(finalMatrix);
glMatrixModview.Load();
}
diff --git a/xbmc/rendering/gles/CMakeLists.txt b/xbmc/rendering/gles/CMakeLists.txt
index cac8ef9ebe..4df58e3c68 100644
--- a/xbmc/rendering/gles/CMakeLists.txt
+++ b/xbmc/rendering/gles/CMakeLists.txt
@@ -1,8 +1,10 @@
if(OPENGLES_FOUND)
set(SOURCES RenderSystemGLES.cpp
+ ../MatrixGL.cpp
GLESShader.cpp)
set(HEADERS RenderSystemGLES.h
+ ../MatrixGL.h
GLESShader.h)
core_add_library(rendering_gles)
diff --git a/xbmc/rendering/gles/GLESShader.cpp b/xbmc/rendering/gles/GLESShader.cpp
index bf23ef7fe9..4600c317e5 100644
--- a/xbmc/rendering/gles/GLESShader.cpp
+++ b/xbmc/rendering/gles/GLESShader.cpp
@@ -19,10 +19,10 @@
*/
#include "GLESShader.h"
-#include "xbmc/guilib/MatrixGLES.h"
#include "ServiceBroker.h"
#include "utils/log.h"
#include "rendering/RenderSystem.h"
+#include "rendering/MatrixGL.h"
#include "windowing/GraphicContext.h"
using namespace Shaders;
@@ -92,8 +92,8 @@ bool CGLESShader::OnEnabled()
{
// This is called after glUseProgram()
- GLfloat *projMatrix = glMatrixProject.Get().m_pMatrix;
- GLfloat *modelMatrix = glMatrixModview.Get().m_pMatrix;
+ const GLfloat *projMatrix = glMatrixProject.Get();
+ const GLfloat *modelMatrix = glMatrixModview.Get();
glUniformMatrix4fv(m_hProj, 1, GL_FALSE, projMatrix);
glUniformMatrix4fv(m_hModel, 1, GL_FALSE, modelMatrix);
diff --git a/xbmc/rendering/gles/GLESShader.h b/xbmc/rendering/gles/GLESShader.h
index fdb688bd49..2456eac6c7 100644
--- a/xbmc/rendering/gles/GLESShader.h
+++ b/xbmc/rendering/gles/GLESShader.h
@@ -65,8 +65,8 @@ protected:
GLint m_hContrast = 0;
GLint m_hBrightness = 0;
- GLfloat *m_proj;
- GLfloat *m_model;
+ const GLfloat *m_proj;
+ const GLfloat *m_model;
bool m_clipPossible;
GLfloat m_clipXFactor;
diff --git a/xbmc/rendering/gles/RenderSystemGLES.cpp b/xbmc/rendering/gles/RenderSystemGLES.cpp
index e1634f61f3..7805b16017 100644
--- a/xbmc/rendering/gles/RenderSystemGLES.cpp
+++ b/xbmc/rendering/gles/RenderSystemGLES.cpp
@@ -21,7 +21,7 @@
#include "windowing/GraphicContext.h"
#include "settings/AdvancedSettings.h"
#include "RenderSystemGLES.h"
-#include "guilib/MatrixGLES.h"
+#include "rendering/MatrixGL.h"
#include "utils/log.h"
#include "utils/GLUtils.h"
#include "utils/TimeUtils.h"
@@ -372,18 +372,7 @@ void CRenderSystemGLES::ApplyHardwareTransform(const TransformMatrix &finalMatri
return;
glMatrixModview.Push();
- GLfloat matrix[4][4];
-
- for(int i = 0; i < 3; i++)
- for(int j = 0; j < 4; j++)
- matrix[j][i] = finalMatrix.m[i][j];
-
- matrix[0][3] = 0.0f;
- matrix[1][3] = 0.0f;
- matrix[2][3] = 0.0f;
- matrix[3][3] = 1.0f;
-
- glMatrixModview->MultMatrixf(&matrix[0][0]);
+ glMatrixModview->MultMatrixf(finalMatrix);
glMatrixModview.Load();
}