There’s no built in variable for determining whether a given light source is enabled or not?
like a gl_LightSource[i].Enabled would be nice.

glEnable(GL_LIGHTX) must set a state.
it sucks having to load a bool[8] array from the app to determine if a light is enabled or not.


Why use gl_LightSource at all? I really dislike the glLight interface, urgh.

Why not just keep them enabled in sequence that way you only need to know the number of lights. After all, you probably are already managing your texturing units in such a way.


I use a function like this:

bool is_light_enabled(in int index)
return ! any(notEqual(vec3(gl_LightSource[index].diffuse), vec3(0.0,0.0,0.0)));

NOTE: You may also want to test the ambient and specular terms, depending upon your environment.

It isn’t perfect, but it is better than passing in an array with a hard-coded size.

Sunray, a follow up as to what you use and your idea of a solution would have been nice.

Moe, thanks for the suggestion…I think I’ll use that.


First of all, I don’t use multiple lights in my shaders. But I guess something like this would work.

// glsl
struct Light
	bool On;
	vec3 Position;
	vec3 Color;
	... whatever you want ...

uniform Light MyLights[NumLights];

// C++
Light[0].On_UniformID = glGetUniformLocationARB(ProgramID, "MyLights[0].On");
Light[0].Position_UniformID = glGetUniformLocationARB(ProgramID, "MyLights[0].Position");

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.