/// <summary> /// Gets blittable values. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="key"></param> /// <returns></returns> public T[] GetValues <T>(ValueParameterKey <T> key) where T : struct { var parameter = GetAccessor(key); var data = GetValuePointer(parameter); // Align to float4 var stride = (Utilities.SizeOf <T>() + 15) / 16 * 16; var values = new T[parameter.Count]; for (int i = 0; i < values.Length; ++i) { Utilities.Read(data, ref values[i]); data += stride; } return(values); }
public override void Serialize(ref ValueParameterKey <T> obj, ArchiveMode mode, SerializationStream stream) { if (mode == ArchiveMode.Serialize) { stream.Write(obj.Name); stream.Write(obj.Length); } else { var parameterName = stream.ReadString(); var parameterLength = stream.ReadInt32(); obj = (ValueParameterKey <T>)ParameterKeys.FindByName(parameterName); // If parameter could not be found, create one matching this type. if (obj == null) { var metadata = new ParameterKeyValueMetadata <T>(); obj = new ValueParameterKey <T>(parameterName, parameterLength, metadata); ParameterKeys.Merge(obj, null, parameterName); } } }
/// <summary> /// Gets a blittable value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameter"></param> /// <returns></returns> public T Get <T>(ValueParameterKey <T> parameter) where T : struct { return(Get(GetAccessor(parameter))); }
/// <summary> /// Sets blittable values. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameter"></param> /// <param name="values"></param> public void Set <T>(ValueParameterKey <T> parameter, int count, ref T firstValue) where T : struct { Set(GetAccessor(parameter, count), count, ref firstValue); }
/// <summary> /// Sets blittable values. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameter"></param> /// <param name="values"></param> public void Set <T>(ValueParameterKey <T> parameter, T[] values) where T : struct { Set(GetAccessor(parameter, values.Length), values.Length, ref values[0]); }
/// <summary> /// Sets a blittable value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameter"></param> /// <param name="value"></param> public void Set <T>(ValueParameterKey <T> parameter, ref T value) where T : struct { Set(GetAccessor(parameter), ref value); }
/// <summary> /// Gets an accessor to get and set blittable values more quickly. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="parameterKey"></param> /// <returns></returns> public ValueParameter <T> GetAccessor <T>(ValueParameterKey <T> parameterKey, int elementCount = 1) where T : struct { var accessor = GetValueAccessorHelper(parameterKey, elementCount); return(new ValueParameter <T>(accessor.Offset, accessor.Count)); }