123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- #ifndef BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
- #define BOOST_COMPUTE_IMAGE_IMAGE_OBJECT_HPP
- #include <algorithm>
- #include <vector>
- #include <boost/compute/config.hpp>
- #include <boost/compute/memory_object.hpp>
- #include <boost/compute/detail/get_object_info.hpp>
- #include <boost/compute/image/image_format.hpp>
- namespace boost {
- namespace compute {
- class image_object : public memory_object
- {
- public:
- image_object()
- : memory_object()
- {
- }
- explicit image_object(cl_mem mem, bool retain = true)
- : memory_object(mem, retain)
- {
- }
- image_object(const image_object &other)
- : memory_object(other)
- {
- }
- image_object& operator=(const image_object &other)
- {
- if(this != &other){
- memory_object::operator=(other);
- }
- return *this;
- }
- #ifndef BOOST_COMPUTE_NO_RVALUE_REFERENCES
- image_object(image_object&& other) BOOST_NOEXCEPT
- : memory_object(std::move(other))
- {
- }
-
- image_object& operator=(image_object&& other) BOOST_NOEXCEPT
- {
- memory_object::operator=(std::move(other));
- return *this;
- }
- #endif
-
- ~image_object()
- {
- }
-
-
-
- template<class T>
- T get_image_info(cl_mem_info info) const
- {
- return detail::get_object_info<T>(clGetImageInfo, m_mem, info);
- }
-
- image_format format() const
- {
- return image_format(get_image_info<cl_image_format>(CL_IMAGE_FORMAT));
- }
-
- image_format get_format() const
- {
- return format();
- }
-
- size_t width() const
- {
- return get_image_info<size_t>(CL_IMAGE_WIDTH);
- }
-
-
-
- size_t height() const
- {
- return get_image_info<size_t>(CL_IMAGE_HEIGHT);
- }
-
-
-
- size_t depth() const
- {
- return get_image_info<size_t>(CL_IMAGE_DEPTH);
- }
-
-
-
- static std::vector<image_format>
- get_supported_formats(const context &context,
- cl_mem_object_type type,
- cl_mem_flags flags = read_write)
- {
- cl_uint count = 0;
- clGetSupportedImageFormats(context, flags, type, 0, 0, &count);
- std::vector<cl_image_format> cl_formats(count);
- clGetSupportedImageFormats(context, flags, type, count, &cl_formats[0], 0);
- std::vector<image_format> formats;
- formats.reserve(count);
- for(cl_uint i = 0; i < count; i++){
- formats.push_back(image_format(cl_formats[i]));
- }
- return formats;
- }
-
-
- static bool is_supported_format(const image_format &format,
- const context &context,
- cl_mem_object_type type,
- cl_mem_flags flags = read_write)
- {
- const std::vector<image_format> formats =
- get_supported_formats(context, type, flags);
- return std::find(formats.begin(), formats.end(), format) != formats.end();
- }
- };
- namespace detail {
- template<>
- struct set_kernel_arg<image_object> : public set_kernel_arg<memory_object> { };
- }
- }
- }
- #endif
|