#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 */
static void make_state_key( struct gl_context *ctx, struct state_key *key )
{
const struct gl_fragment_program *fp;
- GLuint i;
+ GLbitfield mask;
memset(key, 0, sizeof(struct state_key));
fp = ctx->FragmentProgram._Current;
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)) {
ctx->Texture._MaxEnabledTexImageUnit != -1)
key->texture_enabled_global = 1;
- for (i = 0; i < MAX_TEXTURE_COORD_UNITS; i++) {
+ mask = ctx->Texture._EnabledCoordUnits | ctx->Texture._TexGenEnabled
+ | ctx->Texture._TexMatEnabled | ctx->Point.CoordReplace;
+ while (mask) {
+ const int i = u_bit_scan(&mask);
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
if (texUnit->_Current)
key->unit[i].texunit_really_enabled = 1;
if (ctx->Point.PointSprite)
- if (ctx->Point.CoordReplace[i])
+ if (ctx->Point.CoordReplace & (1u << i))
key->unit[i].coord_replace = 1;
if (ctx->Texture._TexMatEnabled & ENABLE_TEXMAT(i))