Skip to content
Snippets Groups Projects
Commit 418b7eec authored by Jaswant Panchumarti (Kitware)'s avatar Jaswant Panchumarti (Kitware)
Browse files

Add timer observer only in interactive mode

- otherwise the shader could produce a different image from the baseline
  in case the timer fired before vtkWindowToImageFilter captured a screenshot
- make the test produce a deterministic image instead of using random
  noise function
parent b19d49f7
No related branches found
No related tags found
No related merge requests found
......@@ -71,22 +71,20 @@ int TestUserShader2D(int argc, char* argv[])
coord->SetReferenceCoordinate(pCoord);
mapper->SetTransformCoordinate(coord);
// render white noise (like a TV that displays noise signal)
// render an animation that zooms out of a grid (only visible in interactive mode)
vtkShaderProperty* sp = actor->GetShaderProperty();
sp->AddFragmentShaderReplacement(
"//VTK::CustomUniforms::Dec", // replace the custom uniforms block
true, // before the standard replacements
R"(
uniform float time;
float generateRandom (vec2 st) { return fract(sin(dot(st.xy, vec2(12.9898,78.233) + sin(time))) * 43758.5453123); }
)",
false // only do it once
);
sp->AddFragmentShaderReplacement("//VTK::Color::Impl", // replace the color block
true, // before the standard replacements
R"(
float noise = mix(-1.0f, 1.0f, generateRandom(tcoordVCVSOutput));
gl_FragData[0] = vec4(noise, noise, noise, 1.0);
gl_FragData[0] = vec4(sin(tcoordVCVSOutput.xy * time * 0.01), 0.0, 1.0);
)", // but we add this
false // only do it once
);
......@@ -103,21 +101,26 @@ gl_FragData[0] = vec4(noise, noise, noise, 1.0);
return EXIT_FAILURE;
}
TestUserShader2D_TimerData timerData;
timerData.shaderProperty = sp;
timerData.time = 0;
timerData.id = iren->CreateRepeatingTimer(10);
vtkNew<vtkCallbackCommand> timerCmd;
timerCmd->SetClientData(&timerData);
timerCmd->SetCallback(::TestUserShader2D_OnTimerCallback);
iren->AddObserver(vtkCommand::TimerEvent, timerCmd);
sp->GetFragmentCustomUniforms()->SetUniformf("time", 150);
renderWindow->Render();
int retVal = vtkRegressionTestImage(renderWindow);
if (retVal == vtkRegressionTester::DO_INTERACTOR)
{
auto* timerData = new TestUserShader2D_TimerData();
timerData->shaderProperty = sp;
timerData->time = 0;
timerData->id = iren->CreateRepeatingTimer(10);
vtkNew<vtkCallbackCommand> timerCmd;
timerCmd->SetClientData(timerData);
timerCmd->SetCallback(::TestUserShader2D_OnTimerCallback);
timerCmd->SetClientDataDeleteCallback([](void* dPtr) {
auto tdPtr = static_cast<TestUserShader2D_TimerData*>(dPtr);
delete tdPtr;
});
iren->AddObserver(vtkCommand::TimerEvent, timerCmd);
iren->Start();
}
......
73375daf4d559467d69e10f116f45014c82aae34d6c571fda5d86c75f4c3d59fc4a31d35eee09cbdf24853606d2f196811c605ff1c8bd05d24c749584d73df30
44d9c7f5bdec8f987bbdf23d98b3733ecbbc222a4d61d94f8a5c140e318c11b4bd3d12a277eb7f47e7243605b756c565868382c3239929abfcb26311a6d19441
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment