iridescence
Loading...
Searching...
No Matches
pointcloud_buffer_cuda.hpp
Go to the documentation of this file.
1#ifndef GLK_POINTCLOUD_BUFFER_CUDA_HPP
2#define GLK_POINTCLOUD_BUFFER_CUDA_HPP
3
4#include <iostream>
5#include <Eigen/Core>
6
7#include <cuda_gl_interop.h>
8#include <thrust/device_vector.h>
10
11namespace glk {
12
13static std::shared_ptr<PointCloudBuffer> create_point_cloud_buffer(const void* src_cuda_ptr, int stride, int num_points) {
14 auto buffer = std::make_shared<PointCloudBuffer>(stride, num_points);
15
16 const auto error_check = [](cudaError_t error) {
17 if(error != cudaSuccess) {
18 // std::cerr << "error : " << cudaGetErrorName(error) << std::endl;
19 // std::cerr << " : " << cudaGetErrorString(error) << std::endl;
20 }
21 };
22
23 cudaGraphicsResource* vbo_resource = 0;
24 error_check(cudaGraphicsGLRegisterBuffer(&vbo_resource, buffer->vbo_id(), cudaGraphicsRegisterFlagsNone));
25
26 float* dst_gl_ptr = nullptr;
27 size_t dst_size = 0;
28
29 error_check(cudaGraphicsMapResources(1, &vbo_resource));
30 error_check(cudaGraphicsResourceGetMappedPointer((void**)&dst_gl_ptr, &dst_size, vbo_resource));
31
32 error_check(cudaMemcpy(dst_gl_ptr, src_cuda_ptr, stride * num_points, cudaMemcpyDeviceToDevice));
33
34 error_check(cudaGraphicsUnmapResources(1, &vbo_resource));
35 error_check(cudaGraphicsUnregisterResource(vbo_resource));
36
37 return buffer;
38}
39
40static std::shared_ptr<PointCloudBuffer> create_point_cloud_buffer(const thrust::device_vector<Eigen::Vector3f>& points) {
41 return create_point_cloud_buffer(thrust::raw_pointer_cast(points.data()), sizeof(Eigen::Vector3f), points.size());
42}
43}
44
45#endif
Definition async_buffer_copy.hpp:6
static std::shared_ptr< PointCloudBuffer > create_point_cloud_buffer(const void *src_cuda_ptr, int stride, int num_points)
Definition pointcloud_buffer_cuda.hpp:13