------------------------------------------------------------------------------
| 282 | |
| 283 | //------------------------------------------------------------------------------ |
| 284 | void vtkOpenGLPolyDataMapper::BuildShaders( |
| 285 | std::map<vtkShader::Type, vtkShader*> shaders, vtkRenderer* ren, vtkActor* actor) |
| 286 | { |
| 287 | this->GetShaderTemplate(shaders, ren, actor); |
| 288 | |
| 289 | // user specified pre replacements |
| 290 | vtkOpenGLShaderProperty* sp = vtkOpenGLShaderProperty::SafeDownCast(actor->GetShaderProperty()); |
| 291 | vtkOpenGLShaderProperty::ReplacementMap repMap = sp->GetAllShaderReplacements(); |
| 292 | for (const auto& i : repMap) |
| 293 | { |
| 294 | if (i.first.ReplaceFirst) |
| 295 | { |
| 296 | std::string ssrc = shaders[i.first.ShaderType]->GetSource(); |
| 297 | vtkShaderProgram::Substitute( |
| 298 | ssrc, i.first.OriginalValue, i.second.Replacement, i.second.ReplaceAll); |
| 299 | shaders[i.first.ShaderType]->SetSource(ssrc); |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | this->ReplaceShaderValues(shaders, ren, actor); |
| 304 | |
| 305 | // user specified post replacements |
| 306 | for (const auto& i : repMap) |
| 307 | { |
| 308 | if (!i.first.ReplaceFirst) |
| 309 | { |
| 310 | std::string ssrc = shaders[i.first.ShaderType]->GetSource(); |
| 311 | vtkShaderProgram::Substitute( |
| 312 | ssrc, i.first.OriginalValue, i.second.Replacement, i.second.ReplaceAll); |
| 313 | shaders[i.first.ShaderType]->SetSource(ssrc); |
| 314 | } |
| 315 | } |
| 316 | |
| 317 | // Fix gl_PrimitiveID in fragment shader after all shader replacements. |
| 318 | // When oglRenderWindow->IsPrimIDBugPresent() returns true, the geometry shader |
| 319 | // ignores values written into gl_PrimitiveID and increments it per output primitive. |
| 320 | // So, here, undo the two increments per line segment with a divide-by-2. |
| 321 | std::string FSSource = shaders[vtkShader::Fragment]->GetSource(); |
| 322 | if (this->HaveWideLines(ren, actor)) |
| 323 | { |
| 324 | if (auto oglRenderWindow = vtkOpenGLRenderWindow::SafeDownCast(ren->GetRenderWindow())) |
| 325 | { |
| 326 | if (oglRenderWindow->IsPrimIDBugPresent()) |
| 327 | { |
| 328 | vtkShaderProgram::Substitute(FSSource, "gl_PrimitiveID", "gl_PrimitiveID / 2"); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | shaders[vtkShader::Fragment]->SetSource(FSSource); |
| 334 | } |
| 335 | |
| 336 | //------------------------------------------------------------------------------ |
| 337 | bool vtkOpenGLPolyDataMapper::HaveWideLines(vtkRenderer* ren, vtkActor* actor) |
no test coverage detected