Пример #1
0
        public unsafe T[] ToArray()
        {
            var result = new T[Count];

            fixed(T *pResult = result)
            NativeUtility.CopyMemory(pResult, Data, Count * sizeof(T));

            return(result);
        }
Пример #2
0
        public static MemoryBlock AllocateAutoReleaseMemoryBlock(IntPtr data, int size)
        {
            var buffer = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Renderer, size);

            NativeUtility.CopyMemory(buffer, data, size);

            var memory = MemoryBlock.MakeRef(buffer, size, buffer, ReleaseHandleCallback);

            return(memory);
        }
Пример #3
0
        public unsafe static MemoryBlock AllocateAutoReleaseMemoryBlock <T>(ArraySegment <T> data) where T : unmanaged
        {
            var size = data.Count * sizeof(T);

            var buffer = NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Renderer, size);

            fixed(T *p = data.Array)
            NativeUtility.CopyMemory(buffer, (IntPtr)(p + data.Offset), size);

            var memory = MemoryBlock.MakeRef(buffer, size, buffer, ReleaseHandleCallback);

            return(memory);
        }
Пример #4
0
            public Image2D(PixelFormat format, Vector2I size, IntPtr data)
            {
                this.format = format;
                this.size   = size;

                this.data = new byte[SizeInBytes];
                if (data != IntPtr.Zero)
                {
                    unsafe
                    {
                        fixed(byte *pData = this.data)
                        NativeUtility.CopyMemory((IntPtr)pData, data, SizeInBytes);
                    }
                }
            }
Пример #5
0
        public unsafe void Add(ref T item)
        {
            if (Count == DataLength)
            {
                T * oldData   = Data;
                int oldLength = DataLength;

                DataLength = oldLength != 0 ? oldLength * 2 : 4;
                Data       = (T *)NativeUtility.Alloc(NativeUtility.MemoryAllocationType.Utility, DataLength * sizeof(T));
                NativeUtility.CopyMemory(Data, oldData, Count * sizeof(T));

                NativeUtility.Free(oldData);
            }
            Data[Count++] = item;
        }
Пример #6
0
        public void Write(IntPtr vertices, int vertexCount)
        {
            if (!(Flags.HasFlag(GpuBufferFlags.Dynamic) || (realObject == null && !Flags.HasFlag(GpuBufferFlags.Dynamic) && !Flags.HasFlag(GpuBufferFlags.ComputeWrite))))
            {
                Log.Fatal("GpuVertexBuffer: Write: The buffer must be dynamic or must be still not be created on GPU.");
            }
            if (vertexCount > this.vertexCount)
            {
                Log.Fatal("GpuIndexBuffer: Write: vertexCount > this.vertexCount.");
            }
            ////change type to dynamic
            //if( !dynamic && realObject != null )
            //	dynamic = true;

            unsafe
            {
                fixed(byte *pVertices = this.vertices)
                NativeUtility.CopyMemory((IntPtr)pVertices, vertices, vertexCount * vertexSize);
            }
            vertexCountActual        = vertexCount;
            dynamic_needUpdateNative = true;
        }
Пример #7
0
        public void Set(string name, ParameterType type, int elementCount, IntPtr value, int checkTotalSizeInBytes)
        {
            if (NamedParameters == null)
            {
                NamedParameters = new Dictionary <string, NamedParameter>(32);
            }

            if (string.IsNullOrEmpty(name))
            {
                Log.Fatal("ParameterContainer: Set: Name can't be empty.");
            }
            if (!ParameterTypeUtility.CanConvertToByteArray(type))
            {
                Log.Fatal("ParameterContainer: Set: !ParameterTypeUtils.CanConvertToByteArray( type )");
            }

            //ParameterItem parameter = null;

            ////use current parameter or new depending format
            //{
            //	ParameterItem currentItem;
            //	if( parameters.TryGetValue( name, out currentItem ) )
            //	{
            //		if( type == currentItem.type && elementCount == currentItem.elementCount )
            //		{
            //			//!!!!!так?
            //			parameter = currentItem;
            //		}
            //		else
            //			Remove( name );
            //	}
            //}

            ////create parameter
            //if( parameter == null )
            //{
            //	parameter = new ParameterItem();
            //	parameter.container = this;
            //	parameter.name = name;
            //	parameter.type = type;
            //	parameter.elementCount = elementCount;
            //	parameters[ name ] = parameter;
            //}

            var parameter = new NamedParameter();

            parameter.Type         = type;
            parameter.ElementCount = elementCount;

            if (parameter.GetTotalSizeInBytes() != checkTotalSizeInBytes)
            {
                Log.Fatal("ParameterContainer: Set: parameter.GetValueSizeInBytes() != checkTotalSizeInBytes.");
            }

            //prepare data array
            //if( parameter.valueDataPosition == -1 )
            {
                int needSize = dataUsedBytes + parameter.GetTotalSizeInBytes();

                if (data == null)
                {
                    data = new byte[256];
                }

                if (needSize > data.Length)
                {
                    int newSize = data.Length * 2;
                    while (newSize < needSize)
                    {
                        newSize *= 2;
                    }
                    byte[] newData = new byte[newSize];
                    Buffer.BlockCopy(data, 0, newData, 0, dataUsedBytes);
                    data = newData;
                }

                parameter.ValueDataPosition = dataUsedBytes;
                dataUsedBytes += parameter.GetTotalSizeInBytes();
            }

            //copy value
            unsafe
            {
                fixed(byte *pData = data)
                NativeUtility.CopyMemory((IntPtr)(pData + parameter.ValueDataPosition), (IntPtr)value, parameter.GetTotalSizeInBytes());
            }

            if (NamedParameters == null)
            {
                NamedParameters = new Dictionary <string, NamedParameter>(32);
            }
            NamedParameters[name] = parameter;

            unchecked
            {
                version++;
            }

            //return parameter;
        }