diff options
author | Brian <[email protected]> | 2007-11-30 13:01:42 -0700 |
---|---|---|
committer | Brian <[email protected]> | 2007-11-30 13:01:42 -0700 |
commit | 1b43babfb126c6318d2f2468ec81b93ee1923774 (patch) | |
tree | 26e6ee2b5e99bbebab943041bf11e3f250fbc89b /src/mesa | |
parent | 43e902f774f8c3cd58310eeb44eec9d3f8f81746 (diff) |
fix broken two-sided stencil
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/context.c | 1 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 6 | ||||
-rw-r--r-- | src/mesa/swrast/s_aalinetemp.h | 1 | ||||
-rw-r--r-- | src/mesa/swrast/s_aatritemp.h | 5 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.c | 17 | ||||
-rw-r--r-- | src/mesa/swrast/s_context.h | 4 | ||||
-rw-r--r-- | src/mesa/swrast/s_fragprog.c | 2 | ||||
-rw-r--r-- | src/mesa/swrast/s_linetemp.h | 3 | ||||
-rw-r--r-- | src/mesa/swrast/s_pointtemp.h | 1 | ||||
-rw-r--r-- | src/mesa/swrast/s_triangle.c | 2 | ||||
-rw-r--r-- | src/mesa/swrast/s_tritemp.h | 9 | ||||
-rw-r--r-- | src/mesa/swrast/swrast.h | 7 | ||||
-rw-r--r-- | src/mesa/swrast_setup/ss_context.c | 3 | ||||
-rw-r--r-- | src/mesa/swrast_setup/ss_triangle.c | 10 | ||||
-rw-r--r-- | src/mesa/swrast_setup/ss_tritmp.h | 2 |
15 files changed, 49 insertions, 24 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c index 754b1a7d823..b599638c771 100644 --- a/src/mesa/main/context.c +++ b/src/mesa/main/context.c @@ -977,7 +977,6 @@ init_attrib_groups(GLcontext *ctx) /* Miscellaneous */ ctx->NewState = _NEW_ALL; ctx->ErrorValue = (GLenum) GL_NO_ERROR; - ctx->_Facing = 0; return GL_TRUE; } diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h index 2cc0622ec8a..96c3515dd2c 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -3032,12 +3032,6 @@ struct __GLcontextRec struct gl_list_extensions ListExt; /**< driver dlist extensions */ - - GLuint _Facing; /**< This is a hack for 2-sided stencil test. - * - * We don't have a better way to communicate this value from - * swrast_setup to swrast. */ - /** \name For debugging/development only */ /*@{*/ GLboolean FirstTimeCurrent; diff --git a/src/mesa/swrast/s_aalinetemp.h b/src/mesa/swrast/s_aalinetemp.h index 80cec0b31d4..074ffe8c9b1 100644 --- a/src/mesa/swrast/s_aalinetemp.h +++ b/src/mesa/swrast/s_aalinetemp.h @@ -141,6 +141,7 @@ NAME(line)(GLcontext *ctx, const SWvertex *v0, const SWvertex *v1) return; INIT_SPAN(line.span, GL_LINE, 0, 0, SPAN_XY | SPAN_COVERAGE); + line.span.facing = swrast->PointLineFacing; line.xAdj = line.dx / line.len * line.halfWidth; line.yAdj = line.dy / line.len * line.halfWidth; diff --git a/src/mesa/swrast/s_aatritemp.h b/src/mesa/swrast/s_aatritemp.h index 9278b5a157a..b26f21f5db0 100644 --- a/src/mesa/swrast/s_aatritemp.h +++ b/src/mesa/swrast/s_aatritemp.h @@ -78,7 +78,7 @@ GLfloat texWidth[FRAG_ATTRIB_MAX]; GLfloat texHeight[FRAG_ATTRIB_MAX]; #endif - GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceSign; + GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceCullSign; (void) swrast; @@ -116,6 +116,7 @@ majDx = vMax->win[0] - vMin->win[0]; majDy = vMax->win[1] - vMin->win[1]; + /* front/back-face determination and cullling */ { const GLfloat botDx = vMid->win[0] - vMin->win[0]; const GLfloat botDy = vMid->win[1] - vMin->win[1]; @@ -124,6 +125,8 @@ if (area * bf < 0 || area == 0 || IS_INF_OR_NAN(area)) return; ltor = (GLboolean) (area < 0.0F); + + span.facing = area * swrast->_BackfaceSign > 0.0F; } /* Plane equation setup: diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c index 2f25edbd811..47d5035c02e 100644 --- a/src/mesa/swrast/s_context.c +++ b/src/mesa/swrast/s_context.c @@ -117,8 +117,8 @@ _swrast_update_rasterflags( GLcontext *ctx ) /** - * Examine polycon culls tate to compute the _BackfaceSign field. - * _BackfaceSign will be 0 if no culling, -1 if culling back-faces, + * Examine polycon culls tate to compute the _BackfaceCullSign field. + * _BackfaceCullSign will be 0 if no culling, -1 if culling back-faces, * and 1 if culling front-faces. The Polygon FrontFace state also * factors in. */ @@ -149,10 +149,15 @@ _swrast_update_polygon( GLcontext *ctx ) backface_sign = 0.0; } - SWRAST_CONTEXT(ctx)->_BackfaceSign = backface_sign; + SWRAST_CONTEXT(ctx)->_BackfaceCullSign = backface_sign; + + /* This is for front/back-face determination, but not for culling */ + SWRAST_CONTEXT(ctx)->_BackfaceSign + = (ctx->Polygon.FrontFace == GL_CW) ? -1.0 : 1.0; } + /** * Update the _PreferPixelFog field to indicate if we need to compute * fog blend factors (from the fog coords) per-fragment. @@ -721,6 +726,12 @@ _swrast_ResetLineStipple( GLcontext *ctx ) } void +_swrast_SetFacing(GLcontext *ctx, GLuint facing) +{ + SWRAST_CONTEXT(ctx)->PointLineFacing = facing; +} + +void _swrast_allow_vertex_fog( GLcontext *ctx, GLboolean value ) { if (SWRAST_DEBUG) { diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h index c8333b8e0a1..58841ad4af9 100644 --- a/src/mesa/swrast/s_context.h +++ b/src/mesa/swrast/s_context.h @@ -128,7 +128,8 @@ typedef struct * _swrast_validate_derived(): */ GLbitfield _RasterMask; - GLfloat _BackfaceSign; + GLfloat _BackfaceSign; /** +1 or -1 */ + GLfloat _BackfaceCullSign; /** +1, 0, or -1 */ GLboolean _PreferPixelFog; /* Compute fog blend factor per fragment? */ GLboolean _AnyTextureCombine; GLboolean _FogEnabled; @@ -151,6 +152,7 @@ typedef struct /* Working values: */ GLuint StippleCounter; /**< Line stipple counter */ + GLuint PointLineFacing; GLbitfield NewState; GLuint StateChanges; GLenum Primitive; /* current primitive being drawn (ala glBegin) */ diff --git a/src/mesa/swrast/s_fragprog.c b/src/mesa/swrast/s_fragprog.c index 7fd94c87096..324afb9c761 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -118,7 +118,7 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, if (ctx->Shader.CurrentProgram) { /* Store front/back facing value in register FOGC.Y */ - machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = (GLfloat) ctx->_Facing; + machine->Attribs[FRAG_ATTRIB_FOGC][col][1] = (GLfloat) span->facing; } machine->CurElement = col; diff --git a/src/mesa/swrast/s_linetemp.h b/src/mesa/swrast/s_linetemp.h index b6e8f287f45..9e240a7d2bb 100644 --- a/src/mesa/swrast/s_linetemp.h +++ b/src/mesa/swrast/s_linetemp.h @@ -317,6 +317,9 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 ) span.attrStepX[FRAG_ATTRIB_WPOS][3] = 0.0F; span.attrStepY[FRAG_ATTRIB_WPOS][3] = 0.0F; + span.facing = swrast->PointLineFacing; + + /* * Draw */ diff --git a/src/mesa/swrast/s_pointtemp.h b/src/mesa/swrast/s_pointtemp.h index 94364643d4b..7dcc1fc9449 100644 --- a/src/mesa/swrast/s_pointtemp.h +++ b/src/mesa/swrast/s_pointtemp.h @@ -105,6 +105,7 @@ NAME ( GLcontext *ctx, const SWvertex *vert ) */ span->interpMask = SPAN_FOG; span->arrayMask = SPAN_XY | SPAN_Z; + span->facing = swrast->PointLineFacing; span->attrStart[FRAG_ATTRIB_FOGC][0] = vert->attrib[FRAG_ATTRIB_FOGC][0]; span->attrStepX[FRAG_ATTRIB_FOGC][0] = 0.0; span->attrStepY[FRAG_ATTRIB_FOGC][0] = 0.0; diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index fc9d29bbf7f..fc40084bebd 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -58,7 +58,7 @@ _swrast_culltriangle( GLcontext *ctx, GLfloat fy = v2->win[1] - v0->win[1]; GLfloat c = ex*fy-ey*fx; - if (c * SWRAST_CONTEXT(ctx)->_BackfaceSign > 0) + if (c * SWRAST_CONTEXT(ctx)->_BackfaceCullSign > 0) return 0; return 1; diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h index dcc3e958cb1..ae30fe5e597 100644 --- a/src/mesa/swrast/s_tritemp.h +++ b/src/mesa/swrast/s_tritemp.h @@ -172,7 +172,7 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, EdgeT eMaj, eTop, eBot; GLfloat oneOverArea; const SWvertex *vMin, *vMid, *vMax; /* Y(vMin)<=Y(vMid)<=Y(vMax) */ - GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceSign; + GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceCullSign; #if !TRIANGLE_WALK_DOUBLE const GLint snapMask = ~((FIXED_ONE / (1 << SUB_PIXEL_BITS)) - 1); /* for x/y coord snapping */ #endif @@ -293,6 +293,7 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; #endif /* Do backface culling */ + if (area * bf < 0.0) return; @@ -300,10 +301,10 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, return; oneOverArea = 1.0F / area; - } - - span.facing = ctx->_Facing; /* for 2-sided stencil test */ + /* 0 = front, 1 = back */ + span.facing = oneOverArea * swrast->_BackfaceSign > 0.0F; + } /* Edge setup. For a triangle strip these could be reused... */ { diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h index 12264a159ad..86405503afc 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -140,6 +140,13 @@ _swrast_Accum(GLcontext *ctx, GLenum op, GLfloat value); extern void _swrast_ResetLineStipple( GLcontext *ctx ); +/** + * Indicates front/back facing for subsequent points/lines when drawing + * unfilled polygons. Needed for two-side stencil. + */ +extern void +_swrast_SetFacing(GLcontext *ctx, GLuint facing); + /* These will always render the correct point/line/triangle for the * current state. * diff --git a/src/mesa/swrast_setup/ss_context.c b/src/mesa/swrast_setup/ss_context.c index 3f6d29403cc..43f2696da95 100644 --- a/src/mesa/swrast_setup/ss_context.c +++ b/src/mesa/swrast_setup/ss_context.c @@ -186,6 +186,9 @@ _swsetup_RenderStart( GLcontext *ctx ) swsetup->NewState = 0; + /* This will change if drawing unfilled tris */ + _swrast_SetFacing(ctx, 0); + _swrast_render_start(ctx); /* Important */ diff --git a/src/mesa/swrast_setup/ss_triangle.c b/src/mesa/swrast_setup/ss_triangle.c index 628e9288e87..830e0645db1 100644 --- a/src/mesa/swrast_setup/ss_triangle.c +++ b/src/mesa/swrast_setup/ss_triangle.c @@ -1,8 +1,8 @@ /* * Mesa 3-D graphics library - * Version: 6.1 + * Version: 7.1 * - * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -68,6 +68,8 @@ static void _swsetup_render_line_tri( GLcontext *ctx, return; } + _swrast_SetFacing(ctx, facing); + if (ctx->Light.ShadeModel == GL_FLAT) { COPY_CHAN4(c[0], v0->color); COPY_CHAN4(c[1], v1->color); @@ -127,6 +129,8 @@ static void _swsetup_render_point_tri( GLcontext *ctx, return; } + _swrast_SetFacing(ctx, facing); + if (ctx->Light.ShadeModel == GL_FLAT) { /* save colors/indexes for v0, v1 vertices */ COPY_CHAN4(c[0], v0->color); @@ -311,6 +315,4 @@ void _swsetup_choose_trifuncs( GLcontext *ctx ) tnl->Driver.Render.Quad = quad_tab[ind]; tnl->Driver.Render.Line = swsetup_line; tnl->Driver.Render.Points = swsetup_points; - - ctx->_Facing = 0; } diff --git a/src/mesa/swrast_setup/ss_tritmp.h b/src/mesa/swrast_setup/ss_tritmp.h index 59c534ee5ee..0e0cbce3c14 100644 --- a/src/mesa/swrast_setup/ss_tritmp.h +++ b/src/mesa/swrast_setup/ss_tritmp.h @@ -43,7 +43,6 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) v[1] = &verts[e1]; v[2] = &verts[e2]; - if (IND & (SS_TWOSIDE_BIT | SS_OFFSET_BIT | SS_UNFILLED_BIT)) { GLfloat ex = v[0]->win[0] - v[2]->win[0]; @@ -55,7 +54,6 @@ static void TAG(triangle)(GLcontext *ctx, GLuint e0, GLuint e1, GLuint e2 ) if (IND & (SS_TWOSIDE_BIT | SS_UNFILLED_BIT)) { facing = (cc < 0.0) ^ ctx->Polygon._FrontBit; - ctx->_Facing = facing; if (IND & SS_UNFILLED_BIT) mode = facing ? ctx->Polygon.BackMode : ctx->Polygon.FrontMode; |