Esempio n. 1
0
        public bool Setup(G2OM_ContextCreateOptions options)
        {
            var result = Interop.G2OM_ContextCreateEx(out _context, ref options);

            if (result == G2OM_Error.Ok)
            {
                Debug.Log("Created G2OM context.");
                return(true);
            }

            Debug.LogError("Failed to create G2OM context. Error code " + result);
            return(false);
        }
        public static G2OM_ContextCreateOptions G2OM_InitializeOptions()
        {
            var internalOptions = new G2OM_Internal_ContextCreateOptions();
            var options         = new G2OM_ContextCreateOptions();

            var result = G2OM_InitializeOptions(ref internalOptions);

            if (result == G2OM_Error.Ok) // What to do if this fails?
            {
                options.capacity     = internalOptions.capacity;
                options.thread_count = internalOptions.thread_count;
            }

            return(options);
        }
        public static G2OM_Error G2OM_ContextCreateEx(out IntPtr context, ref G2OM_ContextCreateOptions options)
        {
            var has_license     = !string.IsNullOrEmpty(options.license_content);
            var internalOptions = new G2OM_Internal_ContextCreateOptions();
            var license         = has_license ? options.license_content : "";

            var bytes = has_license ? Encoding.UTF8.GetBytes(options.license_content) : new byte[0];
            var ptr   = Marshal.AllocHGlobal(license.Length);

            Marshal.Copy(bytes, 0, ptr, bytes.Length);

            internalOptions.capacity       = options.capacity;
            internalOptions.license_length = (uint)license.Length;
            internalOptions.thread_count   = options.thread_count;
            internalOptions.license_ptr    = has_license ? ptr : IntPtr.Zero;

            var result = G2OM_ContextCreateEx(out context, ref internalOptions);

            Marshal.FreeHGlobal(ptr);

            return(result);
        }