From ccb1be2fab853c2d82a2159b049d5975d7fc199d Mon Sep 17 00:00:00 2001 From: Mathias Fröhlich Date: Sun, 22 May 2016 14:10:19 +0200 Subject: mesa: Use bitmask/ffs to iterate enabled lights MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces loops that iterate 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 Signed-off-by: Mathias Fröhlich --- src/mesa/main/rastpos.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/mesa/main/rastpos.c') diff --git a/src/mesa/main/rastpos.c b/src/mesa/main/rastpos.c index b468219e688..8f971f5b8d4 100644 --- a/src/mesa/main/rastpos.c +++ b/src/mesa/main/rastpos.c @@ -37,7 +37,7 @@ #include "state.h" #include "main/dispatch.h" #include "main/viewport.h" -#include "util/simple_list.h" +#include "util/bitscan.h" @@ -125,7 +125,7 @@ shade_rastpos(struct gl_context *ctx, GLfloat Rspec[4]) { /*const*/ GLfloat (*base)[3] = ctx->Light._BaseColor; - const struct gl_light *light; + GLbitfield mask; GLfloat diffuseColor[4], specularColor[4]; /* for RGB mode only */ COPY_3V(diffuseColor, base[0]); @@ -133,7 +133,10 @@ shade_rastpos(struct gl_context *ctx, ctx->Light.Material.Attrib[MAT_ATTRIB_FRONT_DIFFUSE][3], 0.0F, 1.0F ); ASSIGN_4V(specularColor, 0.0, 0.0, 0.0, 1.0); - foreach (light, &ctx->Light.EnabledList) { + mask = ctx->Light._EnabledLights; + while (mask) { + const int i = u_bit_scan(&mask); + struct gl_light *light = &ctx->Light.Light[i]; GLfloat attenuation = 1.0; GLfloat VP[3]; /* vector from vertex to light pos */ GLfloat n_dot_VP; -- cgit v1.2.3