On 25 September 2011 12:52, Paul Berry <span dir="ltr"><<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
This is a follow-up to commit<br>
2d686fe911a89fa477ee3848da41ebfb100500bf, which added decoding of<br>
GL_CLIP_DISTANCE[67] to the _mesa_set_enable() function. This patch<br>
makes the following additional fixes:<br>
<br>
- Uses GL_CLIP_DISTANCEi enums consistently within enable.c rather<br>
than the deprecated GL_CLIP_PLANEi enums.<br>
<br>
- Generates an error if the user tries to access a clip flag that is<br>
unsupported by the hardware.<br>
<br>
- Applies the same change to _mesa_IsEnabled(), so that querying clip<br>
flags using glIsEnabled() works properly.<br>
<br>
- Applies corresponding changes to get.c, so that querying clip flags<br>
using glGet*() works properly.<br>
<br>
Fixes piglit test clip-flag-behavior.<br>
---<br>
src/mesa/main/enable.c | 27 +++++++++++++++++++--------<br>
src/mesa/main/get.c | 43 +++++++++++++++++++++++++++++++++++++------<br>
2 files changed, 56 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c<br>
index 23b6a94..689dc8a 100644<br>
--- a/src/mesa/main/enable.c<br>
+++ b/src/mesa/main/enable.c<br>
@@ -304,7 +304,10 @@ _mesa_set_enable(struct gl_context *ctx, GLenum cap, GLboolean state)<br>
case GL_CLIP_DISTANCE6:<br>
case GL_CLIP_DISTANCE7:<br>
{<br>
- const GLuint p = cap - GL_CLIP_PLANE0;<br>
+ const GLuint p = cap - GL_CLIP_DISTANCE0;<br>
+<br>
+ if (p >= ctx->Const.MaxClipPlanes)<br>
+ goto invalid_enum_error;<br>
<br>
if ((ctx->Transform.ClipPlanesEnabled & (1 << p))<br>
== ((GLuint) state << p))<br>
@@ -1084,13 +1087,21 @@ _mesa_IsEnabled( GLenum cap )<br>
return ctx->Eval.AutoNormal;<br>
case GL_BLEND:<br>
return ctx->Color.BlendEnabled & 1; /* return state for buffer[0] */<br>
- case GL_CLIP_PLANE0:<br>
- case GL_CLIP_PLANE1:<br>
- case GL_CLIP_PLANE2:<br>
- case GL_CLIP_PLANE3:<br>
- case GL_CLIP_PLANE4:<br>
- case GL_CLIP_PLANE5:<br>
- return (ctx->Transform.ClipPlanesEnabled >> (cap - GL_CLIP_PLANE0)) & 1;<br>
+ case GL_CLIP_DISTANCE0:<br>
+ case GL_CLIP_DISTANCE1:<br>
+ case GL_CLIP_DISTANCE2:<br>
+ case GL_CLIP_DISTANCE3:<br>
+ case GL_CLIP_DISTANCE4:<br>
+ case GL_CLIP_DISTANCE5:<br>
+ case GL_CLIP_DISTANCE6:<br>
+ case GL_CLIP_DISTANCE7: {<br>
+ const GLuint p = cap - GL_CLIP_DISTANCE0;<br>
+<br>
+ if (p >= ctx->Const.MaxClipPlanes)<br>
+ goto invalid_enum_error;<br>
+<br>
+ return (ctx->Transform.ClipPlanesEnabled >> p) & 1;<br>
+ }<br>
case GL_COLOR_MATERIAL:<br>
return ctx->Light.ColorMaterialEnabled;<br>
case GL_CULL_FACE:<br>
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c<br>
index 8279069..bc26d81 100644<br>
--- a/src/mesa/main/get.c<br>
+++ b/src/mesa/main/get.c<br>
@@ -102,6 +102,8 @@ enum value_type {<br>
TYPE_BIT_3,<br>
TYPE_BIT_4,<br>
TYPE_BIT_5,<br>
+ TYPE_BIT_6,<br>
+ TYPE_BIT_7,<br>
TYPE_FLOAT,<br>
TYPE_FLOAT_2,<br>
TYPE_FLOAT_3,<br>
@@ -134,6 +136,7 @@ enum value_extra {<br>
EXTRA_NEW_FRAG_CLAMP,<br>
EXTRA_VALID_DRAW_BUFFER,<br>
EXTRA_VALID_TEXTURE_UNIT,<br>
+ EXTRA_VALID_CLIP_DISTANCE,<br>
EXTRA_FLUSH_CURRENT,<br>
};<br>
<br>
@@ -189,6 +192,8 @@ union value {<br>
#define CONTEXT_BIT3(field) CONTEXT_FIELD(field, TYPE_BIT_3)<br>
#define CONTEXT_BIT4(field) CONTEXT_FIELD(field, TYPE_BIT_4)<br>
#define CONTEXT_BIT5(field) CONTEXT_FIELD(field, TYPE_BIT_5)<br>
+#define CONTEXT_BIT6(field) CONTEXT_FIELD(field, TYPE_BIT_6)<br>
+#define CONTEXT_BIT7(field) CONTEXT_FIELD(field, TYPE_BIT_7)<br>
#define CONTEXT_FLOAT(field) CONTEXT_FIELD(field, TYPE_FLOAT)<br>
#define CONTEXT_FLOAT2(field) CONTEXT_FIELD(field, TYPE_FLOAT_2)<br>
#define CONTEXT_FLOAT3(field) CONTEXT_FIELD(field, TYPE_FLOAT_3)<br>
@@ -239,6 +244,11 @@ static const int extra_valid_texture_unit[] = {<br>
EXTRA_END<br>
};<br>
<br>
+static const int extra_valid_clip_distance[] = {<br>
+ EXTRA_VALID_CLIP_DISTANCE,<br>
+ EXTRA_END<br>
+};<br>
+<br>
static const int extra_flush_current_valid_texture_unit[] = {<br>
EXTRA_FLUSH_CURRENT,<br>
EXTRA_VALID_TEXTURE_UNIT,<br>
@@ -525,12 +535,14 @@ static const struct value_desc values[] = {<br>
{ GL_ALPHA_TEST_FUNC, CONTEXT_ENUM(Color.AlphaFunc), NO_EXTRA },<br>
{ GL_ALPHA_TEST_REF, LOC_CUSTOM, TYPE_FLOATN, 0, extra_new_frag_clamp },<br>
{ GL_BLEND_DST, CONTEXT_ENUM(Color.Blend[0].DstRGB), NO_EXTRA },<br>
- { GL_CLIP_PLANE0, CONTEXT_BIT0(Transform.ClipPlanesEnabled), NO_EXTRA },<br>
- { GL_CLIP_PLANE1, CONTEXT_BIT1(Transform.ClipPlanesEnabled), NO_EXTRA },<br>
- { GL_CLIP_PLANE2, CONTEXT_BIT2(Transform.ClipPlanesEnabled), NO_EXTRA },<br>
- { GL_CLIP_PLANE3, CONTEXT_BIT3(Transform.ClipPlanesEnabled), NO_EXTRA },<br>
- { GL_CLIP_PLANE4, CONTEXT_BIT4(Transform.ClipPlanesEnabled), NO_EXTRA },<br>
- { GL_CLIP_PLANE5, CONTEXT_BIT5(Transform.ClipPlanesEnabled), NO_EXTRA },<br>
+ { GL_CLIP_DISTANCE0, CONTEXT_BIT0(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
+ { GL_CLIP_DISTANCE1, CONTEXT_BIT1(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
+ { GL_CLIP_DISTANCE2, CONTEXT_BIT2(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
+ { GL_CLIP_DISTANCE3, CONTEXT_BIT3(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
+ { GL_CLIP_DISTANCE4, CONTEXT_BIT4(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
+ { GL_CLIP_DISTANCE5, CONTEXT_BIT5(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
+ { GL_CLIP_DISTANCE6, CONTEXT_BIT6(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
+ { GL_CLIP_DISTANCE7, CONTEXT_BIT7(Transform.ClipPlanesEnabled), extra_valid_clip_distance },<br>
{ GL_COLOR_MATERIAL, CONTEXT_BOOL(Light.ColorMaterialEnabled), NO_EXTRA },<br>
{ GL_CURRENT_COLOR,<br>
CONTEXT_FIELD(Current.Attrib[VERT_ATTRIB_COLOR0][0], TYPE_FLOATN_4),<br>
@@ -1808,6 +1820,13 @@ check_extra(struct gl_context *ctx, const char *func, const struct value_desc *d<br>
return GL_FALSE;<br>
}<br>
break;<br>
+ case EXTRA_VALID_CLIP_DISTANCE:<br>
+ if (d->pname - GL_CLIP_DISTANCE0 >= ctx->Const.MaxClipPlanes) {<br>
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(clip distance %u)",<br>
+ func, d->pname - GL_CLIP_DISTANCE0);<br></blockquote><div><br>Minor correction: the error should be GL_INVALID_ENUM, not GL_INVALID_OPERATION (I accidentally sent an old version of the patch to the list). I'll make sure to push the correct version to master.<br>
</div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
+ return GL_FALSE;<br>
+ }<br>
+ break;<br>
case EXTRA_END:<br>
break;<br>
default: /* *e is a offset into the extension struct */<br>
@@ -1996,6 +2015,8 @@ _mesa_GetBooleanv(GLenum pname, GLboolean *params)<br>
case TYPE_BIT_3:<br>
case TYPE_BIT_4:<br>
case TYPE_BIT_5:<br>
+ case TYPE_BIT_6:<br>
+ case TYPE_BIT_7:<br>
shift = d->type - TYPE_BIT_0;<br>
params[0] = (*(GLbitfield *) p >> shift) & 1;<br>
break;<br>
@@ -2083,6 +2104,8 @@ _mesa_GetFloatv(GLenum pname, GLfloat *params)<br>
case TYPE_BIT_3:<br>
case TYPE_BIT_4:<br>
case TYPE_BIT_5:<br>
+ case TYPE_BIT_6:<br>
+ case TYPE_BIT_7:<br>
shift = d->type - TYPE_BIT_0;<br>
params[0] = BOOLEAN_TO_FLOAT((*(GLbitfield *) p >> shift) & 1);<br>
break;<br>
@@ -2176,6 +2199,8 @@ _mesa_GetIntegerv(GLenum pname, GLint *params)<br>
case TYPE_BIT_3:<br>
case TYPE_BIT_4:<br>
case TYPE_BIT_5:<br>
+ case TYPE_BIT_6:<br>
+ case TYPE_BIT_7:<br>
shift = d->type - TYPE_BIT_0;<br>
params[0] = (*(GLbitfield *) p >> shift) & 1;<br>
break;<br>
@@ -2270,6 +2295,8 @@ _mesa_GetInteger64v(GLenum pname, GLint64 *params)<br>
case TYPE_BIT_3:<br>
case TYPE_BIT_4:<br>
case TYPE_BIT_5:<br>
+ case TYPE_BIT_6:<br>
+ case TYPE_BIT_7:<br>
shift = d->type - TYPE_BIT_0;<br>
params[0] = (*(GLbitfield *) p >> shift) & 1;<br>
break;<br>
@@ -2358,6 +2385,8 @@ _mesa_GetDoublev(GLenum pname, GLdouble *params)<br>
case TYPE_BIT_3:<br>
case TYPE_BIT_4:<br>
case TYPE_BIT_5:<br>
+ case TYPE_BIT_6:<br>
+ case TYPE_BIT_7:<br>
shift = d->type - TYPE_BIT_0;<br>
params[0] = (*(GLbitfield *) p >> shift) & 1;<br>
break;<br>
@@ -2628,6 +2657,8 @@ _mesa_GetFixedv(GLenum pname, GLfixed *params)<br>
case TYPE_BIT_3:<br>
case TYPE_BIT_4:<br>
case TYPE_BIT_5:<br>
+ case TYPE_BIT_6:<br>
+ case TYPE_BIT_7:<br>
shift = d->type - TYPE_BIT_0;<br>
params[0] = BOOLEAN_TO_FIXED((*(GLbitfield *) p >> shift) & 1);<br>
break;<br>
<font color="#888888">--<br>
1.7.6.2<br>
<br>
</font></blockquote></div><br>