// Currently, Maya leaves lights in GL when you reduce the number of active lights in // your scene. It fills the GL light space from 0 with the visible lights, so, we simply // need to reset the potentially 'old' state of lights after the last one we know to be // visible. We'll put it all back as we found it though. For the moment, this assumes // Maya is filling GL consecutively, if they stop doing that, we'll need to get the // actual light indexes from the view. Its just a bit quicker to assume this, whilst we can. bool ProceduralHolderUI::cleanupLights( const MDrawRequest &request, M3dView &view, LightingState *s ) const { if( !(request.displayStyle()==M3dView::kFlatShaded || request.displayStyle()==M3dView::kGouraudShaded) ) { return false; } M3dView::LightingMode mode; view.getLightingMode(mode); if (mode == M3dView::kLightDefault) { s->numMayaLights = 1; } else { view.getLightCount( s->numMayaLights ); } int sGlMaxLights = 0; glGetIntegerv( GL_MAX_LIGHTS, &sGlMaxLights ); s->numGlLights = sGlMaxLights; if( s->numMayaLights >= s->numGlLights || s->numGlLights == 0 ) { return false; } unsigned int vectorSize = s->numGlLights - s->numMayaLights; s->diffuses.resize( vectorSize ); s->specs.resize( vectorSize ); s->ambients.resize( vectorSize ); static float s_defaultColor[] = { 0.0, 0.0, 0.0, 1.0 }; GLenum light; unsigned int j = 0; for( unsigned int i = s->numMayaLights; i < s->numGlLights; i++ ) { light = GL_LIGHT0 + i; glGetLightfv( light, GL_DIFFUSE, s->diffuses[j].getValue() ); glLightfv( light, GL_DIFFUSE, s_defaultColor ); glGetLightfv( light, GL_SPECULAR, s->specs[j].getValue() ); glLightfv( light, GL_SPECULAR, s_defaultColor ); glGetLightfv( light, GL_AMBIENT, s->ambients[j].getValue() ); glLightfv( light, GL_AMBIENT, s_defaultColor ); j++; } return true; }