Cloo 0.9.1

- Main Page
- Packages
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Properties
Cloo.ComputeContext Class Reference

Represents an OpenCL context. More...

Inheritance diagram for Cloo.ComputeContext:

List of all members.

## Public Member Functions
| ComputeContext (ICollection< ComputeDevice > devices, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr notifyDataPtr)
| Creates a new ComputeContext on a collection of ComputeDevices.
| ComputeContext (ComputeDeviceTypes deviceType, ComputeContextPropertyList properties, ComputeContextNotifier notify, IntPtr userDataPtr)
| Creates a new ComputeContext on all the ComputeDevices that match the specified ComputeDeviceTypes.
## Protected Member Functions
override void | Dispose (bool manual)
| Releases the associated OpenCL object.
## Properties
CLContextHandle | Handle`[get, set]`
| The handle of the ComputeContext.
ReadOnlyCollection< ComputeDevice > | Devices`[get]`
| Gets a read-only collection of the ComputeDevices of the ComputeContext.
ComputePlatform | Platform`[get]`
| Gets the ComputePlatform of the ComputeContext.
ComputeContextPropertyList | Properties`[get]`
| Gets a collection of ComputeContextPropertys of the ComputeContext.

## Detailed Description

Represents an OpenCL context.

The environment within which the kernels execute and the domain in which synchronization and memory management is defined.
This example shows how to create a ComputeContext that is able to share data with an OpenGL context in a Microsoft Windows OS:

            <![CDATA[

            // NOTE: If you see some non C# bits surrounding this code section, ignore them. They're not part of the code.

            // We will need the device context, which is obtained through an OS specific function.
            [DllImport("opengl32.dll")]
            extern static IntPtr wglGetCurrentDC();

            // Query the device context.
            IntPtr deviceContextHandle = wglGetCurrentDC();

            // Select a platform which is capable of OpenCL/OpenGL interop.
            ComputePlatform platform = ComputePlatform.GetByName(name);

            // Create the context property list and populate it.
            ComputeContextProperty p1 = new ComputeContextProperty(ComputeContextPropertyName.Platform, platform.Handle.Value);
            ComputeContextProperty p2 = new ComputeContextProperty(ComputeContextPropertyName.CL_GL_CONTEXT_KHR, openGLContextHandle);
            ComputeContextProperty p3 = new ComputeContextProperty(ComputeContextPropertyName.CL_WGL_HDC_KHR, deviceContextHandle);
            ComputeContextPropertyList cpl = new ComputeContextPropertyList(new ComputeContextProperty[] { p1, p2, p3 });

            // Create the context. Usually, you'll want this on a GPU but other options might be available as well.
            ComputeContext context = new ComputeContext(ComputeDeviceTypes.Gpu, cpl, null, IntPtr.Zero);

            // Create a shared OpenCL/OpenGL buffer.
            // The generic type should match the type of data that the buffer contains.
            // glBufferId is an existing OpenGL buffer identifier.
            ComputeBuffer<float> clglBuffer = ComputeBuffer.CreateFromGLBuffer<float>(context, ComputeMemoryFlags.ReadWrite, glBufferId);

            ]]>

Before working with the `clglBuffer` you should make sure of two things:
1) OpenGL isn't using `glBufferId`. You can achieve this by calling `glFinish`.
2) Make it available to OpenCL through the ComputeCommandQueue.AcquireGLObjects method.
When finished, you should wait until `clglBuffer` isn't used any longer by OpenCL. After that, call ComputeCommandQueue.ReleaseGLObjects to make the buffer available to OpenGL again.

See also:
  ComputeDevice, ComputePlatform

## Constructor & Destructor Documentation

Cloo.ComputeContext.ComputeContext | ( | ICollection< ComputeDevice > | devices,
|  | ComputeContextPropertyList | properties,
|  | ComputeContextNotifier | notify,
|  | IntPtr | notifyDataPtr
| ) |  |

Creates a new ComputeContext on a collection of ComputeDevices.

Parameters:

  devices | A collection of ComputeDevices to associate with the ComputeContext.
  properties | A ComputeContextPropertyList of the ComputeContext.
  notify | A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the ComputeContext. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until ComputeContext is disposed. If notify is `null`, no callback function is registered.
  notifyDataPtr | Optional user data that will be passed to notify .

Cloo.ComputeContext.ComputeContext | ( | ComputeDeviceTypes | deviceType,
|  | ComputeContextPropertyList | properties,
|  | ComputeContextNotifier | notify,
|  | IntPtr | userDataPtr
| ) |  |

Creates a new ComputeContext on all the ComputeDevices that match the specified ComputeDeviceTypes.

Parameters:

  deviceType | A bit-field that identifies the type of ComputeDevice to associate with the ComputeContext.
  properties | A ComputeContextPropertyList of the ComputeContext.
  notify | A delegate instance that refers to a notification routine. This routine is a callback function that will be used by the OpenCL implementation to report information on errors that occur in the ComputeContext. The callback function may be called asynchronously by the OpenCL implementation. It is the application's responsibility to ensure that the callback function is thread-safe and that the delegate instance doesn't get collected by the Garbage Collector until ComputeContext is disposed. If notify is `null`, no callback function is registered.
  userDataPtr | Optional user data that will be passed to notify .

## Member Function Documentation

override void Cloo.ComputeContext.Dispose | ( | bool | manual | ) | `[protected, virtual]`

Releases the associated OpenCL object.

Parameters:

  manual | Specifies the operation mode of this method.

manual must be `true` if this method is invoked directly by the application.

Implements Cloo.ComputeResource.

## Property Documentation

ReadOnlyCollection<ComputeDevice> Cloo.ComputeContext.Devices`[get]`

Gets a read-only collection of the ComputeDevices of the ComputeContext.

A read-only collection of the ComputeDevices of the ComputeContext.

CLContextHandle Cloo.ComputeContext.Handle`[get, set]`

The handle of the ComputeContext.

ComputePlatform Cloo.ComputeContext.Platform`[get]`

Gets the ComputePlatform of the ComputeContext.

The ComputePlatform of the ComputeContext.

ComputeContextPropertyList Cloo.ComputeContext.Properties`[get]`

Gets a collection of ComputeContextPropertys of the ComputeContext.

A collection of ComputeContextPropertys of the ComputeContext.

The documentation for this class was generated from the following file:

- Cloo/Source/ComputeContext.cs