From: Brian Paul Date: Mon, 28 Jan 2002 04:25:56 +0000 (+0000) Subject: Still more texture/span simplification and clean-up. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6e1666437ea091ecc50ab2b56d87129318f641d2;p=mesa.git Still more texture/span simplification and clean-up. Updated comments, fixed indentation, etc. --- diff --git a/src/mesa/swrast/s_copypix.c b/src/mesa/swrast/s_copypix.c index 718a08200e3..7d2bca38f47 100644 --- a/src/mesa/swrast/s_copypix.c +++ b/src/mesa/swrast/s_copypix.c @@ -1,4 +1,4 @@ -/* $Id: s_copypix.c,v 1.30 2002/01/28 03:42:28 brianp Exp $ */ +/* $Id: s_copypix.c,v 1.31 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -299,8 +299,7 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy, SWcontext *swrast = SWRAST_CONTEXT(ctx); GLchan *tmpImage,*p; GLboolean quick_draw; - GLint sy, dy, stepy; - GLint i, j; + GLint sy, dy, stepy, j; GLboolean changeBuffer; GLchan *saveReadAlpha; const GLboolean zoom = ctx->Pixel.ZoomX != 1.0F || ctx->Pixel.ZoomY != 1.0F; diff --git a/src/mesa/swrast/s_pixeltex.c b/src/mesa/swrast/s_pixeltex.c index cbebeaf407b..82afab9ae93 100644 --- a/src/mesa/swrast/s_pixeltex.c +++ b/src/mesa/swrast/s_pixeltex.c @@ -1,4 +1,4 @@ -/* $Id: s_pixeltex.c,v 1.5 2002/01/27 18:32:03 brianp Exp $ */ +/* $Id: s_pixeltex.c,v 1.6 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -94,21 +94,23 @@ _swrast_pixel_texture(GLcontext *ctx, struct sw_span *span) { if (ctx->Texture._ReallyEnabled & ~TEXTURE0_ANY) { /* multitexture! */ - GLchan rgbaOut[MAX_WIDTH][4]; + GLchan primary_rgba[MAX_WIDTH][4]; GLuint unit; - MEMCPY(rgbaOut, span->color.rgba, 4 * span->end * sizeof(GLchan)); + MEMCPY(primary_rgba, span->color.rgba, 4 * span->end * sizeof(GLchan)); for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { if (ctx->Texture.Unit[unit]._ReallyEnabled) { pixeltexgen(ctx, span->end, (const GLchan (*)[4]) span->color.rgba, span->texcoords[unit]); - _swrast_texture_fragments(ctx, unit, span, rgbaOut); + _swrast_texture_fragments(ctx, unit, span->end, + span->texcoords[unit], + span->lambda[unit], + (CONST GLchan (*)[4]) primary_rgba, + span->color.rgba); } } - - MEMCPY(span->color.rgba, rgbaOut, 4 * span->end * sizeof(GLchan)); } else { /* single texture, unit 0 */ @@ -116,6 +118,9 @@ _swrast_pixel_texture(GLcontext *ctx, struct sw_span *span) pixeltexgen(ctx, span->end, (const GLchan (*)[4]) span->color.rgba, span->texcoords[0]); - _swrast_texture_fragments(ctx, 0, span, span->color.rgba); + _swrast_texture_fragments(ctx, 0, span->end, + span->texcoords[0], span->lambda[0], + (CONST GLchan (*)[4]) span->color.rgba, + (GLchan (*)[4]) span->color.rgba); } } diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c index 87b6aa40ee9..f709494a7e2 100644 --- a/src/mesa/swrast/s_span.c +++ b/src/mesa/swrast/s_span.c @@ -1,4 +1,4 @@ -/* $Id: s_span.c,v 1.26 2002/01/28 03:42:28 brianp Exp $ */ +/* $Id: s_span.c,v 1.27 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -648,6 +648,7 @@ _mesa_write_index_span( GLcontext *ctx, struct sw_span *span, } /* Fog */ + /* XXX try to simplify the fog code! */ if (ctx->Fog.Enabled) { if ((span->arrayMask & SPAN_FOG) && !swrast->_PreferPixelFog) _mesa_fog_ci_pixels_with_array( ctx, span, span->fogArray, @@ -798,7 +799,8 @@ _mesa_write_rgba_span( GLcontext *ctx, struct sw_span *span, return; } - /* Per-pixel fog */ + /* Fog */ + /* XXX try to simplify the fog code! */ if (ctx->Fog.Enabled) { if ((span->arrayMask & SPAN_FOG) && !swrast->_PreferPixelFog) _mesa_fog_rgba_pixels_with_array(ctx, span, span->fogArray, @@ -1026,12 +1028,9 @@ _mesa_write_texture_span( GLcontext *ctx, struct sw_span *span, add_colors( span->end, span->color.rgba, span->specArray ); } - /* Per-pixel fog */ + /* Fog */ + /* XXX try to simplify the fog code! */ if (ctx->Fog.Enabled) { -#if 0 - if ((span->interpMask & SPAN_FOG) && (span->arrayMask & SPAN_FOG) == 0) - interpolate_fog(ctx, span); -#endif if ((span->arrayMask & SPAN_FOG) && !swrast->_PreferPixelFog) _mesa_fog_rgba_pixels_with_array( ctx, span, span->fogArray, span->color.rgba); diff --git a/src/mesa/swrast/s_texture.c b/src/mesa/swrast/s_texture.c index 663fa6c7575..0ed753e9678 100644 --- a/src/mesa/swrast/s_texture.c +++ b/src/mesa/swrast/s_texture.c @@ -1,4 +1,4 @@ -/* $Id: s_texture.c,v 1.47 2002/01/28 00:07:33 brianp Exp $ */ +/* $Id: s_texture.c,v 1.48 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -3031,7 +3031,7 @@ sample_depth_texture2(const GLcontext *ctx, * Apply a unit of texture mapping to the incoming fragments. */ void -_old_swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, +_swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, GLfloat texcoords[][4], GLfloat lambda[], CONST GLchan primary_rgba[][4], GLchan rgba[][4] ) @@ -3084,69 +3084,6 @@ _old_swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, GLuint n, } -/* - * Apply a unit of texture mapping to the incoming fragments. - */ -void -_swrast_texture_fragments( GLcontext *ctx, GLuint texUnit, - struct sw_span *span, - GLchan rgbaOut[][4] ) -{ - const GLuint mask = TEXTURE0_ANY << (texUnit * 4); - - if (ctx->Texture._ReallyEnabled & mask) { - const struct gl_texture_unit *textureUnit = &ctx->Texture.Unit[texUnit]; - GLfloat *lambda; - - lambda = (span->arrayMask & SPAN_LAMBDA) ? span->lambda[texUnit] : NULL; - - if (textureUnit->_Current) { /* XXX need this? */ - const struct gl_texture_object *curObj = textureUnit->_Current; - GLchan texel[PB_SIZE][4]; - - if (textureUnit->LodBias != 0.0F) { - /* apply LOD bias, but don't clamp yet */ - GLuint i; - for (i=0;iend;i++) { - lambda[i] += textureUnit->LodBias; - } - } - - if ((curObj->MinLod != -1000.0 || curObj->MaxLod != 1000.0) - && lambda) { - /* apply LOD clamping to lambda */ - const GLfloat min = curObj->MinLod; - const GLfloat max = curObj->MaxLod; - GLuint i; - for (i=0;iend;i++) { - GLfloat l = lambda[i]; - lambda[i] = CLAMP(l, min, max); - } - } - - /* Sample the texture. */ - if (curObj->Image[curObj->BaseLevel]->Format == GL_DEPTH_COMPONENT) { - /* depth texture */ - sample_depth_texture(ctx, textureUnit, span->end, - span->texcoords[texUnit], texel); - } - else { - /* color texture */ - SWRAST_CONTEXT(ctx)->TextureSample[texUnit]( ctx, texUnit, - textureUnit->_Current, - span->end, - span->texcoords[texUnit], - lambda, texel ); - } - apply_texture( ctx, textureUnit, span->end, - (CONST GLchan (*)[4]) span->color.rgba, - (CONST GLchan (*)[4]) texel, - rgbaOut ); - } - } -} - - /* * Apply multiple texture stages (or just unit 0) to the span. * At some point in the future we'll probably modify this so that @@ -3170,7 +3107,7 @@ _swrast_multitexture_fragments( GLcontext *ctx, struct sw_span *span ) /* loop over texture units, modifying the span->color.rgba values */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { if (ctx->Texture.Unit[unit]._ReallyEnabled) { - _old_swrast_texture_fragments( ctx, unit, span->end, + _swrast_texture_fragments( ctx, unit, span->end, span->texcoords[unit], (span->arrayMask & SPAN_LAMBDA) ? span->lambda[unit] : NULL, @@ -3183,7 +3120,7 @@ _swrast_multitexture_fragments( GLcontext *ctx, struct sw_span *span ) /* Just unit 0 enabled */ ASSERT(ctx->Texture._ReallyEnabled & TEXTURE0_ANY); - _old_swrast_texture_fragments( ctx, 0, span->end, + _swrast_texture_fragments( ctx, 0, span->end, span->texcoords[0], (span->arrayMask & SPAN_LAMBDA) ? span->lambda[0] : NULL, diff --git a/src/mesa/swrast/s_texture.h b/src/mesa/swrast/s_texture.h index 6c3b2b801a3..ba9642e04a5 100644 --- a/src/mesa/swrast/s_texture.h +++ b/src/mesa/swrast/s_texture.h @@ -1,4 +1,4 @@ -/* $Id: s_texture.h,v 1.10 2002/01/28 00:07:33 brianp Exp $ */ +/* $Id: s_texture.h,v 1.11 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -38,14 +38,8 @@ _swrast_choose_texture_sample_func( GLcontext *ctx, GLuint texUnit, const struct gl_texture_object *tObj ); - -extern void -_swrast_texture_fragments( GLcontext *ctx, GLuint texSet, - struct sw_span *span, - GLchan rgba[][4] ); - extern void -_old_swrast_texture_fragments( GLcontext *ctx, GLuint texSet, GLuint n, +_swrast_texture_fragments( GLcontext *ctx, GLuint texSet, GLuint n, GLfloat texcoords[][4], GLfloat lambda[], CONST GLchan primary_rgba[][4], GLchan rgba[][4] ); diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c index ce0b127b51e..ace64fcaf3c 100644 --- a/src/mesa/swrast/s_triangle.c +++ b/src/mesa/swrast/s_triangle.c @@ -1,4 +1,4 @@ -/* $Id: s_triangle.c,v 1.51 2002/01/28 03:42:28 brianp Exp $ */ +/* $Id: s_triangle.c,v 1.52 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -85,8 +85,7 @@ static void flat_ci_triangle( GLcontext *ctx, span.index = IntToFixed(v2->index); \ span.indexStep = 0; -#define RENDER_SPAN( span ) \ - _mesa_write_index_span(ctx, &span, GL_POLYGON ); +#define RENDER_SPAN( span ) _mesa_write_index_span(ctx, &span, GL_POLYGON ) #include "s_tritemp.h" } @@ -105,8 +104,7 @@ static void smooth_ci_triangle( GLcontext *ctx, #define INTERP_FOG 1 #define INTERP_INDEX 1 -#define RENDER_SPAN( span ) \ - _mesa_write_index_span(ctx, &span, GL_POLYGON); +#define RENDER_SPAN( span ) _mesa_write_index_span(ctx, &span, GL_POLYGON) #include "s_tritemp.h" } @@ -138,8 +136,7 @@ static void flat_rgba_triangle( GLcontext *ctx, span.blueStep = 0; \ span.alphaStep = 0; -#define RENDER_SPAN( span ) \ - _mesa_write_rgba_span(ctx, &span, GL_POLYGON ); +#define RENDER_SPAN( span ) _mesa_write_rgba_span(ctx, &span, GL_POLYGON ) #include "s_tritemp.h" } @@ -161,8 +158,8 @@ static void smooth_rgba_triangle( GLcontext *ctx, #define INTERP_RGB 1 #define INTERP_ALPHA 1 -#define RENDER_SPAN( span ) \ - ASSERT(span.interpMask & SPAN_RGBA); \ +#define RENDER_SPAN( span ) \ + ASSERT(span.interpMask & SPAN_RGBA); \ _mesa_write_rgba_span(ctx, &span, GL_POLYGON); #include "s_tritemp.h" @@ -926,13 +923,6 @@ static void general_textured_triangle( GLcontext *ctx, #define INTERP_ALPHA 1 #define INTERP_TEX 1 -#define SETUP_CODE \ - const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \ - const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\ - span.texWidth[0] = (GLfloat) texImage->Width; \ - span.texHeight[0] = (GLfloat) texImage->Height; \ - (void) fixedToDepthShift; - #define RENDER_SPAN( span ) _mesa_write_texture_span(ctx, &span, GL_POLYGON); #include "s_tritemp.h" @@ -961,13 +951,6 @@ static void lambda_textured_triangle( GLcontext *ctx, #define INTERP_TEX 1 #define INTERP_LAMBDA 1 -#define SETUP_CODE \ - const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; \ - const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel];\ - span.texWidth[0] = (GLfloat) texImage->Width; \ - span.texHeight[0] = (GLfloat) texImage->Height; \ - (void) fixedToDepthShift; - #define RENDER_SPAN( span ) _mesa_write_texture_span(ctx, &span, GL_POLYGON); #include "s_tritemp.h" @@ -996,20 +979,6 @@ lambda_multitextured_triangle( GLcontext *ctx, #define INTERP_MULTITEX 1 #define INTERP_LAMBDA 1 -#define SETUP_CODE \ - GLuint u; \ - for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { \ - if (ctx->Texture.Unit[u]._ReallyEnabled) { \ - const struct gl_texture_object *texObj; \ - const struct gl_texture_image *texImage; \ - texObj = ctx->Texture.Unit[u]._Current; \ - texImage = texObj->Image[texObj->BaseLevel]; \ - span.texWidth[u] = (GLfloat) texImage->Width; \ - span.texHeight[u] = (GLfloat) texImage->Height; \ - } \ - } \ - (void) fixedToDepthShift; - #define RENDER_SPAN( span ) _mesa_write_texture_span(ctx, &span, GL_POLYGON); #include "s_tritemp.h" diff --git a/src/mesa/swrast/s_tritemp.h b/src/mesa/swrast/s_tritemp.h index 7f9809974b6..ffdfcfa4dc7 100644 --- a/src/mesa/swrast/s_tritemp.h +++ b/src/mesa/swrast/s_tritemp.h @@ -1,4 +1,4 @@ -/* $Id: s_tritemp.h,v 1.32 2002/01/28 03:42:28 brianp Exp $ */ +/* $Id: s_tritemp.h,v 1.33 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -602,10 +602,14 @@ } # ifdef INTERP_LAMBDA { - GLfloat dudx = span.texStep[0][0] * span.texWidth[0]; - GLfloat dudy = dsdy * span.texWidth[0]; - GLfloat dvdx = span.texStep[0][1] * span.texHeight[0]; - GLfloat dvdy = dtdy * span.texHeight[0]; + const struct gl_texture_object *obj = ctx->Texture.Unit[0]._Current; + const struct gl_texture_image *texImage = obj->Image[obj->BaseLevel]; + const GLfloat texWidth = (GLfloat) texImage->Width; + const GLfloat texHeight = (GLfloat) texImage->Height; + GLfloat dudx = span.texStep[0][0] * texWidth; + GLfloat dudy = dsdy * texWidth; + GLfloat dvdx = span.texStep[0][1] * texHeight; + GLfloat dvdy = dtdy * texHeight; GLfloat r1 = dudx * dudx + dudy * dudy; GLfloat r2 = dvdx * dvdx + dvdy * dvdy; span.rho[0] = r1 + r2; /* was rho2 = MAX2(r1,r2) */ @@ -662,10 +666,16 @@ dvdy[u] = oneOverArea * (eMaj.dx * eBot_dv - eMaj_dv * eBot.dx); # ifdef INTERP_LAMBDA { - GLfloat dudx = span.texStep[u][0] * span.texWidth[u]; - GLfloat dudy = dsdy[u] * span.texWidth[u]; - GLfloat dvdx = span.texStep[u][1] * span.texHeight[u]; - GLfloat dvdy = dtdy[u] * span.texHeight[u]; + const struct gl_texture_object *obj + = ctx->Texture.Unit[u]._Current; + const struct gl_texture_image *texImage + = obj->Image[obj->BaseLevel]; + const GLfloat texWidth = (GLfloat) texImage->Width; + const GLfloat texHeight = (GLfloat) texImage->Height; + GLfloat dudx = span.texStep[u][0] * texWidth; + GLfloat dudy = dsdy[u] * texWidth; + GLfloat dvdx = span.texStep[u][1] * texHeight; + GLfloat dvdy = dtdy[u] * texHeight; GLfloat r1 = dudx * dudx + dudy * dudy; GLfloat r2 = dvdx * dvdx + dvdy * dvdy; span.rho[u] = r1 + r2; /* was rho2 = MAX2(r1,r2) */ diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h index 9a20370888c..93263ff2093 100644 --- a/src/mesa/swrast/swrast.h +++ b/src/mesa/swrast/swrast.h @@ -1,4 +1,4 @@ -/* $Id: swrast.h,v 1.18 2002/01/28 03:42:28 brianp Exp $ */ +/* $Id: swrast.h,v 1.19 2002/01/28 04:25:56 brianp Exp $ */ /* * Mesa 3-D graphics library @@ -67,11 +67,14 @@ typedef struct { /* - * The sw_span structure is used by the triangle template code in - * s_tritemp.h. It describes how colors, Z, texcoords, etc are to be - * interpolated across each scanline of triangle. - * With this structure it's easy to hand-off span rasterization to a - * subroutine instead of doing it all inline like we used to do. + * The sw_span structure describes the colors, Z, fogcoord, texcoords, + * etc for a horizontal run of pixels. We can either specify a base/step + * to indicate interpolated values, or fill in arrays of values. + * The interpMask and arrayMask bitfields indicate which are active. + * + * With this structure it's easy to hand-off span rasterization to + * subroutines instead of doing it all inline in the triangle functions + * like we used to do. * It also cleans up the local variable namespace a great deal. * * It would be interesting to experiment with multiprocessor rasterization @@ -81,9 +84,7 @@ typedef struct { */ -/* When the sw_span struct is initialized, these flags indicates - * which values are needed for rendering the triangle. - */ +/* Values for interpMask and arrayMask */ #define SPAN_RGBA 0x001 #define SPAN_SPEC 0x002 #define SPAN_INDEX 0x004 @@ -105,8 +106,9 @@ struct sw_span { /* This flag indicates that only a part of the span is visible */ GLboolean writeAll; - /* This bitmask (bitwise-or of SPAN_* flags) indicates which of the - * x/xStep variables are relevant. + /** + * This bitmask (of SPAN_* flags) indicates which of the x/xStep + * variables are relevant. */ GLuint interpMask; @@ -132,18 +134,17 @@ struct sw_span { GLfloat fog, fogStep; GLfloat tex[MAX_TEXTURE_UNITS][4], texStep[MAX_TEXTURE_UNITS][4]; GLfixed intTex[2], intTexStep[2]; - /* Needed for texture lambda (LOD) computation */ - GLfloat rho[MAX_TEXTURE_UNITS]; - GLfloat texWidth[MAX_TEXTURE_UNITS], texHeight[MAX_TEXTURE_UNITS]; + GLfloat rho[MAX_TEXTURE_UNITS]; /* for texture lambda/lod computation */ - /* This bitmask (bitwise-or of SPAN_* flags) indicates which of the - * fragment arrays are relevant. + /** + * This bitmask (of SPAN_* flags) indicates which of the fragment arrays + * are relevant. */ GLuint arrayMask; /** * Arrays of fragment values. These will either be computed from the - * x/xStep values above or loadd from glDrawPixels, etc. + * x/xStep values above or filled in by glDraw/CopyPixels, etc. */ union { GLchan rgb[MAX_WIDTH][3]; @@ -153,7 +154,6 @@ struct sw_span { GLchan specArray[MAX_WIDTH][4]; GLdepth zArray[MAX_WIDTH]; GLfloat fogArray[MAX_WIDTH]; - /* 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]; @@ -282,19 +282,19 @@ _swrast_print_vertex( GLcontext *ctx, const SWvertex *v ); * Imaging fallbacks (a better solution should be found, perhaps * moving all the imaging fallback code to a new module) */ -void +extern void _swrast_CopyConvolutionFilter2D(GLcontext *ctx, GLenum target, GLenum internalFormat, GLint x, GLint y, GLsizei width, GLsizei height); -void +extern void _swrast_CopyConvolutionFilter1D(GLcontext *ctx, GLenum target, GLenum internalFormat, GLint x, GLint y, GLsizei width); -void +extern void _swrast_CopyColorSubTable( GLcontext *ctx,GLenum target, GLsizei start, GLint x, GLint y, GLsizei width); -void +extern void _swrast_CopyColorTable( GLcontext *ctx, GLenum target, GLenum internalformat, GLint x, GLint y, GLsizei width); @@ -306,31 +306,31 @@ _swrast_CopyColorTable( GLcontext *ctx, */ extern void _swrast_copy_teximage1d(GLcontext *ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, GLint border); + GLenum internalFormat, + GLint x, GLint y, GLsizei width, GLint border); extern void _swrast_copy_teximage2d(GLcontext *ctx, GLenum target, GLint level, - GLenum internalFormat, - GLint x, GLint y, GLsizei width, GLsizei height, - GLint border); + GLenum internalFormat, + GLint x, GLint y, GLsizei width, GLsizei height, + GLint border); extern void _swrast_copy_texsubimage1d(GLcontext *ctx, GLenum target, GLint level, - GLint xoffset, GLint x, GLint y, GLsizei width); + GLint xoffset, GLint x, GLint y, GLsizei width); extern void _swrast_copy_texsubimage2d(GLcontext *ctx, - GLenum target, GLint level, - GLint xoffset, GLint yoffset, - GLint x, GLint y, GLsizei width, GLsizei height); + GLenum target, GLint level, + GLint xoffset, GLint yoffset, + GLint x, GLint y, GLsizei width, GLsizei height); extern void _swrast_copy_texsubimage3d(GLcontext *ctx, - GLenum target, GLint level, - GLint xoffset, GLint yoffset, GLint zoffset, - GLint x, GLint y, GLsizei width, GLsizei height); + GLenum target, GLint level, + GLint xoffset, GLint yoffset, GLint zoffset, + GLint x, GLint y, GLsizei width, GLsizei height);