use BCOPY macro on FreeBSD
[mesa.git] / src / mesa / main / attrib.c
index 4ca036110af18289290e71a4dff77d11567034d4..617a274e03ec1de227806f2d64737209d4f71df3 100644 (file)
@@ -1,10 +1,10 @@
-/* $Id: attrib.c,v 1.11 1999/11/11 01:22:25 brianp Exp $ */
+/* $Id: attrib.c,v 1.20 2000/03/19 01:10:11 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
  * Version:  3.1
  * 
- * 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"),
@@ -30,8 +30,8 @@
 #else
 #include "glheader.h"
 #include "attrib.h"
+#include "buffers.h"
 #include "context.h"
-#include "glmisc.h"
 #include "enable.h"
 #include "enums.h"
 #include "mem.h"
@@ -47,7 +47,8 @@
  * Allocate a new attribute state node.  These nodes have a
  * "kind" value and a pointer to a struct of state data.
  */
-static struct gl_attrib_node *new_attrib_node( GLbitfield kind )
+static struct gl_attrib_node *
+new_attrib_node( GLbitfield kind )
 {
    struct gl_attrib_node *an = MALLOC_STRUCT(gl_attrib_node);
    if (an) {
@@ -61,8 +62,9 @@ static struct gl_attrib_node *new_attrib_node( GLbitfield kind )
 /*
  * Copy texture object state from one texture object to another.
  */
-static void copy_texobj_state( struct gl_texture_object *dest,
-                               const struct gl_texture_object *src )
+static void
+copy_texobj_state( struct gl_texture_object *dest,
+                   const struct gl_texture_object *src )
 {
    /*
    dest->Name = src->Name;
@@ -92,15 +94,17 @@ static void copy_texobj_state( struct gl_texture_object *dest,
 
 
 
-void gl_PushAttrib( GLcontext* ctx, GLbitfield mask )
+void
+_mesa_PushAttrib(GLbitfield mask)
 {
    struct gl_attrib_node *newnode;
    struct gl_attrib_node *head;
 
+   GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushAttrib");
 
    if (MESA_VERBOSE&VERBOSE_API)
-      fprintf(stderr, "glPushAttrib %x\n", mask);
+      fprintf(stderr, "glPushAttrib %x\n", (int)mask);
 
    if (ctx->AttribStackDepth>=MAX_ATTRIB_STACK_DEPTH) {
       gl_error( ctx, GL_STACK_OVERFLOW, "glPushAttrib" );
@@ -386,9 +390,11 @@ void gl_PushAttrib( GLcontext* ctx, GLbitfield mask )
  * This function is kind of long just because we have to call a lot
  * of device driver functions to update device driver state.
  */
-void gl_PopAttrib( GLcontext* ctx )
+void
+_mesa_PopAttrib(void)
 {
    struct gl_attrib_node *attr, *next;
+   GET_CURRENT_CONTEXT(ctx);
 
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopAttrib");
 
@@ -417,21 +423,43 @@ void gl_PopAttrib( GLcontext* ctx )
                GLubyte oldAlphaRef = ctx->Color.AlphaRef;
                GLenum oldBlendSrc = ctx->Color.BlendSrcRGB;
                GLenum oldBlendDst = ctx->Color.BlendDstRGB;
+              GLenum oldLogicOp = ctx->Color.LogicOp;
                MEMCPY( &ctx->Color, attr->data,
                        sizeof(struct gl_colorbuffer_attrib) );
                if (ctx->Color.DrawBuffer != oldDrawBuffer) {
                   _mesa_DrawBuffer( ctx->Color.DrawBuffer);
                }
-               if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
-                    ctx->Color.AlphaRef != oldAlphaRef) &&
-                   ctx->Driver.AlphaFunc)
-                  (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
-                                            ctx->Color.AlphaRef / 255.0F);
                if ((ctx->Color.BlendSrcRGB != oldBlendSrc ||
-                    ctx->Color.BlendSrcRGB != oldBlendDst) &&
+                    ctx->Color.BlendDstRGB != oldBlendDst) &&
                    ctx->Driver.BlendFunc)
                   (*ctx->Driver.BlendFunc)( ctx, ctx->Color.BlendSrcRGB,
                                             ctx->Color.BlendDstRGB);
+              if (ctx->Color.LogicOp != oldLogicOp &&
+                  ctx->Driver.LogicOpcode) {
+                 ctx->Driver.LogicOpcode( ctx, ctx->Color.LogicOp );
+               }
+               if (ctx->Visual->RGBAflag) {
+                  GLubyte r = (GLint) (ctx->Color.ClearColor[0] * 255.0F);
+                  GLubyte g = (GLint) (ctx->Color.ClearColor[1] * 255.0F);
+                  GLubyte b = (GLint) (ctx->Color.ClearColor[2] * 255.0F);
+                  GLubyte a = (GLint) (ctx->Color.ClearColor[3] * 255.0F);
+                  (*ctx->Driver.ClearColor)( ctx, r, g, b, a );
+                  if ((ctx->Color.AlphaFunc != oldAlphaFunc ||
+                       ctx->Color.AlphaRef != oldAlphaRef) &&
+                      ctx->Driver.AlphaFunc)
+                     (*ctx->Driver.AlphaFunc)( ctx, ctx->Color.AlphaFunc,
+                                               ctx->Color.AlphaRef / 255.0F);
+                  if (ctx->Driver.ColorMask) {
+                     (*ctx->Driver.ColorMask)(ctx,
+                                              ctx->Color.ColorMask[0],
+                                              ctx->Color.ColorMask[1],
+                                              ctx->Color.ColorMask[2],
+                                              ctx->Color.ColorMask[3]);
+                  }
+               }
+               else {
+                  (*ctx->Driver.ClearIndex)( ctx, ctx->Color.ClearIndex);
+               }
             }
             break;
          case GL_CURRENT_BIT:
@@ -585,7 +613,7 @@ void gl_PopAttrib( GLcontext* ctx )
                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_INDEX, &index );
                   (*ctx->Driver.Fogfv)( ctx, GL_FOG_COLOR, ctx->Fog.Color );
                }
-              ctx->Enabled &= ENABLE_FOG;
+              ctx->Enabled &= ~ENABLE_FOG;
               if (ctx->Fog.Enabled) ctx->Enabled |= ENABLE_FOG;
             }
             break;
@@ -613,7 +641,13 @@ void gl_PopAttrib( GLcontext* ctx )
                }
                (*ctx->Driver.Enable)( ctx, GL_LIGHTING, ctx->Light.Enabled );
             }
-           ctx->Enabled &= ENABLE_LIGHT;
+            if (ctx->Light.ShadeModel == GL_FLAT)
+               ctx->TriangleCaps |= DD_FLATSHADE;
+            else
+               ctx->TriangleCaps &= ~DD_FLATSHADE;
+            if (ctx->Driver.ShadeModel)
+               (*ctx->Driver.ShadeModel)(ctx, ctx->Light.ShadeModel);
+           ctx->Enabled &= ~ENABLE_LIGHT;
            if (ctx->Light.Enabled && !is_empty_list(&ctx->Light.EnabledList))
               ctx->Enabled |= ENABLE_LIGHT;
             break;
@@ -623,6 +657,11 @@ void gl_PopAttrib( GLcontext* ctx )
                (*ctx->Driver.Enable)( ctx, GL_LINE_SMOOTH, ctx->Line.SmoothFlag );
                (*ctx->Driver.Enable)( ctx, GL_LINE_STIPPLE, ctx->Line.StippleFlag );
             }
+            if (ctx->Driver.LineStipple)
+               (*ctx->Driver.LineStipple)(ctx, ctx->Line.StippleFactor,
+                                          ctx->Line.StipplePattern);
+            if (ctx->Driver.LineWidth)
+               (*ctx->Driver.LineWidth)(ctx, ctx->Line.Width);
             break;
          case GL_LIST_BIT:
             MEMCPY( &ctx->List, attr->data, sizeof(struct gl_list_attrib) );
@@ -659,6 +698,8 @@ void gl_PopAttrib( GLcontext* ctx )
             break;
         case GL_POLYGON_STIPPLE_BIT:
            MEMCPY( ctx->PolygonStipple, attr->data, 32*sizeof(GLuint) );
+           if (ctx->Driver.PolygonStipple) 
+              ctx->Driver.PolygonStipple( ctx, (const GLubyte *) attr->data );
            break;
          case GL_SCISSOR_BIT:
             MEMCPY( &ctx->Scissor, attr->data,
@@ -754,11 +795,13 @@ void gl_PopAttrib( GLcontext* ctx )
 #define GL_CLIENT_UNPACK_BIT (1<<21)
 
 
-void gl_PushClientAttrib( GLcontext *ctx, GLbitfield mask )
+void
+_mesa_PushClientAttrib(GLbitfield mask)
 {
    struct gl_attrib_node *newnode;
    struct gl_attrib_node *head;
 
+   GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPushClientAttrib");
 
    if (ctx->ClientAttribStackDepth>=MAX_CLIENT_ATTRIB_STACK_DEPTH) {
@@ -804,10 +847,12 @@ void gl_PushClientAttrib( GLcontext *ctx, GLbitfield mask )
 
 
 
-void gl_PopClientAttrib( GLcontext *ctx )
+void
+_mesa_PopClientAttrib(void)
 {
    struct gl_attrib_node *attr, *next;
 
+   GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPopClientAttrib");
 
    if (ctx->ClientAttribStackDepth==0) {
@@ -848,35 +893,3 @@ void gl_PopClientAttrib( GLcontext *ctx )
 
 
 
-void
-_mesa_PushAttrib( GLbitfield mask )
-{
-   GET_CURRENT_CONTEXT(ctx);
-   gl_PushAttrib(ctx, mask);
-}
-
-
-void
-_mesa_PopAttrib( void )
-{
-   GET_CURRENT_CONTEXT(ctx);
-   gl_PopAttrib(ctx);
-}
-
-
-void
-_mesa_PushClientAttrib( GLbitfield mask )
-{
-   GET_CURRENT_CONTEXT(ctx);
-   gl_PushClientAttrib(ctx, mask);
-}
-
-
-void
-_mesa_PopClientAttrib( void )
-{
-   GET_CURRENT_CONTEXT(ctx);
-   gl_PopClientAttrib(ctx);
-}
-
-