On 06/25/2012 06:34 PM, Jordan Justen wrote:
pack_int_cases_tmp.h is included in two places:
_mesa_pack_rgba_span_from_ints with GLint rgba[][4]
   and
_mesa_pack_rgba_span_from_uints with GLuint rgba[][4]

Signed-off-by: Jordan Justen<jordan.l.jus...@intel.com>
---
  src/mesa/main/pack.c               |    6 +
  src/mesa/main/pack_int_cases_tmp.h |  304 ++++++++++++++++++++++++++++++++++++
  2 files changed, 310 insertions(+)
  create mode 100644 src/mesa/main/pack_int_cases_tmp.h

diff --git a/src/mesa/main/pack.c b/src/mesa/main/pack.c
index 9fb8771..613d68b 100644
--- a/src/mesa/main/pack.c
+++ b/src/mesa/main/pack.c
@@ -530,6 +530,9 @@ _mesa_pack_rgba_span_from_uints(struct gl_context *ctx, 
GLuint n, GLuint rgba[][
        pack_byte_from_uint_rgba(ctx, dstAddr, dstFormat, rgba, n);
        break;

+   /* Packed integer cases */
+#include "pack_int_cases_tmp.h"
+
     default:
        _mesa_problem(ctx,
           "Unsupported type (%s) for format (%s)",
@@ -615,6 +618,9 @@ _mesa_pack_rgba_span_from_ints(struct gl_context *ctx, 
GLuint n, GLint rgba[][4]
        pack_byte_from_int_rgba(ctx, dstAddr, dstFormat, rgba, n);
        break;

+   /* Packed integer cases */
+#include "pack_int_cases_tmp.h"
+
     default:
        _mesa_problem(ctx,
           "Unsupported type (%s) for format (%s)",
diff --git a/src/mesa/main/pack_int_cases_tmp.h 
b/src/mesa/main/pack_int_cases_tmp.h
new file mode 100644
index 0000000..c1f15e9
--- /dev/null
+++ b/src/mesa/main/pack_int_cases_tmp.h
@@ -0,0 +1,304 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
+ * Copyright (C) 2009-2010  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
+ * THEA 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.
+ */
+
+/*
+ * These case statements are used two places:
+ * pack.c:_mesa_pack_rgba_span_from_ints with GLint rgba[][4]
+ *   and
+ * pack.c:_mesa_pack_rgba_span_from_uints with GLuint rgba[][4]
+ */
+
+   case GL_UNSIGNED_BYTE_3_3_2:
+      if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
+         GLubyte *dst = (GLubyte *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 7)<<  5)
+                   | (CLAMP(rgba[i][GCOMP], 0, 7)<<  2)
+                   | (CLAMP(rgba[i][BCOMP], 0, 3)     );
+         }
+      }
+      break;
+   case GL_UNSIGNED_BYTE_2_3_3_REV:
+      if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
+         GLubyte *dst = (GLubyte *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 7)     )
+                   | (CLAMP(rgba[i][GCOMP], 0, 7)<<  3)
+                   | (CLAMP(rgba[i][BCOMP], 0, 3)<<  6);
+         }
+      }
+      break;
+   case GL_UNSIGNED_SHORT_5_6_5:
+      if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 31)<<  11)
+                   | (CLAMP(rgba[i][GCOMP], 0, 63)<<   5)
+                   | (CLAMP(rgba[i][BCOMP], 0, 31)      );
+         }
+      }
+      break;
+   case GL_UNSIGNED_SHORT_5_6_5_REV:
+      if ((dstFormat == GL_RGB) || (dstFormat == GL_RGB_INTEGER)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 31)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 63)<<   5)
+                   | (CLAMP(rgba[i][BCOMP], 0, 31)<<  11);
+         }
+      }
+      break;
+   case GL_UNSIGNED_SHORT_4_4_4_4:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 15)<<  12)
+                   | (CLAMP(rgba[i][GCOMP], 0, 15)<<   8)
+                   | (CLAMP(rgba[i][BCOMP], 0, 15)<<   4)
+                   | (CLAMP(rgba[i][ACOMP], 0, 15)      );
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 15)<<  12)
+                   | (CLAMP(rgba[i][GCOMP], 0, 15)<<   8)
+                   | (CLAMP(rgba[i][RCOMP], 0, 15)<<   4)
+                   | (CLAMP(rgba[i][ACOMP], 0, 15)      );
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 15)<<  12)
+                   | (CLAMP(rgba[i][BCOMP], 0, 15)<<   8)
+                   | (CLAMP(rgba[i][GCOMP], 0, 15)<<   4)
+                   | (CLAMP(rgba[i][RCOMP], 0, 15)      );
+         }
+      }
+      break;
+   case GL_UNSIGNED_SHORT_4_4_4_4_REV:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 15)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 15)<<   4)
+                   | (CLAMP(rgba[i][BCOMP], 0, 15)<<   8)
+                   | (CLAMP(rgba[i][ACOMP], 0, 15)<<  12);
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 15)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 15)<<   4)
+                   | (CLAMP(rgba[i][RCOMP], 0, 15)<<   8)
+                   | (CLAMP(rgba[i][ACOMP], 0, 15)<<  12);
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 15)      )
+                   | (CLAMP(rgba[i][BCOMP], 0, 15)<<   4)
+                   | (CLAMP(rgba[i][GCOMP], 0, 15)<<   8)
+                   | (CLAMP(rgba[i][RCOMP], 0, 15)<<  12);
+         }
+      }
+      break;
+   case GL_UNSIGNED_SHORT_5_5_5_1:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 31)<<  11)
+                   | (CLAMP(rgba[i][GCOMP], 0, 31)<<   6)
+                   | (CLAMP(rgba[i][BCOMP], 0, 31)<<   1)
+                   | (CLAMP(rgba[i][ACOMP], 0,  1)      );
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 31)<<  11)
+                   | (CLAMP(rgba[i][GCOMP], 0, 31)<<   6)
+                   | (CLAMP(rgba[i][RCOMP], 0, 31)<<   1)
+                   | (CLAMP(rgba[i][ACOMP], 0,  1)      );
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 31)<<  11)
+                   | (CLAMP(rgba[i][BCOMP], 0, 31)<<   6)
+                   | (CLAMP(rgba[i][GCOMP], 0, 31)<<   1)
+                   | (CLAMP(rgba[i][RCOMP], 0,  1)      );
+         }
+      }
+      break;
+   case GL_UNSIGNED_SHORT_1_5_5_5_REV:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 31)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 31)<<   5)
+                   | (CLAMP(rgba[i][BCOMP], 0, 31)<<  10)
+                   | (CLAMP(rgba[i][ACOMP], 0,  1)<<  15);
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 31)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 31)<<   5)
+                   | (CLAMP(rgba[i][RCOMP], 0, 31)<<  10)
+                   | (CLAMP(rgba[i][ACOMP], 0,  1)<<  15);
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLushort *dst = (GLushort *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 31)      )
+                   | (CLAMP(rgba[i][BCOMP], 0, 31)<<   5)
+                   | (CLAMP(rgba[i][GCOMP], 0, 31)<<  10)
+                   | (CLAMP(rgba[i][RCOMP], 0,  1)<<  15);
+         }
+      }
+      break;
+   case GL_UNSIGNED_INT_8_8_8_8:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 255)<<  24)
+                   | (CLAMP(rgba[i][GCOMP], 0, 255)<<  16)
+                   | (CLAMP(rgba[i][BCOMP], 0, 255)<<   8)
+                   | (CLAMP(rgba[i][ACOMP], 0, 255)      );
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 255)<<  24)
+                   | (CLAMP(rgba[i][GCOMP], 0, 255)<<  16)
+                   | (CLAMP(rgba[i][RCOMP], 0, 255)<<   8)
+                   | (CLAMP(rgba[i][ACOMP], 0, 255)      );
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 255)<<  24)
+                   | (CLAMP(rgba[i][BCOMP], 0, 255)<<  16)
+                   | (CLAMP(rgba[i][GCOMP], 0, 255)<<   8)
+                   | (CLAMP(rgba[i][RCOMP], 0, 255)      );
+         }
+      }
+      break;
+   case GL_UNSIGNED_INT_8_8_8_8_REV:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 255)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 255)<<   8)
+                   | (CLAMP(rgba[i][BCOMP], 0, 255)<<  16)
+                   | (CLAMP(rgba[i][ACOMP], 0, 255)<<  24);
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 255)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 255)<<   8)
+                   | (CLAMP(rgba[i][RCOMP], 0, 255)<<  16)
+                   | (CLAMP(rgba[i][ACOMP], 0, 255)<<  24);
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 255)      )
+                   | (CLAMP(rgba[i][BCOMP], 0, 255)<<   8)
+                   | (CLAMP(rgba[i][GCOMP], 0, 255)<<  16)
+                   | (CLAMP(rgba[i][RCOMP], 0, 255)<<  24);
+         }
+      }
+      break;
+   case GL_UNSIGNED_INT_10_10_10_2:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 1023)<<  22)
+                   | (CLAMP(rgba[i][GCOMP], 0, 1023)<<  12)
+                   | (CLAMP(rgba[i][BCOMP], 0, 1023)<<   2)
+                   | (CLAMP(rgba[i][ACOMP], 0,    3)      );
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 1023)<<  22)
+                   | (CLAMP(rgba[i][GCOMP], 0, 1023)<<  12)
+                   | (CLAMP(rgba[i][RCOMP], 0, 1023)<<   2)
+                   | (CLAMP(rgba[i][ACOMP], 0,    3)      );
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 1023)<<  22)
+                   | (CLAMP(rgba[i][BCOMP], 0, 1023)<<  12)
+                   | (CLAMP(rgba[i][GCOMP], 0, 1023)<<   2)
+                   | (CLAMP(rgba[i][RCOMP], 0,    3)      );
+         }
+      }
+      break;
+   case GL_UNSIGNED_INT_2_10_10_10_REV:
+      if ((dstFormat == GL_RGBA) || (dstFormat == GL_RGBA_INTEGER_EXT)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][RCOMP], 0, 1023)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 1023)<<  10)
+                   | (CLAMP(rgba[i][BCOMP], 0, 1023)<<  20)
+                   | (CLAMP(rgba[i][ACOMP], 0,    3)<<  30);
+         }
+      }
+      else if ((dstFormat == GL_BGRA) || (dstFormat == GL_BGRA_INTEGER)) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][BCOMP], 0, 1023)      )
+                   | (CLAMP(rgba[i][GCOMP], 0, 1023)<<  10)
+                   | (CLAMP(rgba[i][RCOMP], 0, 1023)<<  20)
+                   | (CLAMP(rgba[i][ACOMP], 0,    3)<<  30);
+         }
+      }
+      else if (dstFormat == GL_ABGR_EXT) {
+         GLuint *dst = (GLuint *) dstAddr;
+         for (i=0;i<n;i++) {
+            dst[i] = (CLAMP(rgba[i][ACOMP], 0, 1023)      )
+                   | (CLAMP(rgba[i][BCOMP], 0, 1023)<<  10)
+                   | (CLAMP(rgba[i][GCOMP], 0, 1023)<<  20)
+                   | (CLAMP(rgba[i][RCOMP], 0,    3)<<  30);
+         }
+      }
+      break;
+

It's kind of weird to have a bunch of switch cases like this in a header file.

Couldn't the code be put into an ordinary function? Then return true/false to indicate if the type was handled there.

-Brian
_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to