Esempio n. 1
0
        public static ComputeBuffer GetTempPropertyBuffer(int length, int stride, ComputeBufferType type = ComputeBufferType.Default)
        {
            if (!allTempBuffers.isCreated)
            {
                allTempBuffers = new NativeDictionary <BufferKey, int, BufferKey.Equal>(11, Allocator.Persistent, new BufferKey.Equal());
            }
            ComputeBuffer target;
            int           targetIndex;

            if (allTempBuffers.Get(new BufferKey {
                size = stride, type = type
            }, out targetIndex))
            {
                target = MUnsafeUtility.GetHookedObject(targetIndex) as ComputeBuffer;
                if (target.count < length)
                {
                    target.Dispose();
                    target = new ComputeBuffer(length, stride, type);
                    MUnsafeUtility.SetHookedObject(targetIndex, target);
                }
                return(target);
            }
            else
            {
                target            = new ComputeBuffer(length, stride);
                allTempBuffers[new BufferKey {
                                   size = stride, type = type
                               }] = MUnsafeUtility.HookObject(target);
                return(target);
            }
        }