final GL gl = GLContext.getCurrentGL();
// ask for the current state record
final RenderContext context = ContextManager.getCurrentContext();
final ContextCapabilities caps = context.getCapabilities();
final FogStateRecord record = (FogStateRecord) context.getStateRecord(StateType.Fog);
context.setCurrentState(StateType.Fog, state);
if (state.isEnabled()) {
enableFog(true, record);
if (record.isValid()) {
if (record.fogStart != state.getStart()) {
gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_START, state.getStart());
record.fogStart = state.getStart();
}
if (record.fogEnd != state.getEnd()) {
gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_END, state.getEnd());
record.fogEnd = state.getEnd();
}
if (record.density != state.getDensity()) {
gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_DENSITY, state.getDensity());
record.density = state.getDensity();
}
} else {
gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_START, state.getStart());
record.fogStart = state.getStart();
gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_END, state.getEnd());
record.fogEnd = state.getEnd();
gl.getGL2ES1().glFogf(GL2ES1.GL_FOG_DENSITY, state.getDensity());
record.density = state.getDensity();
}
final ReadOnlyColorRGBA fogColor = state.getColor();
applyFogColor(fogColor, record);
applyFogMode(state.getDensityFunction(), record);
applyFogHint(state.getQuality(), record);
applyFogSource(state.getSource(), record, caps);
} else {
enableFog(false, record);
}
if (!record.isValid()) {
record.validate();
}
}