- /* draw to zero or two or more buffers */
- multi_write_index_span( ctx, n, x, y, index, mask );
- }
- else {
- /* normal situation: draw to exactly one buffer */
- if (ctx->Color.IndexLogicOpEnabled) {
- _mesa_logicop_ci_span( ctx, n, x, y, index, mask );
- }
-
- if (ctx->Color.IndexMask == 0) {
- return;
- }
- else if (ctx->Color.IndexMask != 0xffffffff) {
- _mesa_mask_index_span( ctx, n, x, y, index );
- }
-
- /* write pixels */
- (*swrast->Driver.WriteCI32Span)( ctx, n, x, y, index, mask );
- }
-}
-
-
-/*
- * Apply fragment processing to a span of RGBA fragments.
- * Input:
- * n - number of fragments in the span
- * x,y - location of first (left) fragment
- * fog - array of fog factor values in [0,1]
- */
-void
-_old_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
- const GLdepth z[], const GLfloat fog[],
- GLchan rgbaIn[][4], const GLfloat coverage[],
- GLenum primitive )
-{
- const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT |
- LOGIC_OP_BIT | TEXTURE_BIT;
- GLubyte mask[MAX_WIDTH];
- GLboolean write_all = GL_TRUE;
- GLchan rgbaBackup[MAX_WIDTH][4];
- GLchan (*rgba)[4];
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- /* init mask to 1's (all pixels are to be written) */
- MEMSET(mask, 1, n);
-
- if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
- if ((n = old_clip_span( ctx,n,x,y,mask)) == 0) {
- return;
- }
- if (mask[0] == 0)
- write_all = GL_FALSE;
- }
-
- if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits))
- || (swrast->_RasterMask & MULTI_DRAW_BIT)) {
- /* must make a copy of the colors since they may be modified */
- MEMCPY( rgbaBackup, rgbaIn, 4 * n * sizeof(GLchan) );
- rgba = rgbaBackup;
- }
- else {
- rgba = rgbaIn;
- }
-
- /* Do the scissor test */
- if (ctx->Scissor.Enabled) {
- if ((n = _old_scissor_span( ctx, n, x, y, mask )) == 0) {
- return;
- }
- if (mask[0] == 0)
- write_all = GL_FALSE;
- }
-
- /* Polygon Stippling */
- if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
- old_stipple_polygon_span( ctx, n, x, y, mask );
- write_all = GL_FALSE;
- }
-
- /* Do the alpha test */
- if (ctx->Color.AlphaEnabled) {
- if (_old_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) {
- return;
- }
- write_all = GL_FALSE;
- }
-
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_old_stencil_and_ztest_span(ctx, n, x, y, z, mask) == GL_FALSE) {
- return;
- }
- write_all = GL_FALSE;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- GLuint m = _old_depth_test_span( ctx, n, x, y, z, mask );
- if (m == 0) {
- return;
- }
- if (m < n) {
- write_all = GL_FALSE;
- }
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
- /* Per-pixel fog */
- if (ctx->Fog.Enabled) {
- if (fog && !swrast->_PreferPixelFog)
- _old_fog_rgba_pixels( ctx, n, fog, rgba );
- else
- _old_depth_fog_rgba_pixels( ctx, n, z, rgba );
- }
-
- /* Antialias coverage application */
- if (coverage) {
- GLuint i;
- for (i = 0; i < n; i++) {
- rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * coverage[i]);
- }
- }
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- multi_write_rgba_span( ctx, n, x, y, (const GLchan (*)[4]) rgba, mask );
- }
- else {
- /* normal: write to exactly one buffer */
- /* logic op or blending */
- const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
-
- if (ctx->Color.ColorLogicOpEnabled) {
- _mesa_logicop_rgba_span( ctx, n, x, y, rgba, mask );
- }
- else if (ctx->Color.BlendEnabled) {
- _mesa_blend_span( ctx, n, x, y, rgba, mask );
- }
-
- /* Color component masking */
- if (colorMask == 0x0) {
- return;
- }
- else if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, n, x, y, rgba );
- }
-
- /* write pixels */
- (*swrast->Driver.WriteRGBASpan)( ctx, n, x, y,
- (const GLchan (*)[4]) rgba,
- write_all ? ((const GLubyte *) NULL) : mask );
-
- if (swrast->_RasterMask & ALPHABUF_BIT) {
- _mesa_write_alpha_span( ctx, n, x, y,
- (const GLchan (*)[4]) rgba,
- write_all ? ((const GLubyte *) NULL) : mask );
- }
- }
-}
-
-
-/*
- * Write a horizontal span of color index pixels to the frame buffer.
- * Stenciling, Depth-testing, etc. are done as needed.
- * Input: primitive - either GL_POINT, GL_LINE, GL_POLYGON, or GL_BITMAP
- */
-void
-_mesa_write_index_span( GLcontext *ctx, struct sw_span *span,
- const GLfloat fog[MAX_WIDTH], GLenum primitive)
-{
- const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT | LOGIC_OP_BIT;
- GLuint indexBackup[MAX_WIDTH];
- GLuint *index; /* points to indexIn or indexBackup */
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
-
- SET_MASK_TO_ONE(span);
-
- if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
- if (clip_span(ctx,span) == GL_FALSE) {
- return;
- }
- }
-
- if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits))
- || (swrast->_RasterMask & MULTI_DRAW_BIT)) {
- /* Make copy of color indexes */
- MEMCPY( indexBackup, span->color.index, span->end * sizeof(GLuint) );
- index = indexBackup;
- }
- else {
- index = span->color.index;
- }
-
-
- /* Do the scissor test */
- if (ctx->Scissor.Enabled) {
- if (_mesa_scissor_span( ctx, span ) == GL_FALSE) {
- return;
- }
- }
-
- /* Polygon Stippling */
- if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
- stipple_polygon_span(ctx, span);
- }
-
-
- /* I have to think where to put this!! */
- if (span->activeMask & SPAN_Z) {
- SW_SPAN_SET_FLAG(span->filledDepth);
-
- if (ctx->Visual.depthBits <= 16) {
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = FixedToInt(zval);
- zval += span->zStep;
- }
- }
- else {
- /* Deep Z buffer, no fixed->int shift */
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = zval;
- zval += span->zStep;
- }
- }
- }
-
-
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
- return;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == 0)
- return;
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
- if (ctx->Color.DrawBuffer == GL_NONE) {
- /* write no pixels */
- return;
- }
-
- if (ctx->Fog.Enabled) {
- if (fog != NULL && !swrast->_PreferPixelFog)
- _mesa_fog_ci_pixels_with_array( ctx, span, fog, index);
- else if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_ci_pixels( ctx, span, index);
- else
- _mesa_depth_fog_ci_pixels( ctx, span, index);
- }
-
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- ASSERT(span->coverage[i] < 16);
- index[i] = (index[i] & ~0xf) | span->coverage[i];
- }
- }
-#endif
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- /* draw to zero or two or more buffers */
- multi_write_index_span( ctx, span->end, span->x, span->y,
- index, span->mask );
- }
- else {
- /* normal situation: draw to exactly one buffer */
- if (ctx->Color.IndexLogicOpEnabled) {
- _mesa_logicop_ci_span( ctx, span->end, span->x, span->y,
- index, span->mask );
- }
-
- if (ctx->Color.IndexMask == 0) {
- return;
- }
- else if (ctx->Color.IndexMask != 0xffffffff) {
- _mesa_mask_index_span( ctx, span->end, span->x, span->y, index );
- }
-
- /* write pixels */
- (*swrast->Driver.WriteCI32Span)( ctx, span->end, span->x,
- span->y, index, span->mask );
- }
-}
-
-
-
-
-void
-_mesa_write_monoindex_span( GLcontext *ctx, struct sw_span *span,
- GLuint index, GLenum primitive )
-{
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
- GLuint i;
-
-
- SET_MASK_TO_ONE(span);
-
- if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
- if (clip_span(ctx,span) == GL_FALSE) {
- return;
- }
- }
-
- /* Do the scissor test */
- if (ctx->Scissor.Enabled) {
- if (_mesa_scissor_span( ctx, span ) == GL_FALSE) {
- return;
- }
- }
-
- /* Polygon Stippling */
- if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
- stipple_polygon_span( ctx, span);
- }
-
-
- /* I have to think where to put this!! */
- if (span->activeMask & SPAN_Z) {
- SW_SPAN_SET_FLAG(span->filledDepth);
-
- if (ctx->Visual.depthBits <= 16) {
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = FixedToInt(zval);
- zval += span->zStep;
- }
- }
- else {
- /* Deep Z buffer, no fixed->int shift */
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = zval;
- zval += span->zStep;
- }
- }
- }
-
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
- return;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_mesa_depth_test_span( ctx, span) == 0)
- return;
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
- if (ctx->Color.DrawBuffer == GL_NONE) {
- /* write no pixels */
- return;
- }
-
- if (ctx->Fog.Enabled
- || ctx->Color.IndexLogicOpEnabled
- || ctx->Color.IndexMask != 0xffffffff
-#if 0
- || span->coverage) {
-#else
- ) {
-#endif
- /* different index per pixel */
- GLuint indexes[MAX_WIDTH];
- for (i = 0; i < span->end; i++) {
- indexes[i] = index;
- }
-
- if (ctx->Fog.Enabled) {
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_ci_pixels( ctx, span, indexes );
- else
- _mesa_depth_fog_ci_pixels( ctx, span, indexes );
- }
-
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- ASSERT(span->coverage[i] < 16);
- indexes[i] = (indexes[i] & ~0xf) | span->coverage[i];
- }
- }
-#endif
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- /* draw to zero or two or more buffers */
- multi_write_index_span( ctx, span->end, span->x, span->y, indexes, span->mask );
- }
- else {
- /* normal situation: draw to exactly one buffer */
- if (ctx->Color.IndexLogicOpEnabled) {
- _mesa_logicop_ci_span( ctx, span->end, span->x, span->y, indexes, span->mask );
- }
- if (ctx->Color.IndexMask == 0) {
- return;
- }
- else if (ctx->Color.IndexMask != 0xffffffff) {
- _mesa_mask_index_span( ctx, span->end, span->x, span->y, indexes );
- }
- (*swrast->Driver.WriteCI32Span)( ctx, span->end, span->x, span->y, indexes, span->mask );
- }
- }
- else {
- /* same color index for all pixels */
- ASSERT(!ctx->Color.IndexLogicOpEnabled);
- ASSERT(ctx->Color.IndexMask == 0xffffffff);
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- /* draw to zero or two or more buffers */
- GLuint indexes[MAX_WIDTH];
- for (i = 0; i < span->end; i++)
- indexes[i] = index;
- multi_write_index_span( ctx, span->end, span->x, span->y, indexes, span->mask );
- }
- else {
- /* normal situation: draw to exactly one buffer */
- (*swrast->Driver.WriteMonoCISpan)( ctx, span->end, span->x, span->y, index, span->mask );
- }
- }
-}
-
-
-
-/*
- * Apply fragment processing to a span of RGBA fragments.
- * Input:
- */
-void
-_mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
- const GLfloat fog[MAX_WIDTH], GLenum primitive)
-{
- const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT |
- LOGIC_OP_BIT | TEXTURE_BIT;
- GLchan rgbaBackup[MAX_WIDTH][4];
- GLchan (*rgba)[4];
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
-
- SET_MASK_TO_ONE(span);
-
- if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
- if (clip_span( ctx,span ) == GL_FALSE) {
- return;
- }
- }
-
-
- /* Do the scissor test */
- if (ctx->Scissor.Enabled) {
- if (_mesa_scissor_span( ctx, span ) == GL_FALSE) {
- return;
- }
- }
-
-
- /* Polygon Stippling */
- if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
- stipple_polygon_span( ctx, span);
- }
-
-
- if ((primitive==GL_BITMAP && (swrast->_RasterMask & modBits))
- || (swrast->_RasterMask & MULTI_DRAW_BIT)) {
- /* must make a copy of the colors since they may be modified */
- MEMCPY( rgbaBackup, span->color.rgba, 4 * span->end * sizeof(GLchan) );
- rgba = rgbaBackup;
- }
- else {
- rgba = span->color.rgba;
- }
-
-
- /* Do the alpha test */
- if (ctx->Color.AlphaEnabled) {
- if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4]) rgba) == 0) {
- return;
- }
- }
-
- /* I have to think where to put this!! */
- if (span->activeMask & SPAN_Z) {
- SW_SPAN_SET_FLAG(span->filledDepth);
-
- if (ctx->Visual.depthBits <= 16) {
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = FixedToInt(zval);
- zval += span->zStep;
- }
- }
- else {
- /* Deep Z buffer, no fixed->int shift */
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = zval;
- zval += span->zStep;
- }
- }
- }
-
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
- return;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == GL_FALSE)
- return;
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
- /* Per-pixel fog */
- if (ctx->Fog.Enabled) {
- if (fog != NULL && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels_with_array( ctx, span, fog, rgba);
- else if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels( ctx, span, rgba );
- else
- _mesa_depth_fog_rgba_pixels( ctx, span, rgba );
- }
-
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]);
- }
- }
-#endif
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- multi_write_rgba_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask );
- }
- else {
- /* normal: write to exactly one buffer */
- /* logic op or blending */
- const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
-
- if (ctx->Color.ColorLogicOpEnabled) {
- _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
- else if (ctx->Color.BlendEnabled) {
- _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
-
- /* Color component masking */
- if (colorMask == 0x0) {
- return;
- }
- else if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba );
- }
-
- /* write pixels */
- (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
-
- if (swrast->_RasterMask & ALPHABUF_BIT) {
- _mesa_write_alpha_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
- }
- }
-}
-
-
-/*
- * Write a horizontal span of color pixels to the frame buffer.
- * The color is initially constant for the whole span.
- * Alpha-testing, stenciling, depth-testing, and blending are done as needed.
- * Input: r, g, b, a - the color of the pixels
- * primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP.
- */
-void
-_mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
- const GLchan color[4], GLenum primitive )
-{
- const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
- GLuint i;
- GLchan rgba[MAX_WIDTH][4];
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
-
- SET_MASK_TO_ONE(span);
-
- if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
- if (clip_span(ctx,span) == GL_FALSE) {
- return;
- }
- }
-
- /* Do the scissor test */
- if (ctx->Scissor.Enabled) {
- if (_mesa_scissor_span( ctx, span ) == GL_FALSE) {
- return;
- }
- }
-
- /* Polygon Stippling */
- if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
- stipple_polygon_span( ctx, span);
- }
-
- /* Do the alpha test */
- if (ctx->Color.AlphaEnabled) {
- SW_SPAN_SET_FLAG(span->filledAlpha);
- for (i = 0; i < span->end; i++) {
- rgba[i][ACOMP] = color[ACOMP];
- }
- if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4])rgba) == 0) {
- return;
- }
- }
-
- /* I have to think where to put this!! */
- if (span->activeMask & SPAN_Z) {
- SW_SPAN_SET_FLAG(span->filledDepth);
-
- if (ctx->Visual.depthBits <= 16) {
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = FixedToInt(zval);
- zval += span->zStep;
- }
- }
- else {
- /* Deep Z buffer, no fixed->int shift */
- GLuint i;
- GLfixed zval = span->z;
- for (i = 0; i < span->end; i++) {
- span->depth[i] = zval;
- zval += span->zStep;
- }
- }
- }
-
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
- return;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == 0)
- return;
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
- if (ctx->Color.DrawBuffer == GL_NONE) {
- /* write no pixels */
- return;
- }
-
- if (ctx->Color.ColorLogicOpEnabled || colorMask != 0xffffffff ||
-#if 0
- (swrast->_RasterMask & (BLEND_BIT | FOG_BIT)) || coverage) {
-#else
- (swrast->_RasterMask & (BLEND_BIT | FOG_BIT))) {
-#endif
- /* assign same color to each pixel */
- SW_SPAN_SET_FLAG(span->filledColor);
- for (i = 0; i < span->end; i++) {
- if (span->mask[i]) {
- COPY_CHAN4(rgba[i], color);
- }
- }
-
- /* Per-pixel fog */
- if (ctx->Fog.Enabled) {
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels( ctx, span, rgba );
- else
- _mesa_depth_fog_rgba_pixels( ctx, span, rgba );
- }
-
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]);
- }
- }
-#endif
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- multi_write_rgba_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba, span->mask );
- }
- else {
- /* normal: write to exactly one buffer */
- if (ctx->Color.ColorLogicOpEnabled) {
- _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
- else if (ctx->Color.BlendEnabled) {
- _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
-
- /* Color component masking */
- if (colorMask == 0x0) {
- return;
- }
- else if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba );
- }
-
- /* write pixels */
- (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
- if (swrast->_RasterMask & ALPHABUF_BIT) {
- _mesa_write_alpha_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
- }
- }
- }
- else {
- /* same color for all pixels */
- ASSERT(!ctx->Color.BlendEnabled);
- ASSERT(!ctx->Color.ColorLogicOpEnabled);
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- SW_SPAN_SET_FLAG(span->filledColor);
- for (i = 0; i < span->end; i++) {
- if (span->mask[i]) {
- COPY_CHAN4(rgba[i], color);
- }
- }
- multi_write_rgba_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba, span->mask );
- }
- else {
- (*swrast->Driver.WriteMonoRGBASpan)( ctx, span->end, span->x, span->y, color, span->mask );
- if (swrast->_RasterMask & ALPHABUF_BIT) {
- _mesa_write_mono_alpha_span( ctx, span->end, span->x, span->y,
- (GLchan) color[ACOMP],
- span->writeAll ? ((const GLubyte *) NULL) : span->mask );
- }
- }
- }
-}
-
-
-
-/*
- * Add specular color to base color. This is used only when
- * GL_LIGHT_MODEL_COLOR_CONTROL = GL_SEPARATE_SPECULAR_COLOR.
- */
-static void
-add_colors(CONST struct sw_span *span, GLchan rgba[][4])
-{
- GLuint i;
- ASSERT(span->filledSpecular == GL_TRUE);
- ASSERT(span->filledColor == GL_TRUE);
-
- for (i = 0; i < span->end; i++) {
-#if CHAN_TYPE == GL_FLOAT
- /* no clamping */
- rgba[i][RCOMP] += span->specular[i][RCOMP];
- rgba[i][GCOMP] += span->specular[i][GCOMP];
- rgba[i][BCOMP] += span->specular[i][BCOMP];
-#else
- GLint r = rgba[i][RCOMP] + span->specular[i][RCOMP];
- GLint g = rgba[i][GCOMP] + span->specular[i][GCOMP];
- GLint b = rgba[i][BCOMP] + span->specular[i][BCOMP];
- rgba[i][RCOMP] = (GLchan) MIN2(r, CHAN_MAX);
- rgba[i][GCOMP] = (GLchan) MIN2(g, CHAN_MAX);
- rgba[i][BCOMP] = (GLchan) MIN2(b, CHAN_MAX);
-#endif
- }
-}
-
-
-/*
- * Write a horizontal span of textured pixels to the frame buffer.
- * The color of each pixel is different.
- * Alpha-testing, stenciling, depth-testing, and blending are done
- * as needed.
- * Input: span - contains span-data with the exception of
- * fog - array of fog factor values in [0,1]
- * primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP.
- */
-void
-_mesa_write_texture_span( GLcontext *ctx, struct sw_span *span,
- const GLfloat fog[MAX_WIDTH], GLenum primitive )
-{
- const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
- GLchan rgbaBackup[MAX_WIDTH][4];
- GLchan (*rgba)[4]; /* points to either rgbaIn or rgbaBackup */
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
- SET_MASK_TO_ONE(span);
-
- if ((swrast->_RasterMask & WINCLIP_BIT) || primitive==GL_BITMAP) {
- if (clip_span(ctx,span) == GL_FALSE) {
- return;
- }
- }
-
- /* Do the scissor test */
- if (ctx->Scissor.Enabled) {
- if (_mesa_scissor_span( ctx, span ) == GL_FALSE) {
- return;
- }
- }
-
- /* Polygon Stippling */
- if (ctx->Polygon.StippleFlag && primitive==GL_POLYGON) {
- stipple_polygon_span( ctx, span);
- }
-
-
- if (primitive==GL_BITMAP || (swrast->_RasterMask & MULTI_DRAW_BIT)) {
- /* must make a copy of the colors since they may be modified */
- MEMCPY(rgbaBackup, span->color.rgba, 4 * span->end * sizeof(GLchan));
- rgba = rgbaBackup;
- }
- else {
- rgba = span->color.rgba;
- }
-
-
- /* Texture with alpha test */
- if (ctx->Color.AlphaEnabled) {
- /* Texturing without alpha is done after depth-testing which
- gives a potential speed-up. */
- ASSERT(ctx->Texture._ReallyEnabled);
- _swrast_texture_fragments( ctx, 0, span, rgba );
-
- /* Do the alpha test */
- if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4]) rgba ) == 0) {
- return;
- }
- }
-
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
- return;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == 0)
- return;
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
- /* Texture without alpha test */
- if (! ctx->Color.AlphaEnabled) {
- ASSERT(ctx->Texture._ReallyEnabled);
- _swrast_texture_fragments( ctx, 0, span, rgba );
- }
-
-
- /* Add base and specular colors */
- if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/
- (ctx->Fog.ColorSumEnabled ||
- (ctx->Light.Enabled &&
- ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)))
- add_colors(span, rgba); /* rgba = rgba + spec */
-
- /* Per-pixel fog */
- if (ctx->Fog.Enabled) {
- if (fog != NULL && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels_with_array( ctx, span, fog, rgba);
- else if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels( ctx, span, rgba );
- else
- _mesa_depth_fog_rgba_pixels(ctx, span, rgba);
- }
-
-
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]);
- }
- }
-#endif
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- multi_write_rgba_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask );
- }
- else {
- /* normal: write to exactly one buffer */
- if (ctx->Color.ColorLogicOpEnabled) {
- _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
- else if (ctx->Color.BlendEnabled) {
- _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
- if (colorMask == 0x0) {
- return;
- }
- else if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba );
- }
-
- (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? NULL : span->mask );
- if (swrast->_RasterMask & ALPHABUF_BIT) {
- _mesa_write_alpha_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? NULL : span->mask );
- }
- }
-}
-
-
-/*
- * Write a horizontal span of textured pixels to the frame buffer.
- * The color of each pixel is different.
- * Depth-testing, stenciling, scissor-testing etc. should already
- * have been done,
- * only if alpha-testing is used, depth-testing is still done in this
- * function.
- * Input: n - number of pixels in the span
- * x, y - location of leftmost pixel in the span
- * z - array of [n] z-values
- * s, t - array of (s,t) texture coordinates for each pixel
- * lambda - array of texture lambda values
- * rgba - array of [n] color components
- * mask - masked pixels
- * primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP.
- * Contributed by Klaus Niederkrueger.
- */
-static void
-masked_texture_span( GLcontext *ctx, struct sw_span *span)
-{
- const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
- GLchan rgbaBackup[MAX_WIDTH][4];
- GLchan (*rgba)[4]; /* points to either span->color.rgba or rgbaBackup */
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- /* must make a copy of the colors since they may be modified */
- MEMCPY(rgbaBackup, span->color.rgba, 4 * span->end * sizeof(GLchan));
- rgba = rgbaBackup;
- }
- else {
- rgba = span->color.rgba;
- }
-
-
- ASSERT(ctx->Texture._ReallyEnabled);
- _swrast_texture_fragments( ctx, 0, span, rgba );
-
-
- /* Texture with alpha test */
- if (ctx->Color.AlphaEnabled) {
- /* Do the alpha test */
- if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4]) rgba ) == 0) {
- return;
- }
-
- /* Depth test usually in 'rasterize_span' but if alpha test
- needed, we have to wait for that test before depth test can
- be done. */
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
- return;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == 0)
- return;
- }
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
-
- /* Add base and specular colors */
- if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/
- (ctx->Fog.ColorSumEnabled ||
- (ctx->Light.Enabled &&
- ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)))
- add_colors(span, rgba); /* rgba = rgba + spec */
-
- /* Per-pixel fog */
- if (ctx->Fog.Enabled) {
- /* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels(ctx, span, rgba);
- else
- _mesa_depth_fog_rgba_pixels(ctx, span, rgba);
- }
-
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]);
- }
- }
-#endif
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- multi_write_rgba_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask );
- }
- else {
- /* normal: write to exactly one buffer */
- if (ctx->Color.ColorLogicOpEnabled) {
- _mesa_logicop_rgba_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
- else if (ctx->Color.BlendEnabled) {
- _mesa_blend_span( ctx, span->end, span->x, span->y, rgba, span->mask );
- }
- if (colorMask == 0x0) {
- return;
- }
- else if (colorMask != 0xffffffff) {
- _mesa_mask_rgba_span( ctx, span->end, span->x, span->y, rgba );
- }
-
- (*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? NULL : span->mask );
- if (swrast->_RasterMask & ALPHABUF_BIT) {
- _mesa_write_alpha_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba,
- span->writeAll ? NULL : span->mask );
- }
- }
-}
-
-
-/*
- * As above but perform multiple stages of texture application.
- * Contributed by Klaus Niederkrueger.
- */
-static void
-masked_multitexture_span( GLcontext *ctx, struct sw_span *span)
-{
- GLchan rgbaBackup[MAX_WIDTH][4];
- GLchan (*rgba)[4]; /* points to either span->color.rgba or rgbaBackup */
- GLuint i;
- const GLuint texUnits = ctx->Const.MaxTextureUnits;
- SWcontext *swrast = SWRAST_CONTEXT(ctx);
-
-
- if ( (swrast->_RasterMask & MULTI_DRAW_BIT) || texUnits > 1) {
- /* must make a copy of the colors since they may be modified */
- MEMCPY(rgbaBackup, span->color.rgba, 4 * span->end * sizeof(GLchan));
- rgba = rgbaBackup;
- }
- else {
- rgba = span->color.rgba;
- }
-
-
- ASSERT(ctx->Texture._ReallyEnabled);
- for (i = 0; i < texUnits; i++)
- _swrast_texture_fragments( ctx, i, span, rgba );
-
- /* Texture with alpha test */
- if (ctx->Color.AlphaEnabled) {
- /* Do the alpha test */
- if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4])rgba ) == 0) {
- return;
- }
-
- /* Depth test usually in 'rasterize_span' but if alpha test
- needed, we have to wait for that test before depth test can
- be done. */
- if (ctx->Stencil.Enabled) {
- /* first stencil test */
- if (_mesa_stencil_and_ztest_span(ctx, span) == GL_FALSE)
- return;
- }
- else if (ctx->Depth.Test) {
- /* regular depth testing */
- if (_mesa_depth_test_span(ctx, span) == GL_FALSE)
- return;
- }
- }
-
- /* if we get here, something passed the depth test */
- ctx->OcclusionResult = GL_TRUE;
-
-
- /* Add base and specular colors */
- if ((span->activeMask & SPAN_SPEC) && /* Is this right test ???*/
- (ctx->Fog.ColorSumEnabled ||
- (ctx->Light.Enabled &&
- ctx->Light.Model.ColorControl == GL_SEPARATE_SPECULAR_COLOR)))
- add_colors(span, rgba); /* rgba = rgba + spec */
-
- /* Per-pixel fog */
- if (ctx->Fog.Enabled) {
- /* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _mesa_fog_rgba_pixels( ctx, span, rgba );
- else
- _mesa_depth_fog_rgba_pixels( ctx, span, rgba );
- }
-
- /* Antialias coverage application */
-#if 0
- if (span->coverage) {
- GLuint i;
- for (i = 0; i < span->end; i++) {
- rgba[i][ACOMP] = (GLchan) (rgba[i][ACOMP] * span->coverage[i]);
- }
- }
-#endif
-
- if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- multi_write_rgba_span( ctx, span->end, span->x, span->y,
- (const GLchan (*)[4]) rgba, span->mask );