acquire.hpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //---------------------------------------------------------------------------//
  2. // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. // See http://boostorg.github.com/compute for more information.
  9. //---------------------------------------------------------------------------//
  10. #ifndef BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP
  11. #define BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP
  12. #include <boost/compute/command_queue.hpp>
  13. #include <boost/compute/interop/opengl/cl_gl.hpp>
  14. #include <boost/compute/interop/opengl/opengl_buffer.hpp>
  15. #include <boost/compute/utility/wait_list.hpp>
  16. namespace boost {
  17. namespace compute {
  18. /// Enqueues a command to acquire the specified OpenGL memory objects.
  19. ///
  20. /// \see_opencl_ref{clEnqueueAcquireGLObjects}
  21. inline event opengl_enqueue_acquire_gl_objects(size_t num_objects,
  22. const cl_mem *mem_objects,
  23. command_queue &queue,
  24. const wait_list &events = wait_list())
  25. {
  26. BOOST_ASSERT(queue != 0);
  27. event event_;
  28. cl_int ret = clEnqueueAcquireGLObjects(queue.get(),
  29. num_objects,
  30. mem_objects,
  31. events.size(),
  32. events.get_event_ptr(),
  33. &event_.get());
  34. if(ret != CL_SUCCESS){
  35. BOOST_THROW_EXCEPTION(opencl_error(ret));
  36. }
  37. return event_;
  38. }
  39. /// Enqueues a command to release the specified OpenGL memory objects.
  40. ///
  41. /// \see_opencl_ref{clEnqueueReleaseGLObjects}
  42. inline event opengl_enqueue_release_gl_objects(size_t num_objects,
  43. const cl_mem *mem_objects,
  44. command_queue &queue,
  45. const wait_list &events = wait_list())
  46. {
  47. BOOST_ASSERT(queue != 0);
  48. event event_;
  49. cl_int ret = clEnqueueReleaseGLObjects(queue.get(),
  50. num_objects,
  51. mem_objects,
  52. events.size(),
  53. events.get_event_ptr(),
  54. &event_.get());
  55. if(ret != CL_SUCCESS){
  56. BOOST_THROW_EXCEPTION(opencl_error(ret));
  57. }
  58. return event_;
  59. }
  60. /// Enqueues a command to acquire the specified OpenGL buffer.
  61. ///
  62. /// \see_opencl_ref{clEnqueueAcquireGLObjects}
  63. inline event opengl_enqueue_acquire_buffer(const opengl_buffer &buffer,
  64. command_queue &queue,
  65. const wait_list &events = wait_list())
  66. {
  67. BOOST_ASSERT(buffer.get_context() == queue.get_context());
  68. return opengl_enqueue_acquire_gl_objects(1, &buffer.get(), queue, events);
  69. }
  70. /// Enqueues a command to release the specified OpenGL buffer.
  71. ///
  72. /// \see_opencl_ref{clEnqueueReleaseGLObjects}
  73. inline event opengl_enqueue_release_buffer(const opengl_buffer &buffer,
  74. command_queue &queue,
  75. const wait_list &events = wait_list())
  76. {
  77. BOOST_ASSERT(buffer.get_context() == queue.get_context());
  78. return opengl_enqueue_release_gl_objects(1, &buffer.get(), queue, events);
  79. }
  80. } // end compute namespace
  81. } // end boost namespace
  82. #endif // BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP