\class image2d \brief An OpenCL 2D image object For example, to create a 640x480 8-bit RGBA image: \snippet test/test_image2d.cpp create_image \see image_format, image3d
| 37 | /// |
| 38 | /// \see image_format, image3d |
| 39 | class image2d : public image_object |
| 40 | { |
| 41 | public: |
| 42 | /// Creates a null image2d object. |
| 43 | image2d() |
| 44 | : image_object() |
| 45 | { |
| 46 | } |
| 47 | |
| 48 | /// Creates a new image2d object. |
| 49 | /// |
| 50 | /// \see_opencl_ref{clCreateImage} |
| 51 | image2d(const context &context, |
| 52 | size_t image_width, |
| 53 | size_t image_height, |
| 54 | const image_format &format, |
| 55 | cl_mem_flags flags = read_write, |
| 56 | void *host_ptr = 0, |
| 57 | size_t image_row_pitch = 0) |
| 58 | { |
| 59 | cl_int error = 0; |
| 60 | |
| 61 | #ifdef BOOST_COMPUTE_CL_VERSION_1_2 |
| 62 | cl_image_desc desc; |
| 63 | desc.image_type = CL_MEM_OBJECT_IMAGE2D; |
| 64 | desc.image_width = image_width; |
| 65 | desc.image_height = image_height; |
| 66 | desc.image_depth = 1; |
| 67 | desc.image_array_size = 0; |
| 68 | desc.image_row_pitch = image_row_pitch; |
| 69 | desc.image_slice_pitch = 0; |
| 70 | desc.num_mip_levels = 0; |
| 71 | desc.num_samples = 0; |
| 72 | #ifdef BOOST_COMPUTE_CL_VERSION_2_0 |
| 73 | desc.mem_object = 0; |
| 74 | #else |
| 75 | desc.buffer = 0; |
| 76 | #endif |
| 77 | |
| 78 | m_mem = clCreateImage(context, |
| 79 | flags, |
| 80 | format.get_format_ptr(), |
| 81 | &desc, |
| 82 | host_ptr, |
| 83 | &error); |
| 84 | #else |
| 85 | m_mem = clCreateImage2D(context, |
| 86 | flags, |
| 87 | format.get_format_ptr(), |
| 88 | image_width, |
| 89 | image_height, |
| 90 | image_row_pitch, |
| 91 | host_ptr, |
| 92 | &error); |
| 93 | #endif |
| 94 | |
| 95 | if(!m_mem){ |
| 96 | BOOST_THROW_EXCEPTION(opencl_error(error)); |