aboutsummaryrefslogtreecommitdiff
path: root/mesalib/src/mesa/main/blend.c
diff options
context:
space:
mode:
Diffstat (limited to 'mesalib/src/mesa/main/blend.c')
-rw-r--r--mesalib/src/mesa/main/blend.c82
1 files changed, 77 insertions, 5 deletions
diff --git a/mesalib/src/mesa/main/blend.c b/mesalib/src/mesa/main/blend.c
index 309f1d538..09a1c9ae8 100644
--- a/mesalib/src/mesa/main/blend.c
+++ b/mesalib/src/mesa/main/blend.c
@@ -765,24 +765,96 @@ _mesa_ClampColor(GLenum target, GLenum clamp)
switch (target) {
case GL_CLAMP_VERTEX_COLOR_ARB:
+ if (ctx->API == API_OPENGL_CORE &&
+ !ctx->Extensions.ARB_color_buffer_float) {
+ goto invalid_enum;
+ }
FLUSH_VERTICES(ctx, _NEW_LIGHT);
ctx->Light.ClampVertexColor = clamp;
+ _mesa_update_clamp_vertex_color(ctx);
break;
case GL_CLAMP_FRAGMENT_COLOR_ARB:
+ if (ctx->API == API_OPENGL_CORE &&
+ !ctx->Extensions.ARB_color_buffer_float) {
+ goto invalid_enum;
+ }
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);
ctx->Color.ClampReadColor = clamp;
break;
default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(target)");
- return;
+ goto invalid_enum;
}
+ return;
+
+invalid_enum:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glClampColor(%s)",
+ _mesa_lookup_enum_by_nr(target));
+}
+
+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);
}
+/**
+ * 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);
+}
/**********************************************************************/
@@ -832,10 +904,10 @@ void _mesa_init_color( struct gl_context * ctx )
ctx->Color.DrawBuffer[0] = GL_FRONT;
}
- ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
- ctx->Color._ClampFragmentColor = GL_TRUE;
+ ctx->Color.ClampFragmentColor = ctx->API == API_OPENGL_COMPAT ?
+ GL_FIXED_ONLY_ARB : GL_FALSE;
+ ctx->Color._ClampFragmentColor = GL_FALSE;
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. */