Go to the documentation of this file.
10 #ifndef vtk_m_interop_internal_TransferToOpenGL_h
11 #define vtk_m_interop_internal_TransferToOpenGL_h
36 class SMPTransferResource :
public vtkm::interop::internal::TransferResource
40 SMPTransferResource(T,
vtkm::Id numberOfValues)
41 :
vtkm::interop::internal::TransferResource()
45 this->resize<T>(numberOfValues);
48 ~SMPTransferResource() {}
53 if (this->Size != numberOfValues)
55 this->Size = numberOfValues;
56 T* storage =
new T[
static_cast<std::size_t
>(this->Size)];
57 this->TempStorage.reset(
reinterpret_cast<vtkm::UInt8*
>(storage));
67 T* storage =
reinterpret_cast<T*
>(this->TempStorage.get());
76 T* storage =
reinterpret_cast<T*
>(this->TempStorage.get());
81 std::unique_ptr<vtkm::UInt8[]> TempStorage;
87 template <
class ValueType,
class StorageTag,
class DeviceAdapterTag>
95 const GLsizeiptr size =
96 static_cast<GLsizeiptr
>(
sizeof(ValueType)) *
static_cast<GLsizeiptr
>(numberOfValues);
99 vtkm::interop::internal::SMPTransferResource* resource =
100 dynamic_cast<vtkm::interop::internal::SMPTransferResource*
>(state.
GetResource());
109 glBufferData(state.
GetType(), size, 0, GL_DYNAMIC_DRAW);
115 resource->resize<ValueType>(numberOfValues);
124 resource =
new vtkm::interop::internal::SMPTransferResource(ValueType(), numberOfValues);
129 auto resourceHandle = resource->handle<ValueType>(numberOfValues);
130 Algorithm::Copy(handle, resourceHandle);
133 glBufferSubData(state.
GetType(), 0, size, resource->as<ValueType>());
136 template <
class ValueType,
class DeviceAdapterTag>
148 const GLsizeiptr size =
static_cast<GLsizeiptr
>(
sizeof(ValueType)) *
157 glBufferData(state.
GetType(), size, 0, GL_DYNAMIC_DRAW);
166 glBufferSubData(state.
GetType(), 0, size, memory);
176 template <
typename ValueType,
class DeviceAdapterTag>
183 if (!this->State.HasType())
185 this->State.DeduceAndSetType(ValueType());
189 template <
typename StorageTag>
193 if (!glIsBuffer(*this->State.GetHandle()))
195 glGenBuffers(1, this->State.GetHandle());
199 glBindBuffer(this->State.GetType(), *this->State.GetHandle());
216 detail::CopyFromHandle(handle, this->State, DeviceAdapterTag());
230 #if VTKM_DEVICE_ADAPTER == VTKM_DEVICE_ADAPTER_CUDA
234 #endif //vtk_m_interop_internal_TransferToOpenGL_h
Manages the state for transferring an ArrayHandle to opengl.
Definition: BufferState.h:56
Groups connected points that have the same field value.
Definition: Atomic.h:19
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:468
bool ShouldRealloc(vtkm::Int64 desiredSize) const
Definition: BufferState.h:150
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
Struct containing device adapter algorithms.
Definition: DeviceAdapterAlgorithm.h:41
uint8_t UInt8
Base type to use for 8-bit unsigned integer numbers.
Definition: Types.h:169
GLenum GetType() const
return what OpenGL buffer type we are bound to
Definition: BufferState.h:110
vtkm::interop::internal::TransferResource * GetResource()
Definition: BufferState.h:163
vtkm::cont::ArrayPortalToIterators< PortalType >::IteratorType ArrayPortalToIteratorBegin(const PortalType &portal)
Convenience function for converting an ArrayPortal to a begin iterator.
Definition: ArrayPortalToIterators.h:178
ReadPortalType PrepareForInput(vtkm::cont::DeviceAdapterId device, vtkm::cont::Token &token) const
Prepares this array to be used as an input to an operation in the execution environment.
Definition: ArrayHandle.h:599
vtkm::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, vtkm::Id numberOfValues, vtkm::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:270
void TransferToOpenGL(const vtkm::cont::ArrayHandle< ValueType, StorageTag > &handle, BufferState &state, DeviceAdapterTag)
Manages transferring an ArrayHandle to opengl .
Definition: TransferToOpenGL.h:41
void SetCapacity(vtkm::Int64 capacity)
Definition: BufferState.h:160
void SetResource(vtkm::interop::internal::TransferResource *resource)
Definition: BufferState.h:166
void SetSize(vtkm::Int64 size)
Definition: BufferState.h:137