Esempio n. 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));
        }