-/* $Id: fog.c,v 1.1 1999/08/19 00:55:41 jtg Exp $ */
+/* $Id: fog.c,v 1.8 2000/03/07 17:40:34 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.1
+ * Version: 3.3
*
- * Copyright (C) 1999 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2000 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"),
#ifdef PC_HEADER
#include "all.h"
#else
-#include <math.h>
-#include <stdlib.h>
+#include "glheader.h"
#include "context.h"
#include "fog.h"
#include "macros.h"
#include "mmath.h"
#include "types.h"
-#ifdef XFree86Server
-#include "GL/xf86glx.h"
-#endif
+#include "xform.h"
#endif
-void gl_Fogfv( GLcontext *ctx, GLenum pname, const GLfloat *params )
+void
+_mesa_Fogf(GLenum pname, GLfloat param)
+{
+ _mesa_Fogfv(pname, ¶m);
+}
+
+
+void
+_mesa_Fogi(GLenum pname, GLint param )
+{
+ GLfloat fparam = (GLfloat) param;
+ _mesa_Fogfv(pname, &fparam);
+}
+
+
+void
+_mesa_Fogiv(GLenum pname, const GLint *params )
+{
+ GLfloat p[4];
+ switch (pname) {
+ case GL_FOG_MODE:
+ case GL_FOG_DENSITY:
+ case GL_FOG_START:
+ case GL_FOG_END:
+ case GL_FOG_INDEX:
+ p[0] = (GLfloat) *params;
+ break;
+ case GL_FOG_COLOR:
+ p[0] = INT_TO_FLOAT( params[0] );
+ p[1] = INT_TO_FLOAT( params[1] );
+ p[2] = INT_TO_FLOAT( params[2] );
+ p[3] = INT_TO_FLOAT( params[3] );
+ break;
+ default:
+ /* Error will be caught later in _mesa_Fogfv */
+ ;
+ }
+ _mesa_Fogfv(pname, p);
+}
+
+
+void
+_mesa_Fogfv( GLenum pname, const GLfloat *params )
{
+ GET_CURRENT_CONTEXT(ctx);
GLenum m;
switch (pname) {
}
break;
case GL_FOG_START:
-#if 0
- /* Prior to OpenGL 1.1, this was an error */
- if (*params<0.0F) {
- gl_error( ctx, GL_INVALID_VALUE, "glFog(GL_FOG_START)" );
- return;
- }
-#endif
ctx->Fog.Start = *params;
break;
case GL_FOG_END:
-#if 0
- /* Prior to OpenGL 1.1, this was an error */
- if (*params<0.0F) {
- gl_error( ctx, GL_INVALID_VALUE, "glFog(GL_FOG_END)" );
- return;
- }
-#endif
ctx->Fog.End = *params;
break;
case GL_FOG_INDEX:
typedef void (*fog_func)( struct vertex_buffer *VB, GLuint side,
GLubyte flag );
+typedef void (*fog_coord_func)( struct vertex_buffer *VB,
+ const GLvector4f *from,
+ GLubyte flag );
static fog_func fog_ci_tab[2];
static fog_func fog_rgba_tab[2];
+static fog_coord_func make_fog_coord_tab[2];
/*
* Compute the fogged color for an array of vertices.
#define IDX 1
#include "fog_tmp.h"
-void gl_init_fog( void )
+
+void
+_mesa_init_fog( void )
{
init_fog_tab_masked();
init_fog_tab_raw();
}
+
/*
* Compute fog for the vertices in the vertex buffer.
*/
-void gl_fog_vertices( struct vertex_buffer *VB )
+void
+_mesa_fog_vertices( struct vertex_buffer *VB )
{
GLcontext *ctx = VB->ctx;
GLuint i = VB->CullMode & 1;
}
}
+
+static void check_fog_coords( GLcontext *ctx, struct gl_pipeline_stage *d )
+{
+ d->type = 0;
+
+ if (ctx->FogMode==FOG_FRAGMENT)
+ {
+ d->type = PIPE_IMMEDIATE|PIPE_PRECALC;
+ d->inputs = VERT_OBJ_ANY;
+ d->outputs = VERT_FOG_COORD;
+ }
+}
+
+
+static void gl_make_fog_coords( struct vertex_buffer *VB )
+{
+ GLcontext *ctx = VB->ctx;
+
+ /* If full eye coords weren't required, just calculate the eye Z
+ * values.
+ */
+ if (!ctx->NeedEyeCoords) {
+ GLfloat *m = ctx->ModelView.m;
+ GLfloat plane[4];
+
+ plane[0] = m[2];
+ plane[1] = m[6];
+ plane[2] = m[10];
+ plane[3] = m[14];
+
+ gl_dotprod_tab[0][VB->ObjPtr->size](&VB->Eye,
+ 2, /* fill z coordinates */
+ VB->ObjPtr,
+ plane,
+ 0 );
+
+ make_fog_coord_tab[0]( VB, &VB->Eye, 0 );
+ }
+ else
+ {
+ make_fog_coord_tab[0]( VB, VB->EyePtr, 0 );
+ }
+}
+
+
+/* Drivers that want fog coordinates in VB->Spec[0] alpha, can substitute this
+ * stage for the default PIPE_OP_FOG pipeline stage.
+ */
+struct gl_pipeline_stage gl_fog_coord_stage = {
+ "build fog coordinates",
+ PIPE_OP_FOG,
+ PIPE_PRECALC|PIPE_IMMEDIATE,
+ 0,
+ NEW_FOG,
+ NEW_LIGHTING|NEW_RASTER_OPS|NEW_FOG|NEW_MODELVIEW,
+ 0, 0,
+ 0, 0, 0,
+ check_fog_coords,
+ gl_make_fog_coords
+};
+
+
+
+
+
/*
* Apply fog to an array of RGBA pixels.
* Input: n - number of pixels
* red, green, blue, alpha - pixel colors
* Output: red, green, blue, alpha - fogged pixel colors
*/
-void gl_fog_rgba_pixels( const GLcontext *ctx,
- GLuint n, const GLdepth z[], GLubyte rgba[][4] )
+void
+_mesa_fog_rgba_pixels( const GLcontext *ctx,
+ GLuint n, const GLdepth z[], GLubyte rgba[][4] )
{
GLfloat c = ctx->ProjectionMatrix.m[10];
GLfloat d = ctx->ProjectionMatrix.m[14];
}
break;
default:
- gl_problem(ctx, "Bad fog mode in gl_fog_rgba_pixels");
+ gl_problem(ctx, "Bad fog mode in _mesa_fog_rgba_pixels");
return;
}
}
* index - pixel color indexes
* Output: index - fogged pixel color indexes
*/
-void gl_fog_ci_pixels( const GLcontext *ctx,
- GLuint n, const GLdepth z[], GLuint index[] )
+void
+_mesa_fog_ci_pixels( const GLcontext *ctx,
+ GLuint n, const GLdepth z[], GLuint index[] )
{
GLfloat c = ctx->ProjectionMatrix.m[10];
GLfloat d = ctx->ProjectionMatrix.m[14];
}
break;
default:
- gl_problem(ctx, "Bad fog mode in gl_fog_ci_pixels");
+ gl_problem(ctx, "Bad fog mode in _mesa_fog_ci_pixels");
return;
}
}