-/* $Id: s_alpha.c,v 1.4 2001/03/12 00:48:41 gareth Exp $ */
+/* $Id: s_alpha.c,v 1.5 2002/01/21 18:12:34 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"),
#include "s_alpha.h"
+/*
+ * Apply the alpha test to a span of pixels.
+ * In: rgba - array of pixels
+ * In/Out: span -
+ * Return: 0 = all pixels in the span failed the alpha test.
+ * 1 = one or more pixels passed the alpha test.
+ */
+GLint
+_mesa_alpha_test( const GLcontext *ctx, struct sw_span *span,
+ CONST GLchan rgba[][4])
+{
+ GLuint i;
+ const GLchan ref = ctx->Color.AlphaRef;
+ GLubyte *mask = span->mask;
+
+ ASSERT (span->filledMask == GL_TRUE);
+ ASSERT (span->filledAlpha == GL_TRUE);
+
+ SW_SPAN_SET_FLAG(span->testedAlpha);
+
+
+ /* switch cases ordered from most frequent to less frequent */
+ switch (ctx->Color.AlphaFunc) {
+ case GL_LESS:
+ for (i=span->start; i<span->end; i++) {
+ mask[i] &= (rgba[i][ACOMP] < ref);
+ }
+ break;
+ case GL_LEQUAL:
+ for (i=span->start; i<span->end; i++)
+ mask[i] &= (rgba[i][ACOMP] <= ref);
+ break;
+ case GL_GEQUAL:
+ for (i=span->start; i<span->end; i++) {
+ mask[i] &= (rgba[i][ACOMP] >= ref);
+ }
+ break;
+ case GL_GREATER:
+ for (i=span->start; i<span->end; i++) {
+ mask[i] &= (rgba[i][ACOMP] > ref);
+ }
+ break;
+ case GL_NOTEQUAL:
+ for (i=span->start; i<span->end; i++) {
+ mask[i] &= (rgba[i][ACOMP] != ref);
+ }
+ break;
+ case GL_EQUAL:
+ for (i=span->start; i<span->end; i++) {
+ mask[i] &= (rgba[i][ACOMP] == ref);
+ }
+ break;
+ case GL_ALWAYS:
+ /* do nothing */
+ return 1;
+ case GL_NEVER:
+ /* caller should check for zero! */
+ return 0;
+ default:
+ _mesa_problem( ctx, "Invalid alpha test in gl_alpha_test" );
+ return 0;
+ }
+
+ while ((span->start <= span->end) &&
+ (mask[span->start] == 0))
+ span->start ++;
+
+ while ((span->end >= span->start) &&
+ (mask[span->end] == 0))
+ span->end --;
+ span->writeAll = GL_FALSE;
+
+ if (span->start >= span->end)
+ return 0;
+ else
+ return 1;
+}
/*
* 1 = one or more pixels passed the alpha test.
*/
GLint
-_mesa_alpha_test( const GLcontext *ctx,
- GLuint n, CONST GLchan rgba[][4], GLubyte mask[] )
+_old_alpha_test( const GLcontext *ctx,
+ GLuint n, CONST GLchan rgba[][4], GLubyte mask[] )
{
GLuint i;
- GLchan ref = ctx->Color.AlphaRef;
+ const GLchan ref = ctx->Color.AlphaRef;
/* switch cases ordered from most frequent to less frequent */
switch (ctx->Color.AlphaFunc) {
-/* $Id: s_alpha.h,v 1.3 2001/03/12 00:48:41 gareth Exp $ */
+/* $Id: s_alpha.h,v 1.4 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
extern GLint
-_mesa_alpha_test( const GLcontext *ctx, GLuint n,
- CONST GLchan rgba[][4], GLubyte mask[] );
+_old_alpha_test( const GLcontext *ctx, GLuint n,
+ CONST GLchan rgba[][4], GLubyte mask[] );
+extern GLint
+_mesa_alpha_test( const GLcontext *ctx, struct sw_span *span,
+ CONST GLchan rgba[][4]);
+
+#endif
+
-#endif
-/* $Id: s_depth.c,v 1.10 2001/12/17 04:54:35 brianp Exp $ */
+/* $Id: s_depth.c,v 1.11 2002/01/21 18:12:34 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"),
ASSERT(swrast->Driver.WriteDepthSpan);
(*swrast->Driver.WriteDepthSpan)(ctx, span->end, span->x, span->y, zbuffer, span->mask);
if (passed < span->end)
- span->write_all = GL_FALSE;
+ span->writeAll = GL_FALSE;
return passed;
}
else {
passed = depth_test_span32(ctx, span->end, span->x, span->y, zptr, span->depth, span->mask);
}
if (passed < span->end)
- span->write_all = GL_FALSE;
+ span->writeAll = GL_FALSE;
return passed;
}
}
-/* $Id: s_fog.c,v 1.16 2001/12/18 04:06:46 brianp Exp $ */
+/* $Id: s_fog.c,v 1.17 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
-/*
+/**
* Used to convert current raster distance to a fog factor in [0,1].
*/
GLfloat
-/*
+/**
* Apply fog to a span of RGBA pixels.
* Input: ctx -
* span - where span->fog and span->fogStep have to be set.
}
}
-/*
+
+/**
+ * Apply fog given in an array to RGBA pixels.
+ * Input: ctx -
+ * span -
+ * fog - array of fog factors in [0,1]
+ * red, green, blue, alpha - pixel colors
+ * Output: red, green, blue, alpha - fogged pixel colors
+ */
+void
+_mesa_fog_rgba_pixels_with_array( const GLcontext *ctx, struct sw_span *span,
+ const GLfloat fog[], GLchan rgba[][4] )
+{
+ GLuint i;
+ GLchan rFog, gFog, bFog;
+
+ ASSERT(fog != NULL);
+ ASSERT(ctx->Fog.Enabled);
+ ASSERT(span->filledColor == GL_TRUE);
+
+ UNCLAMPED_FLOAT_TO_CHAN(rFog, ctx->Fog.Color[RCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(gFog, ctx->Fog.Color[GCOMP]);
+ UNCLAMPED_FLOAT_TO_CHAN(bFog, ctx->Fog.Color[BCOMP]);
+
+ for (i = span->start; i < span->end; i++) {
+ const GLfloat f = fog[i];
+ const GLfloat g = 1.0F - f;
+ rgba[i][RCOMP] = (GLchan) (f * rgba[i][RCOMP] + g * rFog);
+ rgba[i][GCOMP] = (GLchan) (f * rgba[i][GCOMP] + g * gFog);
+ rgba[i][BCOMP] = (GLchan) (f * rgba[i][BCOMP] + g * bFog);
+ }
+}
+
+/**
* Apply fog to an array of RGBA pixels.
* Input: n - number of pixels
* fog - array of fog factors in [0,1]
}
-/*
+/**
* Apply fog to a span of color index pixels.
* Input: ctx -
* span - where span->fog and span->fogStep have to be set.
}
}
-/*
+
+/**
+ * Apply fog given in an array to a span of color index pixels.
+ * Input: ctx -
+ * span -
+ * fog - array of fog factors in [0,1]
+ * index - pixel color indexes
+ * Output: index - fogged pixel color indexes
+ */
+void
+_mesa_fog_ci_pixels_with_array( const GLcontext *ctx, struct sw_span *span,
+ const GLfloat fog[], GLuint index[] )
+{
+ GLuint idx = (GLuint) ctx->Fog.Index;
+ GLuint i;
+
+ ASSERT(fog != NULL);
+ ASSERT(ctx->Fog.Enabled);
+ ASSERT(span->filledColor == GL_TRUE);
+
+ for (i = span->start; i < span->end; i++) {
+ const GLfloat f = CLAMP(fog[i], 0.0F, 1.0F);
+ index[i] = (GLuint) ((GLfloat) index[i] + (1.0F - f) * idx);
+ }
+}
+
+/**
* Apply fog to an array of color index pixels.
* Input: n - number of pixels
* fog - array of fog factors in [0,1]
-/*
+/**
* Calculate fog factors (in [0,1]) from window z values
* Input: n - number of pixels
* z - array of integer depth values
}
-/*
+/**
* Apply fog to a span of RGBA pixels.
* Input: ctx -
* span - where span->depth has to be filled.
ASSERT(span->filledColor == GL_TRUE);
compute_fog_factors_from_z(ctx, span->end, span->depth, fogFact );
- _old_fog_rgba_pixels( ctx, span->end, fogFact, rgba );
+ _mesa_fog_rgba_pixels_with_array( ctx, span, fogFact, rgba );
}
-/*
+
+/**
* Apply fog to an array of RGBA pixels.
* Input: n - number of pixels
* z - array of integer depth values
}
-/*
+/**
* Apply fog to a span of color index pixels.
* Input: ctx -
* span - where span->depth has to be filled.
ASSERT(span->filledColor == GL_TRUE);
compute_fog_factors_from_z(ctx, span->end, span->depth, fogFact );
- _old_fog_ci_pixels( ctx, span->end, fogFact, index );
+ _mesa_fog_ci_pixels_with_array( ctx, span, fogFact, index );
}
-/*
+/**
* Apply fog to an array of color index pixels.
* Input: n - number of pixels
* z - array of integer depth values
-/* $Id: s_fog.h,v 1.6 2001/12/17 04:54:35 brianp Exp $ */
+/* $Id: s_fog.h,v 1.7 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
extern void
_mesa_fog_rgba_pixels( const GLcontext *ctx, struct sw_span *span,
GLchan rgba[][4]);
+extern void
+_mesa_fog_rgba_pixels_with_array( const GLcontext *ctx, struct sw_span *span,
+ const GLfloat fog[], GLchan rgba[][4] );
+
extern void
_mesa_fog_ci_pixels( const GLcontext *ctx, struct sw_span *span,
GLuint indx[]);
extern void
+_mesa_fog_ci_pixels_with_array( const GLcontext *ctx, struct sw_span *span,
+ const GLfloat fog[], GLuint index[] );
+extern void
_old_fog_ci_pixels( const GLcontext *ctx,
GLuint n, const GLfloat fog[],
GLuint indx[] );
-/* $Id: s_span.c,v 1.22 2002/01/16 16:00:03 brianp Exp $ */
+/* $Id: s_span.c,v 1.23 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
m = highbit;
}
}
- span->write_all = GL_FALSE;
+ span->writeAll = GL_FALSE;
}
}
else {
/* partially off left side */
- span->write_all = GL_FALSE;
+ span->writeAll = GL_FALSE;
BZERO(span->mask, -x * sizeof(GLubyte));
return GL_TRUE;
}
/* Do the alpha test */
if (ctx->Color.AlphaEnabled) {
- if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) {
+ if (_old_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) {
return;
}
write_all = GL_FALSE;
*/
void
_mesa_write_index_span( GLcontext *ctx, struct sw_span *span,
- GLenum primitive )
+ const GLfloat fog[MAX_WIDTH], GLenum primitive)
{
const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT | LOGIC_OP_BIT;
GLuint indexBackup[MAX_WIDTH];
}
if (ctx->Fog.Enabled) {
- /* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ 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);
}
if (ctx->Fog.Enabled) {
- /* Is this the right 'if' ?? */
if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
_mesa_fog_ci_pixels( ctx, span, indexes );
else
*/
void
_mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
- GLenum primitive )
+ const GLfloat fog[MAX_WIDTH], GLenum primitive)
{
const GLuint modBits = FOG_BIT | BLEND_BIT | MASKING_BIT |
LOGIC_OP_BIT | TEXTURE_BIT;
/* Do the alpha test */
if (ctx->Color.AlphaEnabled) {
- if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4]) rgba, span->mask ) == 0) {
+ if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4]) rgba) == 0) {
return;
}
- span->write_all = GL_FALSE;
}
/* I have to think where to put this!! */
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
- /* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ 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 );
/* write pixels */
(*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y,
(const GLchan (*)[4]) rgba,
- span->write_all ? ((const GLubyte *) NULL) : span->mask );
+ 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->write_all ? ((const GLubyte *) NULL) : span->mask );
+ span->writeAll ? ((const GLubyte *) NULL) : span->mask );
}
}
}
/* 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->end, (const GLchan (*)[4])rgba, span->mask ) == 0) {
+ if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4])rgba) == 0) {
return;
}
- span->write_all = GL_FALSE;
}
/* I have to think where to put this!! */
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
- /* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
+ if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
_mesa_fog_rgba_pixels( ctx, span, rgba );
else
_mesa_depth_fog_rgba_pixels( ctx, span, rgba );
/* write pixels */
(*swrast->Driver.WriteRGBASpan)( ctx, span->end, span->x, span->y,
(const GLchan (*)[4]) rgba,
- span->write_all ? ((const GLubyte *) NULL) : span->mask );
+ 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->write_all ? ((const GLubyte *) NULL) : span->mask );
+ span->writeAll ? ((const GLubyte *) NULL) : 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->write_all ? ((const GLubyte *) NULL) : span->mask );
+ _mesa_write_mono_alpha_span( ctx, span->end, span->x, span->y,
+ (GLchan) color[ACOMP],
+ span->writeAll ? ((const GLubyte *) NULL) : span->mask );
}
}
}
*/
void
_mesa_write_texture_span( GLcontext *ctx, struct sw_span *span,
- const GLfloat fog[], GLenum primitive )
+ const GLfloat fog[MAX_WIDTH], GLenum primitive )
{
const GLuint colorMask = *((GLuint *) ctx->Color.ColorMask);
GLchan rgbaBackup[MAX_WIDTH][4];
_swrast_texture_fragments( ctx, 0, span, rgba );
/* Do the alpha test */
- if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4]) rgba, span->mask ) == 0) {
+ if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4]) rgba ) == 0) {
return;
}
- span->write_all = GL_FALSE;
}
if (ctx->Stencil.Enabled) {
/* Per-pixel fog */
if (ctx->Fog.Enabled) {
- /* Is this the right 'if' ?? */
- if ((span->activeMask & SPAN_FOG) && !swrast->_PreferPixelFog)
- _old_fog_rgba_pixels( ctx, span->end, fog, rgba );
+ 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);
}
_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->write_all ? NULL : span->mask );
+ (*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->write_all ? NULL : span->mask );
+ _mesa_write_alpha_span( ctx, span->end, span->x, span->y,
+ (const GLchan (*)[4]) rgba,
+ span->writeAll ? NULL : span->mask );
}
}
-
}
/* Texture with alpha test */
if (ctx->Color.AlphaEnabled) {
/* Do the alpha test */
- if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4]) rgba, span->mask ) == 0) {
+ if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4]) rgba ) == 0) {
return;
}
- span->write_all = GL_FALSE;
/* Depth test usually in 'rasterize_span' but if alpha test
needed, we have to wait for that test before depth test can
_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->write_all ? NULL : span->mask );
+ (*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->write_all ? NULL : span->mask );
+ _mesa_write_alpha_span( ctx, span->end, span->x, span->y,
+ (const GLchan (*)[4]) rgba,
+ span->writeAll ? NULL : span->mask );
}
}
}
/* Texture with alpha test */
if (ctx->Color.AlphaEnabled) {
/* Do the alpha test */
- if (_mesa_alpha_test( ctx, span->end, (const GLchan (*)[4])rgba, span->mask ) == 0) {
+ if (_mesa_alpha_test( ctx, span, (const GLchan (*)[4])rgba ) == 0) {
return;
}
- span->write_all = GL_FALSE;
+
/* Depth test usually in 'rasterize_span' but if alpha test
needed, we have to wait for that test before depth test can
be done. */
#endif
if (swrast->_RasterMask & MULTI_DRAW_BIT) {
- multi_write_rgba_span( ctx, span->end, span->x, span->y, (const GLchan (*)[4]) rgba, span->mask );
+ multi_write_rgba_span( ctx, span->end, span->x, span->y,
+ (const GLchan (*)[4]) rgba, span->mask );
}
else {
/* normal: write to exactly one buffer */
_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->write_all ? NULL : span->mask );
+ (*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->write_all ? NULL : span->mask );
+ _mesa_write_alpha_span( ctx, span->end, span->x, span->y,
+ (const GLchan (*)[4])rgba,
+ span->writeAll ? NULL : span->mask );
}
}
}
}
if (span->activeMask & SPAN_RGBA) {
- ASSERT(span->filledColor == GL_FALSE);
SW_SPAN_SET_FLAG(span->filledColor);
+ SW_SPAN_SET_FLAG(span->filledAlpha);
if (span->activeMask & SPAN_FLAT) {
GLuint i;
GLchan color[4];
}
if (span->activeMask & SPAN_SPEC) {
- SW_SPAN_SET_FLAG(span->filledSpecular);
+ SW_SPAN_SET_FLAG(span->filledSpecular);
if (span->activeMask & SPAN_FLAT) {
const GLchan r = FixedToChan(span->specRed);
const GLchan g = FixedToChan(span->specGreen);
(CONST GLchan (*)[4]) rgba, rgba );
/* Do the alpha test */
- if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) {
+ if (_old_alpha_test( ctx, n, (const GLchan (*)[4]) rgba, mask ) == 0) {
return;
}
write_all = GL_FALSE;
(CONST GLchan (*)[4]) rgbaIn, rgba );
/* Do the alpha test */
- if (_mesa_alpha_test( ctx, n, (const GLchan (*)[4])rgba, mask ) == 0) {
+ if (_old_alpha_test( ctx, n, (const GLchan (*)[4])rgba, mask ) == 0) {
return;
}
write_all = GL_FALSE;
-/* $Id: s_span.h,v 1.10 2002/01/16 16:00:04 brianp Exp $ */
+/* $Id: s_span.h,v 1.11 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
void
_mesa_write_index_span( GLcontext *ctx, struct sw_span *span,
- GLenum primitive);
+ const GLfloat fog[MAX_WIDTH], GLenum primitive);
extern void
_mesa_write_monoindex_span( GLcontext *ctx, struct sw_span *span,
extern void
_mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span,
- GLenum primitive );
+ const GLfloat fog[MAX_WIDTH], GLenum primitive);
extern void
_mesa_write_monocolor_span( GLcontext *ctx, struct sw_span *span,
extern void
_mesa_write_texture_span( GLcontext *ctx, struct sw_span *span,
- const GLfloat fog[], GLenum primitive );
+ const GLfloat fog[MAX_WIDTH], GLenum primitive );
extern void
-/* $Id: s_stencil.c,v 1.14 2002/01/08 14:56:51 brianp Exp $ */
+/* $Id: s_stencil.c,v 1.15 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
span->y, stencil, span->mask );
}
- span->write_all = GL_FALSE;
+ span->writeAll = GL_FALSE;
return result;
}
-/* $Id: s_triangle.c,v 1.47 2002/01/16 16:00:04 brianp Exp $ */
+/* $Id: s_triangle.c,v 1.48 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
span.color.index[i] = FixedToInt(span.index); \
span.index += span.indexStep; \
} \
- _mesa_write_index_span(ctx, &span, GL_POLYGON);
+ _mesa_write_index_span(ctx, &span, NULL, GL_POLYGON);
#include "s_tritemp.h"
}
#define RENDER_SPAN( span ) \
GLuint i; \
SW_SPAN_SET_FLAG(span.filledColor); \
+ SW_SPAN_SET_FLAG(span.filledAlpha); \
for (i = 0; i < span.end; i++) { \
span.color.rgba[i][RCOMP] = FixedToChan(span.red); \
span.color.rgba[i][GCOMP] = FixedToChan(span.green); \
span.blue += span.blueStep; \
span.alpha += span.alphaStep; \
} \
- _mesa_write_rgba_span(ctx, &span, GL_POLYGON);
+ _mesa_write_rgba_span(ctx, &span, NULL, GL_POLYGON);
#include "s_tritemp.h"
#define SETUP_CODE \
SWcontext *swrast = SWRAST_CONTEXT(ctx); \
struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D; \
- GLint b = obj->BaseLevel; \
+ const GLint b = obj->BaseLevel; \
const GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
const GLfloat theight = (GLfloat) obj->Image[b]->Height; \
const GLint twidth_log2 = obj->Image[b]->WidthLog2; \
span.intTex[1] += span.intTexStep[1]; \
} \
(*swrast->Driver.WriteRGBSpan)(ctx, span.end, span.x, span.y, \
- (CONST GLchan (*)[3]) span.color.rgb, NULL );
+ (CONST GLchan (*)[3]) span.color.rgb, \
+ NULL );
#include "s_tritemp.h"
}
#define SETUP_CODE \
SWcontext *swrast = SWRAST_CONTEXT(ctx); \
struct gl_texture_object *obj = ctx->Texture.Unit[0].Current2D; \
- GLint b = obj->BaseLevel; \
- GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
- GLfloat theight = (GLfloat) obj->Image[b]->Height; \
- GLint twidth_log2 = obj->Image[b]->WidthLog2; \
+ const GLint b = obj->BaseLevel; \
+ const GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
+ const GLfloat theight = (GLfloat) obj->Image[b]->Height; \
+ const GLint twidth_log2 = obj->Image[b]->WidthLog2; \
const GLchan *texture = (const GLchan *) obj->Image[b]->Data; \
- GLint smask = obj->Image[b]->Width - 1; \
- GLint tmask = obj->Image[b]->Height - 1; \
+ const GLint smask = obj->Image[b]->Width - 1; \
+ const GLint tmask = obj->Image[b]->Height - 1; \
if (!texture) { \
/* this shouldn't happen */ \
return; \
span.z += span.zStep; \
} \
(*swrast->Driver.WriteRGBSpan)(ctx, span.end, span.x, span.y, \
- (CONST GLchan (*)[3]) span.color.rgb, span.mask );
+ (CONST GLchan (*)[3]) span.color.rgb, \
+ span.mask );
#include "s_tritemp.h"
}
}
break;
}
- _mesa_write_rgba_span(ctx, span, GL_POLYGON);
+ _mesa_write_rgba_span(ctx, span, NULL, GL_POLYGON);
#undef SPAN_NEAREST
#undef SPAN_LINEAR
struct affine_info info; \
struct gl_texture_unit *unit = ctx->Texture.Unit+0; \
struct gl_texture_object *obj = unit->Current2D; \
- GLint b = obj->BaseLevel; \
- GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
- GLfloat theight = (GLfloat) obj->Image[b]->Height; \
+ const GLint b = obj->BaseLevel; \
+ const GLfloat twidth = (GLfloat) obj->Image[b]->Width; \
+ const GLfloat theight = (GLfloat) obj->Image[b]->Height; \
info.texture = (const GLchan *) obj->Image[b]->Data; \
info.twidth_log2 = obj->Image[b]->WidthLog2; \
info.smask = obj->Image[b]->Width - 1; \
break;
}
- _mesa_write_rgba_span(ctx, span, GL_POLYGON);
+ _mesa_write_rgba_span(ctx, span, NULL, GL_POLYGON);
#undef SPAN_NEAREST
#define SETUP_CODE \
struct persp_info info; \
- struct gl_texture_unit *unit = ctx->Texture.Unit+0; \
- struct gl_texture_object *obj = unit->Current2D; \
- GLint b = obj->BaseLevel; \
+ const struct gl_texture_unit *unit = ctx->Texture.Unit+0; \
+ const struct gl_texture_object *obj = unit->Current2D; \
+ const GLint b = obj->BaseLevel; \
info.texture = (const GLchan *) obj->Image[b]->Data; \
info.twidth_log2 = obj->Image[b]->WidthLog2; \
info.smask = obj->Image[b]->Width - 1; \
(void) fixedToDepthShift;
#define RENDER_SPAN( span ) \
- GLfloat fogSpan[MAX_WIDTH]; \
GLuint i; \
SW_SPAN_SET_FLAG(span.filledColor); \
+ SW_SPAN_SET_FLAG(span.filledAlpha); \
SW_SPAN_SET_FLAG(span.filledTex[0]); \
/* NOTE: we could just call rasterize_span() here instead */ \
for (i = 0; i < span.end; i++) { \
GLdouble invQ = span.tex[0][3] ? (1.0 / span.tex[0][3]) : 1.0; \
span.depth[i] = FixedToDepth(span.z); \
span.z += span.zStep; \
- fogSpan[i] = span.fog; \
- span.fog += span.fogStep; \
span.color.rgba[i][RCOMP] = FixedToChan(span.red); \
span.color.rgba[i][GCOMP] = FixedToChan(span.green); \
span.color.rgba[i][BCOMP] = FixedToChan(span.blue); \
span.color.rgba[i][ACOMP] = FixedToChan(span.alpha); \
- span.red += span.redStep; \
+ span.red += span.redStep; \
span.green += span.greenStep; \
span.blue += span.blueStep; \
span.alpha += span.alphaStep; \
span.tex[0][2] += span.texStep[0][2]; \
span.tex[0][3] += span.texStep[0][3]; \
} \
- _mesa_write_texture_span( ctx, &span, fogSpan, \
- GL_POLYGON );
+ _mesa_write_texture_span( ctx, &span, NULL, GL_POLYGON );
#include "s_tritemp.h"
}
#define RENDER_SPAN( span ) \
GLuint i; \
for (i = 0; i < span.end; i++) { \
- GLdepth z = FixedToDepth(span.z); \
+ GLdepth z = FixedToDepth(span.z); \
if (z < zRow[i]) { \
ctx->OcclusionResult = GL_TRUE; \
return; \
-/* $Id: s_zoom.c,v 1.7 2001/12/17 04:54:35 brianp Exp $ */
+/* $Id: s_zoom.c,v 1.8 2002/01/21 18:12:34 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"),
#include "glheader.h"
#include "macros.h"
+#include "mem.h"
+#include "colormac.h"
#include "s_context.h"
#include "s_span.h"
#include "s_zoom.h"
+#ifdef DEBUG
+
+#define SAVE_SPAN(span) struct sw_span tmp_span = (span);
+
+#define RESTORE_SPAN(span) \
+{ \
+ GLint i; \
+ for (i=tmp_span.start; i<tmp_span.end; i++) { \
+ if (tmp_span.color.rgba[i][RCOMP] != \
+ (span).color.rgba[i][RCOMP] || \
+ tmp_span.color.rgba[i][GCOMP] != \
+ (span).color.rgba[i][GCOMP] || \
+ tmp_span.color.rgba[i][BCOMP] != \
+ (span).color.rgba[i][BCOMP]) { \
+ fprintf(stderr, "glZoom: Color-span changed in subfunction."); \
+ } \
+ if (tmp_span.depth[i] != (span).depth[i]) { \
+ fprintf(stderr, "glZoom: Depth-span changed in subfunction."); \
+ } \
+ } \
+ (span) = tmp_span; \
+}
+
+#else /* DEBUG not defined */
+
+#define SAVE_SPAN(span) GLint start = (span).start, end = (span).end;
+#define RESTORE_SPAN(span) (span).start = start, (span).end = end; \
+ (span).writeAll = GL_TRUE;
+
+#endif /* DEBUG */
/*
* Write a span of pixels to the frame buffer while applying a pixel zoom.
const GLfloat *fog,
CONST GLchan rgba[][4], GLint y0 )
{
- GLint m;
- GLint r0, r1, row, r;
- GLint i, j, skipcol;
- GLchan zrgba[MAX_WIDTH][4]; /* zoomed pixel colors */
- GLdepth zdepth[MAX_WIDTH]; /* zoomed depth values */
+ GLint r0, r1, row;
+ GLint i, j;
+ struct sw_span dstspan;
GLfloat zfog[MAX_WIDTH]; /* zoomed fog values */
- GLint maxwidth = MIN2( ctx->DrawBuffer->Width, MAX_WIDTH );
- const GLuint *srcRGBA32 = (const GLuint *) rgba;
- GLuint *dstRGBA32 = (GLuint *) zrgba;
+ const GLint maxwidth = MIN2( ctx->DrawBuffer->Width, MAX_WIDTH );
+
+ SW_SPAN_RESET (dstspan);
/* compute width of output row */
- m = (GLint) ABSF( n * ctx->Pixel.ZoomX );
- if (m==0) {
+ dstspan.end = (GLint) ABSF( n * ctx->Pixel.ZoomX );
+ if (dstspan.end == 0) {
return;
}
+ /*here ok or better latter? like it was before */
+ else if (dstspan.end > maxwidth) {
+ dstspan.end = maxwidth;
+ }
+
if (ctx->Pixel.ZoomX<0.0) {
/* adjust x coordinate for left/right mirroring */
- x = x - m;
+ dstspan.x = x - dstspan.end;
}
+ else
+ dstspan.x = x;
+
/* compute which rows to draw */
row = y-y0;
}
/* check if left edge is outside window */
- skipcol = 0;
- if (x<0) {
- skipcol = -x;
- m += x;
+ if (dstspan.x < 0) {
+ dstspan.start = -x;
}
+
/* make sure span isn't too long or short */
- if (m>maxwidth) {
+ /* if (m>maxwidth) {
m = maxwidth;
- }
- else if (m<=0) {
+ }*/
+
+ if (dstspan.end <= dstspan.start) {
return;
}
- ASSERT( m <= MAX_WIDTH );
+ ASSERT( dstspan.end <= MAX_WIDTH );
/* zoom the span horizontally */
if (ctx->Pixel.ZoomX==-1.0F) {
+ SW_SPAN_SET_FLAG(dstspan.filledColor);
+ SW_SPAN_SET_FLAG(dstspan.filledAlpha);
+ SW_SPAN_SET_FLAG(dstspan.filledDepth);
/* n==m */
- for (j=0;j<m;j++) {
- i = n - (j+skipcol) - 1;
- dstRGBA32[j] = srcRGBA32[i];
- zdepth[j] = z[i];
+ for (j=dstspan.start; j<dstspan.end; j++) {
+ i = n - j - 1;
+ COPY_CHAN4(dstspan.color.rgba[j], rgba[i]);
+ dstspan.depth[j] = z[i];
}
if (fog && ctx->Fog.Enabled) {
- for (j=0;j<m;j++) {
- i = n - (j+skipcol) - 1;
+ for (j=dstspan.start; j<dstspan.end; j++) {
+ i = n - j - 1;
zfog[j] = fog[i];
}
}
}
else {
- GLfloat xscale = 1.0F / ctx->Pixel.ZoomX;
- for (j=0;j<m;j++) {
- i = (GLint) ((j+skipcol) * xscale);
+ const GLfloat xscale = 1.0F / ctx->Pixel.ZoomX;
+ SW_SPAN_SET_FLAG(dstspan.filledColor);
+ SW_SPAN_SET_FLAG(dstspan.filledAlpha);
+ SW_SPAN_SET_FLAG(dstspan.filledDepth);
+ for (j=dstspan.start; j<dstspan.end; j++) {
+ i = (GLint) (j * xscale);
if (i<0) i = n + i - 1;
- dstRGBA32[j] = srcRGBA32[i];
- zdepth[j] = z[i];
+ COPY_CHAN4(dstspan.color.rgba[j], rgba[i]);
+ dstspan.depth[j] = z[i];
}
if (fog && ctx->Fog.Enabled) {
- for (j=0;j<m;j++) {
- i = (GLint) ((j+skipcol) * xscale);
+ for (j=dstspan.start; j<dstspan.end; j++) {
+ i = (GLint) (j * xscale);
if (i<0) i = n + i - 1;
zfog[j] = fog[i];
}
}
/* write the span */
- for (r=r0; r<r1; r++) {
- _old_write_rgba_span( ctx, m, x+skipcol, r, zdepth,
- (fog ? zfog : 0), zrgba, NULL, GL_BITMAP );
+ for (dstspan.y = r0; dstspan.y < r1; dstspan.y++) {
+ SAVE_SPAN(dstspan);
+ _mesa_write_rgba_span(ctx, &dstspan, (fog ? zfog : NULL), GL_BITMAP);
+ RESTORE_SPAN(dstspan);
+ /* problem here: "dstspan" can change inside
+ "_mesa_write_rgba_span". Best solution: make copy "tmpspan"
+ and give to function, but too slow */
}
}
-/* $Id: s_zoom.h,v 1.5 2001/05/03 22:13:32 brianp Exp $ */
+/* $Id: s_zoom.h,v 1.6 2002/01/21 18:12:34 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"),
#include "mtypes.h"
-
+#include "swrast.h"
extern void
_mesa_write_zoomed_rgba_span( GLcontext *ctx,
-/* $Id: swrast.h,v 1.14 2002/01/10 16:54:29 brianp Exp $ */
+/* $Id: swrast.h,v 1.15 2002/01/21 18:12:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
#include "mtypes.h"
-
/* The software rasterizer now uses this format for vertices. Thus a
* 'RasterSetup' stage or other translation is required between the
* tnl module and the swrast rasterization functions. This serves to
struct sw_span {
GLint x, y;
- GLuint start, end; /* start=first pixel in span, end=last pixel in span*/
- /* only end is used until now.(end was before called count) */
+
+ /* only need to process pixels between start <= i < end */
+ GLuint start, end;
+
+ /* This flag indicates that only a part of the span is visible */
+ GLboolean writeAll;
+
GLuint activeMask; /* OR of the SPAN_* flags */
+
#if CHAN_TYPE == GL_FLOAT
GLfloat red, redStep;
GLfloat green, greenStep;
GLfloat rho[MAX_TEXTURE_UNITS];
GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS];
- GLboolean write_all; /* This flag indicates that only a part of */
- /*the span is visible. */
-#ifdef DEBUG
- GLboolean filledDepth, filledMask, filledAlpha;
- GLboolean filledColor, filledSpecular;
- GLboolean filledLambda[MAX_TEXTURE_UNITS], filledTex[MAX_TEXTURE_UNITS];
- GLboolean testedDepth, testedAlpha;
-#endif
- /* The interpolated fragment values */
+ /**
+ * Arrays of fragment values. These will either be computed from the
+ * x/xStep values above or loadd from glDrawPixels, etc.
+ */
GLdepth depth[MAX_WIDTH];
union {
GLchan rgb[MAX_WIDTH][3];
GLchan rgba[MAX_WIDTH][4];
GLuint index[MAX_WIDTH];
} color;
- GLchan specular[MAX_WIDTH][4];
- GLint itexcoords[MAX_WIDTH][2]; /* s, t */
- GLfloat texcoords[MAX_TEXTURE_UNITS][MAX_WIDTH][4]; /* s, t, r */
+ GLchan specular[MAX_WIDTH][4];
+ GLint itexcoords[MAX_WIDTH][2]; /* Integer texture (s, t) */
+ /* Texture (s,t,r). 4th component only used for pixel texture */
+ GLfloat texcoords[MAX_TEXTURE_UNITS][MAX_WIDTH][4];
GLfloat lambda[MAX_TEXTURE_UNITS][MAX_WIDTH];
GLfloat coverage[MAX_WIDTH];
GLubyte mask[MAX_WIDTH];
+
+#ifdef DEBUG
+ GLboolean filledDepth, filledMask, filledAlpha;
+ GLboolean filledColor, filledSpecular;
+ GLboolean filledLambda[MAX_TEXTURE_UNITS], filledTex[MAX_TEXTURE_UNITS];
+ GLboolean testedDepth, testedAlpha;
+#endif
};
+
#ifdef DEBUG
#define SW_SPAN_SET_FLAG(flag) {ASSERT((flag) == GL_FALSE);(flag) = GL_TRUE;}
#define SW_SPAN_RESET(span) { \
MAX_TEXTURE_UNITS*sizeof(GLboolean)); \
MEMSET((span).filledLambda, GL_FALSE, \
MAX_TEXTURE_UNITS*sizeof(GLboolean)); \
- (span).start = 0; (span).write_all = GL_TRUE;}
+ (span).start = 0; (span).writeAll = GL_TRUE;}
#else
#define SW_SPAN_SET_FLAG(flag) ;
-#define SW_SPAN_RESET(span) {(span).start = 0;(span).write_all = GL_TRUE;}
+#define SW_SPAN_RESET(span) {(span).start = 0;(span).writeAll = GL_TRUE;}
#endif
struct swrast_device_driver;