diff options
Diffstat (limited to 'src/mesa/swrast')
-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_points.c | 10 | ||||
-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 |
10 files changed, 48 insertions, 12 deletions
diff --git a/src/mesa/swrast/s_aalinetemp.h b/src/mesa/swrast/s_aalinetemp.h index e7911fec3b5..ca08203d831 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) INIT_SPAN(line.span, GL_LINE); line.span.arrayMask = 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 29609add179..0827b3db9eb 100644 --- a/src/mesa/swrast/s_aatritemp.h +++ b/src/mesa/swrast/s_aatritemp.h @@ -65,7 +65,7 @@ GLfloat attrPlane[FRAG_ATTRIB_MAX][4][4]; GLfloat wPlane[4]; /* win[3] */ #endif - GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceSign; + GLfloat bf = SWRAST_CONTEXT(ctx)->_BackfaceCullSign; (void) swrast; @@ -104,6 +104,7 @@ majDx = vMax->attrib[FRAG_ATTRIB_WPOS][0] - vMin->attrib[FRAG_ATTRIB_WPOS][0]; majDy = vMax->attrib[FRAG_ATTRIB_WPOS][1] - vMin->attrib[FRAG_ATTRIB_WPOS][1]; + /* front/back-face determination and cullling */ { const GLfloat botDx = vMid->attrib[FRAG_ATTRIB_WPOS][0] - vMin->attrib[FRAG_ATTRIB_WPOS][0]; const GLfloat botDy = vMid->attrib[FRAG_ATTRIB_WPOS][1] - vMin->attrib[FRAG_ATTRIB_WPOS][1]; @@ -112,6 +113,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 39569256514..3bf9804befc 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. @@ -764,6 +769,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 daa07e15783..aebc80c2080 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; @@ -156,6 +157,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 4067fd68867..767e485ede2 100644 --- a/src/mesa/swrast/s_fragprog.c +++ b/src/mesa/swrast/s_fragprog.c @@ -120,7 +120,7 @@ init_machine(GLcontext *ctx, struct gl_program_machine *machine, /* if running a GLSL program (not ARB_fragment_program) */ 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 1accfc67e2c..1abf8d6c7f3 100644 --- a/src/mesa/swrast/s_linetemp.h +++ b/src/mesa/swrast/s_linetemp.h @@ -308,6 +308,9 @@ NAME( GLcontext *ctx, const SWvertex *vert0, const SWvertex *vert1 ) span.interpMask = interpFlags; span.arrayMask = SPAN_XY; + span.facing = swrast->PointLineFacing; + + /* * Draw */ diff --git a/src/mesa/swrast/s_points.c b/src/mesa/swrast/s_points.c index dd664b980ed..d60e175baa0 100644 --- a/src/mesa/swrast/s_points.c +++ b/src/mesa/swrast/s_points.c @@ -106,6 +106,8 @@ sprite_point(GLcontext *ctx, const SWvertex *vert) INIT_SPAN(span, GL_POINT); span.interpMask = SPAN_Z | SPAN_RGBA; + span.facing = swrast->PointLineFacing; + span.red = ChanToFixed(vert->color[0]); span.green = ChanToFixed(vert->color[1]); span.blue = ChanToFixed(vert->color[2]); @@ -280,6 +282,8 @@ smooth_point(GLcontext *ctx, const SWvertex *vert) span.interpMask = SPAN_Z | SPAN_RGBA; span.arrayMask = SPAN_COVERAGE | SPAN_MASK; + span.facing = swrast->PointLineFacing; + span.red = ChanToFixed(vert->color[0]); span.green = ChanToFixed(vert->color[1]); span.blue = ChanToFixed(vert->color[2]); @@ -386,6 +390,7 @@ large_point(GLcontext *ctx, const SWvertex *vert) /* span init */ INIT_SPAN(span, GL_POINT); span.arrayMask = SPAN_XY; + span.facing = swrast->PointLineFacing; if (ciMode) { span.interpMask = SPAN_Z | SPAN_INDEX; @@ -492,7 +497,8 @@ pixel_point(GLcontext *ctx, const SWvertex *vert) /* check if we need to flush */ if (span->end >= MAX_WIDTH || - (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT))) { + (swrast->_RasterMask & (BLEND_BIT | LOGIC_OP_BIT | MASKING_BIT)) || + span->facing != swrast->PointLineFacing) { if (ciMode) _swrast_write_index_span(ctx, span); else @@ -502,6 +508,8 @@ pixel_point(GLcontext *ctx, const SWvertex *vert) count = span->end; + span->facing = swrast->PointLineFacing; + /* fragment attributes */ if (ciMode) { span->array->index[count] = (GLuint) vert->attrib[FRAG_ATTRIB_CI][0]; diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index c2555452173..938cdefa561 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->attrib[FRAG_ATTRIB_WPOS][1] - v0->attrib[FRAG_ATTRIB_WPOS][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 cded4a6c1c4..c609210c0ec 100644 --- a/src/mesa/swrast/s_tritemp.h +++ b/src/mesa/swrast/s_tritemp.h @@ -136,7 +136,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; const GLint snapMask = ~((FIXED_ONE / (1 << SUB_PIXEL_BITS)) - 1); /* for x/y coord snapping */ GLfixed vMin_fx, vMin_fy, vMid_fx, vMid_fy, vMax_fx, vMax_fy; @@ -235,6 +235,7 @@ static void NAME(GLcontext *ctx, const SWvertex *v0, { const GLfloat area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; /* Do backface culling */ + if (area * bf < 0.0) return; @@ -242,10 +243,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 85a27fd55bf..047f7991e64 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -143,6 +143,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. * |