private extern static IntPtr clCreateContext( [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties, Int32 num_devices, [MarshalAs(UnmanagedType.LPArray)] IntPtr[] devices, ContextNotifyFunction pfn_notify, IntPtr user_data, out ErrorCode errcode_ret);
/// <summary> /// Create a <see cref="Context"/> using the <see cref="Device"/>s of the specified type in this <see cref="Platform"/>. /// </summary> /// <param name="type"></param> /// <param name="notifyFunction"></param> /// <param name="userData"></param> /// <returns></returns> public Context CreateContext(DeviceType type, ContextNotifyFunction notifyFunction = null, IntPtr userData = default) { Context context = new Context(this, type, notifyFunction, userData); if (context.Error) { return(null); } return(context); }
/// <summary> /// Creates a <see cref="Context"/> using the <see cref="Device"/>s of the selected type in the specified <see cref="Platform"/>. /// </summary> /// <param name="platform"></param> /// <param name="type"></param> /// <param name="notifyFunction"></param> /// <param name="userData"></param> public Context(Platform platform, DeviceType type, ContextNotifyFunction notifyFunction = null, IntPtr userData = default) { IntPtr[] properties = new IntPtr[3]; properties[0] = new IntPtr((int)ContextProperty.Platform); properties[1] = platform.Handle; properties[2] = IntPtr.Zero; Handle = clCreateContextFromType(properties, type, notifyFunction, userData, out error); if (error == ErrorCode.Success) { Devices = platform.GetDevices(type); } }
/// <summary> /// Creates a <see cref="Context"/> using all the <see cref="Device"/>s of the specified <see cref="Platform"/>. /// </summary> /// <param name="platform">The platform to use.</param> /// <param name="notifyFunction">The callback used to report errors during context creation and at runtime.</param> /// <param name="userData">Pointer to user data passed to the callback.</param> public Context(Platform platform, ContextNotifyFunction notifyFunction = null, IntPtr userData = default) { IntPtr[] properties = new IntPtr[3]; properties[0] = new IntPtr((int)ContextProperty.Platform); properties[1] = platform.Handle; properties[2] = IntPtr.Zero; Devices = platform?.GetDevices(); if (Devices != null && Devices.Count > 0) { IntPtr[] deviceHandles = new IntPtr[Devices.Count]; for (int i = 0; i < Devices.Count; i++) { deviceHandles[i] = Devices[i].Handle; } Handle = clCreateContext(properties, Devices.Count, deviceHandles, notifyFunction, userData, out error); } else { error = ErrorCode.InvalidDevice; } }
/// <summary> /// Creates a <see cref="Context"/> using a list of <see cref="Device"/>s. /// </summary> /// <param name="devices">The list of devices to use.</param> /// <param name="notifyFunction">The callback used to report errors during context creation and at runtime.</param> /// <param name="userData">Pointer to user data passed to the callback.</param> public Context(List <Device> devices, ContextNotifyFunction notifyFunction = null, IntPtr userData = default) { if (devices != null && devices.Count > 0) { Devices = devices; IntPtr[] properties = new IntPtr[3]; properties[0] = new IntPtr((int)ContextProperty.Platform); properties[1] = devices[0].Platform.Handle; properties[2] = IntPtr.Zero; IntPtr[] deviceHandles = new IntPtr[devices.Count]; for (int i = 0; i < devices.Count; i++) { deviceHandles[i] = devices[i].Handle; } Handle = clCreateContext(properties, devices.Count, deviceHandles, notifyFunction, userData, out error); } else { error = ErrorCode.InvalidDevice; } }
private extern static IntPtr clCreateContextFromType( [MarshalAs(UnmanagedType.LPArray)] IntPtr[] properties, DeviceType device_type, ContextNotifyFunction pfn_notify, IntPtr user_data, out ErrorCode errcode_ret);