Skip to content
Snippets Groups Projects
Commit 5559c11b authored by Cory Quammen's avatar Cory Quammen
Browse files

Fix picking with 2D actors

No picking support was provided in vtkOpenGLPolyDataMapper2D.  This
change adds such support. The test added in the previous commit will
now pass when either the OpenGL 1 or OpenGL 2 backend is enabled.
parent 5f15afd6
No related branches found
No related tags found
No related merge requests found
......@@ -26,6 +26,9 @@ uniform int PrimitiveIDOffset;
// Depth Peeling
//VTK::DepthPeeling::Dec
// picking support
//VTK::Picking::Dec
// the output of this shader
//VTK::Output::Dec
......@@ -40,4 +43,5 @@ void main()
//VTK::Color::Impl
//VTK::TCoord::Impl
//VTK::DepthPeeling::Impl
//VTK::Picking::Impl
}
......@@ -18,6 +18,7 @@
#include "vtkActor2D.h"
#include "vtkCellArray.h"
#include "vtkHardwareSelector.h"
#include "vtkInformation.h"
#include "vtkMath.h"
#include "vtkMatrix4x4.h"
......@@ -62,6 +63,7 @@ vtkOpenGLPolyDataMapper2D::vtkOpenGLPolyDataMapper2D()
this->LastBoundBO = 0;
this->HaveCellScalars = false;
this->PrimitiveIDOffset = 0;
this->LastPickState = 0;
}
//-----------------------------------------------------------------------------
......@@ -128,7 +130,8 @@ bool vtkOpenGLPolyDataMapper2D::GetNeedToRebuildShaders(
if (cellBO.Program == 0 ||
cellBO.ShaderSourceTime < this->GetMTime() ||
cellBO.ShaderSourceTime < actor->GetMTime() ||
cellBO.ShaderSourceTime < this->GetInput()->GetMTime())
cellBO.ShaderSourceTime < this->GetInput()->GetMTime() ||
cellBO.ShaderSourceTime < this->PickStateChanged)
{
return true;
}
......@@ -277,6 +280,12 @@ void vtkOpenGLPolyDataMapper2D::BuildShaders(
"gl_PrimitiveID = gl_PrimitiveIDIn;");
}
}
vtkRenderer* ren = vtkRenderer::SafeDownCast(viewport);
if (ren && ren->GetRenderWindow()->GetIsPicking())
{
this->ReplaceShaderPicking(FSSource, ren, actor);
}
}
//-----------------------------------------------------------------------------
......@@ -394,6 +403,16 @@ void vtkOpenGLPolyDataMapper2D::SetMapperShaderParameters(
lineWidth[1] = 2.0*actor->GetProperty()->GetLineWidth()/vp[3];
cellBO.Program->SetUniform2f("lineWidthNVC",lineWidth);
}
vtkRenderer* ren = vtkRenderer::SafeDownCast(viewport);
bool picking = ren && ren->GetRenderWindow()->GetIsPicking();
if (picking && cellBO.Program->IsUniformUsed("mapperIndex"))
{
unsigned int idx = ren->GetCurrentPickId();
float color[3];
vtkHardwareSelector::Convert(idx, color);
cellBO.Program->SetUniform3f("mapperIndex", color);
}
}
//-----------------------------------------------------------------------------
......@@ -416,6 +435,18 @@ void vtkOpenGLPolyDataMapper2D::SetPropertyShaderParameters(
}
}
//-----------------------------------------------------------------------------
void vtkOpenGLPolyDataMapper2D::ReplaceShaderPicking(
std::string & fssource,
vtkRenderer *ren, vtkActor2D *)
{
vtkShaderProgram::Substitute(fssource, "//VTK::Picking::Dec",
"uniform vec3 mapperIndex;");
vtkShaderProgram::Substitute(fssource,
"//VTK::Picking::Impl",
"gl_FragData[0] = vec4(mapperIndex,1.0);\n");
}
//-----------------------------------------------------------------------------
void vtkOpenGLPolyDataMapper2D::SetCameraShaderParameters(
vtkOpenGLHelper &cellBO, vtkViewport* viewport, vtkActor2D *actor)
......@@ -755,6 +786,14 @@ void vtkOpenGLPolyDataMapper2D::RenderOverlay(vtkViewport* viewport,
this->CreateDefaultLookupTable();
}
vtkRenderWindow *renWin = vtkRenderWindow::SafeDownCast(viewport->GetVTKWindow());
int picking = renWin->GetIsPicking();
if (picking != this->LastPickState)
{
this->LastPickState = picking;
this->PickStateChanged.Modified();
}
// Assume we want to do Zbuffering for now.
// we may turn this off later
glDepthMask(GL_TRUE);
......
......@@ -31,6 +31,7 @@
#include <string> // For API.
#include <vector> //for ivars
class vtkActor2D;
class vtkMatrix4x4;
class vtkOpenGLBufferObject;
class vtkOpenGLHelper;
......@@ -102,6 +103,13 @@ protected:
// Set the shader parameteres related to the property
void SetPropertyShaderParameters(vtkOpenGLHelper &cellBO, vtkViewport *viewport, vtkActor2D *act);
// Description:
// Perform string replacments on the shader templates, called from
// ReplaceShaderValues
virtual void ReplaceShaderPicking(
std::string & fssource,
vtkRenderer *ren, vtkActor2D *act);
// Description:
// Update the scene when necessary.
void UpdateVBO(vtkActor2D *act, vtkViewport *viewport);
......@@ -126,6 +134,9 @@ protected:
vtkNew<vtkTransform> VBOTransformInverse;
vtkNew<vtkMatrix4x4> VBOShiftScale;
int LastPickState;
vtkTimeStamp PickStateChanged;
// do we have wide lines that require special handling
virtual bool HaveWideLines(vtkViewport *, vtkActor2D *);
......
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