diff options
author | Ian Romanick <[email protected]> | 2010-09-08 10:46:10 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2010-09-08 16:26:15 -0700 |
commit | de1ffd2f62257c174325d877c327d56b1a9e6cbc (patch) | |
tree | 813293304ce12562bca3f39b1d4ebf6f5af70ecb /src/mesa | |
parent | 1a2d498b4164f457c48e9fde9ae8bbadfcf7fa72 (diff) |
mesa: Refactor parameter processing in set_combiner_(operand|source)
The enum values were chosen to have sequential values for a reason.
Use that to compact and simplify the code.
Diffstat (limited to 'src/mesa')
-rw-r--r-- | src/mesa/main/texenv.c | 90 |
1 files changed, 22 insertions, 68 deletions
diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c index 9b9c4b1ccd5..3a55128c736 100644 --- a/src/mesa/main/texenv.c +++ b/src/mesa/main/texenv.c @@ -196,57 +196,34 @@ set_combiner_source(GLcontext *ctx, /* * Translate pname to (term, alpha). + * + * The enums were given sequential values for a reason. */ switch (pname) { case GL_SOURCE0_RGB: - term = 0; - alpha = GL_FALSE; - break; case GL_SOURCE1_RGB: - term = 1; - alpha = GL_FALSE; - break; case GL_SOURCE2_RGB: - term = 2; - alpha = GL_FALSE; - break; case GL_SOURCE3_RGB_NV: - if (ctx->Extensions.NV_texture_env_combine4) { - term = 3; - alpha = GL_FALSE; - } - else { - TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); - return; - } + term = pname - GL_SOURCE0_RGB; + alpha = GL_FALSE; break; case GL_SOURCE0_ALPHA: - term = 0; - alpha = GL_TRUE; - break; case GL_SOURCE1_ALPHA: - term = 1; - alpha = GL_TRUE; - break; case GL_SOURCE2_ALPHA: - term = 2; - alpha = GL_TRUE; - break; case GL_SOURCE3_ALPHA_NV: - if (ctx->Extensions.NV_texture_env_combine4) { - term = 3; - alpha = GL_TRUE; - } - else { - TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); - return; - } + term = pname - GL_SOURCE0_ALPHA; + alpha = GL_TRUE; break; default: TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); return; } + if ((term == 3) && !ctx->Extensions.NV_texture_env_combine4) { + TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); + return; + } + assert(term < MAX_COMBINER_TERMS); /* @@ -310,56 +287,33 @@ set_combiner_operand(GLcontext *ctx, return; } + /* The enums were given sequential values for a reason. + */ switch (pname) { case GL_OPERAND0_RGB: - term = 0; - alpha = GL_FALSE; - break; case GL_OPERAND1_RGB: - term = 1; - alpha = GL_FALSE; - break; case GL_OPERAND2_RGB: - term = 2; - alpha = GL_FALSE; - break; case GL_OPERAND3_RGB_NV: - if (ctx->Extensions.NV_texture_env_combine4) { - term = 3; - alpha = GL_FALSE; - } - else { - TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); - return; - } + term = pname - GL_OPERAND0_RGB; + alpha = GL_FALSE; break; case GL_OPERAND0_ALPHA: - term = 0; - alpha = GL_TRUE; - break; case GL_OPERAND1_ALPHA: - term = 1; - alpha = GL_TRUE; - break; case GL_OPERAND2_ALPHA: - term = 2; - alpha = GL_TRUE; - break; case GL_OPERAND3_ALPHA_NV: - if (ctx->Extensions.NV_texture_env_combine4) { - term = 3; - alpha = GL_TRUE; - } - else { - TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); - return; - } + term = pname - GL_OPERAND0_ALPHA; + alpha = GL_TRUE; break; default: TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); return; } + if ((term == 3) && !ctx->Extensions.NV_texture_env_combine4) { + TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname); + return; + } + assert(term < MAX_COMBINER_TERMS); /* |