public abstract class JoglLightStateUtil {
public static void apply(final JoglRenderer renderer, final LightState state) {
final RenderContext context = ContextManager.getCurrentContext();
final ContextCapabilities caps = context.getCapabilities();
final LightStateRecord record = (LightStateRecord) context.getStateRecord(StateType.Light);
context.setCurrentState(StateType.Light, state);
if (state.isEnabled() && LightState.LIGHTS_ENABLED) {
setLightEnabled(true, record);
setTwoSided(state.getTwoSidedLighting(), record);
setLocalViewer(state.getLocalViewer(), record);
if (caps.isOpenGL1_2Supported()) {
setSpecularControl(state.getSeparateSpecular(), record);
}
for (int i = 0, max = state.getNumberOfChildren(); i < max; i++) {
final Light light = state.get(i);
LightRecord lr = record.getLightRecord(i);
// TODO: use the reference to get the lightrecord - rherlitz
if (lr == null) {
lr = new LightRecord();
record.setLightRecord(lr, i);
}
if (light == null) {
setSingleLightEnabled(false, i, record, lr);
} else {
if (light.isEnabled()) {
setLight(i, light, record, state, lr);
} else {
setSingleLightEnabled(false, i, record, lr);
}
}
}
// disable lights at and above the max count in this state
for (int i = state.getNumberOfChildren(); i < LightState.MAX_LIGHTS_ALLOWED; i++) {
LightRecord lr = record.getLightRecord(i);
if (lr == null) {
lr = new LightRecord();
record.setLightRecord(lr, i);
}
setSingleLightEnabled(false, i, record, lr);
}
if ((state.getLightMask() & LightState.MASK_GLOBALAMBIENT) == 0) {
setModelAmbient(record, state.getGlobalAmbient());
} else {
setModelAmbient(record, ColorRGBA.BLACK_NO_ALPHA);
}
} else {
setLightEnabled(false, record);
}
if (!record.isValid()) {
record.validate();
}
}