From 07c93cbdb0e8ebda1839b67837ae80c710695cdc Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Tue, 16 May 2023 14:29:54 -0700 Subject: [PATCH] mesa/ARB_fp: Drop an extra enum for fog mode. Reviewed-by: Alyssa Rosenzweig Reviewed-by: Erik Faye-Lund Part-of: --- src/mesa/program/arbprogparse.c | 8 ++------ src/mesa/program/program_parse_extra.c | 8 ++++---- src/mesa/program/program_parser.h | 6 +----- src/mesa/program/programopt.c | 14 +++++++------- src/mesa/program/programopt.h | 2 +- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/src/mesa/program/arbprogparse.c b/src/mesa/program/arbprogparse.c index 80cf0a4100b..ba87abb33e3 100644 --- a/src/mesa/program/arbprogparse.c +++ b/src/mesa/program/arbprogparse.c @@ -133,15 +133,11 @@ _mesa_parse_arb_fragment_program(struct gl_context* ctx, GLenum target, * there's no hardware that wants to do fog in a discrete stage separate * from the fragment shader. */ - if (state.option.Fog != OPTION_NONE) { - static const GLenum fog_modes[4] = { - GL_NONE, GL_EXP, GL_EXP2, GL_LINEAR - }; - + if (state.option.Fog != FOG_NONE) { /* XXX: we should somehow recompile this to remove clamping if disabled * On the ATI driver, this is unclampled if fragment clamping is disabled */ - _mesa_append_fog_code(ctx, program, fog_modes[state.option.Fog], GL_TRUE); + _mesa_append_fog_code(ctx, program, state.option.Fog, GL_TRUE); } #if DEBUG_FP diff --git a/src/mesa/program/program_parse_extra.c b/src/mesa/program/program_parse_extra.c index c82c9c1b751..d3464f227d9 100644 --- a/src/mesa/program/program_parse_extra.c +++ b/src/mesa/program/program_parse_extra.c @@ -87,17 +87,17 @@ _mesa_ARBfp_parse_option(struct asm_parser_state *state, const char *option) option += 4; if (strcmp(option, "exp") == 0) { - fog_option = OPTION_FOG_EXP; + fog_option = FOG_EXP; } else if (strcmp(option, "exp2") == 0) { - fog_option = OPTION_FOG_EXP2; + fog_option = FOG_EXP2; } else if (strcmp(option, "linear") == 0) { - fog_option = OPTION_FOG_LINEAR; + fog_option = FOG_LINEAR; } else { /* invalid option */ return 0; } - if (state->option.Fog == OPTION_NONE) { + if (state->option.Fog == FOG_NONE) { state->option.Fog = fog_option; return 1; } diff --git a/src/mesa/program/program_parser.h b/src/mesa/program/program_parser.h index 08229038986..cb3dd33bdc4 100644 --- a/src/mesa/program/program_parser.h +++ b/src/mesa/program/program_parser.h @@ -208,7 +208,7 @@ struct asm_parser_state { struct { unsigned PositionInvariant:1; - unsigned Fog:2; + unsigned Fog:2; /* gl_fog_mode */ unsigned PrecisionHint:2; unsigned DrawBuffers:1; unsigned Shadow:1; @@ -223,10 +223,6 @@ struct asm_parser_state { } fragment; }; -#define OPTION_NONE 0 -#define OPTION_FOG_EXP 1 -#define OPTION_FOG_EXP2 2 -#define OPTION_FOG_LINEAR 3 #define OPTION_NICEST 1 #define OPTION_FASTEST 2 diff --git a/src/mesa/program/programopt.c b/src/mesa/program/programopt.c index 5eb5eda54d4..59304148acd 100644 --- a/src/mesa/program/programopt.c +++ b/src/mesa/program/programopt.c @@ -234,7 +234,7 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_program *vprog) * * \param ctx The GL context * \param fprog Fragment program that fog instructions will be appended to. - * \param fog_mode Fog mode. One of \c GL_EXP, \c GL_EXP2, or \c GL_LINEAR. + * \param fog_mode Fog mode. One of \c FOG_EXP, \c FOG_EXP2, or \c FOG_LINEAR. * \param saturate True if writes to color outputs should be clamped to [0, 1] * * \note @@ -245,7 +245,7 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_program *vprog) */ void _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog, - GLenum fog_mode, GLboolean saturate) + enum gl_fog_mode fog_mode, GLboolean saturate) { static const gl_state_index16 fogPStateOpt[STATE_LENGTH] = { STATE_FOG_PARAMS_OPTIMIZED, 0, 0 }; @@ -258,7 +258,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog, GLint fogPRefOpt, fogColorRef; /* state references */ GLuint colorTemp, fogFactorTemp; /* temporary registerss */ - if (fog_mode == GL_NONE) { + if (fog_mode == FOG_NONE) { _mesa_problem(ctx, "_mesa_append_fog_code() called for fragment program" " with fog_mode == GL_NONE"); return; @@ -313,7 +313,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog, /* emit instructions to compute fog blending factor */ /* this is always clamped to [0, 1] regardless of fragment clamping */ - if (fog_mode == GL_LINEAR) { + if (fog_mode == FOG_LINEAR) { /* MAD fogFactorTemp.x, fragment.fogcoord.x, fogPRefOpt.x, fogPRefOpt.y; */ inst->Opcode = OPCODE_MAD; inst->DstReg.File = PROGRAM_TEMPORARY; @@ -332,7 +332,7 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog, inst++; } else { - assert(fog_mode == GL_EXP || fog_mode == GL_EXP2); + assert(fog_mode == FOG_EXP || fog_mode == FOG_EXP2); /* fogPRefOpt.z = d/ln(2), fogPRefOpt.w = d/sqrt(ln(2) */ /* EXP: MUL fogFactorTemp.x, fogPRefOpt.z, fragment.fogcoord.x; */ /* EXP2: MUL fogFactorTemp.x, fogPRefOpt.w, fragment.fogcoord.x; */ @@ -343,12 +343,12 @@ _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog, inst->SrcReg[0].File = PROGRAM_STATE_VAR; inst->SrcReg[0].Index = fogPRefOpt; inst->SrcReg[0].Swizzle - = (fog_mode == GL_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW; + = (fog_mode == FOG_EXP) ? SWIZZLE_ZZZZ : SWIZZLE_WWWW; inst->SrcReg[1].File = PROGRAM_INPUT; inst->SrcReg[1].Index = VARYING_SLOT_FOGC; inst->SrcReg[1].Swizzle = SWIZZLE_XXXX; inst++; - if (fog_mode == GL_EXP2) { + if (fog_mode == FOG_EXP2) { /* MUL fogFactorTemp.x, fogFactorTemp.x, fogFactorTemp.x; */ inst->Opcode = OPCODE_MUL; inst->DstReg.File = PROGRAM_TEMPORARY; diff --git a/src/mesa/program/programopt.h b/src/mesa/program/programopt.h index 026e8a7a12e..bf4e42ca366 100644 --- a/src/mesa/program/programopt.h +++ b/src/mesa/program/programopt.h @@ -42,7 +42,7 @@ _mesa_insert_mvp_code(struct gl_context *ctx, struct gl_program *vprog); extern void _mesa_append_fog_code(struct gl_context *ctx, struct gl_program *fprog, - GLenum fog_mode, GLboolean saturate); + enum gl_fog_mode fog_mode, GLboolean saturate); #ifdef __cplusplus }