/// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="stream">Stream to bind this field with.</param>
 /// <param name="fieldOffset">Position of the field within the field type.</param>
 /// <param name="context">The purpose of this field.</param>
 /// <param name="fieldType">Data type of the field.</param>
 /// <param name="index">Index of the item, only applicable to certain types of fields.</param>
 internal VertexField(short stream, short fieldOffset, VertexFieldContext context, VertexFieldType fieldType, byte index)
 {
     _stream  = stream;
     _offset  = fieldOffset;
     _context = context;
     _type    = fieldType;
     _index   = index;
     _size    = (short)SizeOf(fieldType);
 }
        /// <summary>
        /// Function to add a field to this vertex.
        /// </summary>
        /// <param name="stream">Stream to bind this field with.</param>
        /// <param name="fieldOffset">Offset of this field within the vertex type..</param>
        /// <param name="context">Context of this field.</param>
        /// <param name="fieldType">Data type of the field.</param>
        /// <param name="index">Index of the field, only required for certain types.</param>
        public void CreateField ( short stream , short fieldOffset , VertexFieldContext context , VertexFieldType fieldType , byte index )
        {
            VertexField newField;	// A new vertex field.

            newField = new VertexField(stream , fieldOffset , context , fieldType , index);
            _fields.Add(newField);

            _changed = true;
            _sizeChanged = true;
        }
        /// <summary>
        /// Function to retrieve whether this vertex definition has a particular field type.
        /// </summary>
        /// <param name="stream">Stream to check.</param>
        /// <param name="fieldType">Type of data to check for.</param>
        /// <returns>TRUE if the type is present, FALSE if not.</returns>
        public bool HasFieldType(short stream, VertexFieldType fieldType)
        {
            int i;                                      // loop.

            for (i = 0; i < _fields.Count; i++)
            {
                if ((_fields[i].Type == fieldType) && (_fields[i].Stream == stream))
                {
                    return(true);
                }
            }

            return(false);
        }
        /// <summary>
        /// Function to return the number of elements within a field.
        /// </summary>
        /// <param name="type">Type of this field.</param>
        /// <returns>The number of elements within a field.</returns>
        static public int FieldElementCount(VertexFieldType type)
        {
            switch (type)
            {
            case VertexFieldType.Float1:
                return(1);

            case VertexFieldType.Float2:
                return(2);

            case VertexFieldType.Float3:
                return(3);

            case VertexFieldType.Float4:
                return(4);

            case VertexFieldType.Short1:
                return(1);

            case VertexFieldType.Short2:
                return(2);

            case VertexFieldType.Short3:
                return(3);

            case VertexFieldType.Short4:
                return(4);

            case VertexFieldType.Color:
                return(1);

            case VertexFieldType.UByte4:
                return(4);
            }

            throw new Exception("Vertex field type '" + type.ToString() + "' is not recognized.");
        }
        /// <summary>
        /// Function to return the size in bytes of a vertex field.
        /// </summary>
        /// <param name="type">Type of the field to evaluate.</param>
        /// <returns>Size of the field in bytes.</returns>
        static public int SizeOf(VertexFieldType type)
        {
            switch (type)
            {
            case VertexFieldType.Float1:
                return(sizeof(float));

            case VertexFieldType.Float2:
                return(sizeof(float) * 2);

            case VertexFieldType.Float3:
                return(sizeof(float) * 3);

            case VertexFieldType.Float4:
                return(sizeof(float) * 4);

            case VertexFieldType.Short1:
                return(sizeof(short));

            case VertexFieldType.Short2:
                return(sizeof(short) * 2);

            case VertexFieldType.Short3:
                return(sizeof(short) * 3);

            case VertexFieldType.Short4:
                return(sizeof(short) * 4);

            case VertexFieldType.Color:
                return(sizeof(int));

            case VertexFieldType.UByte4:
                return(sizeof(byte) * 4);
            }

            throw new Exception("Vertex field type '" + type.ToString() + "' is not recognized.");
        }
        /// <summary>
        /// Function to insert a vertex field at a specified index.
        /// </summary>
        /// <param name="stream">Stream to which the field will be bound.</param>
        /// <param name="fieldIndex">Index after which to insert.</param>
        /// <param name="fieldOffset">Offset of the field in the buffer.</param>
        /// <param name="context">Context of this field.</param>
        /// <param name="fieldType">Data type of this field.</param>
        /// <param name="index">Index of the vertex field, required for certain fields.</param>
        public void InsertField(short stream, int fieldIndex, short fieldOffset, VertexFieldContext context, VertexFieldType fieldType, byte index)
        {
            VertexField newField;       // New _fields[i].

            newField = new VertexField(stream, fieldOffset, context, fieldType, index);
            _fields.Insert(fieldIndex, newField);

            _changed     = true;
            _sizeChanged = true;
        }
 /// <summary>
 /// Function to insert a vertex field at a specified index.
 /// </summary>
 /// <param name="stream">Stream to which the field will be bound.</param>
 /// <param name="fieldIndex">Index after which to insert.</param>
 /// <param name="fieldOffset">Offset of the field in the buffer.</param>
 /// <param name="context">Context of this field.</param>
 /// <param name="fieldType">Data type of this field.</param>
 public void InsertField(short stream, int fieldIndex, short fieldOffset, VertexFieldContext context, VertexFieldType fieldType)
 {
     InsertField(stream, fieldIndex, fieldOffset, context, fieldType, 0);
 }
        /// <summary>
        /// Function to update a vertex _fields[i].
        /// </summary>
        /// <param name="stream">Stream to which the field is bound.</param>
        /// <param name="fieldIndex">Index of the field to update</param>
        /// <param name="fieldOffset">Offset within the buffer.</param>
        /// <param name="context">Context of this field.</param>
        /// <param name="fieldType">Data type of the field.</param>
        /// <param name="index">Index of the field, only required for certain types.</param>
        public void UpdateField(short stream, int fieldIndex, short fieldOffset, VertexFieldContext context, VertexFieldType fieldType, byte index)
        {
            if ((fieldIndex < 0) || (fieldIndex >= _fields.Count))
            {
                throw new IndexOutOfRangeException("The index " + index.ToString() + " is not valid for this collection.");
            }

            _fields[fieldIndex] = new VertexField(stream, fieldOffset, context, fieldType, index);

            _changed     = true;
            _sizeChanged = true;
        }
		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="stream">Stream to bind this field with.</param>
		/// <param name="fieldOffset">Position of the field within the field type.</param>
		/// <param name="context">The purpose of this field.</param>
		/// <param name="fieldType">Data type of the field.</param>
		/// <param name="index">Index of the item, only applicable to certain types of fields.</param>
		internal VertexField(short stream,short fieldOffset, VertexFieldContext context, VertexFieldType fieldType, byte index)
		{
			_stream = stream;
			_offset = fieldOffset;
			_context = context;
			_type = fieldType;
			_index = index;
			_size = (short)SizeOf(fieldType);
		}
		/// <summary>
		/// Function to return the number of elements within a field.
		/// </summary>
		/// <param name="type">Type of this field.</param>
		/// <returns>The number of elements within a field.</returns>
		static public int FieldElementCount(VertexFieldType type)
		{
			switch(type)
			{
				case VertexFieldType.Float1:
					return 1;
				case VertexFieldType.Float2:
					return 2;
				case VertexFieldType.Float3:
					return 3;
				case VertexFieldType.Float4:
					return 4;
				case VertexFieldType.Short1:
					return 1;
				case VertexFieldType.Short2:
					return 2;
				case VertexFieldType.Short3:
					return 3;
				case VertexFieldType.Short4:
					return 4;
				case VertexFieldType.Color:
					return 1;
				case VertexFieldType.UByte4:
					return 4;
			}

			throw new Exception( "Vertex field type '" + type.ToString() + "' is not recognized.");
		}
Beispiel #11
0
 /// <summary>
 /// Function to insert a vertex field at a specified index.
 /// </summary>
 /// <param name="stream">Stream to which the field will be bound.</param>
 /// <param name="fieldIndex">Index after which to insert.</param>
 /// <param name="fieldOffset">Offset of the field in the buffer.</param>
 /// <param name="context">Context of this field.</param>
 /// <param name="fieldType">Data type of this field.</param>
 public void InsertField ( short stream , int fieldIndex , short fieldOffset , VertexFieldContext context , VertexFieldType fieldType )
 {
     InsertField(stream , fieldIndex , fieldOffset , context , fieldType , 0);
 }
Beispiel #12
0
 /// <summary>
 /// Function to add a field to this vertex.
 /// </summary>
 /// <param name="stream">Stream to bind this field with.</param>
 /// <param name="fieldOffset">Offset of this field within the vertex type..</param>
 /// <param name="context">Context of this field.</param>
 /// <param name="fieldType">Data type of the field.</param>
 public void CreateField ( short stream , short fieldOffset , VertexFieldContext context , VertexFieldType fieldType )
 {
     CreateField(stream , fieldOffset , context , fieldType , 0);
 }
Beispiel #13
0
        /// <summary>
        /// Function to retrieve whether this vertex definition has a particular field type.
        /// </summary>
        /// <param name="stream">Stream to check.</param>
        /// <param name="fieldType">Type of data to check for.</param>
        /// <returns>TRUE if the type is present, FALSE if not.</returns>
        public bool HasFieldType ( short stream , VertexFieldType fieldType )
        {
            int i;					// loop.

            for (i = 0 ; i < _fields.Count ; i++)
            {
                if ((_fields[i].Type == fieldType) && (_fields[i].Stream == stream))
                    return true;
            }

            return false;
        }
Beispiel #14
0
        /// <summary>
        /// Function to insert a vertex field at a specified index.
        /// </summary>
        /// <param name="stream">Stream to which the field will be bound.</param>
        /// <param name="fieldIndex">Index after which to insert.</param>
        /// <param name="fieldOffset">Offset of the field in the buffer.</param>
        /// <param name="context">Context of this field.</param>
        /// <param name="fieldType">Data type of this field.</param>
        /// <param name="index">Index of the vertex field, required for certain fields.</param>
        public void InsertField ( short stream , int fieldIndex , short fieldOffset , VertexFieldContext context , VertexFieldType fieldType , byte index )
        {
            VertexField newField;	// New _fields[i].

            newField = new VertexField(stream , fieldOffset , context , fieldType , index);
            _fields.Insert(fieldIndex , newField);

            _changed = true;
            _sizeChanged = true;
        }
 /// <summary>
 /// Function to add a field to this vertex.
 /// </summary>
 /// <param name="stream">Stream to bind this field with.</param>
 /// <param name="fieldOffset">Offset of this field within the vertex type..</param>
 /// <param name="context">Context of this field.</param>
 /// <param name="fieldType">Data type of the field.</param>
 public void CreateField(short stream, short fieldOffset, VertexFieldContext context, VertexFieldType fieldType)
 {
     CreateField(stream, fieldOffset, context, fieldType, 0);
 }
		/// <summary>
		/// Function to return the size in bytes of a vertex field.
		/// </summary>
		/// <param name="type">Type of the field to evaluate.</param>
		/// <returns>Size of the field in bytes.</returns>
		static public int SizeOf(VertexFieldType type)
		{
			switch(type)
			{
				case VertexFieldType.Float1:
					return sizeof(float);
				case VertexFieldType.Float2:
					return sizeof(float) * 2;
				case VertexFieldType.Float3:
					return sizeof(float) * 3;
				case VertexFieldType.Float4:
					return sizeof(float) * 4;
				case VertexFieldType.Short1:
					return sizeof(short);
				case VertexFieldType.Short2:
					return sizeof(short) * 2;
				case VertexFieldType.Short3:
					return sizeof(short) * 3;
				case VertexFieldType.Short4:
					return sizeof(short) * 4;
				case VertexFieldType.Color:
					return sizeof(int);
				case VertexFieldType.UByte4:
					return sizeof(byte) * 4;
			}

			throw new Exception( "Vertex field type '" + type.ToString() + "' is not recognized.");
		}
        /// <summary>
        /// Function to add a field to this vertex.
        /// </summary>
        /// <param name="stream">Stream to bind this field with.</param>
        /// <param name="fieldOffset">Offset of this field within the vertex type..</param>
        /// <param name="context">Context of this field.</param>
        /// <param name="fieldType">Data type of the field.</param>
        /// <param name="index">Index of the field, only required for certain types.</param>
        public void CreateField(short stream, short fieldOffset, VertexFieldContext context, VertexFieldType fieldType, byte index)
        {
            VertexField newField;       // A new vertex field.

            newField = new VertexField(stream, fieldOffset, context, fieldType, index);
            _fields.Add(newField);

            _changed     = true;
            _sizeChanged = true;
        }
Beispiel #18
0
        /// <summary>
        /// Function to update a vertex _fields[i].
        /// </summary>
        /// <param name="stream">Stream to which the field is bound.</param>
        /// <param name="fieldIndex">Index of the field to update</param>
        /// <param name="fieldOffset">Offset within the buffer.</param>
        /// <param name="context">Context of this field.</param>
        /// <param name="fieldType">Data type of the field.</param>
        /// <param name="index">Index of the field, only required for certain types.</param>
        public void UpdateField ( short stream , int fieldIndex , short fieldOffset , VertexFieldContext context , VertexFieldType fieldType , byte index )
        {
            if ((fieldIndex < 0) || (fieldIndex >= _fields.Count))
                throw new IndexOutOfRangeException("The index " + index.ToString() + " is not valid for this collection.");

            _fields[fieldIndex] = new VertexField(stream , fieldOffset , context , fieldType , index);

            _changed = true;
            _sizeChanged = true;
        }