summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
authorDave Airlie <[email protected]>2011-09-12 10:57:40 +0100
committerDave Airlie <[email protected]>2011-09-14 11:18:07 +0100
commit093dc9e548537e6c77e33064a584f849ad90dfa5 (patch)
tree4a3ecd84f123cd89a29fea6700603a5da53d62cb /src/mesa/main
parentb06613c6cc029c3ff200430b0706b5229c4508bd (diff)
mesa: introduce a clear color union to be used for int/unsigned buffers
This introduces a new gl_color_union union and moves the current ClearColorUnclamped to use it, it removes current ClearColor completely and renames CCU to CC, then all drivers are modified to expected unclamped floats instead. also fixes st to use translated color in one place it wasn't. Signed-off-by: Dave Airlie <[email protected]>
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/attrib.c8
-rw-r--r--src/mesa/main/blend.c3
-rw-r--r--src/mesa/main/clear.c82
-rw-r--r--src/mesa/main/dd.h3
-rw-r--r--src/mesa/main/get.c11
-rw-r--r--src/mesa/main/mtypes.h15
6 files changed, 54 insertions, 68 deletions
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 57310040235..9767740a3a6 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -884,10 +884,10 @@ _mesa_PopAttrib(void)
color = (const struct gl_colorbuffer_attrib *) attr->data;
_mesa_ClearIndex((GLfloat) color->ClearIndex);
- _mesa_ClearColor(color->ClearColorUnclamped[0],
- color->ClearColorUnclamped[1],
- color->ClearColorUnclamped[2],
- color->ClearColorUnclamped[3]);
+ _mesa_ClearColor(color->ClearColor.f[0],
+ color->ClearColor.f[1],
+ color->ClearColor.f[2],
+ color->ClearColor.f[3]);
_mesa_IndexMask(color->IndexMask);
if (!ctx->Extensions.EXT_draw_buffers2) {
_mesa_ColorMask((GLboolean) (color->ColorMask[0][0] != 0),
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index 1856f00d53b..4214a661bb8 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -795,8 +795,7 @@ void _mesa_init_color( struct gl_context * ctx )
ctx->Color.IndexMask = ~0u;
memset(ctx->Color.ColorMask, 0xff, sizeof(ctx->Color.ColorMask));
ctx->Color.ClearIndex = 0;
- ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
- ASSIGN_4V( ctx->Color.ClearColorUnclamped, 0, 0, 0, 0 );
+ ASSIGN_4V( ctx->Color.ClearColor.f, 0, 0, 0, 0 );
ctx->Color.AlphaEnabled = GL_FALSE;
ctx->Color.AlphaFunc = GL_ALWAYS;
ctx->Color.AlphaRef = 0;
diff --git a/src/mesa/main/clear.c b/src/mesa/main/clear.c
index fa95e4522f2..301fe694cda 100644
--- a/src/mesa/main/clear.c
+++ b/src/mesa/main/clear.c
@@ -83,16 +83,11 @@ _mesa_ClearColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
tmp[2] = blue;
tmp[3] = alpha;
- if (TEST_EQ_4V(tmp, ctx->Color.ClearColorUnclamped))
+ if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.f))
return; /* no change */
FLUSH_VERTICES(ctx, _NEW_COLOR);
- COPY_4V(ctx->Color.ClearColorUnclamped, tmp);
-
- ctx->Color.ClearColor[0] = CLAMP(tmp[0], 0.0F, 1.0F);
- ctx->Color.ClearColor[1] = CLAMP(tmp[1], 0.0F, 1.0F);
- ctx->Color.ClearColor[2] = CLAMP(tmp[2], 0.0F, 1.0F);
- ctx->Color.ClearColor[3] = CLAMP(tmp[3], 0.0F, 1.0F);
+ COPY_4V(ctx->Color.ClearColor.f, tmp);
if (ctx->Driver.ClearColor) {
/* it's OK to call glClearColor in CI mode but it should be a NOP */
@@ -110,25 +105,22 @@ _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))
+ if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.i))
return; /* no change */
FLUSH_VERTICES(ctx, _NEW_COLOR);
+ COPY_4V(ctx->Color.ClearColor.i, tmp);
- /* XXX we should eventually have a float/int/uint union for
- * the ctx->Color.ClearColor state.
- */
- COPY_4V(ctx->Color.ClearColor, tmp);
-
+ /* these should be NOP calls for drivers supporting EXT_texture_integer */
if (ctx->Driver.ClearColor) {
ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
}
@@ -141,25 +133,22 @@ _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))
+ if (TEST_EQ_4V(tmp, ctx->Color.ClearColor.ui))
return; /* no change */
FLUSH_VERTICES(ctx, _NEW_COLOR);
+ COPY_4V(ctx->Color.ClearColor.ui, tmp);
- /* XXX we should eventually have a float/int/uint union for
- * the ctx->Color.ClearColor state.
- */
- COPY_4V(ctx->Color.ClearColor, tmp);
-
+ /* these should be NOP calls for drivers supporting EXT_texture_integer */
if (ctx->Driver.ClearColor) {
ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
}
@@ -364,21 +353,18 @@ _mesa_ClearBufferiv(GLenum buffer, GLint drawbuffer, const GLint *value)
return;
}
else if (mask) {
- /* XXX note: we're putting the integer clear values into the
- * floating point state var. This will not always work. We'll
- * need a new ctx->Driver.ClearBuffer() hook....
- */
- GLclampf clearSave[4];
+ union gl_color_union clearSave;
+
/* save color */
- COPY_4V(clearSave, ctx->Color.ClearColor);
+ clearSave = ctx->Color.ClearColor;
/* set color */
- COPY_4V_CAST(ctx->Color.ClearColor, value, GLclampf);
+ COPY_4V(ctx->Color.ClearColor.i, value);
if (ctx->Driver.ClearColor)
ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
/* clear buffer(s) */
ctx->Driver.Clear(ctx, mask);
/* restore color */
- COPY_4V(ctx->Color.ClearColor, clearSave);
+ ctx->Color.ClearColor = clearSave;
if (ctx->Driver.ClearColor)
ctx->Driver.ClearColor(ctx, clearSave);
}
@@ -418,21 +404,18 @@ _mesa_ClearBufferuiv(GLenum buffer, GLint drawbuffer, const GLuint *value)
return;
}
else if (mask) {
- /* XXX note: we're putting the uint clear values into the
- * floating point state var. This will not always work. We'll
- * need a new ctx->Driver.ClearBuffer() hook....
- */
- GLclampf clearSave[4];
+ union gl_color_union clearSave;
+
/* save color */
- COPY_4V(clearSave, ctx->Color.ClearColor);
+ clearSave = ctx->Color.ClearColor;
/* set color */
- COPY_4V_CAST(ctx->Color.ClearColor, value, GLclampf);
+ COPY_4V(ctx->Color.ClearColor.ui, value);
if (ctx->Driver.ClearColor)
ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
/* clear buffer(s) */
ctx->Driver.Clear(ctx, mask);
/* restore color */
- COPY_4V(ctx->Color.ClearColor, clearSave);
+ ctx->Color.ClearColor = clearSave;
if (ctx->Driver.ClearColor)
ctx->Driver.ClearColor(ctx, clearSave);
}
@@ -495,17 +478,18 @@ _mesa_ClearBufferfv(GLenum buffer, GLint drawbuffer, const GLfloat *value)
return;
}
else if (mask) {
- GLclampf clearSave[4];
+ union gl_color_union clearSave;
+
/* save color */
- COPY_4V(clearSave, ctx->Color.ClearColor);
+ clearSave = ctx->Color.ClearColor;
/* set color */
- COPY_4V_CAST(ctx->Color.ClearColor, value, GLclampf);
+ COPY_4V_CAST(ctx->Color.ClearColor.f, value, GLclampf);
if (ctx->Driver.ClearColor)
ctx->Driver.ClearColor(ctx, ctx->Color.ClearColor);
/* clear buffer(s) */
ctx->Driver.Clear(ctx, mask);
/* restore color */
- COPY_4V(ctx->Color.ClearColor, clearSave);
+ ctx->Color.ClearColor = clearSave;
if (ctx->Driver.ClearColor)
ctx->Driver.ClearColor(ctx, clearSave);
}
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index b77e4f092f6..d6cc0196d8d 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -589,7 +589,8 @@ struct dd_function_table {
GLenum sfactorRGB, GLenum dfactorRGB,
GLenum sfactorA, GLenum dfactorA);
/** Specify clear values for the color buffers */
- void (*ClearColor)(struct gl_context *ctx, const GLfloat color[4]);
+ void (*ClearColor)(struct gl_context *ctx,
+ const union gl_color_union color);
/** Specify the clear value for the depth buffer */
void (*ClearDepth)(struct gl_context *ctx, GLclampd d);
/** Specify the clear value for the stencil buffer */
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index 069254b18f5..a777bd8c403 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -1673,10 +1673,13 @@ 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);
- else
- COPY_4FV(v->value_float_4, ctx->Color.ClearColorUnclamped);
+ if(ctx->Color._ClampFragmentColor) {
+ v->value_float_4[0] = CLAMP(ctx->Color.ClearColor.f[0], 0.0F, 1.0F);
+ v->value_float_4[1] = CLAMP(ctx->Color.ClearColor.f[1], 0.0F, 1.0F);
+ v->value_float_4[2] = CLAMP(ctx->Color.ClearColor.f[2], 0.0F, 1.0F);
+ v->value_float_4[3] = CLAMP(ctx->Color.ClearColor.f[3], 0.0F, 1.0F);
+ } else
+ COPY_4FV(v->value_float_4, ctx->Color.ClearColor.f);
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 ae500b4c226..a439f129d72 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -719,6 +719,11 @@ struct gl_accum_attrib
GLfloat ClearColor[4]; /**< Accumulation buffer clear color */
};
+union gl_color_union {
+ GLfloat f[4];
+ GLint i[4];
+ GLuint ui[4];
+};
/**
* Color buffer attribute group (GL_COLOR_BUFFER_BIT).
@@ -726,9 +731,7 @@ struct gl_accum_attrib
struct gl_colorbuffer_attrib
{
GLuint ClearIndex; /**< Index to use for glClear */
- GLfloat ClearColorUnclamped[4]; /**< Color to use for glClear*/
- GLclampf ClearColor[4]; /**< Color to use for glClear */
-
+ union gl_color_union ClearColor; /**< Color to use for glClear - this vale is unclamped */
GLuint IndexMask; /**< Color index write mask */
GLubyte ColorMask[MAX_DRAW_BUFFERS][4];/**< Each flag is 0xff or 0x0 */
@@ -1356,11 +1359,7 @@ struct gl_sampler_object
GLenum WrapR; /**< R-axis texture image wrap mode */
GLenum MinFilter; /**< minification filter */
GLenum MagFilter; /**< magnification filter */
- union {
- GLfloat f[4];
- GLuint ui[4];
- GLint i[4];
- } BorderColor; /**< Interpreted according to texture format */
+ union gl_color_union BorderColor; /**< Interpreted according to texture format */
GLfloat MinLod; /**< min lambda, OpenGL 1.2 */
GLfloat MaxLod; /**< max lambda, OpenGL 1.2 */
GLfloat LodBias; /**< OpenGL 1.4 */