summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIan Romanick <[email protected]>2007-05-09 21:45:27 -0700
committerIan Romanick <[email protected]>2007-05-10 08:20:41 -0700
commit58dacc8df1f05cf1d9983a3f45b574b0f20f54c6 (patch)
treeba989d81872539442fa9bac05feba2bdd7306b00
parentb47018937896c67aabab69a30c485a2620abcf19 (diff)
Refactor Enable / Disable and IsEnabled bits related to texture targets.
-rw-r--r--src/mesa/main/enable.c132
1 files changed, 50 insertions, 82 deletions
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index 11b4ad6400e..a1067317697 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -190,6 +190,25 @@ _mesa_DisableClientState( GLenum cap )
}
+/**
+ * Helper function to enable or disable a texture target.
+ */
+static GLboolean
+enable_texture(GLcontext *ctx, GLboolean state, GLuint 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;
+}
+
/**
* Helper function to enable or disable state.
@@ -558,45 +577,21 @@ _mesa_set_enable(GLcontext *ctx, GLenum cap, GLboolean state)
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];
@@ -715,18 +710,9 @@ _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;
@@ -879,18 +865,8 @@ _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;
@@ -1002,6 +978,18 @@ _mesa_Disable( GLenum cap )
/**
+ * Helper function to determine whether a texture target is enabled.
+ */
+static GLboolean
+is_texture_enabled(GLcontext *ctx, GLuint bit)
+{
+ const struct gl_texture_unit *const texUnit =
+ &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
+}
+
+
+/**
* Return simple enable/disable state.
*
* \param cap state variable to query.
@@ -1117,23 +1105,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_2D_BIT);
case GL_TEXTURE_GEN_Q:
{
const struct gl_texture_unit *texUnit;
@@ -1219,11 +1195,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:
@@ -1343,11 +1315,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: