From de1ffd2f62257c174325d877c327d56b1a9e6cbc Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Wed, 8 Sep 2010 10:46:10 -0700 Subject: [PATCH] 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. --- src/mesa/main/texenv.c | 90 +++++++++++------------------------------- 1 file 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); /* -- 2.30.2