Mesa (8.0): swrast: fix span color type selection

Ian Romanick idr at kemper.freedesktop.org
Wed Feb 15 03:19:43 UTC 2012


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

Author: Brian Paul <brianp at vmware.com>
Date:   Fri Feb  3 08:17:24 2012 -0700

swrast: fix span color type selection

Fixes a regression from commit 660ed923ded3552e023ef8c3dd9f92e6792f1bd2.
The basic idea is to look at the format of the dest renderbuffer and
choose either GLubyte or GLfloat for colors.  The previous code used
_mesa_format_to_type_and_comps() which could return a bunch types other
than ubyte/float.

Determine the datatype at renderbuffer mapping time to avoid frequent
calls to the format query functions.

NOTE: This is a candidate for the 8.0 branch.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45578
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=45577
(cherry picked from commit bd1ae51b13535bc4438c663ffe91ded49db4890a)

---

 src/mesa/swrast/s_context.h      |    3 +++
 src/mesa/swrast/s_renderbuffer.c |   28 ++++++++++++++++++++++++++--
 src/mesa/swrast/s_span.c         |   14 +++++++-------
 3 files changed, 36 insertions(+), 9 deletions(-)

diff --git a/src/mesa/swrast/s_context.h b/src/mesa/swrast/s_context.h
index ae239a9..bf1316a 100644
--- a/src/mesa/swrast/s_context.h
+++ b/src/mesa/swrast/s_context.h
@@ -175,6 +175,9 @@ struct swrast_renderbuffer
    /** These fields are only valid while buffer is mapped for rendering */
    GLubyte *Map;
    GLint RowStride;    /**< in bytes */
+
+   /** For span rendering */
+   GLenum ColorType;
 };
 
 
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index 637a7b6..d8a7467 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -615,8 +615,31 @@ unmap_attachment(struct gl_context *ctx,
 
    srb->Map = NULL;
 }
- 
- 
+
+
+/**
+ * Determine what type to use (ubyte vs. float) for span colors for the
+ * given renderbuffer.
+ * See also _swrast_write_rgba_span().
+ */
+static void
+find_renderbuffer_colortype(struct gl_renderbuffer *rb)
+{
+   struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+   GLuint rbMaxBits = _mesa_get_format_max_bits(rb->Format);
+   GLenum rbDatatype = _mesa_get_format_datatype(rb->Format);
+
+   if (rbDatatype == GL_UNSIGNED_NORMALIZED && rbMaxBits <= 8) {
+      /* the buffer's values fit in GLubyte values */
+      srb->ColorType = GL_UNSIGNED_BYTE;
+   }
+   else {
+      /* use floats otherwise */
+      srb->ColorType = GL_FLOAT;
+   }
+}
+
+
 /**
  * Map the renderbuffers we'll use for tri/line/point rendering.
  */
@@ -641,6 +664,7 @@ _swrast_map_renderbuffers(struct gl_context *ctx)
 
    for (buf = 0; buf < fb->_NumColorDrawBuffers; buf++) {
       map_attachment(ctx, fb, fb->_ColorDrawBufferIndexes[buf]);
+      find_renderbuffer_colortype(fb->_ColorDrawBuffers[buf]);
    }
 }
  
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 6d6538c..f62ee94 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1320,15 +1320,15 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
 
          if (rb) {
             GLchan rgbaSave[MAX_WIDTH][4];
+            struct swrast_renderbuffer *srb = swrast_renderbuffer(rb);
+            GLenum colorType = srb->ColorType;
 
-	    GLenum datatype;
-	    GLuint comps;
+            assert(colorType == GL_UNSIGNED_BYTE ||
+                   colorType == GL_FLOAT);
 
-	    _mesa_format_to_type_and_comps(rb->Format, &datatype, &comps);
-
-            /* set span->array->rgba to colors for render buffer's datatype */
-            if (datatype != span->array->ChanType) {
-               convert_color_type(span, datatype, 0);
+            /* set span->array->rgba to colors for renderbuffer's datatype */
+            if (span->array->ChanType != colorType) {
+               convert_color_type(span, colorType, 0);
             }
             else {
                if (span->array->ChanType == GL_UNSIGNED_BYTE) {




More information about the mesa-commit mailing list