/// <summary> /// Changes the format of the <see cref="VertexUnit"/> to fit the given /// semantics. /// </summary> /// <param name="semantics">Semantics to fit.</param> public void ChangeFormat(Semantic[] semantics) { VertexFormat newFormat = format.Clone(semantics); IVertexStream[] newStreams = new IVertexStream[semantics.Length]; for (int i = 0; i < newFormat.Size; i++) { int index = format.GetIndex(newFormat.GetType(i), newFormat.GetUsageIndex(i)); newStreams[i] = this[index]; } this.vertexStreams = newStreams; format = newFormat; }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Initialisation //--------------------------------------------------------------- /// <summary> /// Creates a new instance of a <see cref="VertexUnit"/>. /// </summary> /// <param name="format">The format of the <see cref="VertexUnit"/>.</param> /// <param name="size">The number of elements per stream.</param> public VertexUnit(VertexFormat format, int size) { this.size = size; this.format = format; vertexStreams = new IVertexStream[format.Size]; // create vertexArray from type and add to list (update VertexElements) foreach (Type type in format.Types) { IVertexStream va = (IVertexStream)Activator.CreateInstance(type, new object[] { this }); va.Init(size); SetNextStream(va); } }
/// <summary> /// Creates a new <see cref="VertexUnit"/>. /// </summary> /// <param name="format">The <see cref="VertexFormat"/> of the new format.</param> public VertexUnit Clone(VertexFormat format) { VertexUnit unit = new VertexUnit(format, size); for (int i = 0; i < format.Size; i++) { IGraphicsStream stream = unit[i]; if (this.format.Contains(stream.GetType(), format.GetUsageIndex(i))) { IGraphicsStream from = this[stream.GetType(), format.GetUsageIndex(i)]; Array.Copy(from.Data, stream.Data, from.Size); } } return(unit); }
/// <summary> /// Creates a new instance of a <see cref="VertexUnit"/>. /// </summary> /// <param name="streams">List of offline streams (must have same size).</param> public VertexUnit(IList streams) { size = (streams[0] as IVertexStream).Size; int position = (streams[0] as IVertexStream).Position; vertexStreams = new IVertexStream[streams.Count]; foreach (IVertexStream stream in streams) { if (stream.HasOnlineData() || stream.Size != size || stream.Position != position) { throw new GraphicsException("Streams must be offline, must have same size and position in physical buffer!"); } SetNextStream(stream); } format = new VertexFormat(streams); }
/// <summary> /// New equals function. /// </summary> /// <param name="obj"><see cref="VertexFormat"/> to compare current object with.</param> /// <returns>True if equals.</returns> public override bool Equals(object obj) { // TODO sorting! if (obj == null) { return(false); } VertexFormat format = (VertexFormat)obj; if (this.Size != format.Size) { return(false); } for (int i = 0; i < Types.Length; i++) { if (Types[i] != format.Types[i]) { return(false); } } return(true); }