Ejemplo n.º 1
0
 internal VertexElement(IntPtr offset, VertexElementType type, int count, VertexElementRole role)
 {
     this.offset = offset;
     this.type   = type;
     this.count  = count;
     this.role   = role;
 }
Ejemplo n.º 2
0
		internal VertexElement(IntPtr offset, VertexElementType type, int count, VertexElementRole role)
		{
			this.offset = offset;
			this.type = type;
			this.count = count;
			this.role = role;
		}
Ejemplo n.º 3
0
        private VertexDeclaration(Type dataType, int typeIndex)
        {
            TypeInfo dataTypeInfo = dataType.GetTypeInfo();

            if (dataTypeInfo.IsClass)
            {
                throw new InvalidOperationException("Vertex formats need to be structs. Classes are not supported.");
            }

            FieldInfo[] fields = dataTypeInfo.DeclaredFieldsDeep().Where(m => !m.IsStatic).ToArray();

            this.dataType  = dataType;
            this.typeIndex = typeIndex;
            this.size      = Marshal.SizeOf(dataType);
            this.elements  = new VertexElement[fields.Length];

            for (int i = 0; i < fields.Length; i++)
            {
                VertexElementRole role = VertexElementRole.Unknown;
                VertexElementType type = VertexElementType.Unknown;
                int count = 0;

                VertexElementAttribute attrib = fields[i].GetAttributesCached <VertexElementAttribute>().FirstOrDefault();
                if (attrib != null)
                {
                    role  = attrib.Role;
                    type  = attrib.Type;
                    count = attrib.Count;
                }

                if (type == VertexElementType.Unknown || count == 0)
                {
                    DetermineElement(fields[i].FieldType, out type, out count);
                }
                if (type == VertexElementType.Unknown || count == 0)
                {
                    throw new InvalidOperationException(string.Format("Unable to determine type of field {2}, vertex format {1}. Add a {0} to specify it explicitly",
                                                                      typeof(VertexElementAttribute).Name,
                                                                      dataType.Name,
                                                                      fields[i].Name));
                }

                this.elements[i] = new VertexElement(
                    Marshal.OffsetOf(dataType, fields[i].Name),
                    type,
                    count,
                    role);
            }

            // Add this declaration to the static by-TypeIndex lookup
            while (delcarationByIndex.Count <= this.typeIndex)
            {
                delcarationByIndex.Add(null);
            }
            delcarationByIndex[this.typeIndex] = this;
        }
Ejemplo n.º 4
0
 public VertexElementAttribute(VertexElementType type, int count, VertexElementRole role = VertexElementRole.Unknown)
 {
     this.type  = type;
     this.count = count;
     this.role  = role;
 }
Ejemplo n.º 5
0
 public VertexElementAttribute(VertexElementRole role) : this(VertexElementType.Unknown, 0, role)
 {
 }
Ejemplo n.º 6
0
		public VertexElementAttribute(VertexElementType type, int count, VertexElementRole role = VertexElementRole.Unknown)
		{
			this.type = type;
			this.count = count;
			this.role = role;
		}
Ejemplo n.º 7
0
		public VertexElementAttribute(VertexElementRole role) : this(VertexElementType.Unknown, 0, role) { }