Beispiel #1
0
        public static Context CreateContext(Platform platform, Device[] devices, ContextNotify callback, object userData)
        {
            var pty = platform != null ? new ContextProperty[] { new ContextProperty(ContextProperties.Platform, platform.handle), ContextProperty.Zero } : null;
            var num = devices.Length;
            var dev = new IntPtr[num];

            for (var i = 0; i < num; i++)
            {
                dev[i] = devices[i].handle;
            }
            var pfn = (ContextNotifyData)null;
            var pcb = (ContextNotifyInternal)null;
            var ptr = IntPtr.Zero;

            if (callback != null)
            {
                pfn = new ContextNotifyData(callback, userData);
                pcb = ContextNotifyData.Callback;
                ptr = pfn.Handle;
            }
            var err = ErrorCode.Success;
            var ctx = NativeMethods.clCreateContext(pty, (uint)num, dev, pcb, ptr, out err);

            if (err != ErrorCode.Success)
            {
                throw new OpenClException(err);
            }
            return(new Context(ctx, pfn));
        }
Beispiel #2
0
 protected override void Dispose(bool disposing)
 {
     if (!disposed)
     {
         if (disposing && this.callback != null)
         {
             this.callback.Dispose();
         }
         this.callback = null;
         this.disposed = true;
     }
     base.Dispose(disposing);
 }
Beispiel #3
0
        public static Context CreateContextFromType(Platform platform, DeviceType type, ContextNotify callback, object userData)
        {
            var pty = platform != null ? new ContextProperty[] { new ContextProperty(ContextProperties.Platform, platform.handle), ContextProperty.Zero } : null;
            var pfn = (ContextNotifyData)null;
            var pcb = (ContextNotifyInternal)null;
            var ptr = IntPtr.Zero;

            if (callback != null)
            {
                pfn = new ContextNotifyData(callback, userData);
                pcb = ContextNotifyData.Callback;
                ptr = pfn.Handle;
            }
            var err = ErrorCode.Success;
            var ctx = NativeMethods.clCreateContextFromType(pty, type, pcb, ptr, out err);

            if (err != ErrorCode.Success)
            {
                throw new OpenClException(err);
            }
            return(new Context(ctx, pfn));
        }
Beispiel #4
0
 internal Context(IntPtr handle, ContextNotifyData cb) : base(handle)
 {
     this.callback = cb;
 }