From 29f10ede71ffe8352bdfda154f3994542094bcfb Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Tue, 28 Apr 2020 10:18:47 -0700 Subject: [PATCH] mesa: Add function to calculate an orthographic projection Unlike the existing _math_matrix_ortho, the new _math_float_ortho function just stores the calculated matrix in an array of floats. It does not multiply the new matrix with data already stored. text data bss dec hex filename 12243486 1344936 1290748 14879170 e309c2 before/lib64/dri/i965_dri.so 12243510 1344936 1290748 14879194 e309da after/lib64/dri/i965_dri.so Reviewed-by: Jason Ekstrand Part-of: --- src/mesa/math/m_matrix.c | 42 ++++++++++++++++++++++++++++++---------- src/mesa/math/m_matrix.h | 6 ++++++ 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/src/mesa/math/m_matrix.c b/src/mesa/math/m_matrix.c index 31b7665a3ba..0202c6fa1f2 100644 --- a/src/mesa/math/m_matrix.c +++ b/src/mesa/math/m_matrix.c @@ -1007,9 +1007,9 @@ _math_matrix_frustum( GLmatrix *mat, } /** - * Apply an orthographic projection matrix. + * Create an orthographic projection matrix. * - * \param mat matrix to apply the projection. + * \param m float array in which to store the project matrix * \param left left clipping plane coordinate. * \param right right clipping plane coordinate. * \param bottom bottom clipping plane coordinate. @@ -1017,17 +1017,15 @@ _math_matrix_frustum( GLmatrix *mat, * \param nearval distance to the near clipping plane. * \param farval distance to the far clipping plane. * - * Creates the projection matrix and multiplies it with \p mat, marking the - * MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags. + * Creates the projection matrix and stored the values in \p m. As with other + * OpenGL matrices, the data is stored in column-major ordering. */ void -_math_matrix_ortho( GLmatrix *mat, - GLfloat left, GLfloat right, - GLfloat bottom, GLfloat top, - GLfloat nearval, GLfloat farval ) +_math_float_ortho(float *m, + float left, float right, + float bottom, float top, + float nearval, float farval) { - GLfloat m[16]; - #define M(row,col) m[col*4+row] M(0,0) = 2.0F / (right-left); M(0,1) = 0.0F; @@ -1049,7 +1047,31 @@ _math_matrix_ortho( GLmatrix *mat, M(3,2) = 0.0F; M(3,3) = 1.0F; #undef M +} + +/** + * Apply an orthographic projection matrix. + * + * \param mat matrix to apply the projection. + * \param left left clipping plane coordinate. + * \param right right clipping plane coordinate. + * \param bottom bottom clipping plane coordinate. + * \param top top clipping plane coordinate. + * \param nearval distance to the near clipping plane. + * \param farval distance to the far clipping plane. + * + * Creates the projection matrix and multiplies it with \p mat, marking the + * MAT_FLAG_GENERAL_SCALE and MAT_FLAG_TRANSLATION flags. + */ +void +_math_matrix_ortho( GLmatrix *mat, + GLfloat left, GLfloat right, + GLfloat bottom, GLfloat top, + GLfloat nearval, GLfloat farval ) +{ + GLfloat m[16]; + _math_float_ortho(m, left, right, bottom, top, nearval, farval); matrix_multf( mat, m, (MAT_FLAG_GENERAL_SCALE|MAT_FLAG_TRANSLATION)); } diff --git a/src/mesa/math/m_matrix.h b/src/mesa/math/m_matrix.h index c34d9e3022f..6de9e1a84cd 100644 --- a/src/mesa/math/m_matrix.h +++ b/src/mesa/math/m_matrix.h @@ -109,6 +109,12 @@ _math_matrix_rotate( GLmatrix *m, GLfloat angle, extern void _math_matrix_scale( GLmatrix *mat, GLfloat x, GLfloat y, GLfloat z ); +extern void +_math_float_ortho(float *m, + float left, float right, + float bottom, float top, + float nearval, float farval); + extern void _math_matrix_ortho( GLmatrix *mat, GLfloat left, GLfloat right, -- 2.30.2