Mesa (7.11): st/mesa: use the first non-VOID channel in st_format_datatype

Marek Olšák mareko at kemper.freedesktop.org
Fri Jul 8 04:26:46 PDT 2011


Module: Mesa
Branch: 7.11
Commit: efd0ffd1b0e28d3cb118d501b63b8d92b6e95905
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=efd0ffd1b0e28d3cb118d501b63b8d92b6e95905

Author: Marek Olšák <maraeo at gmail.com>
Date:   Mon Jun 27 19:01:25 2011 +0200

st/mesa: use the first non-VOID channel in st_format_datatype

Otherwise PIPE_FORMAT_X8B8G8R8_UNORM and friends would fail.

NOTE: This is a candidate for the 7.10 and 7.11 branches.

Reviewed-by: Brian Paul <brianp at vmware.com>
(cherry picked from commit 292148dc4b18958d4447df7596311bd2f09fd44f)

---

 src/mesa/state_tracker/st_format.c |   19 ++++++++++++++++---
 1 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
index fa5d8f5..3260297 100644
--- a/src/mesa/state_tracker/st_format.c
+++ b/src/mesa/state_tracker/st_format.c
@@ -68,10 +68,18 @@ GLenum
 st_format_datatype(enum pipe_format format)
 {
    const struct util_format_description *desc;
+   int i;
 
    desc = util_format_description(format);
    assert(desc);
 
+   /* Find the first non-VOID channel. */
+   for (i = 0; i < 4; i++) {
+       if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
+           break;
+       }
+   }
+
    if (desc->layout == UTIL_FORMAT_LAYOUT_PLAIN) {
       if (format == PIPE_FORMAT_B5G5R5A1_UNORM ||
           format == PIPE_FORMAT_B5G6R5_UNORM) {
@@ -85,21 +93,26 @@ st_format_datatype(enum pipe_format format)
       }
       else {
          const GLuint size = format_max_bits(format);
+
+         assert(i < 4);
+         if (i == 4)
+            return GL_NONE;
+
          if (size == 8) {
-            if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
+            if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
                return GL_UNSIGNED_BYTE;
             else
                return GL_BYTE;
          }
          else if (size == 16) {
-            if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
+            if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
                return GL_UNSIGNED_SHORT;
             else
                return GL_SHORT;
          }
          else {
             assert( size <= 32 );
-            if (desc->channel[0].type == UTIL_FORMAT_TYPE_UNSIGNED)
+            if (desc->channel[i].type == UTIL_FORMAT_TYPE_UNSIGNED)
                return GL_UNSIGNED_INT;
             else
                return GL_INT;



More information about the mesa-commit mailing list