Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:01

0001 //---------------------------------------------------------------------------//
0002 // Copyright (c) 2013-2014 Kyle Lutz <kyle.r.lutz@gmail.com>
0003 //
0004 // Distributed under the Boost Software License, Version 1.0
0005 // See accompanying file LICENSE_1_0.txt or copy at
0006 // http://www.boost.org/LICENSE_1_0.txt
0007 //
0008 // See http://boostorg.github.com/compute for more information.
0009 //---------------------------------------------------------------------------//
0010 
0011 #ifndef BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP
0012 #define BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP
0013 
0014 #include <boost/compute/command_queue.hpp>
0015 #include <boost/compute/interop/opengl/cl_gl.hpp>
0016 #include <boost/compute/interop/opengl/opengl_buffer.hpp>
0017 #include <boost/compute/types/fundamental.hpp>
0018 #include <boost/compute/utility/wait_list.hpp>
0019 
0020 namespace boost {
0021 namespace compute {
0022 
0023 /// Enqueues a command to acquire the specified OpenGL memory objects.
0024 ///
0025 /// \see_opencl_ref{clEnqueueAcquireGLObjects}
0026 inline event opengl_enqueue_acquire_gl_objects(const uint_ num_objects,
0027                                               const cl_mem *mem_objects,
0028                                               command_queue &queue,
0029                                               const wait_list &events = wait_list())
0030 {
0031     BOOST_ASSERT(queue != 0);
0032 
0033     event event_;
0034 
0035     cl_int ret = clEnqueueAcquireGLObjects(queue.get(),
0036                                            num_objects,
0037                                            mem_objects,
0038                                            events.size(),
0039                                            events.get_event_ptr(),
0040                                            &event_.get());
0041     if(ret != CL_SUCCESS){
0042         BOOST_THROW_EXCEPTION(opencl_error(ret));
0043     }
0044 
0045     return event_;
0046 }
0047 
0048 /// Enqueues a command to release the specified OpenGL memory objects.
0049 ///
0050 /// \see_opencl_ref{clEnqueueReleaseGLObjects}
0051 inline event opengl_enqueue_release_gl_objects(const uint_ num_objects,
0052                                               const cl_mem *mem_objects,
0053                                               command_queue &queue,
0054                                               const wait_list &events = wait_list())
0055 {
0056     BOOST_ASSERT(queue != 0);
0057 
0058     event event_;
0059 
0060     cl_int ret = clEnqueueReleaseGLObjects(queue.get(),
0061                                            num_objects,
0062                                            mem_objects,
0063                                            events.size(),
0064                                            events.get_event_ptr(),
0065                                            &event_.get());
0066     if(ret != CL_SUCCESS){
0067         BOOST_THROW_EXCEPTION(opencl_error(ret));
0068     }
0069 
0070     return event_;
0071 }
0072 
0073 /// Enqueues a command to acquire the specified OpenGL buffer.
0074 ///
0075 /// \see_opencl_ref{clEnqueueAcquireGLObjects}
0076 inline event opengl_enqueue_acquire_buffer(const opengl_buffer &buffer,
0077                                           command_queue &queue,
0078                                           const wait_list &events = wait_list())
0079 {
0080     BOOST_ASSERT(buffer.get_context() == queue.get_context());
0081 
0082     return opengl_enqueue_acquire_gl_objects(1, &buffer.get(), queue, events);
0083 }
0084 
0085 /// Enqueues a command to release the specified OpenGL buffer.
0086 ///
0087 /// \see_opencl_ref{clEnqueueReleaseGLObjects}
0088 inline event opengl_enqueue_release_buffer(const opengl_buffer &buffer,
0089                                           command_queue &queue,
0090                                           const wait_list &events = wait_list())
0091 {
0092     BOOST_ASSERT(buffer.get_context() == queue.get_context());
0093 
0094     return opengl_enqueue_release_gl_objects(1, &buffer.get(), queue, events);
0095 }
0096 
0097 } // end compute namespace
0098 } // end boost namespace
0099 
0100 #endif // BOOST_COMPUTE_INTEROP_OPENGL_ACQUIRE_HPP