[Mesa-dev] [PATCH 1/5] mesa: refactor clamping controls, get rid of _ClampReadColor
Marek Olšák
maraeo at gmail.com
Thu Mar 28 14:24:35 PDT 2013
---
src/mesa/main/blend.c | 28 +++++++++++++++++++++++++++-
src/mesa/main/blend.h | 8 ++++++++
src/mesa/main/fbobject.c | 10 ++++++++++
src/mesa/main/framebuffer.c | 1 +
src/mesa/main/mtypes.h | 4 +++-
src/mesa/main/readpix.c | 5 +++--
src/mesa/main/state.c | 29 +++--------------------------
7 files changed, 55 insertions(+), 30 deletions(-)
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index 309f1d5..876cbf2 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -782,7 +782,34 @@ _mesa_ClampColor(GLenum target, GLenum clamp)
}
}
+static GLboolean _mesa_get_clamp_color(const struct gl_framebuffer *fb,
+ GLenum clamp)
+{
+ if (clamp == GL_TRUE || clamp == GL_FALSE)
+ return clamp;
+
+ ASSERT(clamp == GL_FIXED_ONLY);
+ if (!fb)
+ return GL_TRUE;
+ return fb->_AllColorBuffersFixedPoint;
+}
+
+GLboolean _mesa_get_clamp_fragment_color(const struct gl_context *ctx)
+{
+ return _mesa_get_clamp_color(ctx->DrawBuffer,
+ ctx->Color.ClampFragmentColor);
+}
+
+GLboolean _mesa_get_clamp_vertex_color(const struct gl_context *ctx)
+{
+ return _mesa_get_clamp_color(ctx->DrawBuffer, ctx->Light.ClampVertexColor);
+}
+
+GLboolean _mesa_get_clamp_read_color(const struct gl_context *ctx)
+{
+ return _mesa_get_clamp_color(ctx->ReadBuffer, ctx->Color.ClampReadColor);
+}
/**********************************************************************/
@@ -835,7 +862,6 @@ void _mesa_init_color( struct gl_context * ctx )
ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
ctx->Color._ClampFragmentColor = GL_TRUE;
ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB;
- ctx->Color._ClampReadColor = GL_TRUE;
if (ctx->API == API_OPENGLES2) {
/* GLES 3 behaves as though GL_FRAMEBUFFER_SRGB is always enabled. */
diff --git a/src/mesa/main/blend.h b/src/mesa/main/blend.h
index a539aa8..694fc5a 100644
--- a/src/mesa/main/blend.h
+++ b/src/mesa/main/blend.h
@@ -99,6 +99,14 @@ _mesa_ColorMaski( GLuint buf, GLboolean red, GLboolean green,
extern void GLAPIENTRY
_mesa_ClampColor(GLenum target, GLenum clamp);
+extern GLboolean
+_mesa_get_clamp_fragment_color(const struct gl_context *ctx);
+
+extern GLboolean
+_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_init_color( struct gl_context * ctx );
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index c1f5299..67c1161 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -784,6 +784,7 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
numImages = 0;
fb->Width = 0;
fb->Height = 0;
+ fb->_AllColorBuffersFixedPoint = GL_TRUE;
/* Start at -2 to more easily loop over all attachment points.
* -2: depth buffer
@@ -900,6 +901,15 @@ _mesa_test_framebuffer_completeness(struct gl_context *ctx,
/* check if integer color */
fb->_IntegerColor = _mesa_is_format_integer_color(attFormat);
+ /* Update _AllColorBuffersFixedPoint. */
+ if (i >= 0) {
+ GLenum type = _mesa_get_format_datatype(attFormat);
+
+ fb->_AllColorBuffersFixedPoint =
+ fb->_AllColorBuffersFixedPoint &&
+ (type == GL_UNSIGNED_NORMALIZED || type == GL_SIGNED_NORMALIZED);
+ }
+
/* Error-check width, height, format */
if (numImages == 1) {
/* save format */
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 619aaa3..5fb3677 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -154,6 +154,7 @@ _mesa_initialize_window_framebuffer(struct gl_framebuffer *fb,
fb->Delete = _mesa_destroy_framebuffer;
fb->_Status = GL_FRAMEBUFFER_COMPLETE_EXT;
+ fb->_AllColorBuffersFixedPoint = !visual->floatMode;
compute_depth_max(fb);
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index a0e7e28..8c64a5b 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -683,7 +683,6 @@ struct gl_colorbuffer_attrib
GLenum ClampFragmentColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
GLboolean _ClampFragmentColor; /** < with GL_FIXED_ONLY_ARB resolved */
GLenum ClampReadColor; /**< GL_TRUE, GL_FALSE or GL_FIXED_ONLY_ARB */
- GLboolean _ClampReadColor; /** < with GL_FIXED_ONLY_ARB resolved */
GLboolean sRGBEnabled; /**< Framebuffer sRGB blending/updating requested */
};
@@ -2670,6 +2669,9 @@ struct gl_framebuffer
/** Integer color values */
GLboolean _IntegerColor;
+ /* ARB_color_buffer_float */
+ GLboolean _AllColorBuffersFixedPoint; /* no integer, no float */
+
/** Array of all renderbuffer attachments, indexed by BUFFER_* tokens. */
struct gl_renderbuffer_attachment Attachment[BUFFER_COUNT];
diff --git a/src/mesa/main/readpix.c b/src/mesa/main/readpix.c
index d3d09de..0dee380 100644
--- a/src/mesa/main/readpix.c
+++ b/src/mesa/main/readpix.c
@@ -24,6 +24,7 @@
#include "glheader.h"
#include "imports.h"
+#include "blend.h"
#include "bufferobj.h"
#include "context.h"
#include "enums.h"
@@ -80,7 +81,7 @@ get_readpixels_transfer_ops(const struct gl_context *ctx, gl_format texFormat,
if (uses_blit) {
/* For blit-based ReadPixels packing, the clamping is done automatically
* unless the type is float. */
- if (ctx->Color._ClampReadColor == GL_TRUE &&
+ if (_mesa_get_clamp_read_color(ctx) &&
(type == GL_FLOAT || type == GL_HALF_FLOAT)) {
transferOps |= IMAGE_CLAMP_BIT;
}
@@ -88,7 +89,7 @@ get_readpixels_transfer_ops(const struct gl_context *ctx, gl_format texFormat,
else {
/* For CPU-based ReadPixels packing, the clamping must always be done
* for non-float types, */
- if (ctx->Color._ClampReadColor == GL_TRUE ||
+ if (_mesa_get_clamp_read_color(ctx) ||
(type != GL_FLOAT && type != GL_HALF_FLOAT)) {
transferOps |= IMAGE_CLAMP_BIT;
}
diff --git a/src/mesa/main/state.c b/src/mesa/main/state.c
index fb8b71c..c94a244 100644
--- a/src/mesa/main/state.c
+++ b/src/mesa/main/state.c
@@ -51,6 +51,7 @@
#include "texobj.h"
#include "texstate.h"
#include "varray.h"
+#include "blend.h"
static void
@@ -313,11 +314,7 @@ update_multisample(struct gl_context *ctx)
static void
update_clamp_fragment_color(struct gl_context *ctx)
{
- if (ctx->Color.ClampFragmentColor == GL_FIXED_ONLY_ARB)
- ctx->Color._ClampFragmentColor =
- !ctx->DrawBuffer || !ctx->DrawBuffer->Visual.floatMode;
- else
- ctx->Color._ClampFragmentColor = ctx->Color.ClampFragmentColor;
+ ctx->Color._ClampFragmentColor = _mesa_get_clamp_fragment_color(ctx);
}
@@ -327,28 +324,11 @@ update_clamp_fragment_color(struct gl_context *ctx)
static void
update_clamp_vertex_color(struct gl_context *ctx)
{
- if (ctx->Light.ClampVertexColor == GL_FIXED_ONLY_ARB)
- ctx->Light._ClampVertexColor =
- !ctx->DrawBuffer || !ctx->DrawBuffer->Visual.floatMode;
- else
- ctx->Light._ClampVertexColor = ctx->Light.ClampVertexColor;
+ ctx->Light._ClampVertexColor = _mesa_get_clamp_vertex_color(ctx);
}
/**
- * Update the ctx->Color._ClampReadColor field
- */
-static void
-update_clamp_read_color(struct gl_context *ctx)
-{
- if (ctx->Color.ClampReadColor == GL_FIXED_ONLY_ARB)
- ctx->Color._ClampReadColor =
- !ctx->ReadBuffer || !ctx->ReadBuffer->Visual.floatMode;
- else
- ctx->Color._ClampReadColor = ctx->Color.ClampReadColor;
-}
-
-/**
* Update the ctx->VertexProgram._TwoSideEnabled flag.
*/
static void
@@ -525,9 +505,6 @@ _mesa_update_state_locked( struct gl_context *ctx )
if (new_state & (_NEW_MULTISAMPLE | _NEW_BUFFERS))
update_multisample( ctx );
- if (new_state & (_NEW_COLOR | _NEW_BUFFERS))
- update_clamp_read_color(ctx);
-
if(new_state & (_NEW_FRAG_CLAMP | _NEW_BUFFERS))
update_clamp_fragment_color(ctx);
--
1.7.10.4
More information about the mesa-dev
mailing list