diff options
author | Mathias Fröhlich <[email protected]> | 2016-05-22 14:10:19 +0200 |
---|---|---|
committer | Mathias Fröhlich <[email protected]> | 2016-06-16 05:50:53 +0200 |
commit | 664aec437088dbee299499f0539adc3fc9a2386f (patch) | |
tree | c2735de0e1a5459082551853d1e9757eff4c04c9 | |
parent | ccb1be2fab853c2d82a2159b049d5975d7fc199d (diff) |
mesa: Use bitmask/ffs to iterate enabled lights for ff shader keys.
Replaces a loop that iterates all lights and test
which of them is enabled by a loop only iterating over
the bits set in the enabled bitmask.
v2: Use _mesa_bit_scan{,64} instead of open coding.
v3: Use u_bit_scan{,64} instead of _mesa_bit_scan{,64}.
Reviewed-by: Brian Paul <[email protected]>
Signed-off-by: Mathias Fröhlich <[email protected]>
-rw-r--r-- | src/mesa/main/ffvertex_prog.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/src/mesa/main/ffvertex_prog.c b/src/mesa/main/ffvertex_prog.c index ecdd0184c86..ca725545f01 100644 --- a/src/mesa/main/ffvertex_prog.c +++ b/src/mesa/main/ffvertex_prog.c @@ -44,6 +44,7 @@ #include "program/prog_parameter.h" #include "program/prog_print.h" #include "program/prog_statevars.h" +#include "util/bitscan.h" /** Max of number of lights and texture coord units */ @@ -148,6 +149,7 @@ static GLboolean check_active_shininess( struct gl_context *ctx, static void make_state_key( struct gl_context *ctx, struct state_key *key ) { const struct gl_fragment_program *fp; + GLbitfield mask; GLuint i; memset(key, 0, sizeof(struct state_key)); @@ -183,23 +185,23 @@ static void make_state_key( struct gl_context *ctx, struct state_key *key ) key->light_color_material_mask = ctx->Light._ColorMaterialBitmask; } - for (i = 0; i < MAX_LIGHTS; i++) { - struct gl_light *light = &ctx->Light.Light[i]; + mask = ctx->Light._EnabledLights; + while (mask) { + const int i = u_bit_scan(&mask); + struct gl_light *light = &ctx->Light.Light[i]; - if (light->Enabled) { - key->unit[i].light_enabled = 1; + key->unit[i].light_enabled = 1; - if (light->EyePosition[3] == 0.0F) - key->unit[i].light_eyepos3_is_zero = 1; + if (light->EyePosition[3] == 0.0F) + key->unit[i].light_eyepos3_is_zero = 1; - if (light->SpotCutoff == 180.0F) - key->unit[i].light_spotcutoff_is_180 = 1; + if (light->SpotCutoff == 180.0F) + key->unit[i].light_spotcutoff_is_180 = 1; - if (light->ConstantAttenuation != 1.0F || - light->LinearAttenuation != 0.0F || - light->QuadraticAttenuation != 0.0F) - key->unit[i].light_attenuated = 1; - } + if (light->ConstantAttenuation != 1.0F || + light->LinearAttenuation != 0.0F || + light->QuadraticAttenuation != 0.0F) + key->unit[i].light_attenuated = 1; } if (check_active_shininess(ctx, key, 0)) { |