public Image(Context context, MemoryFlags flags, ChannelOrder order, ChannelType type, ImageType imageType, ulong width, ulong height, ulong depth, ulong arraySize, ulong rowPitch, ulong slicePitch, IntPtr hostPtr) : this() { if (context == Context.Null) { throw new ArgumentNullException("context"); } if (flags.HasFlag(MemoryFlags.WriteOnly) & flags.HasFlag(MemoryFlags.ReadOnly)) { throw new ArgumentException("MemoryFlags.WriteOnly and MemoryFlags.ReadOnly are mutually exclusive."); } if (flags.HasFlag(MemoryFlags.HostWriteOnly) & flags.HasFlag(MemoryFlags.HostReadOnly)) { throw new ArgumentException("MemoryFlags.HostWriteOnly and MemoryFlags.HostReadOnly are mutually exclusive."); } if (flags.HasFlag(MemoryFlags.HostWriteOnly) & flags.HasFlag(MemoryFlags.HostNoAccess)) { throw new ArgumentException("MemoryFlags.HostWriteOnly and MemoryFlags.HostNoAccess are mutually exclusive."); } if (flags.HasFlag(MemoryFlags.HostReadOnly) & flags.HasFlag(MemoryFlags.HostNoAccess)) { throw new ArgumentException("MemoryFlags.HostReadOnly and MemoryFlags.HostNoAccess are mutually exclusive."); } if (width == 0) { throw new ArgumentOutOfRangeException("width", width, "width is 0."); } if (height == 0) { throw new ArgumentOutOfRangeException("height", height, "height is 0."); } if (depth == 0) { throw new ArgumentOutOfRangeException("depth", depth, "depth is 0."); } if (hostPtr == IntPtr.Zero) { if (flags.HasFlag(MemoryFlags.UseHostPtr)) { throw new ArgumentException("MemoryFlags.UseHostPtr is not valid."); } if (flags.HasFlag(MemoryFlags.CopyHostPtr)) { throw new ArgumentException("MemoryFlags.CopyHostPtr is not valid."); } if (rowPitch != 0) { throw new ArgumentOutOfRangeException("rowPitch", rowPitch, "rowPitch is not 0."); } if (slicePitch != 0) { throw new ArgumentOutOfRangeException("slicePitch", slicePitch, "slicePitch is not 0."); } } else { if (!flags.HasFlag(MemoryFlags.UseHostPtr) & !flags.HasFlag(MemoryFlags.CopyHostPtr)) { throw new ArgumentException("MemoryFlags.UseHostPtr or MemoryFlags.CopyHostPtr is required."); } if (flags.HasFlag(MemoryFlags.UseHostPtr) & flags.HasFlag(MemoryFlags.CopyHostPtr)) { throw new ArgumentException("MemoryFlags.UseHostPtr and MemoryFlags.CopyHostPtr are mutually exclusive."); } if (flags.HasFlag(MemoryFlags.UseHostPtr) & flags.HasFlag(MemoryFlags.AllocHostPtr)) { throw new ArgumentException("MemoryFlags.UseHostPtr and MemoryFlags.AllocHostPtr are mutually exclusive."); } if (rowPitch != 0 && rowPitch < width) { throw new ArgumentOutOfRangeException("rowPitch", rowPitch, "rowPitch is not 0 and is less than width."); } if (slicePitch != 0 && slicePitch < height) { throw new ArgumentOutOfRangeException("slicePitch", slicePitch, "slicePitch is not 0 and is less than height."); } } unsafe { Cl.image_format image_format = new Cl.image_format() { image_channel_order = (uint)order, image_channel_data_type = (uint)type, }; Cl.image_desc image_desc = new Cl.image_desc() { image_type = (uint)imageType, image_width = new UIntPtr(width), image_height = new UIntPtr(height), image_depth = new UIntPtr(depth), image_array_size = new UIntPtr(arraySize), image_row_pitch = new UIntPtr(rowPitch), image_slice_pitch = new UIntPtr(slicePitch), num_mip_level = 0, num_samples = 0, buffer = IntPtr.Zero, }; int error; Handle = Cl.CreateImage( context.Handle, (ulong)flags, &image_format, &image_desc, hostPtr.ToPointer(), &error); ClHelper.GetError(error); } }