VTK-m  2.0
TransferToOpenGL.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_interop_TransferToOpenGL_h
11 #define vtk_m_interop_TransferToOpenGL_h
12 
13 #include <vtkm/cont/ArrayHandle.h>
16 #include <vtkm/cont/TryExecute.h>
19 
23 
24 namespace vtkm
25 {
26 namespace interop
27 {
28 
40 template <typename ValueType, class StorageTag, class DeviceAdapterTag>
42  BufferState& state,
43  DeviceAdapterTag)
44 {
45  vtkm::interop::internal::TransferToOpenGL<ValueType, DeviceAdapterTag> toGL(state);
46  toGL.Transfer(handle);
47 }
48 
62 template <typename ValueType, typename StorageTag>
64  BufferState& state)
65 {
66  // First, try to transfer data that already exists on a device.
67  bool success = vtkm::cont::TryExecute([&](auto device) {
68  if (handle.IsOnDevice(device))
69  {
70  TransferToOpenGL(handle, state, device);
71  return true;
72  }
73  else
74  {
75  return false;
76  }
77  });
78  if (!success)
79  {
80  // Generally, we are here because the array is not already on a device
81  // or for some reason the transfer failed on that device. Try any device.
82  success = vtkm::cont::TryExecute([&](auto device) {
83  TransferToOpenGL(handle, state, device);
84  return true;
85  });
86  }
87  if (!success)
88  {
89  throw vtkm::cont::ErrorBadValue("Failed to transfer array to OpenGL on any device.");
90  }
91 }
92 }
93 }
94 
95 #endif //vtk_m_interop_TransferToOpenGL_h
vtkm::interop::TransferToOpenGL
VTKM_CONT void TransferToOpenGL(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &handle, BufferState &state, DeviceAdapterTag)
Manages transferring an ArrayHandle to opengl .
Definition: TransferToOpenGL.h:41
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm::interop::BufferState
Manages the state for transferring an ArrayHandle to opengl.
Definition: BufferState.h:56
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
DeviceAdapterTBB.h
DeviceAdapter.h
TryExecute.h
DeviceAdapterCuda.h
DeviceAdapterSerial.h
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::cont::ErrorBadValue
This class is thrown when a VTKm function or method encounters an invalid value that inhibits progres...
Definition: ErrorBadValue.h:25
ErrorBadValue.h
vtkm::cont::ArrayHandle::IsOnDevice
VTKM_CONT bool IsOnDevice(vtkm::cont::DeviceAdapterId device) const
Returns true if the ArrayHandle's data is on the given device.
Definition: ArrayHandle.h:624
BufferState.h
TransferToOpenGL.h
vtkm::cont::TryExecute
VTKM_CONT bool TryExecute(Functor &&functor, Args &&... args)
Try to execute a functor on a set of devices until one succeeds.
Definition: TryExecute.h:244