[Mesa-dev] [PATCH 3/5] mesa: introduce int/unsigned int storage for clear colors.

Dave Airlie airlied at gmail.com
Mon Sep 12 05:17:29 PDT 2011


From: Dave Airlie <airlied at redhat.com>

Add save/restore support around the GL3.0 clear APIs.

for the get.c change I'm not sure the spec says what we should do in this case, couldn't find any mention in EXT_texture_integer at least, for now just convert to float and return values.

Signed-off-by: Dave Airlie <airlied at redhat.com>
---
 src/mesa/main/clear.c  |   85 ++++++++++++++++++++++++++++++-----------------
 src/mesa/main/get.c    |   19 ++++++++--
 src/mesa/main/mtypes.h |    2 +
 3 files changed, 71 insertions(+), 35 deletions(-)

diff --git a/src/mesa/main/clear.c b/src/mesa/main/clear.c
index 3754756..cec0a57 100644
--- a/src/mesa/main/clear.c
+++ b/src/mesa/main/clear.c
@@ -111,16 +111,17 @@ _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
 void GLAPIENTRY
 _mesa_ClearColorIiEXT(GLint r, GLint g, GLint b, GLint a)
 {
-   GLfloat tmp[4];
+   GLint tmp[4];
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   tmp[0] = (GLfloat) r;
-   tmp[1] = (GLfloat) g;
-   tmp[2] = (GLfloat) b;
-   tmp[3] = (GLfloat) a;
+   tmp[0] = r;
+   tmp[1] = g;
+   tmp[2] = b;
+   tmp[3] = a;
 
-   if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.f))
+   if (TEST_EQ_4V(tmp, ctx->Color.ClearColorUnclamped.i) &&
+       ctx->Color._ClearColorType == GL_INT)
       return; /* no change */
 
    FLUSH_VERTICES(ctx, _NEW_COLOR);
@@ -128,11 +129,12 @@ _mesa_ClearColorIiEXT(GLint r, GLint g, GLint b, GLint a)
    /* XXX we should eventually have a float/int/uint union for
     * the ctx->Color.ClearColor state.
     */
-   ctx->Color._ClearColorType = GL_FLOAT;
-   COPY_4V(ctx->Color.ClearColor.f, tmp);
+   ctx->Color._ClearColorType = GL_INT;
+   COPY_4V(ctx->Color.ClearColorUnclamped.i, tmp);
 
+   /* these should be NOP calls for drivers supporting EXT_texture_integer */
    if (ctx->Driver.ClearColor) {
-      ctx->Driver.ClearColor(ctx, ctx->Color._ClearColorType, ctx->Color.ClearColor);
+      ctx->Driver.ClearColor(ctx, ctx->Color._ClearColorType, ctx->Color.ClearColorUnclamped);
    }
 }
 
@@ -143,16 +145,17 @@ _mesa_ClearColorIiEXT(GLint r, GLint g, GLint b, GLint a)
 void GLAPIENTRY
 _mesa_ClearColorIuiEXT(GLuint r, GLuint g, GLuint b, GLuint a)
 {
-   GLfloat tmp[4];
+   GLuint tmp[4];
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   tmp[0] = (GLfloat) r;
-   tmp[1] = (GLfloat) g;
-   tmp[2] = (GLfloat) b;
-   tmp[3] = (GLfloat) a;
+   tmp[0] = r;
+   tmp[1] = g;
+   tmp[2] = b;
+   tmp[3] = a;
 
-   if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.f))
+   if (TEST_EQ_4V(tmp, ctx->Color.ClearColorUnclamped.ui) &&
+       ctx->Color._ClearColorType == GL_UNSIGNED_INT)
       return; /* no change */
 
    FLUSH_VERTICES(ctx, _NEW_COLOR);
@@ -160,11 +163,12 @@ _mesa_ClearColorIuiEXT(GLuint r, GLuint g, GLuint b, GLuint a)
    /* XXX we should eventually have a float/int/uint union for
     * the ctx->Color.ClearColor state.
     */
-   ctx->Color._ClearColorType = GL_FLOAT;
-   COPY_4V(ctx->Color.ClearColor.f, tmp);
+   ctx->Color._ClearColorType = GL_UNSIGNED_INT;
+   COPY_4V(ctx->Color.ClearColorUnclamped.ui, tmp);
 
+   /* these should be NOP calls for drivers supporting EXT_texture_integer */
    if (ctx->Driver.ClearColor) {
-      ctx->Driver.ClearColor(ctx, ctx->Color._ClearColorType, ctx->Color.ClearColor);
+      ctx->Driver.ClearColor(ctx, ctx->Color._ClearColorType, ctx->Color.ClearColorUnclamped);
    }
 }
 
@@ -317,7 +321,20 @@ make_color_buffer_mask(struct gl_context *ctx, GLint drawbuffer)
    return mask;
 }
 
-
+#define COPY_CLEAR_COLOR(type, dst, src) do { \
+      switch ((type)) {                                    \
+      case GL_UNSIGNED_INT:                                \
+         COPY_4V((dst).ui, (src).ui);                      \
+         break;                                            \
+      case GL_INT:                                         \
+         COPY_4V((dst).i, (src).i);                        \
+         break;                                            \
+      case GL_FLOAT:                                       \
+      default:                                             \
+         COPY_4V((dst).cl, (src).cl);                      \
+         break;                                            \
+      }                                                    \
+   } while(0)
 
 /**
  * New in GL 3.0
@@ -376,10 +393,11 @@ _mesa_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value)
 
             /* save color */
 	    clearColorTypeSave = ctx->Color._ClearColorType;
-            COPY_4V(clearSave.cl, ctx->Color.ClearColor.cl);
+            COPY_CLEAR_COLOR(ctx->Color._ClearColorType,
+                             clearSave, ctx->Color.ClearColorUnclamped);
             /* set color */
-	    ctx->Color._ClearColorType = GL_FLOAT;
-            COPY_4V_CAST(ctx->Color.ClearColor.cl, value, GLclampf);
+            ctx->Color._ClearColorType = GL_INT;
+            COPY_4V(ctx->Color.ClearColorUnclamped.i, value);
             if (ctx->Driver.ClearColor)
                ctx->Driver.ClearColor(ctx, ctx->Color._ClearColorType,
                                       ctx->Color.ClearColor);
@@ -387,7 +405,8 @@ _mesa_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value)
             ctx->Driver.Clear(ctx, mask);
             /* restore color */
             ctx->Color._ClearColorType = clearColorTypeSave;
-            COPY_4V(ctx->Color.ClearColor.cl, clearSave.cl);
+            COPY_CLEAR_COLOR(ctx->Color._ClearColorType,
+                             ctx->Color.ClearColorUnclamped, clearSave);
             if (ctx->Driver.ClearColor)
                ctx->Driver.ClearColor(ctx, clearColorTypeSave, clearSave);
          }
@@ -436,10 +455,11 @@ _mesa_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value)
 
             /* save color */
 	    clearColorTypeSave = ctx->Color._ClearColorType;
-            COPY_4V(clearSave.cl, ctx->Color.ClearColor.cl);
+            COPY_CLEAR_COLOR(ctx->Color._ClearColorType,
+                             clearSave, ctx->Color.ClearColorUnclamped);
             /* set color */
-	    ctx->Color._ClearColorType = GL_FLOAT;
-            COPY_4V_CAST(ctx->Color.ClearColor.cl, value, GLclampf);
+            ctx->Color._ClearColorType = GL_UNSIGNED_INT;
+            COPY_4V(ctx->Color.ClearColor.ui, value);
             if (ctx->Driver.ClearColor)
                ctx->Driver.ClearColor(ctx, ctx->Color._ClearColorType,
                                       ctx->Color.ClearColor);
@@ -447,7 +467,8 @@ _mesa_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value)
             ctx->Driver.Clear(ctx, mask);
             /* restore color */
             ctx->Color._ClearColorType = clearColorTypeSave;
-            COPY_4V(ctx->Color.ClearColor.cl, clearSave.cl);
+            COPY_CLEAR_COLOR(ctx->Color._ClearColorType,
+                             ctx->Color.ClearColorUnclamped, clearSave);
             if (ctx->Driver.ClearColor)
                ctx->Driver.ClearColor(ctx, clearColorTypeSave, clearSave);
          }
@@ -515,10 +536,11 @@ _mesa_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value)
 
             /* save color */
 	    clearColorTypeSave = ctx->Color._ClearColorType;
-            COPY_4V(clearSave.cl, ctx->Color.ClearColor.cl);
+            COPY_CLEAR_COLOR(ctx->Color._ClearColorType,
+                             clearSave, ctx->Color.ClearColorUnclamped);
             /* set color */
-	    ctx->Color._ClearColorType = GL_FLOAT;
-            COPY_4V_CAST(ctx->Color.ClearColor.cl, value, GLclampf);
+            ctx->Color._ClearColorType = GL_FLOAT;
+            COPY_4V_CAST(ctx->Color.ClearColorUnclamped.cl, value, GLclampf);
             if (ctx->Driver.ClearColor)
                ctx->Driver.ClearColor(ctx, ctx->Color._ClearColorType,
                                       ctx->Color.ClearColor);
@@ -526,7 +548,8 @@ _mesa_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value)
             ctx->Driver.Clear(ctx, mask);
             /* restore color */
             ctx->Color._ClearColorType = clearColorTypeSave;
-            COPY_4V(ctx->Color.ClearColor.cl, clearSave.cl);
+            COPY_CLEAR_COLOR(ctx->Color._ClearColorType,
+                             ctx->Color.ClearColorUnclamped, clearSave);
             if (ctx->Driver.ClearColor)
                ctx->Driver.ClearColor(ctx, clearColorTypeSave, clearSave);
          }
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 41b1a82..9f6932f 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1673,10 +1673,21 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
          COPY_4FV(v->value_float_4, ctx->Fog.ColorUnclamped);
       break;
    case GL_COLOR_CLEAR_VALUE:
-      if(ctx->Color._ClampFragmentColor)
-         COPY_4FV(v->value_float_4, ctx->Color.ClearColor.cl);
-      else
-         COPY_4FV(v->value_float_4, ctx->Color.ClearColorUnclamped.f);
+		switch (ctx->Color._ClearColorType) {
+		case GL_FLOAT:
+		default:
+			if(ctx->Color._ClampFragmentColor)
+				COPY_4FV(v->value_float_4, ctx->Color.ClearColor.cl);
+			else
+				COPY_4FV(v->value_float_4, ctx->Color.ClearColorUnclamped.f);
+			break;
+		case GL_UNSIGNED_INT:
+			COPY_4V_CAST(v->value_float_4, ctx->Color.ClearColorUnclamped.ui, GLfloat);
+			break;
+		case GL_INT:
+			COPY_4V_CAST(v->value_float_4, ctx->Color.ClearColorUnclamped.i, GLfloat);
+			break;
+		}
       break;
    case GL_BLEND_COLOR_EXT:
       if(ctx->Color._ClampFragmentColor)
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 29d6add..34583db 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -722,6 +722,8 @@ struct gl_accum_attrib
 union gl_clear_color {
    GLfloat f[4];
    GLclampf cl[4];
+   GLint i[4];
+   GLuint ui[4];
 };
 
 /**
-- 
1.7.6



More information about the mesa-dev mailing list