/// <summary> /// Converts Unity vertex attribute format to glTF component type. /// </summary> /// <param name="format">vertex attribute format</param> /// <returns>glTF component type</returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static GLTFComponentType GetComponentType(VertexAttributeFormat format) { switch (format) { case VertexAttributeFormat.Float32: case VertexAttributeFormat.Float16: return(GLTFComponentType.Float); case VertexAttributeFormat.UNorm8: case VertexAttributeFormat.UInt8: return(GLTFComponentType.UnsignedByte); case VertexAttributeFormat.SNorm8: case VertexAttributeFormat.SInt8: return(GLTFComponentType.Byte); case VertexAttributeFormat.UNorm16: case VertexAttributeFormat.UInt16: return(GLTFComponentType.UnsignedShort); case VertexAttributeFormat.SNorm16: case VertexAttributeFormat.SInt16: return(GLTFComponentType.Short); case VertexAttributeFormat.UInt32: case VertexAttributeFormat.SInt32: return(GLTFComponentType.UnsignedInt); default: throw new ArgumentOutOfRangeException(nameof(format), format, null); } }
public AttributeMapBase(VertexAttribute attribute, VertexAttributeFormat format) { this.attribute = attribute; this.format = format; offset = 0; stream = 0; }
static DataType GetDataType(VertexAttributeFormat format) { switch (format) { case VertexAttributeFormat.Float32: case VertexAttributeFormat.Float16: return(DataType.DT_FLOAT32); case VertexAttributeFormat.UNorm8: case VertexAttributeFormat.UInt8: return(DataType.DT_UINT8); case VertexAttributeFormat.SNorm8: case VertexAttributeFormat.SInt8: return(DataType.DT_INT8); case VertexAttributeFormat.UInt16: case VertexAttributeFormat.UNorm16: return(DataType.DT_UINT16); case VertexAttributeFormat.SInt16: case VertexAttributeFormat.SNorm16: return(DataType.DT_INT16); case VertexAttributeFormat.UInt32: case VertexAttributeFormat.SInt32: return(DataType.DT_INT32); default: throw new ArgumentOutOfRangeException(nameof(format), format, null); } }
private void SetSizedArrayForChannel(VertexAttribute channel, VertexAttributeFormat format, int dim, System.Array values, int valuesArrayLength, int valuesStart, int valuesCount) { if (canAccess) { if (valuesStart < 0) { throw new ArgumentOutOfRangeException(nameof(valuesStart), valuesStart, "Mesh data array start index can't be negative."); } if (valuesCount < 0) { throw new ArgumentOutOfRangeException(nameof(valuesCount), valuesCount, "Mesh data array length can't be negative."); } if (valuesStart >= valuesArrayLength && valuesCount != 0) { throw new ArgumentOutOfRangeException(nameof(valuesStart), valuesStart, "Mesh data array start is outside of array size."); } if (valuesStart + valuesCount > valuesArrayLength) { throw new ArgumentOutOfRangeException(nameof(valuesCount), valuesStart + valuesCount, "Mesh data array start+count is outside of array size."); } if (values == null) { valuesStart = 0; } SetArrayForChannelImpl(channel, format, dim, values, valuesArrayLength, valuesStart, valuesCount); } else { PrintErrorCantAccessChannel(channel); } }
static int ConvertFormatToSize(VertexAttributeFormat format) { switch (format) { case VertexAttributeFormat.Float32: case VertexAttributeFormat.UInt32: case VertexAttributeFormat.SInt32: return(4); case VertexAttributeFormat.Float16: case VertexAttributeFormat.UNorm16: case VertexAttributeFormat.SNorm16: case VertexAttributeFormat.UInt16: case VertexAttributeFormat.SInt16: return(2); case VertexAttributeFormat.UNorm8: case VertexAttributeFormat.SNorm8: case VertexAttributeFormat.UInt8: case VertexAttributeFormat.SInt8: return(1); default: throw new ArgumentOutOfRangeException(nameof(format), format, $"Unknown vertex format {format}"); } }
public static bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension) { if (!IsValidEnumValue(format)) { throw new ArgumentException("Failed SupportsVertexAttributeFormat; format is not a valid VertexAttributeFormat"); } if (dimension < 1 || dimension > 4) { throw new ArgumentException("Failed SupportsVertexAttributeFormat; dimension must be in 1..4 range"); } return(SupportsVertexAttributeFormatNative(format, dimension)); }
public static VertexAttribPointerType ToOpenGlAttribType(this VertexAttributeFormat att) { switch (att) { case VertexAttributeFormat.Float32: return(VertexAttribPointerType.Float); case VertexAttributeFormat.Int32: return(VertexAttribPointerType.Int); } throw new NotImplementedException(); }
public static int ByteSize(this VertexAttributeFormat att) { switch (att) { case VertexAttributeFormat.Float32: return(sizeof(float)); case VertexAttributeFormat.Int32: return(sizeof(int)); } throw new NotImplementedException(); }
private T[] GetAllocArrayFromChannel <T>(VertexAttribute channel, VertexAttributeFormat format, int dim) { if (canAccess) { if (HasVertexAttribute(channel)) { return((T[])GetAllocArrayFromChannelImpl(channel, format, dim)); } } else { PrintErrorCantAccessChannel(channel); } return(new T[0]); }
public static bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension) { bool flag = !EditorSystemInfo.IsValidEnumValue(format); if (flag) { throw new ArgumentException("Failed SupportsVertexAttributeFormat; format is not a valid VertexAttributeFormat"); } bool flag2 = dimension < 1 || dimension > 4; if (flag2) { throw new ArgumentException("Failed SupportsVertexAttributeFormat; dimension must be in 1..4 range"); } return(EditorSystemInfo.SupportsVertexAttributeFormatNative(format, dimension)); }
static unsafe int GetAttributeSize(VertexAttributeFormat format) { switch (format) { case VertexAttributeFormat.Float32: return(sizeof(float)); case VertexAttributeFormat.Float16: return(sizeof(half)); case VertexAttributeFormat.UNorm8: return(sizeof(byte)); case VertexAttributeFormat.SNorm8: return(sizeof(sbyte)); case VertexAttributeFormat.UNorm16: return(sizeof(ushort)); case VertexAttributeFormat.SNorm16: return(sizeof(short)); case VertexAttributeFormat.UInt8: return(sizeof(byte)); case VertexAttributeFormat.SInt8: return(sizeof(sbyte)); case VertexAttributeFormat.UInt16: return(sizeof(ushort)); case VertexAttributeFormat.SInt16: return(sizeof(short)); case VertexAttributeFormat.UInt32: return(sizeof(uint)); case VertexAttributeFormat.SInt32: return(sizeof(int)); default: throw new ArgumentOutOfRangeException(nameof(format), format, null); } }
public DefaultVertexFormatDescriptor() { AttributeFormats = new Dictionary <string, VertexAttributeFormat>(); AttributeFormats["aPosition"] = new VertexAttributeFormat() { ComponentCount = 3, ComponentType = WebGLType.FLOAT, IsNormalized = false, Stride = 40, Offset = 0 }; AttributeFormats["aTexture"] = new VertexAttributeFormat() { ComponentCount = 2, ComponentType = WebGLType.FLOAT, IsNormalized = false, Stride = 40, Offset = 12 }; AttributeFormats["aColor"] = new VertexAttributeFormat() { ComponentCount = 4, ComponentType = WebGLType.FLOAT, IsNormalized = false, Stride = 40, Offset = 20 }; AttributeFormats["aSamplerIndex"] = new VertexAttributeFormat() { ComponentCount = 1, ComponentType = WebGLType.FLOAT, IsNormalized = false, Stride = 40, Offset = 36 }; }
private static int GetByteSize(VertexAttributeFormat format) { switch (format) { case VertexAttributeFormat.Float32: case VertexAttributeFormat.UInt32: case VertexAttributeFormat.SInt32: return(4); case VertexAttributeFormat.Float16: case VertexAttributeFormat.UNorm16: case VertexAttributeFormat.SNorm16: case VertexAttributeFormat.UInt16: case VertexAttributeFormat.SInt16: return(2); case VertexAttributeFormat.UNorm8: case VertexAttributeFormat.SNorm8: case VertexAttributeFormat.UInt8: case VertexAttributeFormat.SInt8: return(1); } throw new System.IndexOutOfRangeException(); }
public override bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension) { return(base.SupportsVertexAttributeFormat(format, dimension)); }
public AttributeMap(DracoAttribute *dracoAttribute, VertexAttribute attribute, VertexAttributeFormat format, bool convertSpace) : base(attribute, format) { this.dracoAttribute = dracoAttribute; this.convertSpace = convertSpace; }
public VertexBufferLayout(VertexAttribute att, VertexAttributeFormat format, int size) { this.att = att; this.format = format; this.size = size; }
public virtual bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension) { return(UnityEngine.SystemInfo.SupportsVertexAttributeFormat(format, dimension)); }
public CalculatedAttributeMap(VertexAttribute attribute, VertexAttributeFormat format, int numComponents, int componentSize) : base(attribute, format) { m_numComponents = numComponents; m_elementSize = componentSize * numComponents; }
public VertexAttributeDescriptor(VertexAttribute attribute = VertexAttribute.Position, VertexAttributeFormat format = VertexAttributeFormat.Float32, int dimension = 3, int stream = 0) { this.attribute = attribute; this.format = format; this.dimension = dimension; this.stream = stream; }
extern private System.Array GetAllocArrayFromChannelImpl(VertexAttribute channel, VertexAttributeFormat format, int dim);
static extern bool SupportsVertexAttributeFormatNative(VertexAttributeFormat format, int dimension);
private static int GetByteSize(VertexAttributeFormat format, int dimension) { return(GetByteSize(format) * dimension); }
public static bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension) { return(ShimManager.SystemInfoShim.SupportsVertexAttributeFormat(format, dimension)); }
unsafe void CopyAttributeInto <T>(NativeArray <T> buffer, VertexAttribute channel, VertexAttributeFormat format, int dim) where T : struct { CheckReadAccess(); if (!HasVertexAttribute(channel)) { throw new InvalidOperationException($"Mesh data does not have {channel} vertex component"); } if (buffer.Length < vertexCount) { throw new InvalidOperationException($"Not enough space in output buffer (need {vertexCount}, has {buffer.Length})"); } CopyAttributeIntoPtr(m_Ptr, channel, format, dim, (IntPtr)buffer.GetUnsafePtr()); }
extern private void SetNativeArrayForChannelImpl(VertexAttribute channel, VertexAttributeFormat format, int dim, IntPtr values, int arraySize, int valuesStart, int valuesCount, UnityEngine.Rendering.MeshUpdateFlags flags);
extern private void SetArrayForChannelImpl(VertexAttribute channel, VertexAttributeFormat format, int dim, System.Array values, int arraySize, int valuesStart, int valuesCount);
extern private void GetArrayFromChannelImpl(VertexAttribute channel, VertexAttributeFormat format, int dim, System.Array values);
extern private void SetNativeArrayForChannelImpl(VertexAttribute channel, VertexAttributeFormat format, int dim, IntPtr values, int arraySize, int valuesStart, int valuesCount);
[NativeMethod(IsThreadSafe = true)] static extern void CopyAttributeIntoPtr(IntPtr self, VertexAttribute attr, VertexAttributeFormat format, int dim, IntPtr dst);
private void GetListForChannel <T>(List <T> buffer, int capacity, VertexAttribute channel, int dim, VertexAttributeFormat channelType) { buffer.Clear(); if (!canAccess) { PrintErrorCantAccessChannel(channel); return; } if (!HasVertexAttribute(channel)) { return; } NoAllocHelpers.EnsureListElemCount(buffer, capacity); GetArrayFromChannelImpl(channel, channelType, dim, NoAllocHelpers.ExtractArrayFromList(buffer)); }