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_OPENGL_BUFFER_HPP
0012 #define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP
0013 
0014 #include <boost/compute/buffer.hpp>
0015 #include <boost/compute/interop/opengl/gl.hpp>
0016 #include <boost/compute/interop/opengl/cl_gl.hpp>
0017 
0018 namespace boost {
0019 namespace compute {
0020 
0021 /// \class opengl_buffer
0022 ///
0023 /// A OpenCL buffer for accessing an OpenGL memory object.
0024 class opengl_buffer : public buffer
0025 {
0026 public:
0027     /// Creates a null OpenGL buffer object.
0028     opengl_buffer()
0029         : buffer()
0030     {
0031     }
0032 
0033     /// Creates a new OpenGL buffer object for \p mem.
0034     explicit opengl_buffer(cl_mem mem, bool retain = true)
0035         : buffer(mem, retain)
0036     {
0037     }
0038 
0039     /// Creates a new OpenGL buffer object in \p context for \p bufobj
0040     /// with \p flags.
0041     ///
0042     /// \see_opencl_ref{clCreateFromGLBuffer}
0043     opengl_buffer(const context &context,
0044                   GLuint bufobj,
0045                   cl_mem_flags flags = read_write)
0046     {
0047         cl_int error = 0;
0048         m_mem = clCreateFromGLBuffer(context, flags, bufobj, &error);
0049         if(!m_mem){
0050             BOOST_THROW_EXCEPTION(opencl_error(error));
0051         }
0052     }
0053 
0054     /// Creates a new OpenGL buffer object as a copy of \p other.
0055     opengl_buffer(const opengl_buffer &other)
0056         : buffer(other)
0057     {
0058     }
0059 
0060     /// Copies the OpenGL buffer object from \p other.
0061     opengl_buffer& operator=(const opengl_buffer &other)
0062     {
0063         if(this != &other){
0064             buffer::operator=(other);
0065         }
0066 
0067         return *this;
0068     }
0069 
0070     /// Destroys the OpenGL buffer object.
0071     ~opengl_buffer()
0072     {
0073     }
0074 
0075     /// Returns the OpenGL memory object ID.
0076     ///
0077     /// \see_opencl_ref{clGetGLObjectInfo}
0078     GLuint get_opengl_object() const
0079     {
0080         GLuint object = 0;
0081         clGetGLObjectInfo(m_mem, 0, &object);
0082         return object;
0083     }
0084 
0085     /// Returns the OpenGL memory object type.
0086     ///
0087     /// \see_opencl_ref{clGetGLObjectInfo}
0088     cl_gl_object_type get_opengl_type() const
0089     {
0090         cl_gl_object_type type;
0091         clGetGLObjectInfo(m_mem, &type, 0);
0092         return type;
0093     }
0094 };
0095 
0096 namespace detail {
0097 
0098 // set_kernel_arg specialization for opengl_buffer
0099 template<>
0100 struct set_kernel_arg<opengl_buffer> : set_kernel_arg<memory_object> { };
0101 
0102 } // end detail namespace
0103 } // end compute namespace
0104 } // end boost namespace
0105 
0106 #endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_BUFFER_HPP