X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Ftnl%2Ft_vb_cliptmp.h;h=c6546668806eda497499200b3d259e5ccbc08386;hb=b864e3d7eee82accf3430b46d5a9269323fe0ba0;hp=0d2183a9e67ecbf7c2ac3ab9f0a3d4493c481d64;hpb=f058b25881e08c9d89a33345e5c84e1357396932;p=mesa.git diff --git a/src/mesa/tnl/t_vb_cliptmp.h b/src/mesa/tnl/t_vb_cliptmp.h index 0d2183a9e67..c6546668806 100644 --- a/src/mesa/tnl/t_vb_cliptmp.h +++ b/src/mesa/tnl/t_vb_cliptmp.h @@ -1,6 +1,5 @@ /* * Mesa 3-D graphics library - * Version: 6.5.2 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. * @@ -17,12 +16,13 @@ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN - * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. * * Authors: - * Keith Whitwell + * Keith Whitwell */ @@ -41,12 +41,12 @@ do { \ GLuint idx = inlist[i]; \ GLfloat dp = CLIP_DOTPROD(idx, A, B, C, D ); \ \ - if (!IS_NEGATIVE(dpPrev)) { \ + if (dpPrev >= 0.0f) { \ outlist[outcount++] = idxPrev; \ } \ \ if (DIFFERENT_SIGNS(dp, dpPrev)) { \ - if (IS_NEGATIVE(dp)) { \ + if (dp < 0.0f) { \ /* Going out of bounds. Avoid division by zero as we \ * know dp != dpPrev from DIFFERENT_SIGNS, above. \ */ \ @@ -80,103 +80,20 @@ do { \ } while (0) -#define POLY_USERCLIP(PLANE) \ -do { \ - if (mask & CLIP_USER_BIT) { \ - GLuint idxPrev = inlist[0]; \ - GLfloat dpPrev = VB->ClipDistancePtr[PLANE][idxPrev]; \ - GLuint outcount = 0; \ - GLuint i; \ - \ - inlist[n] = inlist[0]; /* prevent rotation of vertices */ \ - for (i = 1; i <= n; i++) { \ - GLuint idx = inlist[i]; \ - GLfloat dp = VB->ClipDistancePtr[PLANE][idx]; \ - \ - if (!IS_NEGATIVE(dpPrev)) { \ - outlist[outcount++] = idxPrev; \ - } \ - \ - if (DIFFERENT_SIGNS(dp, dpPrev)) { \ - if (IS_NEGATIVE(dp)) { \ - /* Going out of bounds. Avoid division by zero as we \ - * know dp != dpPrev from DIFFERENT_SIGNS, above. \ - */ \ - GLfloat t = dp / (dp - dpPrev); \ - INTERP_4F( t, coord[newvert], coord[idx], coord[idxPrev]); \ - interp( ctx, t, newvert, idx, idxPrev, GL_TRUE ); \ - } else { \ - /* Coming back in. \ - */ \ - GLfloat t = dpPrev / (dpPrev - dp); \ - INTERP_4F( t, coord[newvert], coord[idxPrev], coord[idx]); \ - interp( ctx, t, newvert, idxPrev, idx, GL_FALSE ); \ - } \ - outlist[outcount++] = newvert++; \ - } \ - \ - idxPrev = idx; \ - dpPrev = dp; \ - } \ - \ - if (outcount < 3) \ - return; \ - \ - { \ - GLuint *tmp = inlist; \ - inlist = outlist; \ - outlist = tmp; \ - n = outcount; \ - } \ - } \ -} while (0) - - #define LINE_CLIP(PLANE_BIT, A, B, C, D ) \ do { \ if (mask & PLANE_BIT) { \ const GLfloat dp0 = CLIP_DOTPROD( v0, A, B, C, D ); \ const GLfloat dp1 = CLIP_DOTPROD( v1, A, B, C, D ); \ - const GLboolean neg_dp0 = IS_NEGATIVE(dp0); \ - const GLboolean neg_dp1 = IS_NEGATIVE(dp1); \ + const GLboolean neg_dp0 = dp0 < 0.0f; \ + const GLboolean neg_dp1 = dp1 < 0.0f; \ \ /* For regular clipping, we know from the clipmask that one \ * (or both) of these must be negative (otherwise we wouldn't \ * be here). \ * For userclip, there is only a single bit for all active \ * planes, so we can end up here when there is nothing to do, \ - * hence the second IS_NEGATIVE() test: \ - */ \ - if (neg_dp0 && neg_dp1) \ - return; /* both vertices outside clip plane: discard */ \ - \ - if (neg_dp1) { \ - GLfloat t = dp1 / (dp1 - dp0); \ - if (t > t1) t1 = t; \ - } else if (neg_dp0) { \ - GLfloat t = dp0 / (dp0 - dp1); \ - if (t > t0) t0 = t; \ - } \ - if (t0 + t1 >= 1.0) \ - return; /* discard */ \ - } \ -} while (0) - - -#define LINE_USERCLIP(PLANE) \ -do { \ - if (mask & CLIP_USER_BIT) { \ - const GLfloat dp0 = VB->ClipDistancePtr[PLANE][v0]; \ - const GLfloat dp1 = VB->ClipDistancePtr[PLANE][v1]; \ - const GLboolean neg_dp0 = IS_NEGATIVE(dp0); \ - const GLboolean neg_dp1 = IS_NEGATIVE(dp1); \ - \ - /* For regular clipping, we know from the clipmask that one \ - * (or both) of these must be negative (otherwise we wouldn't \ - * be here). \ - * For userclip, there is only a single bit for all active \ - * planes, so we can end up here when there is nothing to do, \ - * hence the second IS_NEGATIVE() test: \ + * hence the second < 0.0f test: \ */ \ if (neg_dp0 && neg_dp1) \ return; /* both vertices outside clip plane: discard */ \ @@ -197,8 +114,8 @@ do { \ /* Clip a line against the viewport and user clip planes. */ -static INLINE void -TAG(clip_line)( GLcontext *ctx, GLuint v0, GLuint v1, GLubyte mask ) +static inline void +TAG(clip_line)( struct gl_context *ctx, GLuint v0, GLuint v1, GLubyte mask ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; @@ -207,7 +124,6 @@ TAG(clip_line)( GLcontext *ctx, GLuint v0, GLuint v1, GLubyte mask ) GLuint newvert = VB->Count; GLfloat t0 = 0; GLfloat t1 = 0; - GLuint p; const GLuint v0_orig = v0; if (mask & CLIP_FRUSTUM_BITS) { @@ -220,10 +136,14 @@ TAG(clip_line)( GLcontext *ctx, GLuint v0, GLuint v1, GLubyte mask ) } if (mask & CLIP_USER_BIT) { - for (p = 0; p < ctx->Const.MaxClipPlanes; p++) { - if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { - LINE_USERCLIP(p); - } + GLbitfield enabled = ctx->Transform.ClipPlanesEnabled; + while (enabled) { + const int p = u_bit_scan(&enabled); + const GLfloat a = ctx->Transform._ClipUserPlane[p][0]; + const GLfloat b = ctx->Transform._ClipUserPlane[p][1]; + const GLfloat c = ctx->Transform._ClipUserPlane[p][2]; + const GLfloat d = ctx->Transform._ClipUserPlane[p][3]; + LINE_CLIP( CLIP_USER_BIT, a, b, c, d ); } } @@ -234,7 +154,7 @@ TAG(clip_line)( GLcontext *ctx, GLuint v0, GLuint v1, GLubyte mask ) newvert++; } else { - ASSERT(t0 == 0.0); + assert(t0 == 0.0); } /* Note: we need to use vertex v0_orig when computing the new @@ -253,7 +173,7 @@ TAG(clip_line)( GLcontext *ctx, GLuint v0, GLuint v1, GLubyte mask ) newvert++; } else { - ASSERT(t1 == 0.0); + assert(t1 == 0.0); } tnl->Driver.Render.ClippedLine( ctx, v0, v1 ); @@ -262,8 +182,8 @@ TAG(clip_line)( GLcontext *ctx, GLuint v0, GLuint v1, GLubyte mask ) /* Clip a triangle against the viewport and user clip planes. */ -static INLINE void -TAG(clip_tri)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask ) +static inline void +TAG(clip_tri)( struct gl_context *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask ) { TNLcontext *tnl = TNL_CONTEXT(ctx); struct vertex_buffer *VB = &tnl->vb; @@ -273,7 +193,6 @@ TAG(clip_tri)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask ) GLuint pv = v2; GLuint vlist[2][MAX_CLIPPED_VERTICES]; GLuint *inlist = vlist[0], *outlist = vlist[1]; - GLuint p; GLuint n = 3; ASSIGN_3V(inlist, v2, v0, v1 ); /* pv rotated to slot zero */ @@ -281,12 +200,12 @@ TAG(clip_tri)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask ) if (0) { /* print pre-clip vertex coords */ GLuint i, j; - _mesa_printf("pre clip:\n"); + printf("pre clip:\n"); for (i = 0; i < n; i++) { j = inlist[i]; - _mesa_printf(" %u: %u: %f, %f, %f, %f\n", - i, j, - coord[j][0], coord[j][1], coord[j][2], coord[j][3]); + printf(" %u: %u: %f, %f, %f, %f\n", + i, j, + coord[j][0], coord[j][1], coord[j][2], coord[j][3]); assert(!IS_INF_OR_NAN(coord[j][0])); assert(!IS_INF_OR_NAN(coord[j][1])); assert(!IS_INF_OR_NAN(coord[j][2])); @@ -305,16 +224,20 @@ TAG(clip_tri)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask ) } if (mask & CLIP_USER_BIT) { - for (p = 0; p < ctx->Const.MaxClipPlanes; p++) { - if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { - POLY_USERCLIP(p); - } + GLbitfield enabled = ctx->Transform.ClipPlanesEnabled; + while (enabled) { + const int p = u_bit_scan(&enabled); + const GLfloat a = ctx->Transform._ClipUserPlane[p][0]; + const GLfloat b = ctx->Transform._ClipUserPlane[p][1]; + const GLfloat c = ctx->Transform._ClipUserPlane[p][2]; + const GLfloat d = ctx->Transform._ClipUserPlane[p][3]; + POLY_CLIP( CLIP_USER_BIT, a, b, c, d ); } } if (ctx->Light.ShadeModel == GL_FLAT) { if (pv != inlist[0]) { - ASSERT( inlist[0] >= VB->Count ); + assert( inlist[0] >= VB->Count ); tnl->Driver.Render.CopyPV( ctx, inlist[0], pv ); } } @@ -322,12 +245,12 @@ TAG(clip_tri)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask ) if (0) { /* print post-clip vertex coords */ GLuint i, j; - _mesa_printf("post clip:\n"); + printf("post clip:\n"); for (i = 0; i < n; i++) { j = inlist[i]; - _mesa_printf(" %u: %u: %f, %f, %f, %f\n", - i, j, - coord[j][0], coord[j][1], coord[j][2], coord[j][3]); + printf(" %u: %u: %f, %f, %f, %f\n", + i, j, + coord[j][0], coord[j][1], coord[j][2], coord[j][3]); } } @@ -337,8 +260,8 @@ TAG(clip_tri)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLubyte mask ) /* Clip a quad against the viewport and user clip planes. */ -static INLINE void -TAG(clip_quad)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, +static inline void +TAG(clip_quad)( struct gl_context *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLubyte mask ) { TNLcontext *tnl = TNL_CONTEXT(ctx); @@ -349,7 +272,6 @@ TAG(clip_quad)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, GLuint pv = v3; GLuint vlist[2][MAX_CLIPPED_VERTICES]; GLuint *inlist = vlist[0], *outlist = vlist[1]; - GLuint p; GLuint n = 4; ASSIGN_4V(inlist, v3, v0, v1, v2 ); /* pv rotated to slot zero */ @@ -364,16 +286,20 @@ TAG(clip_quad)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, } if (mask & CLIP_USER_BIT) { - for (p = 0; p < ctx->Const.MaxClipPlanes; p++) { - if (ctx->Transform.ClipPlanesEnabled & (1 << p)) { - POLY_USERCLIP(p); - } + GLbitfield enabled = ctx->Transform.ClipPlanesEnabled; + while (enabled) { + const int p = u_bit_scan(&enabled); + const GLfloat a = ctx->Transform._ClipUserPlane[p][0]; + const GLfloat b = ctx->Transform._ClipUserPlane[p][1]; + const GLfloat c = ctx->Transform._ClipUserPlane[p][2]; + const GLfloat d = ctx->Transform._ClipUserPlane[p][3]; + POLY_CLIP( CLIP_USER_BIT, a, b, c, d ); } } if (ctx->Light.ShadeModel == GL_FLAT) { if (pv != inlist[0]) { - ASSERT( inlist[0] >= VB->Count ); + assert( inlist[0] >= VB->Count ); tnl->Driver.Render.CopyPV( ctx, inlist[0], pv ); } } @@ -388,6 +314,4 @@ TAG(clip_quad)( GLcontext *ctx, GLuint v0, GLuint v1, GLuint v2, GLuint v3, #undef SIZE #undef TAG #undef POLY_CLIP -#undef POLY_USERCLIP #undef LINE_CLIP -#undef LINE_USERCLIP