------------------------------------------------------------------------------
| 76 | |
| 77 | //------------------------------------------------------------------------------ |
| 78 | void vtkExternalOpenGLRenderer::SynchronizeGLLights() |
| 79 | { |
| 80 | // Lights |
| 81 | // Query lights existing in the external context |
| 82 | // and tweak them based on vtkExternalLight objects added by the user |
| 83 | GLenum curLight; |
| 84 | for (curLight = GL_LIGHT0; curLight < GL_LIGHT0 + MAX_LIGHTS; curLight++) |
| 85 | { |
| 86 | GLboolean status; |
| 87 | glGetBooleanv(curLight, &status); |
| 88 | |
| 89 | int l_ind = static_cast<int>(curLight - GL_LIGHT0); |
| 90 | bool light_created = false; |
| 91 | vtkLight* light = vtkLight::SafeDownCast(this->GetLights()->GetItemAsObject(l_ind)); |
| 92 | if (light) |
| 93 | { |
| 94 | if (!status) |
| 95 | { |
| 96 | // This is the case when we have a VTK light in the scene but no |
| 97 | // external light corresponding to that index in the context. |
| 98 | // In this case, we remove the VTK light as well. |
| 99 | light->SwitchOff(); |
| 100 | this->RemoveLight(light); |
| 101 | |
| 102 | // No need to go forward |
| 103 | continue; |
| 104 | } |
| 105 | } |
| 106 | else |
| 107 | { |
| 108 | // No matching light found in the VTK light collection |
| 109 | if (status) |
| 110 | { |
| 111 | // Create a new light only if one is present in the external context |
| 112 | light = vtkLight::New(); |
| 113 | // Headlight because VTK will apply transform matrices |
| 114 | light->SetLightTypeToHeadlight(); |
| 115 | light_created = true; |
| 116 | } |
| 117 | else |
| 118 | { |
| 119 | // No need to go forward as this light is not being used |
| 120 | continue; |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | // Find out if there is an external light object associated with this |
| 125 | // light index. |
| 126 | vtkCollectionSimpleIterator sit; |
| 127 | vtkExternalLight* eLight; |
| 128 | vtkExternalLight* curExtLight = nullptr; |
| 129 | for (this->ExternalLights->InitTraversal(sit); |
| 130 | (eLight = vtkExternalLight::SafeDownCast(this->ExternalLights->GetNextLight(sit)));) |
| 131 | { |
| 132 | if (eLight && (static_cast<GLenum>(eLight->GetLightIndex()) == curLight)) |
| 133 | { |
| 134 | curExtLight = eLight; |
| 135 | break; |
no test coverage detected