From f058b25881e08c9d89a33345e5c84e1357396932 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Thu, 8 Oct 2009 17:28:02 -0700 Subject: Store clipping distance for user clip planes as part of vertex processing Once the clipping distance is calculated and stored per vertex, the distances can be re-used when clipping is actually performed. This doesn't have any immediate benefit, but it paves the way for implementing gl_ClipDistance in vertex shaders and result.clip[] in vertex programs. This has not produces any oglconform regressions on my G31 system which uses software TNL. Signed-off-by: Ian Romanick Reviewed-by: Brian Paul --- src/mesa/tnl/t_vb_vertex.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'src/mesa/tnl/t_vb_vertex.c') diff --git a/src/mesa/tnl/t_vb_vertex.c b/src/mesa/tnl/t_vb_vertex.c index 4734754ea4..2a61ff1177 100644 --- a/src/mesa/tnl/t_vb_vertex.c +++ b/src/mesa/tnl/t_vb_vertex.c @@ -44,6 +44,7 @@ struct vertex_stage_data { GLvector4f eye; GLvector4f clip; GLvector4f proj; + GLfloat *clipdistance[MAX_CLIP_PLANES]; GLubyte *clipmask; GLubyte ormask; GLubyte andmask; @@ -56,11 +57,12 @@ struct vertex_stage_data { /* This function implements cliptesting for user-defined clip planes. * The clipping of primitives to these planes is implemented in - * t_render_clip.h. + * t_vp_cliptmp.h. */ #define USER_CLIPTEST(NAME, SZ) \ static void NAME( GLcontext *ctx, \ GLvector4f *clip, \ + GLfloat *clipdistances[MAX_CLIP_PLANES], \ GLubyte *clipmask, \ GLubyte *clipormask, \ GLubyte *clipandmask ) \ @@ -88,6 +90,8 @@ static void NAME( GLcontext *ctx, \ clipmask[i] |= CLIP_USER_BIT; \ } \ \ + clipdistances[p][i] = dp; \ + \ STRIDE_F(coord, stride); \ } \ \ @@ -107,8 +111,9 @@ USER_CLIPTEST(userclip3, 3) USER_CLIPTEST(userclip4, 4) static void (*(usercliptab[5]))( GLcontext *, - GLvector4f *, GLubyte *, - GLubyte *, GLubyte * ) = + GLvector4f *, + GLfloat *[MAX_CLIP_PLANES], + GLubyte *, GLubyte *, GLubyte * ) = { NULL, NULL, @@ -214,12 +219,16 @@ static GLboolean run_vertex_stage( GLcontext *ctx, if (ctx->Transform.ClipPlanesEnabled) { usercliptab[VB->ClipPtr->size]( ctx, VB->ClipPtr, + store->clipdistance, store->clipmask, &store->ormask, &store->andmask ); if (store->andmask) return GL_FALSE; + + memcpy(VB->ClipDistancePtr, store->clipdistance, + sizeof(store->clipdistance)); } VB->ClipAndMask = store->andmask; @@ -236,6 +245,7 @@ static GLboolean init_vertex_stage( GLcontext *ctx, struct vertex_buffer *VB = &TNL_CONTEXT(ctx)->vb; struct vertex_stage_data *store; GLuint size = VB->Size; + unsigned i; stage->privatePtr = CALLOC(sizeof(*store)); store = VERTEX_STAGE_DATA(stage); @@ -247,8 +257,17 @@ static GLboolean init_vertex_stage( GLcontext *ctx, _mesa_vector4f_alloc( &store->proj, 0, size, 32 ); store->clipmask = (GLubyte *) ALIGN_MALLOC(sizeof(GLubyte)*size, 32 ); + for (i = 0; i < MAX_CLIP_PLANES; i++) + store->clipdistance[i] = + (GLfloat *) ALIGN_MALLOC(sizeof(GLfloat) * size, 32); if (!store->clipmask || + !store->clipdistance[0] || + !store->clipdistance[1] || + !store->clipdistance[2] || + !store->clipdistance[3] || + !store->clipdistance[4] || + !store->clipdistance[5] || !store->eye.data || !store->clip.data || !store->proj.data) @@ -262,10 +281,16 @@ static void dtr( struct tnl_pipeline_stage *stage ) struct vertex_stage_data *store = VERTEX_STAGE_DATA(stage); if (store) { + unsigned i; + _mesa_vector4f_free( &store->eye ); _mesa_vector4f_free( &store->clip ); _mesa_vector4f_free( &store->proj ); ALIGN_FREE( store->clipmask ); + + for (i = 0; i < MAX_CLIP_PLANES; i++) + ALIGN_FREE(store->clipdistance[i]); + FREE(store); stage->privatePtr = NULL; stage->run = init_vertex_stage; -- cgit v1.2.3