more work on GL_ARB_texture_compression
[mesa.git] / src / mesa / main / lines.c
index 50b13e83f228904397540b080f65bea6faeed8a0..28f9e38fbf530e2aff1b00c12754ad8f58b23fb7 100644 (file)
@@ -1,8 +1,8 @@
-/* $Id: lines.c,v 1.4 1999/11/08 07:36:44 brianp Exp $ */
+/* $Id: lines.c,v 1.10 2000/05/10 22:36:05 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
- * Version:  3.1
+ * Version:  3.3
  * 
  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  * 
  */
 
 
-
-
-
 #ifdef PC_HEADER
 #include "all.h"
 #else
-#ifndef XFree86Server
-#include <assert.h>
-#else
-#include "GL/xf86glx.h"
-#endif
+#include "glheader.h"
 #include "context.h"
 #include "depth.h"
 #include "feedback.h"
 
 
 
-void gl_LineWidth( GLcontext *ctx, GLfloat width )
+void
+_mesa_LineWidth( GLfloat width )
 {
+   GET_CURRENT_CONTEXT(ctx);
    if (width<=0.0) {
       gl_error( ctx, GL_INVALID_VALUE, "glLineWidth" );
       return;
@@ -63,17 +58,24 @@ void gl_LineWidth( GLcontext *ctx, GLfloat width )
       ctx->TriangleCaps &= ~DD_LINE_WIDTH;
       if (width != 1.0) ctx->TriangleCaps |= DD_LINE_WIDTH;
       ctx->NewState |= NEW_RASTER_OPS;
+      if (ctx->Driver.LineWidth)
+         (*ctx->Driver.LineWidth)(ctx, width);
    }
 }
 
 
 
-void gl_LineStipple( GLcontext *ctx, GLint factor, GLushort pattern )
+void
+_mesa_LineStipple( GLint factor, GLushort pattern )
 {
+   GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glLineStipple");
    ctx->Line.StippleFactor = CLAMP( factor, 1, 256 );
    ctx->Line.StipplePattern = pattern;
    ctx->NewState |= NEW_RASTER_OPS;
+
+   if (ctx->Driver.LineStipple)
+      ctx->Driver.LineStipple( ctx, factor, pattern );
 }
 
 
@@ -114,23 +116,14 @@ void gl_LineStipple( GLcontext *ctx, GLint factor, GLushort pattern )
 static void flat_ci_line( GLcontext *ctx,
                           GLuint vert0, GLuint vert1, GLuint pvert )
 {
-   GLint count;
-   GLint *pbx = ctx->PB->x;
-   GLint *pby = ctx->PB->y;
-   PB_SET_INDEX( ctx, ctx->PB, ctx->VB->IndexPtr->data[pvert] );
-   count = ctx->PB->count;
+   PB_SET_INDEX( ctx->PB, ctx->VB->IndexPtr->data[pvert] );
 
 #define INTERP_XY 1
-
-#define PLOT(X,Y)              \
-       pbx[count] = X;         \
-       pby[count] = Y;         \
-       count++;
+#define PLOT(X,Y)  PB_WRITE_PIXEL(ctx->PB, X, Y, 0);
 
 #include "linetemp.h"
 
-   ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -139,26 +132,15 @@ static void flat_ci_line( GLcontext *ctx,
 static void flat_ci_z_line( GLcontext *ctx,
                             GLuint vert0, GLuint vert1, GLuint pvert )
 {
-   GLint count;
-   GLint *pbx = ctx->PB->x;
-   GLint *pby = ctx->PB->y;
-   GLdepth *pbz = ctx->PB->z;
-   PB_SET_INDEX( ctx, ctx->PB, ctx->VB->IndexPtr->data[pvert] );
-   count = ctx->PB->count;
+   PB_SET_INDEX( ctx->PB, ctx->VB->IndexPtr->data[pvert] );
 
 #define INTERP_XY 1
 #define INTERP_Z 1
-
-#define PLOT(X,Y)              \
-       pbx[count] = X;         \
-       pby[count] = Y;         \
-       pbz[count] = Z;         \
-       count++;
+#define PLOT(X,Y)  PB_WRITE_PIXEL(ctx->PB, X, Y, Z);
 
 #include "linetemp.h"
 
-   ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -167,24 +149,15 @@ static void flat_ci_z_line( GLcontext *ctx,
 static void flat_rgba_line( GLcontext *ctx,
                             GLuint vert0, GLuint vert1, GLuint pvert )
 {
-   GLint count;
-   GLint *pbx = ctx->PB->x;
-   GLint *pby = ctx->PB->y;
-   GLubyte *color = ctx->VB->ColorPtr->data[pvert];
-   PB_SET_COLOR( ctx, ctx->PB, color[0], color[1], color[2], color[3] );
-   count = ctx->PB->count;
+   const GLubyte *color = ctx->VB->ColorPtr->data[pvert];
+   PB_SET_COLOR( ctx->PB, color[0], color[1], color[2], color[3] );
 
 #define INTERP_XY 1
-
-#define PLOT(X,Y)              \
-       pbx[count] = X;         \
-       pby[count] = Y;         \
-       count++;
+#define PLOT(X,Y)   PB_WRITE_PIXEL(ctx->PB, X, Y, 0);
 
 #include "linetemp.h"
 
-   ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -193,27 +166,16 @@ static void flat_rgba_line( GLcontext *ctx,
 static void flat_rgba_z_line( GLcontext *ctx,
                               GLuint vert0, GLuint vert1, GLuint pvert )
 {
-   GLint count;
-   GLint *pbx = ctx->PB->x;
-   GLint *pby = ctx->PB->y;
-   GLdepth *pbz = ctx->PB->z;
-   GLubyte *color = ctx->VB->ColorPtr->data[pvert];
-   PB_SET_COLOR( ctx, ctx->PB, color[0], color[1], color[2], color[3] );
-   count = ctx->PB->count;
+   const GLubyte *color = ctx->VB->ColorPtr->data[pvert];
+   PB_SET_COLOR( ctx->PB, color[0], color[1], color[2], color[3] );
 
 #define INTERP_XY 1
 #define INTERP_Z 1
-
-#define PLOT(X,Y)      \
-       pbx[count] = X; \
-       pby[count] = Y; \
-       pbz[count] = Z; \
-       count++;
+#define PLOT(X,Y)   PB_WRITE_PIXEL(ctx->PB, X, Y, Z);
 
 #include "linetemp.h"
 
-   ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -225,9 +187,11 @@ static void smooth_ci_line( GLcontext *ctx,
    GLint count = ctx->PB->count;
    GLint *pbx = ctx->PB->x;
    GLint *pby = ctx->PB->y;
-   GLuint *pbi = ctx->PB->i;
+   GLuint *pbi = ctx->PB->index;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
 #define INTERP_XY 1
 #define INTERP_INDEX 1
 
@@ -240,7 +204,7 @@ static void smooth_ci_line( GLcontext *ctx,
 #include "linetemp.h"
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -253,9 +217,11 @@ static void smooth_ci_z_line( GLcontext *ctx,
    GLint *pbx = ctx->PB->x;
    GLint *pby = ctx->PB->y;
    GLdepth *pbz = ctx->PB->z;
-   GLuint *pbi = ctx->PB->i;
+   GLuint *pbi = ctx->PB->index;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
 #define INTERP_XY 1
 #define INTERP_Z 1
 #define INTERP_INDEX 1
@@ -270,7 +236,7 @@ static void smooth_ci_z_line( GLcontext *ctx,
 #include "linetemp.h"
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -285,6 +251,8 @@ static void smooth_rgba_line( GLcontext *ctx,
    GLubyte (*pbrgba)[4] = ctx->PB->rgba;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
 #define INTERP_XY 1
 #define INTERP_RGB 1
 #define INTERP_ALPHA 1
@@ -301,7 +269,7 @@ static void smooth_rgba_line( GLcontext *ctx,
 #include "linetemp.h"
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -317,6 +285,8 @@ static void smooth_rgba_z_line( GLcontext *ctx,
    GLubyte (*pbrgba)[4] = ctx->PB->rgba;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
 #define INTERP_XY 1
 #define INTERP_Z 1
 #define INTERP_RGB 1
@@ -335,7 +305,7 @@ static void smooth_rgba_z_line( GLcontext *ctx,
 #include "linetemp.h"
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -356,9 +326,11 @@ static void general_smooth_ci_line( GLcontext *ctx,
    GLint *pbx = ctx->PB->x;
    GLint *pby = ctx->PB->y;
    GLdepth *pbz = ctx->PB->z;
-   GLuint *pbi = ctx->PB->i;
+   GLuint *pbi = ctx->PB->index;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
    if (ctx->Line.StippleFlag) {
       /* stippled */
 #define INTERP_XY 1
@@ -416,7 +388,7 @@ static void general_smooth_ci_line( GLcontext *ctx,
    }
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -428,7 +400,7 @@ static void general_flat_ci_line( GLcontext *ctx,
    GLint *pbx = ctx->PB->x;
    GLint *pby = ctx->PB->y;
    GLdepth *pbz = ctx->PB->z;
-   PB_SET_INDEX( ctx, ctx->PB, ctx->VB->IndexPtr->data[pvert] );
+   PB_SET_INDEX( ctx->PB, ctx->VB->IndexPtr->data[pvert] );
    count = ctx->PB->count;
 
    if (ctx->Line.StippleFlag) {
@@ -481,7 +453,7 @@ static void general_flat_ci_line( GLcontext *ctx,
    }
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -496,6 +468,8 @@ static void general_smooth_rgba_line( GLcontext *ctx,
    GLubyte (*pbrgba)[4] = ctx->PB->rgba;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
    if (ctx->Line.StippleFlag) {
       /* stippled */
 #define INTERP_XY 1
@@ -576,7 +550,7 @@ static void general_smooth_rgba_line( GLcontext *ctx,
    }
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -588,7 +562,7 @@ static void general_flat_rgba_line( GLcontext *ctx,
    GLint *pby = ctx->PB->y;
    GLdepth *pbz = ctx->PB->z;
    GLubyte *color = ctx->VB->ColorPtr->data[pvert];
-   PB_SET_COLOR( ctx, ctx->PB, color[0], color[1], color[2], color[3] );
+   PB_SET_COLOR( ctx->PB, color[0], color[1], color[2], color[3] );
    count = ctx->PB->count;
 
    if (ctx->Line.StippleFlag) {
@@ -641,7 +615,7 @@ static void general_flat_rgba_line( GLcontext *ctx,
    }
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -657,7 +631,7 @@ static void flat_textured_line( GLcontext *ctx,
    GLfloat *pbt = ctx->PB->t[0];
    GLfloat *pbu = ctx->PB->u[0];
    GLubyte *color = ctx->VB->ColorPtr->data[pv];
-   PB_SET_COLOR( ctx, ctx->PB, color[0], color[1], color[2], color[3] );
+   PB_SET_COLOR( ctx->PB, color[0], color[1], color[2], color[3] );
    count = ctx->PB->count;
 
    if (ctx->Line.StippleFlag) {
@@ -701,7 +675,7 @@ static void flat_textured_line( GLcontext *ctx,
    }
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -720,6 +694,8 @@ static void smooth_textured_line( GLcontext *ctx,
    GLubyte (*pbrgba)[4] = ctx->PB->rgba;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
    if (ctx->Line.StippleFlag) {
       /* stippled */
 #define INTERP_XY 1
@@ -773,7 +749,7 @@ static void smooth_textured_line( GLcontext *ctx,
    }
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -797,6 +773,8 @@ static void smooth_multitextured_line( GLcontext *ctx,
    GLubyte (*pbspec)[3] = ctx->PB->spec;
    (void) pvert;
 
+   ctx->PB->mono = GL_FALSE;
+
    if (ctx->Line.StippleFlag) {
       /* stippled */
 #define INTERP_XY 1
@@ -866,7 +844,7 @@ static void smooth_multitextured_line( GLcontext *ctx,
    }
 
    ctx->PB->count = count;
-   PB_CHECK_FLUSH( ctx, ctx->PB );
+   gl_flush_pb(ctx);
 }
 
 
@@ -1027,8 +1005,7 @@ void gl_set_line_function( GLcontext *ctx )
       else {
         if (ctx->Light.ShadeModel==GL_SMOOTH) {
            /* Width==1, non-stippled, smooth-shaded */
-            if (ctx->Depth.Test
-               || (ctx->Fog.Enabled && ctx->Hint.Fog==GL_NICEST)) {
+            if (ctx->Depth.Test || ctx->FogMode == FOG_FRAGMENT) {
                if (rgbmode)
                   ctx->Driver.LineFunc = smooth_rgba_z_line;
                else
@@ -1043,8 +1020,7 @@ void gl_set_line_function( GLcontext *ctx )
         }
          else {
            /* Width==1, non-stippled, flat-shaded */
-            if (ctx->Depth.Test
-                || (ctx->Fog.Enabled && ctx->Hint.Fog==GL_NICEST)) {
+            if (ctx->Depth.Test || ctx->FogMode == FOG_FRAGMENT) {
                if (rgbmode)
                   ctx->Driver.LineFunc = flat_rgba_z_line;
                else