X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fmesa%2Fswrast%2Fs_drawpix.c;h=389012653464fa093ec73056821c54fa1e7064b6;hb=ad7306b23cbcc55cb9c943de8da2e3f80b3b46c4;hp=e618dc0a233b0c4fe4581fbfbc876eb5e63075a0;hpb=acc722d4b890da7ed0ede24751e2bcaf28cc1468;p=mesa.git diff --git a/src/mesa/swrast/s_drawpix.c b/src/mesa/swrast/s_drawpix.c index e618dc0a233..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.22 2001/06/26 21:15:36 brianp 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"), @@ -37,7 +37,6 @@ #include "s_context.h" #include "s_drawpix.h" -#include "s_fog.h" #include "s_pixeltex.h" #include "s_span.h" #include "s_stencil.h" @@ -103,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 @@ -232,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++; } @@ -307,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; } } @@ -324,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++; } @@ -369,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; } } @@ -388,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++; } @@ -425,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; @@ -439,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]; - GLfloat fogSpan[MAX_WIDTH]; - - drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; - - /* Fragment depth values */ - if (ctx->Depth.Test || ctx->Fog.Enabled) { - GLdepth zval = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMaxF); - GLfloat fog; - GLint i; + GLint row, drawWidth = (width > MAX_WIDTH) ? MAX_WIDTH : width; + struct sw_span span; - 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); + INIT_SPAN(span); + span.arrayMask |= SPAN_INDEX; - 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); - } - else { - _mesa_write_index_span(ctx, drawWidth, x, y, zspan, fogSpan, indexes, - NULL, 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); } } @@ -560,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++) { @@ -589,7 +600,6 @@ draw_stencil_pixels( GLcontext *ctx, GLint x, GLint y, } - /* * Do a glDrawPixels of depth values. */ @@ -601,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 @@ -616,62 +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, - NULL, 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, - NULL, 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, @@ -681,31 +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, NULL, 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, NULL, GL_BITMAP); - } + if (zoom) + _mesa_write_zoomed_index_span(ctx, &span, desty); + else + _mesa_write_index_span(ctx, &span, GL_BITMAP); } - } } } @@ -723,11 +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]; - 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)"); @@ -738,24 +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); - 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;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 @@ -822,61 +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) { - GLchan primary_rgba[MAX_WIDTH][4]; - GLuint unit; - DEFARRAY(GLfloat, s, MAX_WIDTH); /* mac 32k limitation */ - DEFARRAY(GLfloat, t, MAX_WIDTH); - DEFARRAY(GLfloat, r, MAX_WIDTH); - DEFARRAY(GLfloat, q, MAX_WIDTH); - CHECKARRAY(s, return); /* mac 32k limitation */ - CHECKARRAY(t, return); - CHECKARRAY(r, return); - CHECKARRAY(q, return); - - /* 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); - } - } - UNDEFARRAY(s); /* mac 32k limitation */ - UNDEFARRAY(t); - UNDEFARRAY(r); - UNDEFARRAY(q); + 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); + 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, fogSpan, - rgba, NULL, GL_BITMAP); + span.x = x; + span.y = y; + span.end = width; + _mesa_write_rgba_span(ctx, &span, GL_BITMAP); } } } @@ -907,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 );