-/* $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"),
{
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
zSpan[i] = z;
/* save Y value of first row */
- zoomY0 = (GLint) (ctx->Current.RasterPos[1] + 0.5F);
+ zoomY0 = IROUND(ctx->Current.RasterPos[1]);
}
/* with zooming */
GLint row;
for (row=0; row<drawHeight; row++) {
- _mesa_write_zoomed_rgba_span(ctx, drawWidth, destX, destY,
- zSpan, 0, (CONST GLchan (*)[4]) src, zoomY0);
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _mesa_write_zoomed_rgba_span(ctx, &span,
+ (CONST GLchan (*)[4]) src, zoomY0);
src += rowLength * 4;
destY++;
}
/* with zooming */
GLint row;
for (row=0; row<drawHeight; row++) {
- _mesa_write_zoomed_rgb_span(ctx, drawWidth, destX, destY,
- zSpan, 0, (CONST GLchan (*)[3]) src, zoomY0);
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _mesa_write_zoomed_rgb_span(ctx, &span,
+ (CONST GLchan (*)[3]) src, zoomY0);
src += rowLength * 3;
destY++;
}
for (row=0; row<drawHeight; row++) {
GLint i;
for (i=0;i<drawWidth;i++) {
- rgb[i][0] = src[i];
- rgb[i][1] = src[i];
- rgb[i][2] = src[i];
+ span.color.rgb[i][0] = src[i];
+ span.color.rgb[i][1] = src[i];
+ span.color.rgb[i][2] = src[i];
}
(*swrast->Driver.WriteRGBSpan)(ctx, drawWidth, destX, destY,
- (CONST GLchan (*)[3]) rgb, NULL);
+ (CONST GLchan (*)[3]) span.color.rgb, NULL);
src += rowLength;
destY++;
}
for (row=0; row<drawHeight; row++) {
GLint i;
for (i=0;i<drawWidth;i++) {
- rgb[i][0] = src[i];
- rgb[i][1] = src[i];
- rgb[i][2] = src[i];
+ span.color.rgb[i][0] = src[i];
+ span.color.rgb[i][1] = src[i];
+ span.color.rgb[i][2] = src[i];
}
destY--;
(*swrast->Driver.WriteRGBSpan)(ctx, drawWidth, destX, destY,
- (CONST GLchan (*)[3]) rgb, NULL);
+ (CONST GLchan (*)[3]) span.color.rgb, NULL);
src += rowLength;
}
}
for (row=0; row<drawHeight; row++) {
GLint i;
for (i=0;i<drawWidth;i++) {
- rgb[i][0] = src[i];
- rgb[i][1] = src[i];
- rgb[i][2] = src[i];
+ span.color.rgb[i][0] = src[i];
+ span.color.rgb[i][1] = src[i];
+ span.color.rgb[i][2] = src[i];
}
- _mesa_write_zoomed_rgb_span(ctx, drawWidth, destX, destY,
- zSpan, 0, (CONST GLchan (*)[3]) rgb, zoomY0);
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _mesa_write_zoomed_rgb_span(ctx, &span,
+ (CONST GLchan (*)[3]) span.color.rgb, zoomY0);
src += rowLength;
destY++;
}
GLint i;
GLchan *ptr = src;
for (i=0;i<drawWidth;i++) {
- rgba[i][0] = *ptr;
- rgba[i][1] = *ptr;
- rgba[i][2] = *ptr++;
- rgba[i][3] = *ptr++;
+ span.color.rgba[i][0] = *ptr;
+ span.color.rgba[i][1] = *ptr;
+ span.color.rgba[i][2] = *ptr++;
+ span.color.rgba[i][3] = *ptr++;
}
(*swrast->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY,
- (CONST GLchan (*)[4]) rgba, NULL);
+ (CONST GLchan (*)[4]) span.color.rgba, NULL);
src += rowLength*2;
destY++;
}
GLint i;
GLchan *ptr = src;
for (i=0;i<drawWidth;i++) {
- rgba[i][0] = *ptr;
- rgba[i][1] = *ptr;
- rgba[i][2] = *ptr++;
- rgba[i][3] = *ptr++;
+ span.color.rgba[i][0] = *ptr;
+ span.color.rgba[i][1] = *ptr;
+ span.color.rgba[i][2] = *ptr++;
+ span.color.rgba[i][3] = *ptr++;
}
destY--;
(*swrast->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY,
- (CONST GLchan (*)[4]) rgba, NULL);
+ (CONST GLchan (*)[4]) span.color.rgba, NULL);
src += rowLength*2;
}
}
GLchan *ptr = src;
GLint i;
for (i=0;i<drawWidth;i++) {
- rgba[i][0] = *ptr;
- rgba[i][1] = *ptr;
- rgba[i][2] = *ptr++;
- rgba[i][3] = *ptr++;
+ span.color.rgba[i][0] = *ptr;
+ span.color.rgba[i][1] = *ptr;
+ span.color.rgba[i][2] = *ptr++;
+ span.color.rgba[i][3] = *ptr++;
}
- _mesa_write_zoomed_rgba_span(ctx, drawWidth, destX, destY,
- zSpan, 0, (CONST GLchan (*)[4]) rgba, zoomY0);
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _mesa_write_zoomed_rgba_span(ctx, &span,
+ (CONST GLchan (*)[4]) span.color.rgba, zoomY0);
src += rowLength*2;
destY++;
}
GLint row;
for (row=0; row<drawHeight; row++) {
ASSERT(drawWidth < MAX_WIDTH);
- _mesa_map_ci8_to_rgba(ctx, drawWidth, src, rgba);
+ _mesa_map_ci8_to_rgba(ctx, drawWidth, src, span.color.rgba);
(*swrast->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY,
- (const GLchan (*)[4]) rgba,
- NULL);
+ (const GLchan (*)[4]) span.color.rgba, NULL);
src += rowLength;
destY++;
}
GLint row;
for (row=0; row<drawHeight; row++) {
ASSERT(drawWidth < MAX_WIDTH);
- _mesa_map_ci8_to_rgba(ctx, drawWidth, src, rgba);
+ _mesa_map_ci8_to_rgba(ctx, drawWidth, src, span.color.rgba);
destY--;
(*swrast->Driver.WriteRGBASpan)(ctx, drawWidth, destX, destY,
- (CONST GLchan (*)[4]) rgba,
- NULL);
+ (CONST GLchan (*)[4]) span.color.rgba, NULL);
src += rowLength;
}
return GL_TRUE;
GLint row;
for (row=0; row<drawHeight; row++) {
ASSERT(drawWidth < MAX_WIDTH);
- _mesa_map_ci8_to_rgba(ctx, drawWidth, src, rgba);
- _mesa_write_zoomed_rgba_span(ctx, drawWidth, destX, destY,
- zSpan, 0, (CONST GLchan (*)[4]) rgba, zoomY0);
+ _mesa_map_ci8_to_rgba(ctx, drawWidth, src, span.color.rgba);
+ span.x = destX;
+ span.y = destY;
+ span.end = drawWidth;
+ _mesa_write_zoomed_rgba_span(ctx, &span,
+ (CONST GLchan (*)[4]) span.color.rgba, zoomY0);
src += rowLength;
destY++;
}
{
const GLboolean zoom = ctx->Pixel.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);
}
}
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++) {
}
-
/*
* Do a glDrawPixels of depth values.
*/
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
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,
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);
}
-
}
}
}
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)");
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;i<width;i++) {
- zspan[i] = z;
- }
- }
-
+ 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 == 0 && !zoom && x >= 0 && y >= 0
&& x + width <= ctx->DrawBuffer->Width
* 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);
}
}
}
_swrast_validate_derived( ctx );
RENDER_START(swrast,ctx);
-
switch (format) {
case GL_STENCIL_INDEX:
draw_stencil_pixels( ctx, x, y, width, height, type, pixels );