summaryrefslogtreecommitdiff
path: root/dist/Mesa/src/mesa/main/enable.c
diff options
context:
space:
mode:
authorMatthieu Herrb <matthieu@cvs.openbsd.org>2008-02-12 21:09:28 +0000
committerMatthieu Herrb <matthieu@cvs.openbsd.org>2008-02-12 21:09:28 +0000
commitb597d23cbc3cc1c1361b89e621fcca7ddf9c024a (patch)
tree931175127192ecb3f18f61b71ed40d57e5612576 /dist/Mesa/src/mesa/main/enable.c
parent95e90dfb93882027d8e88ed60c6d24fb226511e7 (diff)
Update to Mesa 7.0.2. Tested by naddy@ (full ports build), simon@
and oga@ (with dri enabled).
Diffstat (limited to 'dist/Mesa/src/mesa/main/enable.c')
-rw-r--r--dist/Mesa/src/mesa/main/enable.c242
1 files changed, 96 insertions, 146 deletions
diff --git a/dist/Mesa/src/mesa/main/enable.c b/dist/Mesa/src/mesa/main/enable.c
index 91268b596..1c6167b79 100644
--- a/dist/Mesa/src/mesa/main/enable.c
+++ b/dist/Mesa/src/mesa/main/enable.c
@@ -49,11 +49,14 @@
}
+/**
+ * Helper to enable/disable client-side state.
+ */
static void
-client_state( GLcontext *ctx, GLenum cap, GLboolean state )
+client_state(GLcontext *ctx, GLenum cap, GLboolean state)
{
GLuint flag;
- GLuint *var;
+ GLboolean *var;
switch (cap) {
case GL_VERTEX_ARRAY:
@@ -134,17 +137,14 @@ client_state( GLcontext *ctx, GLenum cap, GLboolean state )
ctx->Array.ArrayObj->_Enabled &= ~flag;
if (ctx->Driver.Enable) {
- (*ctx->Driver.Enable)( ctx, cap, state );
+ ctx->Driver.Enable( ctx, cap, state );
}
}
/**
* Enable GL capability.
- *
- * \param cap capability.
- *
- * \sa glEnable().
+ * \param cap state to enable/disable.
*
* Get's the current context, assures that we're outside glBegin()/glEnd() and
* calls client_state().
@@ -160,10 +160,7 @@ _mesa_EnableClientState( GLenum cap )
/**
* Disable GL capability.
- *
- * \param cap capability.
- *
- * \sa glDisable().
+ * \param cap state to enable/disable.
*
* Get's the current context, assures that we're outside glBegin()/glEnd() and
* calls client_state().
@@ -193,12 +190,31 @@ _mesa_DisableClientState( GLenum cap )
}
+/**
+ * Helper function to enable or disable a texture target.
+ */
+static GLboolean
+enable_texture(GLcontext *ctx, GLboolean state, GLbitfield bit)
+{
+ const GLuint curr = ctx->Texture.CurrentUnit;
+ struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
+ const GLuint newenabled = (!state)
+ ? (texUnit->Enabled & ~bit) : (texUnit->Enabled | bit);
+
+ if (!ctx->DrawBuffer->Visual.rgbMode || texUnit->Enabled == newenabled)
+ return GL_FALSE;
+
+ FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ texUnit->Enabled = newenabled;
+ return GL_TRUE;
+}
+
/**
- * Perform glEnable() and glDisable() calls.
+ * Helper function to enable or disable state.
*
* \param ctx GL context.
- * \param cap capability.
+ * \param cap the state to enable/disable
* \param state whether to enable or disable the specified capability.
*
* Updates the current context and flushes the vertices as needed. For
@@ -206,7 +222,8 @@ _mesa_DisableClientState( GLenum cap )
* are effectivly present before updating. Notifies the driver via
* dd_function_table::Enable.
*/
-void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
+void
+_mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
{
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "%s %s (newstate is %x)\n",
@@ -285,7 +302,6 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
FLUSH_VERTICES(ctx, _NEW_POLYGON);
ctx->Polygon.CullFlag = state;
break;
-
case GL_CULL_VERTEX_EXT:
CHECK_EXTENSION(EXT_cull_vertex, cap);
if (ctx->Transform.CullVertexFlag == state)
@@ -293,13 +309,12 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
FLUSH_VERTICES(ctx, _NEW_TRANSFORM);
ctx->Transform.CullVertexFlag = state;
break;
-
case GL_DEPTH_TEST:
if (state && ctx->DrawBuffer->Visual.depthBits == 0) {
_mesa_warning(ctx,"glEnable(GL_DEPTH_TEST) but no depth buffer");
return;
}
- if (ctx->Depth.Test==state)
+ if (ctx->Depth.Test == state)
return;
FLUSH_VERTICES(ctx, _NEW_DEPTH);
ctx->Depth.Test = state;
@@ -308,13 +323,13 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
if (ctx->NoDither) {
state = GL_FALSE; /* MESA_NO_DITHER env var */
}
- if (ctx->Color.DitherFlag==state)
+ if (ctx->Color.DitherFlag == state)
return;
FLUSH_VERTICES(ctx, _NEW_COLOR);
ctx->Color.DitherFlag = state;
break;
case GL_FOG:
- if (ctx->Fog.Enabled==state)
+ if (ctx->Fog.Enabled == state)
return;
FLUSH_VERTICES(ctx, _NEW_FOG);
ctx->Fog.Enabled = state;
@@ -349,14 +364,12 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
case GL_LIGHTING:
if (ctx->Light.Enabled == state)
return;
- FLUSH_VERTICES(ctx, _NEW_LIGHT);
- ctx->Light.Enabled = state;
-
if (ctx->Light.Enabled && ctx->Light.Model.TwoSide)
- ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
+ ctx->_TriangleCaps |= DD_TRI_LIGHT_TWOSIDE;
else
- ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
-
+ ctx->_TriangleCaps &= ~DD_TRI_LIGHT_TWOSIDE;
+ FLUSH_VERTICES(ctx, _NEW_LIGHT);
+ ctx->Light.Enabled = state;
break;
case GL_LINE_SMOOTH:
if (ctx->Line.SmoothFlag == state)
@@ -505,41 +518,41 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
ctx->Transform.Normalize = state;
break;
case GL_POINT_SMOOTH:
- if (ctx->Point.SmoothFlag==state)
+ if (ctx->Point.SmoothFlag == state)
return;
FLUSH_VERTICES(ctx, _NEW_POINT);
ctx->Point.SmoothFlag = state;
ctx->_TriangleCaps ^= DD_POINT_SMOOTH;
break;
case GL_POLYGON_SMOOTH:
- if (ctx->Polygon.SmoothFlag==state)
+ if (ctx->Polygon.SmoothFlag == state)
return;
FLUSH_VERTICES(ctx, _NEW_POLYGON);
ctx->Polygon.SmoothFlag = state;
ctx->_TriangleCaps ^= DD_TRI_SMOOTH;
break;
case GL_POLYGON_STIPPLE:
- if (ctx->Polygon.StippleFlag==state)
+ if (ctx->Polygon.StippleFlag == state)
return;
FLUSH_VERTICES(ctx, _NEW_POLYGON);
ctx->Polygon.StippleFlag = state;
ctx->_TriangleCaps ^= DD_TRI_STIPPLE;
break;
case GL_POLYGON_OFFSET_POINT:
- if (ctx->Polygon.OffsetPoint==state)
+ if (ctx->Polygon.OffsetPoint == state)
return;
FLUSH_VERTICES(ctx, _NEW_POLYGON);
ctx->Polygon.OffsetPoint = state;
break;
case GL_POLYGON_OFFSET_LINE:
- if (ctx->Polygon.OffsetLine==state)
+ if (ctx->Polygon.OffsetLine == state)
return;
FLUSH_VERTICES(ctx, _NEW_POLYGON);
ctx->Polygon.OffsetLine = state;
break;
case GL_POLYGON_OFFSET_FILL:
/*case GL_POLYGON_OFFSET_EXT:*/
- if (ctx->Polygon.OffsetFill==state)
+ if (ctx->Polygon.OffsetFill == state)
return;
FLUSH_VERTICES(ctx, _NEW_POLYGON);
ctx->Polygon.OffsetFill = state;
@@ -551,7 +564,7 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
ctx->Transform.RescaleNormals = state;
break;
case GL_SCISSOR_TEST:
- if (ctx->Scissor.Enabled==state)
+ if (ctx->Scissor.Enabled == state)
return;
FLUSH_VERTICES(ctx, _NEW_SCISSOR);
ctx->Scissor.Enabled = state;
@@ -568,50 +581,26 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
"glEnable(GL_STENCIL_TEST) but no stencil buffer");
return;
}
- if (ctx->Stencil.Enabled==state)
+ if (ctx->Stencil.Enabled == state)
return;
FLUSH_VERTICES(ctx, _NEW_STENCIL);
ctx->Stencil.Enabled = state;
break;
- case GL_TEXTURE_1D: {
- const GLuint curr = ctx->Texture.CurrentUnit;
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
- GLuint newenabled = texUnit->Enabled & ~TEXTURE_1D_BIT;
- if (state)
- newenabled |= TEXTURE_1D_BIT;
- if (!ctx->DrawBuffer->Visual.rgbMode
- || texUnit->Enabled == newenabled)
+ case GL_TEXTURE_1D:
+ if (!enable_texture(ctx, state, TEXTURE_1D_BIT)) {
return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->Enabled = newenabled;
+ }
break;
- }
- case GL_TEXTURE_2D: {
- const GLuint curr = ctx->Texture.CurrentUnit;
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
- GLuint newenabled = texUnit->Enabled & ~TEXTURE_2D_BIT;
- if (state)
- newenabled |= TEXTURE_2D_BIT;
- if (!ctx->DrawBuffer->Visual.rgbMode
- || texUnit->Enabled == newenabled)
+ case GL_TEXTURE_2D:
+ if (!enable_texture(ctx, state, TEXTURE_2D_BIT)) {
return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->Enabled = newenabled;
+ }
break;
- }
- case GL_TEXTURE_3D: {
- const GLuint curr = ctx->Texture.CurrentUnit;
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
- GLuint newenabled = texUnit->Enabled & ~TEXTURE_3D_BIT;
- if (state)
- newenabled |= TEXTURE_3D_BIT;
- if (!ctx->DrawBuffer->Visual.rgbMode
- || texUnit->Enabled == newenabled)
+ case GL_TEXTURE_3D:
+ if (!enable_texture(ctx, state, TEXTURE_3D_BIT)) {
return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->Enabled = newenabled;
+ }
break;
- }
case GL_TEXTURE_GEN_Q: {
GLuint unit = ctx->Texture.CurrentUnit;
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
@@ -678,24 +667,24 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
/* GL_SGI_color_table */
case GL_COLOR_TABLE_SGI:
CHECK_EXTENSION(SGI_color_table, cap);
- if (ctx->Pixel.ColorTableEnabled == state)
+ if (ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION] == state)
return;
FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.ColorTableEnabled = state;
+ ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION] = state;
break;
case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
CHECK_EXTENSION(SGI_color_table, cap);
- if (ctx->Pixel.PostConvolutionColorTableEnabled == state)
+ if (ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION] == state)
return;
FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.PostConvolutionColorTableEnabled = state;
+ ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION] = state;
break;
case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
CHECK_EXTENSION(SGI_color_table, cap);
- if (ctx->Pixel.PostColorMatrixColorTableEnabled == state)
+ if (ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX] == state)
return;
FLUSH_VERTICES(ctx, _NEW_PIXEL);
- ctx->Pixel.PostColorMatrixColorTableEnabled = state;
+ ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX] = state;
break;
case GL_TEXTURE_COLOR_TABLE_SGI:
CHECK_EXTENSION(SGI_texture_color_table, cap);
@@ -730,18 +719,9 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
/* GL_ARB_texture_cube_map */
case GL_TEXTURE_CUBE_MAP_ARB:
- {
- const GLuint curr = ctx->Texture.CurrentUnit;
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
- GLuint newenabled = texUnit->Enabled & ~TEXTURE_CUBE_BIT;
- CHECK_EXTENSION(ARB_texture_cube_map, cap);
- if (state)
- newenabled |= TEXTURE_CUBE_BIT;
- if (!ctx->DrawBuffer->Visual.rgbMode
- || texUnit->Enabled == newenabled)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->Enabled = newenabled;
+ CHECK_EXTENSION(ARB_texture_cube_map, cap);
+ if (!enable_texture(ctx, state, TEXTURE_CUBE_BIT)) {
+ return;
}
break;
@@ -894,18 +874,8 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
/* GL_NV_texture_rectangle */
case GL_TEXTURE_RECTANGLE_NV:
CHECK_EXTENSION(NV_texture_rectangle, cap);
- {
- const GLuint curr = ctx->Texture.CurrentUnit;
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[curr];
- GLuint newenabled = texUnit->Enabled & ~TEXTURE_RECT_BIT;
- CHECK_EXTENSION(NV_texture_rectangle, cap);
- if (state)
- newenabled |= TEXTURE_RECT_BIT;
- if (!ctx->DrawBuffer->Visual.rgbMode
- || texUnit->Enabled == newenabled)
- return;
- FLUSH_VERTICES(ctx, _NEW_TEXTURE);
- texUnit->Enabled = newenabled;
+ if (!enable_texture(ctx, state, TEXTURE_RECT_BIT)) {
+ return;
}
break;
@@ -916,11 +886,10 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
return;
FLUSH_VERTICES(ctx, _NEW_STENCIL);
ctx->Stencil.TestTwoSide = state;
- if (state) {
+ if (state)
ctx->_TriangleCaps |= DD_TRI_TWOSTENCIL;
- } else {
+ else
ctx->_TriangleCaps &= ~DD_TRI_TWOSTENCIL;
- }
break;
#if FEATURE_ARB_fragment_program
@@ -973,20 +942,14 @@ void _mesa_set_enable( GLcontext *ctx, GLenum cap, GLboolean state )
}
if (ctx->Driver.Enable) {
- (*ctx->Driver.Enable)( ctx, cap, state );
+ ctx->Driver.Enable( ctx, cap, state );
}
}
/**
- * Enable GL capability.
- *
- * \param cap capability.
- *
- * \sa glEnable().
- *
- * Get's the current context, assures that we're outside glBegin()/glEnd() and
- * calls _mesa_set_enable().
+ * Enable GL capability. Called by glEnable()
+ * \param cap state to enable.
*/
void GLAPIENTRY
_mesa_Enable( GLenum cap )
@@ -999,14 +962,8 @@ _mesa_Enable( GLenum cap )
/**
- * Disable GL capability.
- *
- * \param cap capability.
- *
- * \sa glDisable().
- *
- * Get's the current context, assures that we're outside glBegin()/glEnd() and
- * calls _mesa_set_enable().
+ * Disable GL capability. Called by glDisable()
+ * \param cap state to disable.
*/
void GLAPIENTRY
_mesa_Disable( GLenum cap )
@@ -1032,10 +989,23 @@ _mesa_Disable( GLenum cap )
return GL_FALSE; \
}
+
+/**
+ * Helper function to determine whether a texture target is enabled.
+ */
+static GLboolean
+is_texture_enabled(GLcontext *ctx, GLbitfield bit)
+{
+ const struct gl_texture_unit *const texUnit =
+ &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
+}
+
+
/**
- * Test whether a capability is enabled.
+ * Return simple enable/disable state.
*
- * \param cap capability.
+ * \param cap state variable to query.
*
* Returns the state of the specified capability from the current GL context.
* For the capabilities associated with extensions verifies that those
@@ -1148,23 +1118,11 @@ _mesa_IsEnabled( GLenum cap )
case GL_STENCIL_TEST:
return ctx->Stencil.Enabled;
case GL_TEXTURE_1D:
- {
- const struct gl_texture_unit *texUnit;
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- return (texUnit->Enabled & TEXTURE_1D_BIT) ? GL_TRUE : GL_FALSE;
- }
+ return is_texture_enabled(ctx, TEXTURE_1D_BIT);
case GL_TEXTURE_2D:
- {
- const struct gl_texture_unit *texUnit;
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- return (texUnit->Enabled & TEXTURE_2D_BIT) ? GL_TRUE : GL_FALSE;
- }
+ return is_texture_enabled(ctx, TEXTURE_2D_BIT);
case GL_TEXTURE_3D:
- {
- const struct gl_texture_unit *texUnit;
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- return (texUnit->Enabled & TEXTURE_3D_BIT) ? GL_TRUE : GL_FALSE;
- }
+ return is_texture_enabled(ctx, TEXTURE_3D_BIT);
case GL_TEXTURE_GEN_Q:
{
const struct gl_texture_unit *texUnit;
@@ -1223,13 +1181,13 @@ _mesa_IsEnabled( GLenum cap )
/* GL_SGI_color_table */
case GL_COLOR_TABLE_SGI:
CHECK_EXTENSION(SGI_color_table);
- return ctx->Pixel.ColorTableEnabled;
+ return ctx->Pixel.ColorTableEnabled[COLORTABLE_PRECONVOLUTION];
case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
CHECK_EXTENSION(SGI_color_table);
- return ctx->Pixel.PostConvolutionColorTableEnabled;
+ return ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCONVOLUTION];
case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
CHECK_EXTENSION(SGI_color_table);
- return ctx->Pixel.PostColorMatrixColorTableEnabled;
+ return ctx->Pixel.ColorTableEnabled[COLORTABLE_POSTCOLORMATRIX];
/* GL_SGI_texture_color_table */
case GL_TEXTURE_COLOR_TABLE_SGI:
@@ -1250,11 +1208,7 @@ _mesa_IsEnabled( GLenum cap )
/* GL_ARB_texture_cube_map */
case GL_TEXTURE_CUBE_MAP_ARB:
CHECK_EXTENSION(ARB_texture_cube_map);
- {
- const struct gl_texture_unit *texUnit;
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- return (texUnit->Enabled & TEXTURE_CUBE_BIT) ? GL_TRUE : GL_FALSE;
- }
+ return is_texture_enabled(ctx, TEXTURE_CUBE_BIT);
/* GL_EXT_secondary_color */
case GL_COLOR_SUM_EXT:
@@ -1374,11 +1328,7 @@ _mesa_IsEnabled( GLenum cap )
/* GL_NV_texture_rectangle */
case GL_TEXTURE_RECTANGLE_NV:
CHECK_EXTENSION(NV_texture_rectangle);
- {
- const struct gl_texture_unit *texUnit;
- texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- return (texUnit->Enabled & TEXTURE_RECT_BIT) ? GL_TRUE : GL_FALSE;
- }
+ return is_texture_enabled(ctx, TEXTURE_RECT_BIT);
/* GL_EXT_stencil_two_side */
case GL_STENCIL_TEST_TWO_SIDE_EXT: