[Mesa-dev] [PATCH 3/5] mesa: move updating clamp control derived state out of mesa_update_state_locked

Marek Olšák maraeo at gmail.com
Thu Mar 28 14:24:37 PDT 2013


It has 2 dependencies: glClampColor and the framebuffer, we might just as well
do the update where those two are changed.
---
 src/mesa/main/blend.c       |   28 ++++++++++++++++++++++++++++
 src/mesa/main/blend.h       |    6 ++++++
 src/mesa/main/framebuffer.c |    4 ++++
 src/mesa/main/state.c       |   36 ------------------------------------
 4 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index c1b49b1..6cc2310 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -767,10 +767,12 @@ _mesa_ClampColor(GLenum target, GLenum clamp)
    case GL_CLAMP_VERTEX_COLOR_ARB:
       FLUSH_VERTICES(ctx, _NEW_LIGHT);
       ctx->Light.ClampVertexColor = clamp;
+      _mesa_update_clamp_vertex_color(ctx);
       break;
    case GL_CLAMP_FRAGMENT_COLOR_ARB:
       FLUSH_VERTICES(ctx, _NEW_FRAG_CLAMP);
       ctx->Color.ClampFragmentColor = clamp;
+      _mesa_update_clamp_fragment_color(ctx);
       break;
    case GL_CLAMP_READ_COLOR_ARB:
       FLUSH_VERTICES(ctx, _NEW_COLOR);
@@ -811,6 +813,32 @@ GLboolean _mesa_get_clamp_read_color(const struct gl_context *ctx)
    return _mesa_get_clamp_color(ctx->ReadBuffer, ctx->Color.ClampReadColor);
 }
 
+/**
+ * Update the ctx->Color._ClampFragmentColor field
+ */
+void _mesa_update_clamp_fragment_color(struct gl_context *ctx)
+{
+   struct gl_framebuffer *fb = ctx->DrawBuffer;
+
+   /* Don't clamp if:
+    * - there is no colorbuffer
+    * - all colorbuffers are unsigned normalized, so clamping has no effect
+    * - there is an integer colorbuffer
+    */
+   if (!fb || !fb->_HasSNormOrFloatColorBuffer || fb->_IntegerColor)
+      ctx->Color._ClampFragmentColor = GL_FALSE;
+   else
+      ctx->Color._ClampFragmentColor = _mesa_get_clamp_fragment_color(ctx);
+}
+
+/**
+ * Update the ctx->Color._ClampVertexColor field
+ */
+void _mesa_update_clamp_vertex_color(struct gl_context *ctx)
+{
+   ctx->Light._ClampVertexColor = _mesa_get_clamp_vertex_color(ctx);
+}
+
 
 /**********************************************************************/
 /** \name Initialization */
diff --git a/src/mesa/main/blend.h b/src/mesa/main/blend.h
index 694fc5a..621311d 100644
--- a/src/mesa/main/blend.h
+++ b/src/mesa/main/blend.h
@@ -108,6 +108,12 @@ _mesa_get_clamp_vertex_color(const struct gl_context *ctx);
 extern GLboolean
 _mesa_get_clamp_read_color(const struct gl_context *ctx);
 
+extern void
+_mesa_update_clamp_fragment_color(struct gl_context *ctx);
+
+extern void
+_mesa_update_clamp_vertex_color(struct gl_context *ctx);
+
 extern void  
 _mesa_init_color( struct gl_context * ctx );
 
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 757c4b0..6c69774 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -32,6 +32,7 @@
 
 #include "glheader.h"
 #include "imports.h"
+#include "blend.h"
 #include "buffers.h"
 #include "context.h"
 #include "enums.h"
@@ -742,6 +743,9 @@ _mesa_update_framebuffer(struct gl_context *ctx)
    update_framebuffer(ctx, drawFb);
    if (readFb != drawFb)
       update_framebuffer(ctx, readFb);
+
+   _mesa_update_clamp_vertex_color(ctx);
+   _mesa_update_clamp_fragment_color(ctx);
 }
 
 
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index 73c5a1c..251c1ae 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -309,36 +309,6 @@ update_multisample(struct gl_context *ctx)
 
 
 /**
- * Update the ctx->Color._ClampFragmentColor field
- */
-static void
-update_clamp_fragment_color(struct gl_context *ctx)
-{
-   struct gl_framebuffer *fb = ctx->DrawBuffer;
-
-   /* Don't clamp if:
-    * - there is no colorbuffer
-    * - all colorbuffers are unsigned normalized, so clamping has no effect
-    * - there is an integer colorbuffer
-    */
-   if (!fb || !fb->_HasSNormOrFloatColorBuffer || fb->_IntegerColor)
-      ctx->Color._ClampFragmentColor = GL_FALSE;
-   else
-      ctx->Color._ClampFragmentColor = _mesa_get_clamp_fragment_color(ctx);
-}
-
-
-/**
- * Update the ctx->Color._ClampVertexColor field
- */
-static void
-update_clamp_vertex_color(struct gl_context *ctx)
-{
-   ctx->Light._ClampVertexColor = _mesa_get_clamp_vertex_color(ctx);
-}
-
-
-/**
  * Update the ctx->VertexProgram._TwoSideEnabled flag.
  */
 static void
@@ -497,9 +467,6 @@ _mesa_update_state_locked( struct gl_context *ctx )
    if (new_state & (_NEW_LIGHT | _NEW_PROGRAM))
       update_twoside( ctx );
 
-   if (new_state & (_NEW_LIGHT | _NEW_BUFFERS))
-      update_clamp_vertex_color(ctx);
-
    if (new_state & (_NEW_STENCIL | _NEW_BUFFERS))
       _mesa_update_stencil( ctx );
 
@@ -515,9 +482,6 @@ _mesa_update_state_locked( struct gl_context *ctx )
    if (new_state & (_NEW_MULTISAMPLE | _NEW_BUFFERS))
       update_multisample( ctx );
 
-   if(new_state & (_NEW_FRAG_CLAMP | _NEW_BUFFERS))
-      update_clamp_fragment_color(ctx);
-
 #if 0
    if (new_state & (_NEW_POINT | _NEW_LINE | _NEW_POLYGON | _NEW_LIGHT
                     | _NEW_STENCIL | _MESA_NEW_SEPARATE_SPECULAR))
-- 
1.7.10.4



More information about the mesa-dev mailing list