[Mesa-dev] [PATCH 6/6] mesa: check for identity matrix in _mesa_LoadMatrixf()

Anuj Phogat anuj.phogat at gmail.com
Mon Jul 20 11:24:34 PDT 2015


On Fri, Jul 17, 2015 at 5:48 PM, Brian Paul <brianp at vmware.com> wrote:
> Google Earth often calls glLoadMatrixf() with an identity matrix instead
> of glLoadIdentity() to set the modelview and texture matrices.  In many
> cases, the matrix is already the identity so the calls are redundant.
>
> By being a bit smarter in _mesa_LoadMatrixf() we can avoid quite a few
> matrix-related state validations.
> ---
>  src/mesa/main/matrix.c | 23 ++++++++++++++++++++---
>  1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/main/matrix.c b/src/mesa/main/matrix.c
> index 5ac97f8..e6bdff8 100644
> --- a/src/mesa/main/matrix.c
> +++ b/src/mesa/main/matrix.c
> @@ -330,8 +330,16 @@ _mesa_LoadIdentity( void )
>  void GLAPIENTRY
>  _mesa_LoadMatrixf( const GLfloat *m )
>  {
> +   static const GLfloat identity[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,
> +      0.0f, 0.0f, 0.0f, 1.0f };
>     GET_CURRENT_CONTEXT(ctx);
> -   if (!m) return;
> +
> +   if (!m)
> +      return;
> +
>     if (MESA_VERBOSE & VERBOSE_API)
>        _mesa_debug(ctx,
>            "glLoadMatrix(%f %f %f %f, %f %f %f %f, %f %f %f %f, %f %f %f %f\n",
> @@ -341,8 +349,17 @@ _mesa_LoadMatrixf( const GLfloat *m )
>            m[3], m[7], m[11], m[15]);
>
>     FLUSH_VERTICES(ctx, 0);
> -   _math_matrix_loadf( ctx->CurrentStack->Top, m );
> -   ctx->NewState |= ctx->CurrentStack->DirtyFlag;
> +
> +   if (memcmp(m, identity, sizeof(identity)) == 0) {
> +      /* Setting the identity matrix */
> +      if (_math_matrix_set_identity(ctx->CurrentStack->Top)) {
> +         ctx->NewState |= ctx->CurrentStack->DirtyFlag;
> +      }
> +   }
> +   else {
> +      _math_matrix_loadf(ctx->CurrentStack->Top, m);
> +      ctx->NewState |= ctx->CurrentStack->DirtyFlag;
> +   }
>  }
>
>
> --
> 1.9.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Series is:
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>


More information about the mesa-dev mailing list