Viskores  1.0
TransferToOpenGL.h
Go to the documentation of this file.
1 //============================================================================
2 // The contents of this file are covered by the Viskores license. See
3 // LICENSE.txt for details.
4 //
5 // By contributing to this file, all contributors agree to the Developer
6 // Certificate of Origin Version 1.1 (DCO 1.1) as stated in DCO.txt.
7 //============================================================================
8 
9 //============================================================================
10 // Copyright (c) Kitware, Inc.
11 // All rights reserved.
12 // See LICENSE.txt for details.
13 //
14 // This software is distributed WITHOUT ANY WARRANTY; without even
15 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
16 // PURPOSE. See the above copyright notice for more information.
17 //============================================================================
18 #ifndef viskores_interop_TransferToOpenGL_h
19 #define viskores_interop_TransferToOpenGL_h
20 
27 
31 
32 namespace viskores
33 {
34 namespace interop
35 {
36 
48 template <typename ValueType, class StorageTag, class DeviceAdapterTag>
51  BufferState& state,
52  DeviceAdapterTag)
53 {
54  viskores::interop::internal::TransferToOpenGL<ValueType, DeviceAdapterTag> toGL(state);
55  toGL.Transfer(handle);
56 }
57 
71 template <typename ValueType, typename StorageTag>
74  BufferState& state)
75 {
76  // First, try to transfer data that already exists on a device.
77  bool success = viskores::cont::TryExecute(
78  [&](auto device)
79  {
80  if (handle.IsOnDevice(device))
81  {
82  TransferToOpenGL(handle, state, device);
83  return true;
84  }
85  else
86  {
87  return false;
88  }
89  });
90  if (!success)
91  {
92  // Generally, we are here because the array is not already on a device
93  // or for some reason the transfer failed on that device. Try any device.
95  [&](auto device)
96  {
97  TransferToOpenGL(handle, state, device);
98  return true;
99  });
100  }
101  if (!success)
102  {
103  throw viskores::cont::ErrorBadValue("Failed to transfer array to OpenGL on any device.");
104  }
105 }
106 }
107 }
108 
109 #endif //viskores_interop_TransferToOpenGL_h
ArrayHandle.h
DeviceAdapterTBB.h
viskores::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:313
DeviceAdapter.h
VISKORES_CONT
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores
Groups connected points that have the same field value.
Definition: Atomic.h:27
viskores::cont::TryExecute
bool TryExecute(Functor &&functor, Args &&... args)
Try to execute a functor on a set of devices until one succeeds.
Definition: TryExecute.h:252
TryExecute.h
DeviceAdapterCuda.h
viskores::interop::BufferState
Manages the state for transferring an ArrayHandle to opengl.
Definition: BufferState.h:64
DeviceAdapterSerial.h
viskores::interop::TransferToOpenGL
void TransferToOpenGL(const viskores::cont::ArrayHandle< ValueType, StorageTag > &handle, BufferState &state, DeviceAdapterTag)
Manages transferring an ArrayHandle to opengl .
Definition: TransferToOpenGL.h:49
viskores::cont::ArrayHandle::IsOnDevice
bool IsOnDevice(viskores::cont::DeviceAdapterId device) const
Returns true if the ArrayHandle's data is on the given device.
Definition: ArrayHandle.h:665
viskores::cont::ErrorBadValue
This class is thrown when a Viskores function or method encounters an invalid value that inhibits pro...
Definition: ErrorBadValue.h:33
ErrorBadValue.h
BufferState.h
TransferToOpenGL.h