[Mesa-dev] [PATCH 3/4] tnl: Maintain the _WindowMap matrix in TNLcontext v2.

Ilia Mirkin imirkin at alum.mit.edu
Thu Aug 6 09:32:18 PDT 2015


On Thu, Apr 2, 2015 at 12:30 PM,  <Mathias.Froehlich at gmx.net> wrote:
> From: Mathias Froehlich <Mathias.Froehlich at web.de>
>
> Hi Brian,
>
> Thanks for the review!
> The Patch with unneeded parentheses removed.
> Ok, to push?
>
> Greetings
>
> Mathias
>
>
> This is the only real user of _WindowMap which has the depth
> buffer scaling multiplied in. Maintain the _WindowMap of the
> one and only viewport inside TNLcontext.
>
> v2:
> Remove unneeded parentheses.
>
> Reviewed-by: Brian Paul <brianp at vmware.com>
> Signed-off-by: Mathias Froehlich <Mathias.Froehlich at web.de>
> ---
>  src/mesa/swrast_setup/ss_context.c |  5 +++--
>  src/mesa/tnl/t_context.c           | 12 ++++++++++++
>  src/mesa/tnl/t_context.h           |  1 +
>  src/mesa/tnl/t_rasterpos.c         | 13 ++++++-------
>  4 files changed, 22 insertions(+), 9 deletions(-)
>
> diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c
> index 4fc90c3..74b1da3 100644
> --- a/src/mesa/swrast_setup/ss_context.c
> +++ b/src/mesa/swrast_setup/ss_context.c
> @@ -167,7 +167,7 @@ setup_vertex_format(struct gl_context *ctx)
>           EMIT_ATTR( _TNL_ATTRIB_POINTSIZE, EMIT_1F, pointSize );
>
>        _tnl_install_attrs( ctx, map, e,
> -                          ctx->ViewportArray[0]._WindowMap.m,
> +                          tnl->_WindowMap.m,
>                            sizeof(SWvertex) );
>
>        swsetup->last_index_bitset = index_bitset;
> @@ -265,7 +265,8 @@ _swsetup_Wakeup( struct gl_context *ctx )
>  void
>  _swsetup_Translate( struct gl_context *ctx, const void *vertex, SWvertex *dest )
>  {
> -   const GLfloat *m = ctx->ViewportArray[0]._WindowMap.m;
> +   TNLcontext *tnl = TNL_CONTEXT(ctx);
> +   const GLfloat *m = tnl->_WindowMap.m;
>     GLfloat tmp[4];
>     GLuint i;
>
> diff --git a/src/mesa/tnl/t_context.c b/src/mesa/tnl/t_context.c
> index bc705d7..5b9dd54 100644
> --- a/src/mesa/tnl/t_context.c
> +++ b/src/mesa/tnl/t_context.c
> @@ -35,6 +35,7 @@
>  #include "math/m_translate.h"
>  #include "math/m_xform.h"
>  #include "main/state.h"
> +#include "main/viewport.h"
>
>  #include "tnl.h"
>  #include "t_context.h"
> @@ -69,6 +70,8 @@ _tnl_CreateContext( struct gl_context *ctx )
>        _tnl_install_pipeline( ctx, _tnl_default_pipeline );
>     }
>
> +   _math_matrix_ctr(&tnl->_WindowMap);
> +
>     tnl->NeedNdcCoords = GL_TRUE;
>     tnl->AllowVertexFog = GL_TRUE;
>     tnl->AllowPixelFog = GL_TRUE;
> @@ -108,6 +111,8 @@ _tnl_DestroyContext( struct gl_context *ctx )
>     struct tnl_shine_tab *s, *tmps;
>     TNLcontext *tnl = TNL_CONTEXT(ctx);
>
> +   _math_matrix_dtr(&tnl->_WindowMap);
> +
>     /* Free lighting shininess exponentiation table */
>     foreach_s( s, tmps, tnl->_ShineTabList ) {
>        free( s );
> @@ -182,6 +187,13 @@ _tnl_InvalidateState( struct gl_context *ctx, GLuint new_state )
>           }
>        }
>     }
> +
> +   if (new_state & (_NEW_VIEWPORT | _NEW_BUFFERS)) {
> +      double scale[3], translate[3];
> +      _mesa_get_viewport_xform(ctx, 0, scale, translate);
> +      _math_matrix_viewport(&tnl->_WindowMap, scale, translate,
> +                            ctx->DrawBuffer->_DepthMaxF);

This appears to crash nouveau_vieux on startup. See
https://bugs.freedesktop.org/show_bug.cgi?id=91570 . I suspect that
ctx->DrawBuffer is null. What's the proper way to handle that
situation -- predicate on a drawbuffer being bound? Or make sure that
something is bound to the drawbuffer before we call tnl_wakeup?

> +   }
>  }
>
>
> diff --git a/src/mesa/tnl/t_context.h b/src/mesa/tnl/t_context.h
> index e89a7f8..e7adb5f 100644
> --- a/src/mesa/tnl/t_context.h
> +++ b/src/mesa/tnl/t_context.h
> @@ -514,6 +514,7 @@ typedef struct
>     /* Clipspace/ndc/window vertex managment:
>      */
>     struct tnl_clipspace clipspace;
> +   GLmatrix _WindowMap;
>
>     /* Probably need a better configuration mechanism:
>      */
> diff --git a/src/mesa/tnl/t_rasterpos.c b/src/mesa/tnl/t_rasterpos.c
> index 1cd3981..d4b45ba 100644
> --- a/src/mesa/tnl/t_rasterpos.c
> +++ b/src/mesa/tnl/t_rasterpos.c
> @@ -30,6 +30,7 @@
>  #include "main/macros.h"
>  #include "util/simple_list.h"
>  #include "main/mtypes.h"
> +#include "main/viewport.h"
>
>  #include "math/m_matrix.h"
>  #include "tnl/tnl.h"
> @@ -377,6 +378,7 @@ _tnl_RasterPos(struct gl_context *ctx, const GLfloat vObj[4])
>        GLfloat eye[4], clip[4], ndc[3], d;
>        GLfloat *norm, eyenorm[3];
>        GLfloat *objnorm = ctx->Current.Attrib[VERT_ATTRIB_NORMAL];
> +      double scale[3], translate[3];
>
>        /* apply modelview matrix:  eye = MV * obj */
>        TRANSFORM_POINT( eye, ctx->ModelviewMatrixStack.Top->m, vObj );
> @@ -409,13 +411,10 @@ _tnl_RasterPos(struct gl_context *ctx, const GLfloat vObj[4])
>        ndc[1] = clip[1] * d;
>        ndc[2] = clip[2] * d;
>        /* wincoord = viewport_mapping(ndc) */
> -      ctx->Current.RasterPos[0] = (ndc[0] * ctx->ViewportArray[0]._WindowMap.m[MAT_SX]
> -                                   + ctx->ViewportArray[0]._WindowMap.m[MAT_TX]);
> -      ctx->Current.RasterPos[1] = (ndc[1] * ctx->ViewportArray[0]._WindowMap.m[MAT_SY]
> -                                   + ctx->ViewportArray[0]._WindowMap.m[MAT_TY]);
> -      ctx->Current.RasterPos[2] = (ndc[2] * ctx->ViewportArray[0]._WindowMap.m[MAT_SZ]
> -                                   + ctx->ViewportArray[0]._WindowMap.m[MAT_TZ])
> -                                  / ctx->DrawBuffer->_DepthMaxF;
> +      _mesa_get_viewport_xform(ctx, 0, scale, translate);
> +      ctx->Current.RasterPos[0] = ndc[0] * scale[0] + translate[0];
> +      ctx->Current.RasterPos[1] = ndc[1] * scale[1] + translate[1];
> +      ctx->Current.RasterPos[2] = ndc[2] * scale[2] + translate[2];
>        ctx->Current.RasterPos[3] = clip[3];
>
>        if (ctx->Transform.DepthClamp) {
> --
> 2.1.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list