Added OSMesaColorClamp(), bug 4917
authorBrian Paul <brian.paul@tungstengraphics.com>
Sat, 12 Nov 2005 18:44:29 +0000 (18:44 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sat, 12 Nov 2005 18:44:29 +0000 (18:44 +0000)
include/GL/osmesa.h
src/mesa/drivers/osmesa/osmesa.c
src/mesa/main/blend.c
src/mesa/main/context.c
src/mesa/main/image.c
src/mesa/main/mtypes.h
src/mesa/swrast/s_context.c
src/mesa/swrast/s_context.h
src/mesa/swrast/s_span.c

index ef64590..c505781 100644 (file)
@@ -1,8 +1,8 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.3
+ * Version:  6.5
  * 
- * Copyright (C) 1999-2003  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2005  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"),
@@ -267,6 +267,15 @@ GLAPI OSMESAproc GLAPIENTRY
 OSMesaGetProcAddress( const char *funcName );
 
 
+
+/**
+ * Enable/disable color clamping, off by default.
+ * New in Mesa 6.5
+ */
+GLAPI void GLAPIENTRY
+OSMesaColorClamp(GLboolean enable);
+
+
 #if defined(__BEOS__) || defined(__QUICKDRAW__)
 #pragma export off
 #endif
index e4cb27d..9d74c33 100644 (file)
@@ -1255,3 +1255,19 @@ OSMesaGetProcAddress( const char *funcName )
    }
    return _glapi_get_proc_address(funcName);
 }
+
+
+GLAPI void GLAPIENTRY
+OSMesaColorClamp(GLboolean enable)
+{
+   OSMesaContext osmesa = OSMesaGetCurrentContext();
+
+   if (enable == GL_TRUE) {
+      osmesa->mesa.Color.ClampFragmentColor = GL_TRUE;
+   }
+   else {
+      osmesa->mesa.Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
+   }
+}
+
+
index 61b2b17..aebc704 100644 (file)
@@ -574,6 +574,9 @@ void _mesa_init_color( GLcontext * ctx )
    else {
       ctx->Color.DrawBuffer[0] = GL_FRONT;
    }
+
+   ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
+   ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB;
 }
 
 /*@}*/
index 698dbd3..b25300a 100644 (file)
@@ -1090,12 +1090,6 @@ init_attrib_groups( GLcontext *ctx )
    ctx->NewState = _NEW_ALL;
    ctx->ErrorValue = (GLenum) GL_NO_ERROR;
    ctx->_Facing = 0;
-#if CHAN_TYPE == GL_FLOAT
-   ctx->ClampFragmentColors = GL_FALSE; /* XXX temporary */
-#else
-   ctx->ClampFragmentColors = GL_TRUE;
-#endif
-   ctx->ClampVertexColors = GL_TRUE;
 
    return GL_TRUE;
 }
index b9a0323..0a117a9 100644 (file)
@@ -1079,7 +1079,7 @@ _mesa_pack_rgba_span_float( GLcontext *ctx,
 
    if (dstFormat == GL_LUMINANCE || dstFormat == GL_LUMINANCE_ALPHA) {
       /* compute luminance values */
-      if (ctx->ClampFragmentColors) {
+      if (ctx->Color.ClampReadColor == GL_TRUE) {
          for (i = 0; i < n; i++) {
             GLfloat sum = rgba[i][RCOMP] + rgba[i][GCOMP] + rgba[i][BCOMP];
             luminance[i] = CLAMP(sum, 0.0F, 1.0F);
index 1a90583..17978e7 100644 (file)
@@ -536,6 +536,9 @@ struct gl_colorbuffer_attrib
    /*@}*/
 
    GLboolean DitherFlag;               /**< Dither enable flag */
+
+   GLenum ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
+   GLenum ClampReadColor;     /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
 };
 
 
@@ -2896,12 +2899,6 @@ struct __GLcontextRec
                    * We don't have a better way to communicate this value from
                    * swrast_setup to swrast. */
 
-   /** \name Color clamping (tentative part of GL_ARB_color_clamp_control) */
-   /*@{*/
-   GLboolean ClampFragmentColors;
-   GLboolean ClampVertexColors;
-   /*@}*/
-
    /** \name For debugging/development only */
    /*@{*/
    GLboolean FirstTimeCurrent;
index 186fda0..9d283b0 100644 (file)
@@ -105,6 +105,12 @@ _swrast_update_rasterflags( GLcontext *ctx )
       rasterMask |= ATIFRAGSHADER_BIT;
    }
 
+#if CHAN_TYPE == GL_FLOAT
+   if (ctx->Color.ClampFragmentColor == GL_TRUE) {
+      rasterMask |= CLAMPING_BIT;
+   }
+#endif
+
    SWRAST_CONTEXT(ctx)->_RasterMask = rasterMask;
 }
 
index 3d73881..5cfe762 100644 (file)
@@ -245,6 +245,7 @@ typedef void (*swrast_tri_func)( GLcontext *ctx, const SWvertex *,
 #define TEXTURE_BIT            0x1000  /**< Texturing really enabled */
 #define FRAGPROG_BIT            0x2000  /**< Fragment program enabled */
 #define ATIFRAGSHADER_BIT       0x4000  /**< ATI Fragment shader enabled */
+#define CLAMPING_BIT            0x8000  /**< Clamp colors to [0,1] */
 /*@}*/
 
 #define _SWRAST_NEW_RASTERMASK (_NEW_BUFFERS|  \
index fbff31b..1cf743a 100644 (file)
@@ -1276,6 +1276,20 @@ _swrast_write_rgba_span( GLcontext *ctx, struct sw_span *span)
       }
    }
 
+   /* Clamp color/alpha values over the range [0.0, 1.0] before storage */
+#if CHAN_TYPE == GL_FLOAT
+   if (ctx->Color.ClampFragmentColor) {
+      GLchan (*rgba)[4] = span->array->rgba;
+      GLuint i;
+      for (i = 0; i < span->end; i++) {
+         rgba[i][RCOMP] = CLAMP(rgba[i][RCOMP], 0.0, CHAN_MAXF);
+         rgba[i][GCOMP] = CLAMP(rgba[i][GCOMP], 0.0, CHAN_MAXF);
+         rgba[i][BCOMP] = CLAMP(rgba[i][BCOMP], 0.0, CHAN_MAXF);
+         rgba[i][ACOMP] = CLAMP(rgba[i][ACOMP], 0.0, CHAN_MAXF);
+      }
+   }
+#endif
+
    if (swrast->_RasterMask & MULTI_DRAW_BIT) {
       /* need to do blend/logicop separately for each color buffer */
       multi_write_rgba_span(ctx, span);