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_RENDERBUFFER_HPP
0012 #define BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP
0013 
0014 #include <boost/compute/image/image_object.hpp>
0015 #include <boost/compute/interop/opengl/gl.hpp>
0016 #include <boost/compute/interop/opengl/cl_gl.hpp>
0017 #include <boost/compute/type_traits/type_name.hpp>
0018 #include <boost/compute/utility/extents.hpp>
0019 
0020 namespace boost {
0021 namespace compute {
0022 
0023 /// \class opengl_renderbuffer
0024 ///
0025 /// A OpenCL buffer for accessing an OpenGL renderbuffer object.
0026 class opengl_renderbuffer : public image_object
0027 {
0028 public:
0029     /// Creates a null OpenGL renderbuffer object.
0030     opengl_renderbuffer()
0031         : image_object()
0032     {
0033     }
0034 
0035     /// Creates a new OpenGL renderbuffer object for \p mem.
0036     explicit opengl_renderbuffer(cl_mem mem, bool retain = true)
0037         : image_object(mem, retain)
0038     {
0039     }
0040 
0041     /// Creates a new OpenGL renderbuffer object in \p context for
0042     /// \p renderbuffer with \p flags.
0043     ///
0044     /// \see_opencl_ref{clCreateFromGLRenderbuffer}
0045     opengl_renderbuffer(const context &context,
0046                         GLuint renderbuffer,
0047                         cl_mem_flags flags = read_write)
0048     {
0049         cl_int error = 0;
0050 
0051         m_mem = clCreateFromGLRenderbuffer(
0052             context, flags, renderbuffer, &error
0053         );
0054 
0055         if(!m_mem){
0056             BOOST_THROW_EXCEPTION(opencl_error(error));
0057         }
0058     }
0059 
0060     /// Creates a new OpenGL renderbuffer object as a copy of \p other.
0061     opengl_renderbuffer(const opengl_renderbuffer &other)
0062         : image_object(other)
0063     {
0064     }
0065 
0066     /// Copies the OpenGL renderbuffer object from \p other.
0067     opengl_renderbuffer& operator=(const opengl_renderbuffer &other)
0068     {
0069         if(this != &other){
0070             image_object::operator=(other);
0071         }
0072 
0073         return *this;
0074     }
0075 
0076     /// Destroys the OpenGL buffer object.
0077     ~opengl_renderbuffer()
0078     {
0079     }
0080 
0081     /// Returns the size (width, height) of the renderbuffer.
0082     extents<2> size() const
0083     {
0084         extents<2> size;
0085         size[0] = get_image_info<size_t>(CL_IMAGE_WIDTH);
0086         size[1] = get_image_info<size_t>(CL_IMAGE_HEIGHT);
0087         return size;
0088     }
0089 
0090     /// Returns the origin of the renderbuffer (\c 0, \c 0).
0091     extents<2> origin() const
0092     {
0093         return extents<2>();
0094     }
0095 
0096     /// Returns the OpenGL memory object ID.
0097     ///
0098     /// \see_opencl_ref{clGetGLObjectInfo}
0099     GLuint get_opengl_object() const
0100     {
0101         GLuint object = 0;
0102         clGetGLObjectInfo(m_mem, 0, &object);
0103         return object;
0104     }
0105 
0106     /// Returns the OpenGL memory object type.
0107     ///
0108     /// \see_opencl_ref{clGetGLObjectInfo}
0109     cl_gl_object_type get_opengl_type() const
0110     {
0111         cl_gl_object_type type;
0112         clGetGLObjectInfo(m_mem, &type, 0);
0113         return type;
0114     }
0115 };
0116 
0117 namespace detail {
0118 
0119 // set_kernel_arg() specialization for opengl_renderbuffer
0120 template<>
0121 struct set_kernel_arg<opengl_renderbuffer> : public set_kernel_arg<image_object> { };
0122 
0123 } // end detail namespace
0124 } // end compute namespace
0125 } // end boost namespace
0126 
0127 BOOST_COMPUTE_TYPE_NAME(boost::compute::opengl_renderbuffer, image2d_t)
0128 
0129 #endif // BOOST_COMPUTE_INTEROP_OPENGL_OPENGL_RENDERBUFFER_HPP