diff options
author | Marek Olšák <[email protected]> | 2013-03-28 01:50:21 +0100 |
---|---|---|
committer | Marek Olšák <[email protected]> | 2013-04-06 23:57:04 +0200 |
commit | 21d407c1b8bf3be1eff87121d528d03c240ce207 (patch) | |
tree | 5909f109a8e529e2e2663b42a10e56a5aca848d1 /src/mesa | |
parent | c4629ad3f9440ec7ad3d9f4881d0aba41a93f2f5 (diff) |
mesa: refactor clamping controls, get rid of _ClampReadColor
v2: cosmetic changes from Brian's email
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/blend.c | 31 | ||||
-rw-r--r-- | src/mesa/main/blend.h | 8 | ||||
-rw-r--r-- | src/mesa/main/fbobject.c | 10 | ||||
-rw-r--r-- | src/mesa/main/framebuffer.c | 1 | ||||
-rw-r--r-- | src/mesa/main/mtypes.h | 4 | ||||
-rw-r--r-- | src/mesa/main/readpix.c | 5 | ||||
-rw-r--r-- | src/mesa/main/state.c | 29 |
7 files changed, 58 insertions, 30 deletions
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c index 309f1d538f9..88bf3654c10 100644 --- a/src/mesa/main/blend.c +++ b/src/mesa/main/blend.c @@ -782,7 +782,37 @@ _mesa_ClampColor(GLenum target, GLenum clamp) } } +static GLboolean +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 get_clamp_color(ctx->DrawBuffer, + ctx->Color.ClampFragmentColor); +} +GLboolean +_mesa_get_clamp_vertex_color(const struct gl_context *ctx) +{ + return get_clamp_color(ctx->DrawBuffer, ctx->Light.ClampVertexColor); +} + +GLboolean +_mesa_get_clamp_read_color(const struct gl_context *ctx) +{ + return get_clamp_color(ctx->ReadBuffer, ctx->Color.ClampReadColor); +} /**********************************************************************/ @@ -835,7 +865,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 a539aa80937..694fc5af385 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 c1f52990c60..67c116163db 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 619aaa33754..5fb36776b45 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 e731fe3ab30..40a567620ee 100644 --- a/src/mesa/main/mtypes.h +++ b/src/mesa/main/mtypes.h @@ -673,7 +673,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 */ }; @@ -2661,6 +2660,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 d3d09dea345..0dee3806333 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 fb8b71cfe22..c94a2449930 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); |