diff options
author | Brian Paul <brian.paul@tungstengraphics.com> | 2002-01-27 18:32:03 +0000 |
---|---|---|
committer | Brian Paul <brian.paul@tungstengraphics.com> | 2002-01-27 18:32:03 +0000 |
commit | 2a182a98973edc9ecf2936b1288485bb2b3fa722 (patch) | |
tree | 4c832bef597d1cbbccb7e7ab80f508aac2bbaba9 /src/mesa/swrast/s_drawpix.c | |
parent | 6a731f343e847226537080122e2fb327e2486564 (diff) |
LOTS of changes, building upon Klaus's work.
struct sw_span is used throughout span/fragment processing.
This is leading to less code and more chances for optimization.
Diffstat (limited to 'src/mesa/swrast/s_drawpix.c')
-rw-r--r-- | src/mesa/swrast/s_drawpix.c | 190 |
1 files changed, 88 insertions, 102 deletions
diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index dfe7166880..4be186bb91 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -1,4 +1,4 @@ -/* $Id: s_drawpix.c,v 1.25 2002/01/15 21:49:58 brianp Exp $ */ +/* $Id: s_drawpix.c,v 1.26 2002/01/27 18:32:03 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -489,46 +489,37 @@ draw_index_pixels( GLcontext *ctx, GLint x, GLint y, { const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0; const GLint desty = y; - GLint row, drawWidth; - GLdepth zspan[MAX_WIDTH]; - GLfloat fogSpan[MAX_WIDTH]; + GLint row, drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; + struct sw_span span; - drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; + INIT_SPAN(span); + span.arrayMask |= SPAN_INDEX; - /* Fragment depth values */ - if (ctx->Depth.Test || ctx->Fog.Enabled) { - GLdepth zval = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMaxF); - GLfloat fog; - GLint i; - - if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) - fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterFogCoord); - else - fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance); - - for (i = 0; i < drawWidth; i++) { - zspan[i] = zval; - fogSpan[i] = fog; - } - } + if (ctx->Depth.Test) + _mesa_span_default_z(ctx, &span); + if (ctx->Fog.Enabled) + _mesa_span_default_fog(ctx, &span); /* * General solution */ for (row = 0; row < height; row++, y++) { - GLuint indexes[MAX_WIDTH]; const GLvoid *source = _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_COLOR_INDEX, type, 0, row, 0); - _mesa_unpack_index_span(ctx, drawWidth, GL_UNSIGNED_INT, indexes, + _mesa_unpack_index_span(ctx, drawWidth, GL_UNSIGNED_INT, + span.color.index, type, source, &ctx->Unpack, ctx->_ImageTransferState); if (zoom) { - _mesa_write_zoomed_index_span(ctx, drawWidth, x, y, zspan, fogSpan, - indexes, desty); + _mesa_write_zoomed_index_span(ctx, drawWidth, x, y, + span.zArray, span.fogArray, + span.color.index, desty); } else { - _old_write_index_span(ctx, drawWidth, x, y, zspan, fogSpan, indexes, - NULL, GL_BITMAP); + span.x = x; + span.y = y; + span.end = drawWidth; + _mesa_write_index_span(ctx, &span, GL_BITMAP); } } } @@ -594,7 +585,6 @@ draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y, } - /* * Do a glDrawPixels of depth values. */ @@ -606,9 +596,12 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, const GLboolean bias_or_scale = ctx->Pixel.DepthBias!=0.0 || ctx->Pixel.DepthScale!=1.0; const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0; const GLint desty = y; - GLchan rgba[MAX_WIDTH][4]; - GLuint ispan[MAX_WIDTH]; GLint drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; + struct sw_span span; + + INIT_SPAN(span); + span.arrayMask |= SPAN_Z; + span.end = drawWidth; if (type != GL_BYTE && type != GL_UNSIGNED_BYTE @@ -621,42 +614,28 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, return; } - /* Colors or indexes */ - if (ctx->Visual.rgbMode) { - GLint i; - GLint r, g, b, a; - UNCLAMPED_FLOAT_TO_CHAN(r, ctx->Current.RasterColor[0]); - UNCLAMPED_FLOAT_TO_CHAN(g, ctx->Current.RasterColor[1]); - UNCLAMPED_FLOAT_TO_CHAN(b, ctx->Current.RasterColor[2]); - UNCLAMPED_FLOAT_TO_CHAN(a, ctx->Current.RasterColor[3]); - for (i = 0; i < drawWidth; i++) { - rgba[i][RCOMP] = r; - rgba[i][GCOMP] = g; - rgba[i][BCOMP] = b; - rgba[i][ACOMP] = a; - } - } - else { - GLint i; - for (i = 0; i < drawWidth; i++) { - ispan[i] = ctx->Current.RasterIndex; - } - } + _mesa_span_default_color(ctx, &span); + + if (ctx->Fog.Enabled) + _mesa_span_default_fog(ctx, &span); if (type==GL_UNSIGNED_SHORT && sizeof(GLdepth)==sizeof(GLushort) && !bias_or_scale && !zoom && ctx->Visual.rgbMode) { /* Special case: directly write 16-bit depth values */ GLint row; for (row = 0; row < height; row++, y++) { - GLdepth zspan[MAX_WIDTH]; const GLushort *zptr = (const GLushort *) _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0); GLint i; - for (i = 0; i < width; i++) - zspan[i] = zptr[i]; - _old_write_rgba_span(ctx, width, x, y, zspan, 0, rgba, - NULL, GL_BITMAP); + for (i = 0; i < drawWidth; i++) + span.zArray[i] = zptr[i]; + + span.x = x; + span.y = y; + span.end = drawWidth; + span.filledDepth = GL_TRUE; /* XXX temporary */ + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } else if (type==GL_UNSIGNED_INT && ctx->Visual.depthBits == 32 @@ -667,8 +646,15 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, const GLuint *zptr = (const GLuint *) _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0); - _old_write_rgba_span(ctx, width, x, y, zptr, 0, rgba, - NULL, GL_BITMAP); + + /* XXX get rid of this loop. use zArray pointer in span */ + GLint i; + for (i = 0; i < drawWidth; i++) + span.zArray[i] = zptr[i]; + span.x = x; + span.y = y; + span.end = drawWidth; + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } else { @@ -676,7 +662,6 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, GLint row; for (row = 0; row < height; row++, y++) { GLfloat fspan[MAX_WIDTH]; - GLdepth zspan[MAX_WIDTH]; const GLvoid *src = _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0); _mesa_unpack_depth_span( ctx, drawWidth, fspan, type, src, @@ -686,31 +671,35 @@ draw_depth_pixels( GLcontext *ctx, GLint x, GLint y, const GLfloat zs = ctx->DepthMaxF; GLint i; for (i = 0; i < drawWidth; i++) { - zspan[i] = (GLdepth) (fspan[i] * zs); + span.zArray[i] = (GLdepth) (fspan[i] * zs); } } if (ctx->Visual.rgbMode) { if (zoom) { - _mesa_write_zoomed_rgba_span(ctx, width, x, y, zspan, 0, - (const GLchan (*)[4]) rgba, desty); + _mesa_write_zoomed_rgba_span(ctx, width, x, y, span.zArray, 0, + (const GLchan (*)[4]) span.color.rgba, desty); } else { - _old_write_rgba_span(ctx, width, x, y, zspan, 0, - rgba, NULL, GL_BITMAP); + span.x = x; + span.y = y; + span.end = drawWidth; + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } else { if (zoom) { - _mesa_write_zoomed_index_span(ctx, width, x, y, zspan, 0, - ispan, GL_BITMAP); + _mesa_write_zoomed_index_span(ctx, drawWidth, x, y, + span.zArray, 0, + span.color.index, GL_BITMAP); } else { - _old_write_index_span(ctx, width, x, y, zspan, 0, - ispan, NULL, GL_BITMAP); + span.x = x; + span.y = y; + span.end = drawWidth; + _mesa_write_index_span(ctx, &span, GL_BITMAP); } } - } } } @@ -728,11 +717,13 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, const struct gl_pixelstore_attrib *unpack = &ctx->Unpack; const GLboolean zoom = ctx->Pixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0; const GLint desty = y; - GLdepth zspan[MAX_WIDTH]; - GLfloat fogSpan[MAX_WIDTH]; GLboolean quickDraw; GLfloat *convImage = NULL; GLuint transferOps = ctx->_ImageTransferState; + struct sw_span span; + + INIT_SPAN(span); + span.arrayMask |= SPAN_RGBA; if (!_mesa_is_legal_format_and_type(format, type)) { _mesa_error(ctx, GL_INVALID_ENUM, "glDrawPixels(format or type)"); @@ -756,11 +747,14 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance); for (i=0;i<width;i++) { - zspan[i] = z; - fogSpan[i] = fog; + span.zArray[i] = z; + span.fogArray[i] = fog; } } + if (ctx->Fog.Enabled) + _mesa_span_default_fog(ctx, &span); + span.arrayMask |= SPAN_Z; if (SWRAST_CONTEXT(ctx)->_RasterMask == 0 && !zoom && x >= 0 && y >= 0 && x + width <= ctx->DrawBuffer->Width @@ -827,54 +821,47 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, * General solution */ { - GLchan rgba[MAX_WIDTH][4]; GLint row; if (width > MAX_WIDTH) width = MAX_WIDTH; for (row = 0; row < height; row++, y++) { const GLvoid *source = _mesa_image_address(unpack, pixels, width, height, format, type, 0, row, 0); - _mesa_unpack_chan_color_span(ctx, width, GL_RGBA, (GLchan *) rgba, + /* printf("Unpack f=0x%x t=0x%x\n", format, type);*/ + _mesa_unpack_chan_color_span(ctx, width, GL_RGBA, + (GLchan *) span.color.rgba, format, type, source, unpack, transferOps); + if (0){ + int k; + for (k = 0; k < width; k++) + printf("%02x ", span.color.rgba[k][3]); + printf("\n"); + } + if ((ctx->Pixel.MinMaxEnabled && ctx->MinMax.Sink) || (ctx->Pixel.HistogramEnabled && ctx->Histogram.Sink)) continue; - if (ctx->Texture._ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { - GLchan primary_rgba[MAX_WIDTH][4]; - GLuint unit; - - DEFMARRAY(GLfloat, texcoord, MAX_WIDTH, 4);/* mac 32k limitation */ - CHECKARRAY(texcoord, return); /* mac 32k limitation */ - - /* XXX not sure how multitexture is supposed to work here */ - MEMCPY(primary_rgba, rgba, 4 * width * sizeof(GLchan)); - - for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { - if (ctx->Texture.Unit[unit]._ReallyEnabled) { - _mesa_pixeltexgen(ctx, width, (const GLchan (*)[4]) rgba, - texcoord); - _old_swrast_texture_fragments( ctx, unit, width, - texcoord, NULL, - (CONST GLchan (*)[4]) primary_rgba, - rgba); - } - } - UNDEFARRAY(texcoord); /* mac 32k limitation */ + if (ctx->Pixel.PixelTextureEnabled && ctx->Texture._ReallyEnabled) { + span.end = width; + _swrast_pixel_texture(ctx, &span); } if (quickDraw) { (*swrast->Driver.WriteRGBASpan)(ctx, width, x, y, - (CONST GLchan (*)[4]) rgba, NULL); + (CONST GLchan (*)[4]) span.color.rgba, NULL); } else if (zoom) { - _mesa_write_zoomed_rgba_span(ctx, width, x, y, zspan, fogSpan, - (CONST GLchan (*)[4]) rgba, desty); + _mesa_write_zoomed_rgba_span(ctx, width, x, y, span.zArray, + span.fogArray, + (CONST GLchan (*)[4]) span.color.rgba, desty); } else { - _old_write_rgba_span(ctx, (GLuint) width, x, y, zspan, fogSpan, - rgba, NULL, GL_BITMAP); + span.x = x; + span.y = y; + span.end = width; + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } } @@ -905,7 +892,6 @@ _swrast_DrawPixels( GLcontext *ctx, _swrast_validate_derived( ctx ); RENDER_START(swrast,ctx); - switch (format) { case GL_STENCIL_INDEX: draw_stencil_pixels( ctx, x, y, width, height, type, pixels ); |