mirror of
https://github.com/OpenMW/openmw.git
synced 2025-01-21 07:53:53 +00:00
Manually apply the osg::Light state
Reduce the amount of virtual function calls. Don't use the osg::Light's lightNum. Don't set spotlight state that we're not using (yet).
This commit is contained in:
parent
58e0e8bd4e
commit
174dd82894
1 changed files with 17 additions and 4 deletions
|
@ -51,14 +51,27 @@ namespace SceneUtil
|
|||
state.applyModelViewMatrix(state.getInitialViewMatrix());
|
||||
|
||||
for (unsigned int i=0; i<mLights.size(); ++i)
|
||||
{
|
||||
mLights[i]->setLightNum(i+mIndex);
|
||||
mLights[i]->apply(state);
|
||||
}
|
||||
applyLight((GLenum)((int)GL_LIGHT0 + i + mIndex), mLights[i].get());
|
||||
|
||||
state.applyModelViewMatrix(modelViewMatrix);
|
||||
}
|
||||
|
||||
void applyLight(GLenum lightNum, const osg::Light* light) const
|
||||
{
|
||||
glLightfv( lightNum, GL_AMBIENT, light->getAmbient().ptr() );
|
||||
glLightfv( lightNum, GL_DIFFUSE, light->getDiffuse().ptr() );
|
||||
glLightfv( lightNum, GL_SPECULAR, light->getSpecular().ptr() );
|
||||
glLightfv( lightNum, GL_POSITION, light->getPosition().ptr() );
|
||||
// TODO: enable this once spot lights are supported
|
||||
// need to transform SPOT_DIRECTION by the world matrix?
|
||||
//glLightfv( lightNum, GL_SPOT_DIRECTION, light->getDirection().ptr() );
|
||||
//glLightf ( lightNum, GL_SPOT_EXPONENT, light->getSpotExponent() );
|
||||
//glLightf ( lightNum, GL_SPOT_CUTOFF, light->getSpotCutoff() );
|
||||
glLightf ( lightNum, GL_CONSTANT_ATTENUATION, light->getConstantAttenuation() );
|
||||
glLightf ( lightNum, GL_LINEAR_ATTENUATION, light->getLinearAttenuation() );
|
||||
glLightf ( lightNum, GL_QUADRATIC_ATTENUATION, light->getQuadraticAttenuation() );
|
||||
}
|
||||
|
||||
private:
|
||||
unsigned int mIndex;
|
||||
|
||||
|
|
Loading…
Reference in a new issue