OSMesa + vtkHardwareSelector - is that possible ?

Hi everyone,

I am trying to use a vtkHardwareSelector with an OSMesa-based VTK distribution. And it does not work so far … help ! :pray:
Has anyone ever attempted this ?

I tried looking on the Paraview side, but nothing obivous jumped out when trying to get info on how PV does the selection offscreen with OSMesa.

Below are the CMake build & the piece of code that is relevant to the operation. Thank you very much in advance for your help ! :pray:

The CMake build is done like this :

cmake \
-DCMAKE_C_FLAGS="-Wno-incompatible-function-pointer-types" \
-DCMAKE_CXX_FLAGS="-Wno-incompatible-function-pointer-types" \
-DCMAKE_EXE_LINKER_FLAGS="-L${LLVM_ROOT}/lib/c++ -Wl,-rpath,${LLVM_ROOT}/lib/c++" \
-DCMAKE_INSTALL_PREFIX=${CODE_DIR}/${SUB_DIR}/vtk/build/install \
${@} \
-S .. -B .

And based on multiple examples in the documentation I am using this snippet:

    _graphics_factory = vtkSmartPointer<vtkGraphicsFactory>::New();

    _renderer = vtkSmartPointer<vtkRenderer>::New();

    _mapper = vtkSmartPointer<vtkPolyDataMapper>::New();

    _actor = vtkSmartPointer<vtkActor>::New();

    Vertex focal_point = centroid;
    Vertex position = (focal_point - (initial_sight_direction * _bounding_sphere_radius /
                                      std::sin(0.5 * vtkMath::RadiansFromDegrees(_field_of_view))));
    _camera = vtkSmartPointer<vtkCamera>::New();
    _camera->SetPosition(position.x(), position.y(), position.z());
    _camera->SetFocalPoint(focal_point.x(), focal_point.y(), focal_point.z());

    _render_window = vtkSmartPointer<vtkRenderWindow>::New();
    _render_window->SetSize(_window_width, _window_height);


    _hardware_selector = vtkSmartPointer<vtkOpenGLHardwareSelector>::New();
    _hardware_selector->SetArea(0, 0, _window_width - 1, _window_height - 1);


    // Pick the visible cells
    vtkSelection* selection = _hardware_selector->Select();
    vtkSelectionNode* selection_node = selection->GetNode(0);
    vtkIdTypeArray* selection_ids =

    std::vector<vtkIdType> visible_cells;
    for (vtkIdType i = 0; i < selection_ids->GetNumberOfTuples(); ++i) {

    return visible_cells;

@tbridel As long as you’ve built with osmesa, you don’t need to setup the graphics factory. Try removing the following lines:

Also, you should be fine with using vtkHardwareSelector directly instead of vtkOpenGLHardwareSelector i.e.

_hardware_selector = vtkSmartPointer<vtkHardwareSelector>::New();

Hi @sankhesh

So sorry for the delayed answer, I was on another branch for a while.
I came back to it and did as you suggested (removing the graphics factory, using only a vtkHardwareSelector).
The use case I am playing with works without any problems when vtk is not compiled with Mesa, but when it is, I get that

vtkSelection *selection = _hardware_selector->Select();

is not a nullptr, but all


are nullptr. Any idea what could be happening ?

I am building OSMesa with the following attached script - I did not find many pointers online, so maybe something is wrong there too. I am open to any advice about this as well :pray: .

build_mesa_darwin.zsh (3.2 KB)