SetOpenGLDevice.h 1.26 KB
Newer Older
1 2 3 4
//============================================================================
//  Copyright (c) Kitware, Inc.
//  All rights reserved.
//  See LICENSE.txt for details.
5
//
6 7 8 9
//  This software is distributed WITHOUT ANY WARRANTY; without even
//  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
//  PURPOSE.  See the above copyright notice for more information.
//============================================================================
10 11
#ifndef vtk_m_cuda_interop_SetOpenGLDevice_h
#define vtk_m_cuda_interop_SetOpenGLDevice_h
12 13 14 15 16 17

#include <cuda.h>
#include <cuda_gl_interop.h>

#include <vtkm/cont/ErrorExecution.h>

18 19 20 21 22 23
namespace vtkm
{
namespace interop
{
namespace cuda
{
24 25 26 27 28 29 30 31 32 33 34

static void SetCudaGLDevice(int id)
{
//With Cuda 5.0 cudaGLSetGLDevice is deprecated and shouldn't be needed
//anymore. But it seems that macs still require you to call it or we
//segfault
#ifdef __APPLE__
  cudaError_t cError = cudaGLSetGLDevice(id);
#else
  cudaError_t cError = cudaSetDevice(id);
#endif
35 36
  if (cError != cudaSuccess)
  {
37 38 39
    std::string cuda_error_msg("Unable to setup cuda/opengl interop. Error: ");
    cuda_error_msg.append(cudaGetErrorString(cError));
    throw vtkm::cont::ErrorExecution(cuda_error_msg);
40
  }
41 42 43 44 45
}
}
}
} //namespace

46
#endif //vtk_m_cuda_interop_SetOpenGLDevice_h