internal unsafe PlaneBoundaryCollection(MLPlaneBoundaries planeBoundaries, Pose planePose)
        {
            m_Boundaries = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <MLPlaneBoundary>(
                planeBoundaries.boundaries,
                (int)planeBoundaries.boundaries_count,
                Allocator.None);

            m_Pose = planePose;
        }
Ejemplo n.º 2
0
        unsafe void UpdateMesh(ImDrawDataPtr drawData, Vector2 fbSize)
        {
            int subMeshCount = 0; // nr of submeshes is the same as the nr of ImDrawCmd

            for (int n = 0, nMax = drawData.CmdListsCount; n < nMax; ++n)
            {
                subMeshCount += drawData.CmdListsRange[n].CmdBuffer.Size;
            }

            // set mesh structure
            if (_prevSubMeshCount != subMeshCount)
            {
                _mesh.Clear(true); // occasionally crashes when changing subMeshCount without clearing first
                _mesh.subMeshCount = _prevSubMeshCount = subMeshCount;
            }
            _mesh.SetVertexBufferParams(drawData.TotalVtxCount, s_attributes);
            _mesh.SetIndexBufferParams(drawData.TotalIdxCount, IndexFormat.UInt16);

            // upload data into mesh
            int vtxOf = 0;
            int idxOf = 0;
            int subOf = 0;

            for (int n = 0, nMax = drawData.CmdListsCount; n < nMax; ++n)
            {
                ImDrawListPtr            drawList = drawData.CmdListsRange[n];
                NativeArray <ImDrawVert> vtxArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <ImDrawVert>(
                    (void *)drawList.VtxBuffer.Data, drawList.VtxBuffer.Size, Allocator.None);
                NativeArray <ushort> idxArray = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <ushort>(
                    (void *)drawList.IdxBuffer.Data, drawList.IdxBuffer.Size, Allocator.None);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
                NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref vtxArray, AtomicSafetyHandle.GetTempMemoryHandle());
                NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref idxArray, AtomicSafetyHandle.GetTempMemoryHandle());
#endif
                // upload vertex/index data
                _mesh.SetVertexBufferData(vtxArray, 0, vtxOf, vtxArray.Length, 0, NoMeshChecks);
                _mesh.SetIndexBufferData(idxArray, 0, idxOf, idxArray.Length, NoMeshChecks);

                // define subMeshes
                for (int i = 0, iMax = drawList.CmdBuffer.Size; i < iMax; ++i)
                {
                    ImDrawCmdPtr cmd        = drawList.CmdBuffer[i];
                    var          descriptor = new SubMeshDescriptor
                    {
                        topology   = MeshTopology.Triangles,
                        indexStart = idxOf + (int)cmd.IdxOffset,
                        indexCount = (int)cmd.ElemCount,
                        baseVertex = vtxOf + (int)cmd.VtxOffset,
                    };
                    _mesh.SetSubMesh(subOf++, descriptor, NoMeshChecks);
                }
                vtxOf += vtxArray.Length;
                idxOf += idxArray.Length;
            }
            _mesh.UploadMeshData(false);
        }
Ejemplo n.º 3
0
        public unsafe NativeArray <T> GetSubArray(int start, int length)
        {
            this.CheckGetSubArrayArguments(start, length);
            NativeArray <T> result = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>((void *)((byte *)this.m_Buffer + (long)UnsafeUtility.SizeOf <T>() * (long)start), length, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle <T>(ref result, this.m_Safety);
            result.m_DisposeSentinel = null;
            return(result);
        }
Ejemplo n.º 4
0
        internal NativeArray <T> ToNativeArray()
        {
            var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(_pointer, Length, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, AtomicSafetyHandle.GetTempUnsafePtrSliceHandle());
#endif
            return(array);
        }
        public unsafe NativeArray <Entity> GetNativeArray(ArchetypeChunkEntityType archetypeChunkEntityType)
        {
            AtomicSafetyHandle.CheckReadAndThrow(archetypeChunkEntityType.m_Safety);
            int count = this.m_Chunk.Count;
            NativeArray <Entity> array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Entity>((void *)(&this.m_Chunk.Buffer.FixedElementField + this.m_Chunk.Archetype.Offsets[0]), count, Allocator.None);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle <Entity>(ref array, archetypeChunkEntityType.m_Safety);
            return(array);
        }
Ejemplo n.º 6
0
        public unsafe NativeArray <Matrix4x4> GetBatchMatrices(int batchIndex)
        {
            int   length                   = 0;
            void *batchMatrices            = this.GetBatchMatrices(batchIndex, out length);
            NativeArray <Matrix4x4> result = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Matrix4x4>(batchMatrices, length, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle <Matrix4x4>(ref result, this.GetMatricesSafetyHandle(batchIndex));
            return(result);
        }
    public NativeArray <T> AsArray()
    {
        var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(ptr, (int)(memoryMappedViewAccessor.Capacity / UnsafeUtility.SizeOf <T>()), Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
        NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, AtomicSafetyHandle.Create());
#endif
        return(array);
    }
Ejemplo n.º 8
0
        public unsafe NativeArray <Matrix4x4> GetBatchMatrixArray(int batchIndex, int propertyName)
        {
            int   length = 0;
            void *batchMatrixArray_Internal = this.GetBatchMatrixArray_Internal(batchIndex, propertyName, out length);
            NativeArray <Matrix4x4> result  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Matrix4x4>(batchMatrixArray_Internal, length, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle <Matrix4x4>(ref result, this.GetBatchArraySafetyHandle_Int(batchIndex, propertyName));
            return(result);
        }
        unsafe public NativeArray <Matrix4x4> GetBatchMatrices(int batchIndex)
        {
            int matricesCount = 0;
            var matrices      = GetBatchMatrices(batchIndex, out matricesCount);
            var arr           = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Matrix4x4>((void *)matrices, matricesCount, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref arr, GetMatricesSafetyHandle(batchIndex));
            return(arr);
        }
Ejemplo n.º 10
0
        public NativeArray <T> AsArray <T>() where T : unmanaged
        {
            var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(m_ListData->Ptr, m_ListData->Length, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, AtomicSafetyHandle.GetTempMemoryHandle());
#endif
            return(array);
        }
Ejemplo n.º 11
0
        public unsafe NativeArray <int> GetBatchVectorArrayInt(int batchIndex, string propertyName)
        {
            int               length           = 0;
            void *            batchVectorArray = this.GetBatchVectorArray(batchIndex, propertyName, out length);
            NativeArray <int> result           = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(batchVectorArray, length, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle <int>(ref result, this.GetBatchArraySafetyHandle(batchIndex, propertyName));
            return(result);
        }
        public unsafe NativeArray <T> GetFrameMetaData <T>(Guid id, int tag, int index) where T : struct
        {
            var stride = UnsafeUtility.SizeOf <T>();
            var data   = GetFrameMetaData(id.ToByteArray(), tag, index);
            var array  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(data.ptr.ToPointer(), data.size / stride, Allocator.None);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, GetSafetyHandle());
            return(array);
        }
Ejemplo n.º 13
0
        private NativeArray <U> InternalReinterpret <U>(int length) where U : struct
        {
            var result = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <U>(m_Buffer, length, m_AllocatorLabel);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref result, m_Safety);
            SetDisposeSentinel(ref result);
#endif
            return(result);
        }
Ejemplo n.º 14
0
        public unsafe ElementPool(void *userBuffer, int capacity)
        {
            m_Elements = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(userBuffer, capacity, Allocator.None);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref m_Elements, AtomicSafetyHandle.GetTempUnsafePtrSliceHandle());
#endif
            m_DisposeArray   = false;
            m_FirstFreeIndex = -1;
            PeakCount        = 0;
        }
Ejemplo n.º 15
0
        unsafe public NativeArray <Matrix4x4> GetBatchMatrixArray(int batchIndex, int propertyName)
        {
            int elementCount = 0;

            var elements = GetBatchMatrixArray_Internal(batchIndex, propertyName, out elementCount);
            var arr      = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Matrix4x4>((void *)elements, elementCount, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref arr, GetBatchArraySafetyHandle_Int(batchIndex, propertyName));
            return(arr);
        }
Ejemplo n.º 16
0
        public unsafe NativeArray <int> GetSharedValueIndicesBySharedIndex(int index)
        {
            int num  = 2 * this.m_Source.Length;
            int num3 = 3 * this.m_Source.Length;
            int num5 = this.m_SortedBuffer * this.m_Source.Length;
            NativeArray <int> arr = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks <int>(this.m_Buffer) + ((num5 + this.m_Buffer[num3 + index]) * 4), this.m_Buffer[num + index], Allocator.Invalid);

            this.SharedValueIndicesSetSafetyHandle(ref arr);
            return(arr);
        }
        unsafe private NativeArray <T> GetNativeDataArray <T>(SpriteShapeDataType dataType) where T : struct
        {
            RefreshSafetyHandle(dataType);

            var info  = GetDataInfo(dataType);
            var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(info.buffer, info.count, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, GetSafetyHandle(dataType));
            return(array);
        }
Ejemplo n.º 18
0
        unsafe public NativeArray <int> GetBatchVectorArrayInt(int batchIndex, string propertyName)
        {
            int elementCount = 0;

            var elements = GetBatchVectorArray(batchIndex, propertyName, out elementCount);
            var arr      = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>((void *)elements, elementCount, Allocator.Invalid);

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref arr, GetBatchArraySafetyHandle(batchIndex, propertyName));
            return(arr);
        }
        /// <summary>
        /// Indices into source NativeArray sorted by value
        /// </summary>
        /// <returns>Index NativeArray where each element refers to alement ini source NativeArray</returns>
        public unsafe NativeArray <int> GetSortedIndices()
        {
            int *rawIndices = ((int *)m_Buffer.GetUnsafeReadOnlyPtr()) + (m_SortedBuffer * m_Source.Length);
            var  arr        = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(rawIndices, m_Source.Length, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            SortedIndicesSetSafetyHandle(ref arr);
#endif
            return(arr);
        }
Ejemplo n.º 20
0
 public BatchCullingContext(NativeArray <Plane> inCullingPlanes, NativeArray <BatchVisibility> inOutBatchVisibility, NativeArray <int> outVisibleIndices, LODParameters inLodParameters, Matrix4x4 inCullingMatrix, float inNearPlane)
 {
     this.cullingPlanes   = inCullingPlanes;
     this.batchVisibility = inOutBatchVisibility;
     this.visibleIndices  = outVisibleIndices;
     this.visibleIndicesY = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(null, 0, Allocator.Invalid);
     this.lodParameters   = inLodParameters;
     this.cullingMatrix   = inCullingMatrix;
     this.nearPlane       = inNearPlane;
 }
Ejemplo n.º 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="chunkComponentType"></param>
        /// <param name="expectedTypeSize"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        public NativeArray <T> GetDynamicComponentDataArrayReinterpret <T>(ArchetypeChunkComponentTypeDynamic chunkComponentType, int expectedTypeSize)
            where T : struct
        {
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (chunkComponentType.m_IsZeroSized)
            {
                throw new ArgumentException($"ArchetypeChunk.GetDynamicComponentDataArrayReinterpret<{typeof(T)}> cannot be called on zero-sized IComponentData");
            }

            AtomicSafetyHandle.CheckReadAndThrow(chunkComponentType.m_Safety);
#endif
            var archetype            = m_Chunk->Archetype;
            int typeIndexInArchetype = chunkComponentType.m_TypeLookupCache;
            ChunkDataUtility.GetIndexInTypeArray(m_Chunk->Archetype, chunkComponentType.m_TypeIndex, ref typeIndexInArchetype);
            chunkComponentType.m_TypeLookupCache = (short)typeIndexInArchetype;
            if (typeIndexInArchetype == -1)
            {
                var emptyResult =
                    NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(null, 0, 0);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
                NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref emptyResult, chunkComponentType.m_Safety);
#endif
                return(emptyResult);
            }

            var typeSize    = archetype->SizeOfs[typeIndexInArchetype];
            var length      = m_Chunk->Count;
            var byteLen     = length * typeSize;
            var outTypeSize = UnsafeUtility.SizeOf <T>();
            var outLength   = byteLen / outTypeSize;

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            if (typeSize != expectedTypeSize)
            {
                throw new InvalidOperationException($"Dynamic chunk component type {TypeManager.GetType(chunkComponentType.m_TypeIndex)} (size = {typeSize}) size does not equal {expectedTypeSize}. Component size must match with expectedTypeSize.");
            }

            if (outTypeSize * outLength != byteLen)
            {
                throw new InvalidOperationException($"Dynamic chunk component type {TypeManager.GetType(chunkComponentType.m_TypeIndex)} (array length {length}) and {typeof(T)} cannot be aliased due to size constraints. The size of the types and lengths involved must line up.");
            }
#endif

            var buffer      = m_Chunk->Buffer;
            var startOffset = archetype->Offsets[typeIndexInArchetype];
            var result      = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(buffer + startOffset, outLength, Allocator.None);
#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref result, chunkComponentType.m_Safety);
#endif
            if (!chunkComponentType.IsReadOnly)
            {
                m_Chunk->SetChangeVersion(typeIndexInArchetype, chunkComponentType.GlobalSystemVersion);
            }
            return(result);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Get all the available <see cref="ARCoreFaceRegion"/>s.
        /// </summary>
        /// <param name="trackableId">The id associated with the face to query.</param>
        /// <param name="allocator">The allocator to use if <paramref name="regions"/> requires a resize. C# Jobs are used, so the allocator
        /// must be either <c>Allocator.TempJob</c> or <c>Allocator.Persistent</c>.</param>
        /// <param name="regions">An array of <see cref="ARCoreFaceRegionData"/>s. If <paramref name="regions"/> is allocated
        /// and the correct size, then its memory is reused. Otherwise, it is reallocated.</param>
        /// <exception cref="System.InvalidOperationException">Thrown if <paramref name="allocator"/> is <c>Allocator.Temp</c>.</exception>
        /// <exception cref="System.InvalidOperationException">Thrown if <paramref name="allocator"/> is <c>Allocator.None</c>.</exception>
        public unsafe void GetRegionPoses(
            TrackableId trackableId,
            Allocator allocator,
            ref NativeArray <ARCoreFaceRegionData> regions)
        {
            if (allocator == Allocator.Temp)
            {
                throw new InvalidOperationException("Allocator.Temp is not supported. Use Allocator.TempJob if you wish to use a temporary allocator.");
            }

            if (allocator == Allocator.None)
            {
                throw new InvalidOperationException("Allocator.None is not a valid allocator.");
            }

            int count;
            var regionPtr = UnityARCore_faceTracking_acquireRegions(trackableId, out count);

            if (regionPtr == null)
            {
                if (regions.IsCreated)
                {
                    regions.Dispose();
                }
                regions = default(NativeArray <ARCoreFaceRegionData>);
                return;
            }

            try
            {
                // Resize regions if necessary
                if (regions.IsCreated)
                {
                    if (regions.Length != count)
                    {
                        regions.Dispose();
                        regions = new NativeArray <ARCoreFaceRegionData>(count, allocator);
                    }
                }
                else
                {
                    regions = new NativeArray <ARCoreFaceRegionData>(count, allocator);
                }

                new TransformPoseJob
                {
                    regionsIn  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <FaceRegionWithARCorePose>(regionPtr, count, Allocator.None),
                    regionsOut = regions
                }.Schedule(count, 1).Complete();
            }
            finally
            {
                UnityARCore_faceTracking_deallocateTemp(regionPtr);
            }
        }
Ejemplo n.º 23
0
            public unsafe override void GetFaceMesh(
                TrackableId faceId,
                Allocator allocator,
                ref XRFaceMesh faceMesh)
            {
                int   vertexCount, triangleCount;
                void *vertexPtr, normalPtr, indexPtr, uvPtr;

                if (!UnityARCore_faceTracking_TryGetFaceData(
                        faceId,
                        out vertexPtr, out normalPtr, out uvPtr, out vertexCount,
                        out indexPtr, out triangleCount))
                {
                    faceMesh.Dispose();
                    faceMesh = default(XRFaceMesh);
                    return;
                }

                faceMesh.Resize(
                    vertexCount,
                    triangleCount,
                    XRFaceMesh.Attributes.Normals | XRFaceMesh.Attributes.UVs,
                    allocator);

                var vertexJobHandle = new TransformVerticesJob
                {
                    verticesIn  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Vector3>(vertexPtr, vertexCount, Allocator.None),
                    verticesOut = faceMesh.vertices
                }.Schedule(vertexCount, 32);

                var normalJobHandle = new TransformVerticesJob
                {
                    verticesIn  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Vector3>(normalPtr, vertexCount, Allocator.None),
                    verticesOut = faceMesh.normals
                }.Schedule(vertexCount, 32);

                var uvJobHandle = new TransformUVsJob
                {
                    uvsIn  = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Vector2>(uvPtr, vertexCount, Allocator.None),
                    uvsOut = faceMesh.uvs
                }.Schedule(vertexCount, 32);

                var indexJobHandle = new TransformIndicesJob
                {
                    triangleIndicesIn = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Triangle <ushort> >(indexPtr, triangleCount, Allocator.None),
                    // "cast" it to an array of Triangles
                    triangleIndicesOut = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <Triangle <int> >(faceMesh.indices.GetUnsafePtr(), triangleCount, Allocator.None)
                }.Schedule(triangleCount, 32);

                // Wait on all four
                JobHandle.CombineDependencies(
                    JobHandle.CombineDependencies(vertexJobHandle, normalJobHandle),
                    indexJobHandle, uvJobHandle).Complete();
            }
Ejemplo n.º 24
0
        public void CopyFrom(NativeArray <T> v)
        {
            ResizeUninitialized(v.Length);

            var shadow = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(GetBasePointer(), Length, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref shadow, m_Safety);
#endif
            shadow.CopyFrom(v);
        }
        /// <summary>
        ///     Array of number of occurrences of all shared values.
        ///     For example, given source array: [A,A,A,B,B,C,C,A,B]
        ///     shared values are: [A,B,C]
        ///     Shared value counts: [4,3,2] (number of occurrences of a shared value)
        /// </summary>
        /// <returns>Count NativeArray where each element refers to the number of occurrences of each shared value.</returns>
        public unsafe NativeArray <int> GetSharedValueIndexCountArray()
        {
            // Capacity cannot be changed, so offset is valid.
            var rawIndices = (int *)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(m_WorkingBuffer) + 2 * m_SourceBuffer.Length;
            var arr        = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(rawIndices, SharedValueCount, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            SharedValueIndexCountArraySetSafetyHandle(ref arr);
#endif
            return(arr);
        }
        public unsafe NativeArray <int> GetSharedIndexArray()
        {
            // Capacity cannot be changed, so offset is valid.
            int *rawIndices = (int *)NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks(m_Buffer) + ((m_SortedBuffer ^ 1) * m_Source.Length);
            var  arr        = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <int>(rawIndices, m_Source.Length, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            SharedIndexArraySetSafetyHandle(ref arr);
#endif
            return(arr);
        }
Ejemplo n.º 27
0
        unsafe public static NativeArray <byte> ToArray(void *dataPointer, int length)
        {
            unsafe {
                var array = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <byte>(dataPointer, length, Allocator.Persistent);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
                NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref array, AtomicSafetyHandle.Create());
#endif
                return(array);
            }
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Return a native array that aliases the buffer contents. The array is only legal to access as long as the buffer is not reallocated.
        /// </summary>
        public NativeArray <T> ToNativeArray()
        {
            var shadow = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(GetBasePointer(), Length, Allocator.Invalid);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            var handle = m_ArrayInvalidationSafety;
            AtomicSafetyHandle.UseSecondaryVersion(ref handle);
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref shadow, handle);
#endif
            return(shadow);
        }
Ejemplo n.º 29
0
        public unsafe static NativeArray <byte> EncodeNativeArrayToPNG <T>(NativeArray <T> input, GraphicsFormat format, uint width, uint height, uint rowBytes = 0u) where T : struct
        {
            int   length                          = input.Length * UnsafeUtility.SizeOf <T>();
            void *dataPointer                     = ImageConversion.UnsafeEncodeNativeArrayToPNG(NativeArrayUnsafeUtility.GetUnsafeBufferPointerWithoutChecks <T>(input), ref length, format, width, height, rowBytes);
            NativeArray <byte> result             = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <byte>(dataPointer, length, Allocator.Persistent);
            AtomicSafetyHandle atomicSafetyHandle = AtomicSafetyHandle.Create();

            NativeArrayUnsafeUtility.SetAtomicSafetyHandle <byte>(ref result, atomicSafetyHandle);
            AtomicSafetyHandle.SetAllowReadOrWriteAccess(atomicSafetyHandle, true);
            return(result);
        }
Ejemplo n.º 30
0
        public ElementEnumerable <T> GetElements <T>() where T : unmanaged, IPoolElement
        {
            NativeArray <T> slice = NativeArrayUnsafeUtility.ConvertExistingDataToNativeArray <T>(m_Elements, PeakCount, Allocator.None);

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            NativeArrayUnsafeUtility.SetAtomicSafetyHandle(ref slice, AtomicSafetyHandle.GetTempUnsafePtrSliceHandle());
#endif
            return(new ElementEnumerable <T> {
                Slice = slice
            });
        }