[Mesa-dev] [PATCH 15/15] mesa: move last bits of GLchan stuff into swrast

Brian Paul brian.e.paul at gmail.com
Sat Sep 17 15:41:28 PDT 2011


From: Brian Paul <brianp at vmware.com>

This removes the last remnants of the GLchan datatype and associated
macros out of core Mesa and into swrast.
---
 src/mesa/drivers/dri/swrast/swrast_span.c |    2 +-
 src/mesa/main/colormac.h                  |   75 ------------------
 src/mesa/main/config.h                    |    2 +-
 src/mesa/main/mtypes.h                    |   23 ------
 src/mesa/math/m_translate.h               |    2 +-
 src/mesa/swrast/s_chan.h                  |  119 +++++++++++++++++++++++++++++
 src/mesa/swrast/s_span.h                  |    2 +
 src/mesa/swrast/swrast.h                  |    1 +
 src/mesa/tnl/t_vertex.c                   |    2 +-
 src/mesa/tnl/t_vertex_generic.c           |    1 +
 10 files changed, 127 insertions(+), 102 deletions(-)
 create mode 100644 src/mesa/swrast/s_chan.h

diff --git a/src/mesa/drivers/dri/swrast/swrast_span.c b/src/mesa/drivers/dri/swrast/swrast_span.c
index c7d0bfd..772d09f 100644
--- a/src/mesa/drivers/dri/swrast/swrast_span.c
+++ b/src/mesa/drivers/dri/swrast/swrast_span.c
@@ -45,7 +45,7 @@ static const GLubyte kernel[16] = {
 #if DITHER
 #define DITHER_COMP(X, Y) kernel[((X) & 0x3) | (((Y) & 0x3) << 2)]
 
-#define DITHER_CLAMP(X) (((X) < CHAN_MAX) ? (X) : CHAN_MAX)
+#define DITHER_CLAMP(X) (((X) < 255) ? (X) : 255)
 #else
 #define DITHER_COMP(X, Y) 0
 
diff --git a/src/mesa/main/colormac.h b/src/mesa/main/colormac.h
index 46377ac..0b8864a 100644
--- a/src/mesa/main/colormac.h
+++ b/src/mesa/main/colormac.h
@@ -38,81 +38,6 @@
 #include "mtypes.h"
 
 
-/** \def CHAN_TO_UBYTE
- * Convert from GLchan to GLubyte */
-
-/** \def CHAN_TO_FLOAT
- * Convert from GLchan to GLfloat */
-
-/** \def CLAMPED_FLOAT_TO_CHAN
- * Convert from GLclampf to GLchan */
-
-/** \def UNCLAMPED_FLOAT_TO_CHAN
- * Convert from GLfloat to GLchan */
-
-/** \def COPY_CHAN4
- * Copy a GLchan[4] array */
-
-#if CHAN_BITS == 8
-
-#define CHAN_TO_UBYTE(c)  (c)
-#define CHAN_TO_USHORT(c) (((c) << 8) | (c))
-#define CHAN_TO_SHORT(c)  (((c) << 7) | ((c) >> 1))
-#define CHAN_TO_FLOAT(c)  UBYTE_TO_FLOAT(c)
-
-#define CLAMPED_FLOAT_TO_CHAN(c, f)    CLAMPED_FLOAT_TO_UBYTE(c, f)
-#define UNCLAMPED_FLOAT_TO_CHAN(c, f)  UNCLAMPED_FLOAT_TO_UBYTE(c, f)
-
-#define COPY_CHAN4(DST, SRC)  COPY_4UBV(DST, SRC)
-
-#elif CHAN_BITS == 16
-
-#define CHAN_TO_UBYTE(c)  ((c) >> 8)
-#define CHAN_TO_USHORT(c) (c)
-#define CHAN_TO_SHORT(c)  ((c) >> 1)
-#define CHAN_TO_FLOAT(c)  ((GLfloat) ((c) * (1.0 / CHAN_MAXF)))
-
-#define CLAMPED_FLOAT_TO_CHAN(c, f)    CLAMPED_FLOAT_TO_USHORT(c, f)
-#define UNCLAMPED_FLOAT_TO_CHAN(c, f)  UNCLAMPED_FLOAT_TO_USHORT(c, f)
-
-#define COPY_CHAN4(DST, SRC)  COPY_4V(DST, SRC)
-
-#elif CHAN_BITS == 32
-
-#define CHAN_TO_UBYTE(c)  FLOAT_TO_UBYTE(c)
-#define CHAN_TO_USHORT(c) ((GLushort) (CLAMP((c), 0.0f, 1.0f) * 65535.0))
-#define CHAN_TO_SHORT(c)  ((GLshort) (CLAMP((c), 0.0f, 1.0f) * 32767.0))
-#define CHAN_TO_FLOAT(c)  (c)
-
-#define CLAMPED_FLOAT_TO_CHAN(c, f)  c = (f)
-#define UNCLAMPED_FLOAT_TO_CHAN(c, f)      c = (f)
-
-#define COPY_CHAN4(DST, SRC)  COPY_4V(DST, SRC)
-
-#else
-
-#error unexpected CHAN_BITS size
-
-#endif
-
-
-/**
- * Convert 4 channels at once.
- *
- * \param dst pointer to destination GLchan[4] array.
- * \param f pointer to source GLfloat[4] array.
- *
- * \sa #UNCLAMPED_FLOAT_TO_CHAN.
- */
-#define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f)	\
-do {						\
-   UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]);	\
-   UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]);	\
-   UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]);	\
-   UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]);	\
-} while (0)
-
-
 /**
  * Convert four float values in [0,1] to ubytes in [0,255] with clamping.
  */
diff --git a/src/mesa/main/config.h b/src/mesa/main/config.h
index 91aef90..1ac3c12 100644
--- a/src/mesa/main/config.h
+++ b/src/mesa/main/config.h
@@ -329,7 +329,7 @@
 
 
 /**
- * Bits per color channel:  8, 16 or 32
+ * For swrast, bits per color channel:  8, 16 or 32
  */
 #ifndef CHAN_BITS
 #define CHAN_BITS 8
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 429c8b4..1e82020 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -44,29 +44,6 @@
 
 
 /**
- * Color channel data type.
- */
-#if CHAN_BITS == 8
-   typedef GLubyte GLchan;
-#define CHAN_MAX 255
-#define CHAN_MAXF 255.0F
-#define CHAN_TYPE GL_UNSIGNED_BYTE
-#elif CHAN_BITS == 16
-   typedef GLushort GLchan;
-#define CHAN_MAX 65535
-#define CHAN_MAXF 65535.0F
-#define CHAN_TYPE GL_UNSIGNED_SHORT
-#elif CHAN_BITS == 32
-   typedef GLfloat GLchan;
-#define CHAN_MAX 1.0
-#define CHAN_MAXF 1.0F
-#define CHAN_TYPE GL_FLOAT
-#else
-#error "illegal number of color channel bits"
-#endif
-
-
-/**
  * Stencil buffer data type.
  */
 #if STENCIL_BITS==8
diff --git a/src/mesa/math/m_translate.h b/src/mesa/math/m_translate.h
index 5804103..bf7485c 100644
--- a/src/mesa/math/m_translate.h
+++ b/src/mesa/math/m_translate.h
@@ -29,7 +29,7 @@
 #include "main/compiler.h"
 #include "main/glheader.h"
 #include "main/mtypes.h"		/* hack for GLchan */
-
+#include "swrast/s_chan.h"
 
 /**
  * Array translation.
diff --git a/src/mesa/swrast/s_chan.h b/src/mesa/swrast/s_chan.h
new file mode 100644
index 0000000..94ac8b6
--- /dev/null
+++ b/src/mesa/swrast/s_chan.h
@@ -0,0 +1,119 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2011  VMware, Inc.  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"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+ * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * Types, macros, etc for the GLchan datatype.
+ * The swrast module is kind of hard-coded for 8bpp color channels but
+ * may be recompiled to use 16- or 32-bit color channels.  But that
+ * feature is seldom used and is likely broken in various ways.
+ */
+
+#ifndef U_CHAN_H
+#define U_CHAN_H
+
+
+#include "main/config.h"
+
+
+/**
+ * Color channel data type.
+ */
+#if CHAN_BITS == 8
+   typedef GLubyte GLchan;
+#define CHAN_MAX 255
+#define CHAN_MAXF 255.0F
+#define CHAN_TYPE GL_UNSIGNED_BYTE
+#elif CHAN_BITS == 16
+   typedef GLushort GLchan;
+#define CHAN_MAX 65535
+#define CHAN_MAXF 65535.0F
+#define CHAN_TYPE GL_UNSIGNED_SHORT
+#elif CHAN_BITS == 32
+   typedef GLfloat GLchan;
+#define CHAN_MAX 1.0
+#define CHAN_MAXF 1.0F
+#define CHAN_TYPE GL_FLOAT
+#else
+#error "illegal number of color channel bits"
+#endif
+
+
+#if CHAN_BITS == 8
+
+#define CHAN_TO_UBYTE(c)  (c)
+#define CHAN_TO_USHORT(c) (((c) << 8) | (c))
+#define CHAN_TO_SHORT(c)  (((c) << 7) | ((c) >> 1))
+#define CHAN_TO_FLOAT(c)  UBYTE_TO_FLOAT(c)
+
+#define CLAMPED_FLOAT_TO_CHAN(c, f)    CLAMPED_FLOAT_TO_UBYTE(c, f)
+#define UNCLAMPED_FLOAT_TO_CHAN(c, f)  UNCLAMPED_FLOAT_TO_UBYTE(c, f)
+
+#define COPY_CHAN4(DST, SRC)  COPY_4UBV(DST, SRC)
+
+#elif CHAN_BITS == 16
+
+#define CHAN_TO_UBYTE(c)  ((c) >> 8)
+#define CHAN_TO_USHORT(c) (c)
+#define CHAN_TO_SHORT(c)  ((c) >> 1)
+#define CHAN_TO_FLOAT(c)  ((GLfloat) ((c) * (1.0 / CHAN_MAXF)))
+
+#define CLAMPED_FLOAT_TO_CHAN(c, f)    CLAMPED_FLOAT_TO_USHORT(c, f)
+#define UNCLAMPED_FLOAT_TO_CHAN(c, f)  UNCLAMPED_FLOAT_TO_USHORT(c, f)
+
+#define COPY_CHAN4(DST, SRC)  COPY_4V(DST, SRC)
+
+#elif CHAN_BITS == 32
+
+#define CHAN_TO_UBYTE(c)  FLOAT_TO_UBYTE(c)
+#define CHAN_TO_USHORT(c) ((GLushort) (CLAMP((c), 0.0f, 1.0f) * 65535.0))
+#define CHAN_TO_SHORT(c)  ((GLshort) (CLAMP((c), 0.0f, 1.0f) * 32767.0))
+#define CHAN_TO_FLOAT(c)  (c)
+
+#define CLAMPED_FLOAT_TO_CHAN(c, f)  c = (f)
+#define UNCLAMPED_FLOAT_TO_CHAN(c, f)      c = (f)
+
+#define COPY_CHAN4(DST, SRC)  COPY_4V(DST, SRC)
+
+#else
+
+#error unexpected CHAN_BITS size
+
+#endif
+
+
+/**
+ * Convert 4 floats to GLchan values.
+ * \param dst pointer to destination GLchan[4] array.
+ * \param f pointer to source GLfloat[4] array.
+ */
+#define UNCLAMPED_FLOAT_TO_RGBA_CHAN(dst, f)	\
+do {						\
+   UNCLAMPED_FLOAT_TO_CHAN((dst)[0], (f)[0]);	\
+   UNCLAMPED_FLOAT_TO_CHAN((dst)[1], (f)[1]);	\
+   UNCLAMPED_FLOAT_TO_CHAN((dst)[2], (f)[2]);	\
+   UNCLAMPED_FLOAT_TO_CHAN((dst)[3], (f)[3]);	\
+} while (0)
+
+
+
+#endif /* U_CHAN_H */
diff --git a/src/mesa/swrast/s_span.h b/src/mesa/swrast/s_span.h
index afafbe0..382c3d2 100644
--- a/src/mesa/swrast/s_span.h
+++ b/src/mesa/swrast/s_span.h
@@ -31,6 +31,8 @@
 #include "main/config.h"
 #include "main/glheader.h"
 #include "main/mtypes.h"
+#include "swrast/s_chan.h"
+
 
 struct gl_context;
 struct gl_renderbuffer;
diff --git a/src/mesa/swrast/swrast.h b/src/mesa/swrast/swrast.h
index 390b422..06cc651 100644
--- a/src/mesa/swrast/swrast.h
+++ b/src/mesa/swrast/swrast.h
@@ -33,6 +33,7 @@
 #define SWRAST_H
 
 #include "main/mtypes.h"
+#include "swrast/s_chan.h"
 
 /**
  * \struct SWvertex
diff --git a/src/mesa/tnl/t_vertex.c b/src/mesa/tnl/t_vertex.c
index f1cb795..6582949 100644
--- a/src/mesa/tnl/t_vertex.c
+++ b/src/mesa/tnl/t_vertex.c
@@ -28,7 +28,7 @@
 #include "main/glheader.h"
 #include "main/context.h"
 #include "main/colormac.h"
-
+#include "swrast/s_chan.h"
 #include "t_context.h"
 #include "t_vertex.h"
 
diff --git a/src/mesa/tnl/t_vertex_generic.c b/src/mesa/tnl/t_vertex_generic.c
index 12da30f..9dcecdd 100644
--- a/src/mesa/tnl/t_vertex_generic.c
+++ b/src/mesa/tnl/t_vertex_generic.c
@@ -30,6 +30,7 @@
 #include "main/context.h"
 #include "main/colormac.h"
 #include "main/simple_list.h"
+#include "swrast/s_chan.h"
 #include "t_context.h"
 #include "t_vertex.h"
 
-- 
1.7.3.4



More information about the mesa-dev mailing list