mesa: Add function to calculate an orthographic projection
authorIan Romanick <ian.d.romanick@intel.com>
Tue, 28 Apr 2020 17:18:47 +0000 (10:18 -0700)
committerMarge Bot <eric+marge@anholt.net>
Thu, 14 May 2020 15:35:43 +0000 (15:35 +0000)
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 <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/856>

src/mesa/math/m_matrix.c
src/mesa/math/m_matrix.h

index 31b7665a3bad237cadfbca5e09a8d9558162bd5c..0202c6fa1f2e6f1e8c355f2cec61bcf2687a80d6 100644 (file)
@@ -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));
 }
 
index c34d9e3022f7e9044ec8fc46e027278beed00576..6de9e1a84cd865bd6375daf5ef1be1e6659d474b 100644 (file)
@@ -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,