Ejemplo n.º 1
0
        /// <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);
            }
        }
Ejemplo n.º 2
0
 public AttributeMapBase(VertexAttribute attribute, VertexAttributeFormat format)
 {
     this.attribute = attribute;
     this.format    = format;
     offset         = 0;
     stream         = 0;
 }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
0
 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);
     }
 }
Ejemplo n.º 5
0
        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}");
            }
        }
Ejemplo n.º 6
0
 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));
 }
Ejemplo n.º 7
0
        public static VertexAttribPointerType ToOpenGlAttribType(this VertexAttributeFormat att)
        {
            switch (att)
            {
            case VertexAttributeFormat.Float32:
                return(VertexAttribPointerType.Float);

            case VertexAttributeFormat.Int32:
                return(VertexAttribPointerType.Int);
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 8
0
        public static int ByteSize(this VertexAttributeFormat att)
        {
            switch (att)
            {
            case VertexAttributeFormat.Float32:
                return(sizeof(float));

            case VertexAttributeFormat.Int32:
                return(sizeof(int));
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 9
0
 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]);
 }
Ejemplo n.º 10
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));
        }
Ejemplo n.º 11
0
        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);
            }
        }
Ejemplo n.º 12
0
        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
            };
        }
Ejemplo n.º 13
0
        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();
        }
Ejemplo n.º 14
0
 public override bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension)
 {
     return(base.SupportsVertexAttributeFormat(format, dimension));
 }
Ejemplo n.º 15
0
 public AttributeMap(DracoAttribute *dracoAttribute, VertexAttribute attribute, VertexAttributeFormat format, bool convertSpace) : base(attribute, format)
 {
     this.dracoAttribute = dracoAttribute;
     this.convertSpace   = convertSpace;
 }
Ejemplo n.º 16
0
 public VertexBufferLayout(VertexAttribute att, VertexAttributeFormat format, int size)
 {
     this.att    = att;
     this.format = format;
     this.size   = size;
 }
Ejemplo n.º 17
0
 public virtual bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension)
 {
     return(UnityEngine.SystemInfo.SupportsVertexAttributeFormat(format, dimension));
 }
Ejemplo n.º 18
0
 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;
 }
Ejemplo n.º 20
0
 extern private System.Array GetAllocArrayFromChannelImpl(VertexAttribute channel, VertexAttributeFormat format, int dim);
Ejemplo n.º 21
0
 static extern bool SupportsVertexAttributeFormatNative(VertexAttributeFormat format, int dimension);
Ejemplo n.º 22
0
 private static int GetByteSize(VertexAttributeFormat format, int dimension)
 {
     return(GetByteSize(format) * dimension);
 }
Ejemplo n.º 23
0
 public static bool SupportsVertexAttributeFormat(VertexAttributeFormat format, int dimension)
 {
     return(ShimManager.SystemInfoShim.SupportsVertexAttributeFormat(format, dimension));
 }
Ejemplo n.º 24
0
 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());
 }
Ejemplo n.º 25
0
 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);
Ejemplo n.º 27
0
 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);
Ejemplo n.º 29
0
 [NativeMethod(IsThreadSafe = true)] static extern void CopyAttributeIntoPtr(IntPtr self, VertexAttribute attr, VertexAttributeFormat format, int dim, IntPtr dst);
Ejemplo n.º 30
0
        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));
        }