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 <brianp@vmware.com>
Signed-off-by: Mathias Fröhlich <Mathias.Froehlich@web.de>
#include "math/m_translate.h"
#include "math/m_translate.h"
+#include "util/bitscan.h"
+
#include "t_context.h"
#include "t_pipeline.h"
#include "tnl.h"
#include "t_context.h"
#include "t_pipeline.h"
#include "tnl.h"
tab = _tnl_light_tab;
}
else {
tab = _tnl_light_tab;
}
else {
- if (ctx->Light.EnabledList.next == ctx->Light.EnabledList.prev)
+ /* Power of two means only a single active light. */
+ if (_mesa_is_pow_two(ctx->Light._EnabledLights))
tab = _tnl_light_fast_single_tab;
else
tab = _tnl_light_fast_tab;
tab = _tnl_light_fast_single_tab;
else
tab = _tnl_light_fast_tab;
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
GLfloat sum[2][3], spec[2][3];
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
GLfloat sum[2][3], spec[2][3];
- struct gl_light *light;
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
#endif
/* Add contribution from each enabled light source */
#endif
/* Add contribution from each enabled light source */
- foreach (light, &ctx->Light.EnabledList) {
+ mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int l = u_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
GLfloat n_dot_h;
GLfloat correction;
GLint side;
GLfloat n_dot_h;
GLfloat correction;
GLint side;
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
GLfloat sum[2][3];
for (j = 0; j < nr; j++,STRIDE_F(vertex,vstride),STRIDE_F(normal,nstride)) {
GLfloat sum[2][3];
- struct gl_light *light;
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
#endif
/* Add contribution from each enabled light source */
#endif
/* Add contribution from each enabled light source */
- foreach (light, &ctx->Light.EnabledList) {
+ mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int l = u_bit_scan(&mask);
+ struct gl_light *light = &ctx->Light.Light[l];
GLfloat n_dot_h;
GLfloat correction;
GLint side;
GLfloat n_dot_h;
GLfloat correction;
GLint side;
#if IDX & LIGHT_TWOSIDE
GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
#endif
#if IDX & LIGHT_TWOSIDE
GLfloat (*Bcolor)[4] = (GLfloat (*)[4]) store->LitColor[1].data;
#endif
- const struct gl_light *light = ctx->Light.EnabledList.next;
+ const struct gl_light *light =
+ &ctx->Light.Light[ffs(ctx->Light._EnabledLights) - 1];
GLuint j = 0;
GLfloat base[2][4];
#if IDX & LIGHT_MATERIAL
GLuint j = 0;
GLfloat base[2][4];
#if IDX & LIGHT_MATERIAL
#else
const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
#endif
#else
const GLuint nr = VB->AttribPtr[_TNL_ATTRIB_NORMAL]->count;
#endif
- const struct gl_light *light;
#ifdef TRACE
fprintf(stderr, "%s %d\n", __func__, nr );
#ifdef TRACE
fprintf(stderr, "%s %d\n", __func__, nr );
for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
GLfloat sum[2][3];
for (j = 0; j < nr; j++, STRIDE_F(normal,nstride)) {
GLfloat sum[2][3];
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
#if IDX & LIGHT_MATERIAL
update_materials( ctx, store );
COPY_3V(sum[1], ctx->Light._BaseColor[1]);
#endif
COPY_3V(sum[1], ctx->Light._BaseColor[1]);
#endif
- foreach (light, &ctx->Light.EnabledList) {
+ mask = ctx->Light._EnabledLights;
+ while (mask) {
+ const int l = u_bit_scan(&mask);
+ const struct gl_light *light = &ctx->Light.Light[l];
GLfloat n_dot_h, n_dot_VP, spec;
ACC_3V(sum[0], light->_MatAmbient[0]);
GLfloat n_dot_h, n_dot_VP, spec;
ACC_3V(sum[0], light->_MatAmbient[0]);