acquire.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/types/fundamental.hpp>
  16. #include <boost/compute/utility/wait_list.hpp>
  17. namespace boost {
  18. namespace compute {
  19. /// Enqueues a command to acquire the specified OpenGL memory objects.
  20. ///
  21. /// \see_opencl_ref{clEnqueueAcquireGLObjects}
  22. inline event opengl_enqueue_acquire_gl_objects(const uint_ num_objects,
  23. const cl_mem *mem_objects,
  24. command_queue &queue,
  25. const wait_list &events = wait_list())
  26. {
  27. BOOST_ASSERT(queue != 0);
  28. event event_;
  29. cl_int ret = clEnqueueAcquireGLObjects(queue.get(),
  30. num_objects,
  31. mem_objects,
  32. events.size(),
  33. events.get_event_ptr(),
  34. &event_.get());
  35. if(ret != CL_SUCCESS){
  36. BOOST_THROW_EXCEPTION(opencl_error(ret));
  37. }
  38. return event_;
  39. }
  40. /// Enqueues a command to release the specified OpenGL memory objects.
  41. ///
  42. /// \see_opencl_ref{clEnqueueReleaseGLObjects}
  43. inline event opengl_enqueue_release_gl_objects(const uint_ num_objects,
  44. const cl_mem *mem_objects,
  45. command_queue &queue,
  46. const wait_list &events = wait_list())
  47. {
  48. BOOST_ASSERT(queue != 0);
  49. event event_;
  50. cl_int ret = clEnqueueReleaseGLObjects(queue.get(),
  51. num_objects,
  52. mem_objects,
  53. events.size(),
  54. events.get_event_ptr(),
  55. &event_.get());
  56. if(ret != CL_SUCCESS){
  57. BOOST_THROW_EXCEPTION(opencl_error(ret));
  58. }
  59. return event_;
  60. }
  61. /// Enqueues a command to acquire the specified OpenGL buffer.
  62. ///
  63. /// \see_opencl_ref{clEnqueueAcquireGLObjects}
  64. inline event opengl_enqueue_acquire_buffer(const opengl_buffer &buffer,
  65. command_queue &queue,
  66. const wait_list &events = wait_list())
  67. {
  68. BOOST_ASSERT(buffer.get_context() == queue.get_context());
  69. return opengl_enqueue_acquire_gl_objects(1, &buffer.get(), queue, events);
  70. }
  71. /// Enqueues a command to release the specified OpenGL buffer.
  72. ///
  73. /// \see_opencl_ref{clEnqueueReleaseGLObjects}
  74. inline event opengl_enqueue_release_buffer(const opengl_buffer &buffer,
  75. command_queue &queue,
  76. const wait_list &events = wait_list())
  77. {
  78. BOOST_ASSERT(buffer.get_context() == queue.get_context());
  79. return opengl_enqueue_release_gl_objects(1, &buffer.get(), queue, events);
  80. }
  81. } // end compute namespace
  82. } // end boost namespace
  83. #endif // BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP