Browse Source

fix glDraw/CopyPixels w/ fog bug. minor fog code clean-ups.

tags/mesa_3_5
Brian Paul 24 years ago
parent
commit
af197f5f8f

+ 6
- 4
src/mesa/swrast/s_bitmap.c View File

@@ -1,4 +1,4 @@
/* $Id: s_bitmap.c,v 1.10 2001/05/30 15:22:05 brianp Exp $ */
/* $Id: s_bitmap.c,v 1.11 2001/06/18 23:55:18 brianp Exp $ */

/*
* Mesa 3-D graphics library
@@ -75,10 +75,12 @@ _swrast_Bitmap( GLcontext *ctx, GLint px, GLint py,
fragZ = (GLdepth) ( ctx->Current.RasterPos[2] * ctx->DepthMaxF);

if (ctx->Fog.Enabled) {
if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT)
if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fogCoord = ctx->Current.FogCoord;
else
fogCoord = ctx->Current.RasterDistance;
}
else {
fogCoord = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
}
}
else {
fogCoord = 0.0;

+ 38
- 9
src/mesa/swrast/s_copypix.c View File

@@ -1,4 +1,4 @@
/* $Id: s_copypix.c,v 1.19 2001/05/30 15:22:05 brianp Exp $ */
/* $Id: s_copypix.c,v 1.20 2001/06/18 23:55:18 brianp Exp $ */

/*
* Mesa 3-D graphics library
@@ -37,6 +37,7 @@

#include "s_context.h"
#include "s_depth.h"
#include "s_fog.h"
#include "s_histogram.h"
#include "s_pixeltex.h"
#include "s_span.h"
@@ -110,9 +111,16 @@ copy_conv_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
GLfloat fog;
GLint i;

if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fog = ctx->Current.RasterFogCoord;
}
else {
fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
}

for (i = 0; i < width; i++) {
zspan[i] = z;
fogSpan[i] = fog;
@@ -344,8 +352,15 @@ copy_rgba_pixels(GLcontext *ctx, GLint srcx, GLint srcy,
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
GLfloat fog;

if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fog = ctx->Current.RasterFogCoord;
}
else {
fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
}

for (i=0;i<width;i++) {
zspan[i] = z;
fogSpan[i] = fog;
@@ -603,8 +618,15 @@ static void copy_ci_pixels( GLcontext *ctx,
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMax);
GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
GLfloat fog;

if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fog = ctx->Current.RasterFogCoord;
}
else {
fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
}

for (i=0;i<width;i++) {
zspan[i] = z;
fogSpan[i] = fog;
@@ -745,8 +767,15 @@ static void copy_depth_pixels( GLcontext *ctx, GLint srcx, GLint srcy,
}

if (ctx->Fog.Enabled) {
GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
GLfloat fog;

if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fog = ctx->Current.RasterFogCoord;
}
else {
fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
}

for (i = 0; i < width; i++) {
fogSpan[i] = fog;
}

+ 20
- 5
src/mesa/swrast/s_drawpix.c View File

@@ -1,4 +1,4 @@
/* $Id: s_drawpix.c,v 1.20 2001/05/30 15:22:05 brianp Exp $ */
/* $Id: s_drawpix.c,v 1.21 2001/06/18 23:55:18 brianp Exp $ */

/*
* Mesa 3-D graphics library
@@ -37,6 +37,7 @@

#include "s_context.h"
#include "s_drawpix.h"
#include "s_fog.h"
#include "s_pixeltex.h"
#include "s_span.h"
#include "s_stencil.h"
@@ -497,9 +498,16 @@ draw_index_pixels( GLcontext *ctx, GLint x, GLint y,
/* Fragment depth values */
if (ctx->Depth.Test || ctx->Fog.Enabled) {
GLdepth zval = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMaxF);
GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
GLfloat fog;
GLint i;

if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fog = ctx->Current.RasterFogCoord;
}
else {
fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
}

for (i = 0; i < drawWidth; i++) {
zspan[i] = zval;
fogSpan[i] = fog;
@@ -736,9 +744,16 @@ draw_rgba_pixels( GLcontext *ctx, GLint x, GLint y,
if (ctx->Depth.Test || ctx->Fog.Enabled) {
/* fill in array of z values */
GLdepth z = (GLdepth) (ctx->Current.RasterPos[2] * ctx->DepthMaxF);
GLfloat fog = (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) ?
ctx->Current.RasterFogCoord : ctx->Current.RasterDistance;
GLfloat fog;
GLint i;

if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) {
fog = ctx->Current.RasterFogCoord;
}
else {
fog = _mesa_z_to_fogfactor(ctx, ctx->Current.RasterDistance);
}

for (i=0;i<width;i++) {
zspan[i] = z;
fogSpan[i] = fog;

+ 56
- 22
src/mesa/swrast/s_fog.c View File

@@ -1,4 +1,4 @@
/* $Id: s_fog.c,v 1.12 2001/05/03 22:13:32 brianp Exp $ */
/* $Id: s_fog.c,v 1.13 2001/06/18 23:55:18 brianp Exp $ */

/*
* Mesa 3-D graphics library
@@ -36,10 +36,44 @@
#include "s_pb.h"




/*
* Used to convert current raster distance to a fog factor in [0,1].
*/
GLfloat
_mesa_z_to_fogfactor(GLcontext *ctx, GLfloat z)
{
GLfloat d, f;

switch (ctx->Fog.Mode) {
case GL_LINEAR:
if (ctx->Fog.Start == ctx->Fog.End)
d = 1.0F;
else
d = 1.0F / (ctx->Fog.End - ctx->Fog.Start);
f = (ctx->Fog.End - z) * d;
return CLAMP(f, 0.0F, 1.0F);
case GL_EXP:
d = ctx->Fog.Density;
f = exp(-d * z);
return f;
case GL_EXP2:
d = ctx->Fog.Density;
f = exp(-(d * d * z * z));
return f;
default:
_mesa_problem(ctx, "Bad fog mode in make_fog_coord");
return 0.0;
}
}



/*
* Apply fog to an array of RGBA pixels.
* Input: n - number of pixels
* fog - array of interpolated screen-space fog coordinates in [0..1]
* fog - array of fog factors in [0,1]
* red, green, blue, alpha - pixel colors
* Output: red, green, blue, alpha - fogged pixel colors
*/
@@ -70,7 +104,7 @@ _mesa_fog_rgba_pixels( const GLcontext *ctx,
/*
* Apply fog to an array of color index pixels.
* Input: n - number of pixels
* z - array of integer depth values
* fog - array of fog factors in [0,1]
* index - pixel color indexes
* Output: index - fogged pixel color indexes
*/
@@ -90,7 +124,7 @@ _mesa_fog_ci_pixels( const GLcontext *ctx,


/*
* Calculate fog coords from window z values
* Calculate fog factors (in [0,1]) from window z values
* Input: n - number of pixels
* z - array of integer depth values
* red, green, blue, alpha - pixel colors
@@ -98,11 +132,11 @@ _mesa_fog_ci_pixels( const GLcontext *ctx,
*
* Use lookup table & interpolation?
*/
void
_mesa_win_fog_coords_from_z( const GLcontext *ctx,
GLuint n,
const GLdepth z[],
GLfloat fogcoord[] )
static void
compute_fog_factors_from_z( const GLcontext *ctx,
GLuint n,
const GLdepth z[],
GLfloat fogFact[] )
{
const GLboolean ortho = (ctx->ProjectionMatrix.m[15] != 0.0F);
const GLfloat p10 = ctx->ProjectionMatrix.m[10];
@@ -154,7 +188,7 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
GLfloat eyez = (ndcz - p14) / p10;
if (eyez < 0.0)
eyez = -eyez;
fogcoord[i] = (fogEnd - eyez) * fogScale;
fogFact[i] = (fogEnd - eyez) * fogScale;
}
}
else {
@@ -164,7 +198,7 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
GLfloat eyez = p14 / (ndcz + p10);
if (eyez < 0.0)
eyez = -eyez;
fogcoord[i] = (fogEnd - eyez) * fogScale;
fogFact[i] = (fogEnd - eyez) * fogScale;
}
}
}
@@ -176,7 +210,7 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
GLfloat eyez = (ndcz - p14) / p10;
if (eyez < 0.0)
eyez = -eyez;
fogcoord[i] = exp( -ctx->Fog.Density * eyez );
fogFact[i] = exp( -ctx->Fog.Density * eyez );
}
}
else {
@@ -186,7 +220,7 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
GLfloat eyez = p14 / (ndcz + p10);
if (eyez < 0.0)
eyez = -eyez;
fogcoord[i] = exp( -ctx->Fog.Density * eyez );
fogFact[i] = exp( -ctx->Fog.Density * eyez );
}
}
break;
@@ -203,7 +237,7 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
if (tmp < FLT_MIN_10_EXP)
tmp = FLT_MIN_10_EXP;
#endif
fogcoord[i] = exp( tmp );
fogFact[i] = exp( tmp );
}
}
else {
@@ -217,13 +251,13 @@ _mesa_win_fog_coords_from_z( const GLcontext *ctx,
if (tmp < FLT_MIN_10_EXP)
tmp = FLT_MIN_10_EXP;
#endif
fogcoord[i] = exp( tmp );
fogFact[i] = exp( tmp );
}
}
}
break;
default:
_mesa_problem(ctx, "Bad fog mode in _mesa_win_fog_coords_from_z");
_mesa_problem(ctx, "Bad fog mode in compute_fog_factors_from_z");
return;
}
}
@@ -240,10 +274,10 @@ void
_mesa_depth_fog_rgba_pixels( const GLcontext *ctx,
GLuint n, const GLdepth z[], GLchan rgba[][4] )
{
GLfloat fog[PB_SIZE];
GLfloat fogFact[PB_SIZE];
ASSERT(n <= PB_SIZE);
_mesa_win_fog_coords_from_z( ctx, n, z, fog );
_mesa_fog_rgba_pixels( ctx, n, fog, rgba );
compute_fog_factors_from_z( ctx, n, z, fogFact );
_mesa_fog_rgba_pixels( ctx, n, fogFact, rgba );
}


@@ -258,8 +292,8 @@ void
_mesa_depth_fog_ci_pixels( const GLcontext *ctx,
GLuint n, const GLdepth z[], GLuint index[] )
{
GLfloat fog[PB_SIZE];
GLfloat fogFact[PB_SIZE];
ASSERT(n <= PB_SIZE);
_mesa_win_fog_coords_from_z( ctx, n, z, fog );
_mesa_fog_ci_pixels( ctx, n, fog, index );
compute_fog_factors_from_z( ctx, n, z, fogFact );
_mesa_fog_ci_pixels( ctx, n, fogFact, index );
}

+ 5
- 1
src/mesa/swrast/s_fog.h View File

@@ -1,4 +1,4 @@
/* $Id: s_fog.h,v 1.4 2001/05/03 22:13:32 brianp Exp $ */
/* $Id: s_fog.h,v 1.5 2001/06/18 23:55:18 brianp Exp $ */

/*
* Mesa 3-D graphics library
@@ -33,6 +33,10 @@
#include "swrast.h"


extern GLfloat
_mesa_z_to_fogfactor(GLcontext *ctx, GLfloat z);


extern void
_mesa_fog_rgba_pixels( const GLcontext *ctx,
GLuint n, const GLfloat fog[],

+ 3
- 1
src/mesa/swrast/s_span.c View File

@@ -1,4 +1,4 @@
/* $Id: s_span.c,v 1.14 2001/05/15 21:30:27 brianp Exp $ */
/* $Id: s_span.c,v 1.15 2001/06/18 23:55:18 brianp Exp $ */

/*
* Mesa 3-D graphics library
@@ -175,6 +175,7 @@ multi_write_index_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
* Input: n - number of pixels in the span
* x, y - location of leftmost pixel in the span
* z - array of [n] z-values
* fog - array of fog factor values in [0,1]
* index - array of [n] color indexes
* primitive - either GL_POINT, GL_LINE, GL_POLYGON, or GL_BITMAP
*/
@@ -603,6 +604,7 @@ _mesa_write_rgba_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
* Input: n - number of pixels in the span
* x, y - location of leftmost pixel in the span
* z - array of [n] z-values
* fog - array of fog factor values in [0,1]
* r, g, b, a - the color of the pixels
* primitive - either GL_POINT, GL_LINE, GL_POLYGON or GL_BITMAP.
*/

Loading…
Cancel
Save