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_IMAGE3D_HPP
12 #define BOOST_COMPUTE_IMAGE_IMAGE3D_HPP
14 #include <boost/throw_exception.hpp>
16 #include <boost/compute/detail/get_object_info.hpp>
17 #include <boost/compute/exception/opencl_error.hpp>
18 #include <boost/compute/image/image_format.hpp>
19 #include <boost/compute/image/image_object.hpp>
20 #include <boost/compute/type_traits/type_name.hpp>
21 #include <boost/compute/utility/extents.hpp>
26 // forward declarations
30 /// \brief An OpenCL 3D image object
32 /// \see image_format, image2d
33 class image3d : public image_object
36 /// Creates a null image3d object.
42 /// Creates a new image3d object.
44 /// \see_opencl_ref{clCreateImage}
45 image3d(const context &context,
49 const image_format &format,
50 cl_mem_flags flags = read_write,
52 size_t image_row_pitch = 0,
53 size_t image_slice_pitch = 0)
57 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
59 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
60 desc.image_width = image_width;
61 desc.image_height = image_height;
62 desc.image_depth = image_depth;
63 desc.image_array_size = 0;
64 desc.image_row_pitch = image_row_pitch;
65 desc.image_slice_pitch = image_slice_pitch;
66 desc.num_mip_levels = 0;
68 #ifdef BOOST_COMPUTE_CL_VERSION_2_0
74 m_mem = clCreateImage(context,
76 format.get_format_ptr(),
81 m_mem = clCreateImage3D(context,
83 format.get_format_ptr(),
94 BOOST_THROW_EXCEPTION(opencl_error(error));
98 /// \internal_ (deprecated)
99 image3d(const context &context,
101 const image_format &format,
105 size_t image_row_pitch,
106 size_t image_slice_pitch = 0,
111 #ifdef BOOST_COMPUTE_CL_VERSION_1_2
113 desc.image_type = CL_MEM_OBJECT_IMAGE3D;
114 desc.image_width = image_width;
115 desc.image_height = image_height;
116 desc.image_depth = image_depth;
117 desc.image_array_size = 0;
118 desc.image_row_pitch = image_row_pitch;
119 desc.image_slice_pitch = image_slice_pitch;
120 desc.num_mip_levels = 0;
121 desc.num_samples = 0;
122 #ifdef BOOST_COMPUTE_CL_VERSION_2_0
128 m_mem = clCreateImage(context,
130 format.get_format_ptr(),
135 m_mem = clCreateImage3D(context,
137 format.get_format_ptr(),
148 BOOST_THROW_EXCEPTION(opencl_error(error));
152 /// Creates a new image3d as a copy of \p other.
153 image3d(const image3d &other)
154 : image_object(other)
158 /// Copies the image3d from \p other.
159 image3d& operator=(const image3d &other)
161 image_object::operator=(other);
166 #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
167 /// Move-constructs a new image object from \p other.
168 image3d(image3d&& other) BOOST_NOEXCEPT
169 : image_object(std::move(other))
173 /// Move-assigns the image from \p other to \c *this.
174 image3d& operator=(image3d&& other) BOOST_NOEXCEPT
176 image_object::operator=(std::move(other));
180 #endif // BOOST_COMPUTE_NO_RVALUE_REFERENCES
182 /// Destroys the image3d object.
187 /// Returns the size (width, height, depth) of the image.
188 extents<3> size() const
191 size[0] = get_info<size_t>(CL_IMAGE_WIDTH);
192 size[1] = get_info<size_t>(CL_IMAGE_HEIGHT);
193 size[2] = get_info<size_t>(CL_IMAGE_DEPTH);
197 /// Returns the origin of the image (\c 0, \c 0, \c 0).
198 extents<3> origin() const
203 /// Returns information about the image.
205 /// \see_opencl_ref{clGetImageInfo}
207 T get_info(cl_image_info info) const
209 return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
214 typename detail::get_object_info_type<image3d, Enum>::type
217 /// Returns the supported 3D image formats for the context.
219 /// \see_opencl_ref{clGetSupportedImageFormats}
220 static std::vector<image_format>
221 get_supported_formats(const context &context, cl_mem_flags flags = read_write)
223 return image_object::get_supported_formats(context, CL_MEM_OBJECT_IMAGE3D, flags);
226 /// Returns \c true if \p format is a supported 3D image format for
228 static bool is_supported_format(const image_format &format,
229 const context &context,
230 cl_mem_flags flags = read_write)
232 return image_object::is_supported_format(
233 format, context, CL_MEM_OBJECT_IMAGE3D, flags
237 /// Creates a new image with a copy of the data in \c *this. Uses \p queue
238 /// to perform the copy operation.
239 image3d clone(command_queue &queue) const;
242 /// \internal_ define get_info() specializations for image3d
243 BOOST_COMPUTE_DETAIL_DEFINE_GET_INFO_SPECIALIZATIONS(image3d,
244 ((cl_image_format, CL_IMAGE_FORMAT))
245 ((size_t, CL_IMAGE_ELEMENT_SIZE))
246 ((size_t, CL_IMAGE_ROW_PITCH))
247 ((size_t, CL_IMAGE_SLICE_PITCH))
248 ((size_t, CL_IMAGE_WIDTH))
249 ((size_t, CL_IMAGE_HEIGHT))
250 ((size_t, CL_IMAGE_DEPTH))
255 // set_kernel_arg() specialization for image3d
257 struct set_kernel_arg<image3d> : public set_kernel_arg<image_object> { };
259 } // end detail namespace
260 } // end compute namespace
261 } // end boost namespace
263 BOOST_COMPUTE_TYPE_NAME(boost::compute::image3d, image3d_t)
265 #endif // BOOST_COMPUTE_IMAGE_IMAGE3D_HPP