1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2013-2015 Kyle Lutz <kyle.r.lutz@gmail.com>
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
8 // See http://boostorg.github.com/compute for more information.
9 //---------------------------------------------------------------------------//
11 #ifndef BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
12 #define BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
17 #include <boost/compute/config.hpp>
18 #include <boost/compute/memory_object.hpp>
19 #include <boost/compute/detail/get_object_info.hpp>
20 #include <boost/compute/image/image_format.hpp>
25 /// \class image_object
26 /// \brief Base-class for image objects.
28 /// The image_object class is the base-class for image objects on compute
31 /// \see image1d, image2d, image3d
32 class image_object : public memory_object
40 explicit image_object(cl_mem mem, bool retain = true)
41 : memory_object(mem, retain)
45 image_object(const image_object &other)
46 : memory_object(other)
50 image_object& operator=(const image_object &other)
53 memory_object::operator=(other);
59 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
60 image_object(image_object&& other) BOOST_NOEXCEPT
61 : memory_object(std::move(other))
66 image_object& operator=(image_object&& other) BOOST_NOEXCEPT
68 memory_object::operator=(std::move(other));
72 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
74 /// Destroys the image object.
79 /// Returns information about the image object.
81 /// \see_opencl_ref{clGetImageInfo}
83 T get_image_info(cl_mem_info info) const
85 return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
88 /// Returns the format for the image.
89 image_format format() const
91 return image_format(get_image_info<cl_image_format>(CL_IMAGE_FORMAT));
94 /// \internal_ (deprecated)
95 image_format get_format() const
100 /// Returns the width of the image.
103 return get_image_info<size_t>(CL_IMAGE_WIDTH);
106 /// Returns the height of the image.
108 /// For 1D images, this function will return \c 1.
109 size_t height() const
111 return get_image_info<size_t>(CL_IMAGE_HEIGHT);
114 /// Returns the depth of the image.
116 /// For 1D and 2D images, this function will return \c 1.
119 return get_image_info<size_t>(CL_IMAGE_DEPTH);
122 /// Returns the supported image formats for the \p type in \p context.
124 /// \see_opencl_ref{clGetSupportedImageFormats}
125 static std::vector<image_format>
126 get_supported_formats(const context &context,
127 cl_mem_object_type type,
128 cl_mem_flags flags = read_write)
131 clGetSupportedImageFormats(context, flags, type, 0, 0, &count);
133 std::vector<cl_image_format> cl_formats(count);
134 clGetSupportedImageFormats(context, flags, type, count, &cl_formats[0], 0);
136 std::vector<image_format> formats;
137 formats.reserve(count);
139 for(cl_uint i = 0; i < count; i++){
140 formats.push_back(image_format(cl_formats[i]));
146 /// Returns \c true if \p format is a supported image format for
147 /// \p type in \p context with \p flags.
148 static bool is_supported_format(const image_format &format,
149 const context &context,
150 cl_mem_object_type type,
151 cl_mem_flags flags = read_write)
153 const std::vector<image_format> formats =
154 get_supported_formats(context, type, flags);
156 return std::find(formats.begin(), formats.end(), format) != formats.end();
162 // set_kernel_arg() specialization for image_object
164 struct set_kernel_arg<image_object> : public set_kernel_arg<memory_object> { };
166 } // end detail namespace
167 } // end compute namespace
168 } // end boost namespace
170 #endif // BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP