X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmesa%2Fswrast%2Fs_drawpix.c;h=389012653464fa093ec73056821c54fa1e7064b6;hb=ad7306b23cbcc55cb9c943de8da2e3f80b3b46c4;hp=cfc1383a63b0930736cce914f9b0e6a2e6202d73;hpb=709892459922a32096fe9dd8261d0d92337bb02f;p=mesa.git diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index cfc1383a63b..38901265346 100644 --- a/src/mesa/swrast/s_drawpix.c +++ b/src/mesa/swrast/s_drawpix.c @@ -1,10 +1,10 @@ -/* $Id: s_drawpix.c,v 1.15 2001/03/19 02:25:36 keithw Exp $ */ +/* $Id: s_drawpix.c,v 1.31 2002/02/17 17:30:23 brianp Exp $ */ /* * Mesa 3-D graphics library - * Version: 3.5 + * Version: 4.1 * - * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. + * Copyright (C) 1999-2002 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"), @@ -102,14 +102,21 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, { SWcontext *swrast = SWRAST_CONTEXT(ctx); const struct gl_pixelstore_attrib *unpack = &ctx->Unpack; - GLchan rgb[MAX_WIDTH][3]; - GLchan rgba[MAX_WIDTH][4]; + struct sw_span span; + + INIT_SPAN(span); + span.arrayMask |= SPAN_RGBA; if (!ctx->Current.RasterPosValid) { return GL_TRUE; /* no-op */ } - if ((SWRAST_CONTEXT(ctx)->_RasterMask&(~(SCISSOR_BIT|WINCLIP_BIT)))==0 + if (ctx->Depth.Test) + _mesa_span_default_z(ctx, &span); + if (ctx->Fog.Enabled) + _mesa_span_default_fog(ctx, &span); + + if ((SWRAST_CONTEXT(ctx)->_RasterMask & ~CLIP_BIT) == 0 && ctx->Texture._ReallyEnabled == 0 && unpack->Alignment == 1 && !unpack->SwapBytes @@ -190,7 +197,7 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, zSpan[i] = z; /* save Y value of first row */ - zoomY0 = (GLint) (ctx->Current.RasterPos[1] + 0.5F); + zoomY0 = IROUND(ctx->Current.RasterPos[1]); } @@ -231,8 +238,11 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, /* with zooming */ GLint row; for (row=0; rowDriver.WriteRGBSpan)(ctx, drawWidth, destX, destY, - (CONST GLchan (*)[3]) rgb, NULL); + (CONST GLchan (*)[3]) span.color.rgb, NULL); src += rowLength; destY++; } @@ -306,13 +319,13 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, for (row=0; rowDriver.WriteRGBSpan)(ctx, drawWidth, destX, destY, - (CONST GLchan (*)[3]) rgb, NULL); + (CONST GLchan (*)[3]) span.color.rgb, NULL); src += rowLength; } } @@ -323,12 +336,15 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, for (row=0; rowDriver.WriteRGBASpan)(ctx, drawWidth, destX, destY, - (CONST GLchan (*)[4]) rgba, NULL); + (CONST GLchan (*)[4]) span.color.rgba, NULL); src += rowLength*2; destY++; } @@ -368,14 +384,14 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, GLint i; GLchan *ptr = src; for (i=0;iDriver.WriteRGBASpan)(ctx, drawWidth, destX, destY, - (CONST GLchan (*)[4]) rgba, NULL); + (CONST GLchan (*)[4]) span.color.rgba, NULL); src += rowLength*2; } } @@ -387,13 +403,16 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, GLchan *ptr = src; GLint i; for (i=0;iDriver.WriteRGBASpan)(ctx, drawWidth, destX, destY, - (const GLchan (*)[4]) rgba, - NULL); + (const GLchan (*)[4]) span.color.rgba, NULL); src += rowLength; destY++; } @@ -424,11 +442,10 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, GLint row; for (row=0; rowDriver.WriteRGBASpan)(ctx, drawWidth, destX, destY, - (CONST GLchan (*)[4]) rgba, - NULL); + (CONST GLchan (*)[4]) span.color.rgba, NULL); src += rowLength; } return GL_TRUE; @@ -438,9 +455,12 @@ fast_draw_pixels(GLcontext *ctx, GLint x, GLint y, GLint row; for (row=0; rowPixel.ZoomX!=1.0 || ctx->Pixel.ZoomY!=1.0; const GLint desty = y; - GLint row, drawWidth; - GLdepth zspan[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); - GLint i; - for (i = 0; i < drawWidth; i++) { - zspan[i] = zval; - } - } + 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, 0, indexes, desty); - } - else { - _mesa_write_index_span(ctx, drawWidth, x, y, zspan, 0, indexes, GL_BITMAP); - } + span.x = x; + span.y = y; + span.end = drawWidth; + if (zoom) + _mesa_write_zoomed_index_span(ctx, &span, desty); + else + _mesa_write_index_span(ctx, &span, GL_BITMAP); } } @@ -548,6 +566,11 @@ draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y, return; } + if (ctx->Visual.stencilBits == 0) { + _mesa_error( ctx, GL_INVALID_OPERATION, "glDrawPixels(no stencil buffer)"); + return; + } + drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; for (row = 0; row < height; row++, y++) { @@ -577,7 +600,6 @@ draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y, } - /* * Do a glDrawPixels of depth values. */ @@ -589,9 +611,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 @@ -604,60 +629,51 @@ 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 (type==GL_UNSIGNED_SHORT && sizeof(GLdepth)==sizeof(GLushort) + if (ctx->Fog.Enabled) + _mesa_span_default_fog(ctx, &span); + + if (type==GL_UNSIGNED_SHORT && ctx->Visual.depthBits == 16 && !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]; + span.x = x; + span.y = y; + span.end = drawWidth; + for (row = 0; row < height; row++, span.y++) { 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]; - _mesa_write_rgba_span( ctx, width, x, y, zspan, 0, rgba, GL_BITMAP ); + for (i = 0; i < drawWidth; i++) + span.zArray[i] = zptr[i]; + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } else if (type==GL_UNSIGNED_INT && ctx->Visual.depthBits == 32 && !bias_or_scale && !zoom && ctx->Visual.rgbMode) { /* Special case: directly write 32-bit depth values */ GLint row; - for (row = 0; row < height; row++, y++) { + span.x = x; + span.y = y; + span.end = drawWidth; + for (row = 0; row < height; row++, span.y++) { const GLuint *zptr = (const GLuint *) _mesa_image_address(&ctx->Unpack, pixels, width, height, GL_DEPTH_COMPONENT, type, 0, row, 0); - _mesa_write_rgba_span( ctx, width, x, y, zptr, 0, rgba, GL_BITMAP ); + MEMCPY(span.zArray, zptr, drawWidth * sizeof(GLdepth)); + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } else { /* General case */ GLint row; - for (row = 0; row < height; row++, y++) { + span.x = x; + span.y = y; + span.end = drawWidth; + for (row = 0; row < height; row++, span.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, @@ -667,30 +683,22 @@ 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 + 0.5F); } } - if (ctx->Visual.rgbMode) { - if (zoom) { - _mesa_write_zoomed_rgba_span(ctx, width, x, y, zspan, 0, - (const GLchan (*)[4]) rgba, desty); - } - else { - _mesa_write_rgba_span(ctx, width, x, y, zspan, 0, rgba, GL_BITMAP); - } + if (zoom) + _mesa_write_zoomed_rgba_span(ctx, &span, + (const GLchan (*)[4]) span.color.rgba, desty); + else + _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); - } - else { - _mesa_write_index_span(ctx, width, x, y, zspan, 0, - ispan, GL_BITMAP); - } + if (zoom) + _mesa_write_zoomed_index_span(ctx, &span, desty); + else + _mesa_write_index_span(ctx, &span, GL_BITMAP); } - } } } @@ -708,10 +716,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]; 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)"); @@ -722,16 +733,10 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y, if (fast_draw_pixels(ctx, x, y, width, height, format, type, pixels)) return; - /* Fragment depth values */ - if (ctx->Depth.Test || ctx->Fog.Enabled) { - /* fill in array of z values */ - GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMaxF); - GLint i; - for (i=0;iDepth.Test) + _mesa_span_default_z(ctx, &span); + if (ctx->Fog.Enabled) + _mesa_span_default_fog(ctx, &span); if (SWRAST_CONTEXT(ctx)->_RasterMask == 0 && !zoom && x >= 0 && y >= 0 && x + width <= ctx->DrawBuffer->Width @@ -798,50 +803,42 @@ 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, + _mesa_unpack_chan_color_span(ctx, width, GL_RGBA, + (GLchan *) span.color.rgba, format, type, source, unpack, transferOps); + if ((ctx->Pixel.MinMaxEnabled && ctx->MinMax.Sink) || (ctx->Pixel.HistogramEnabled && ctx->Histogram.Sink)) continue; - if (ctx->Texture._ReallyEnabled && ctx->Pixel.PixelTextureEnabled) { - GLfloat s[MAX_WIDTH], t[MAX_WIDTH], r[MAX_WIDTH], q[MAX_WIDTH]; - GLchan primary_rgba[MAX_WIDTH][4]; - GLuint unit; - /* 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, - s, t, r, q); - _swrast_texture_fragments(ctx, unit, width, s, t, r, NULL, - (CONST GLchan (*)[4]) primary_rgba, - rgba); - } - } + 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 (*)[]) rgba, NULL); + (*swrast->Driver.WriteRGBASpan)(ctx, width, x, y, + (CONST GLchan (*)[4]) span.color.rgba, NULL); } else if (zoom) { - _mesa_write_zoomed_rgba_span( ctx, width, x, y, zspan, 0, - (CONST GLchan (*)[]) rgba, desty ); + span.x = x; + span.y = y; + span.end = width; + _mesa_write_zoomed_rgba_span(ctx, &span, + (CONST GLchan (*)[4]) span.color.rgba, desty); } else { - _mesa_write_rgba_span( ctx, (GLuint) width, x, y, zspan, 0, - rgba, GL_BITMAP); + span.x = x; + span.y = y; + span.end = width; + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } } @@ -872,7 +869,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 );