/// <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> /// copies VertexUnit data /// </summary> /// <param name="source">VertexUnit containing source streams</param> /// <param name="sourceIndex">index of source</param> /// <param name="dest">ertexUnit containing destination streams</param> /// <param name="destIndex">index of destination</param> /// <param name="length">number of elements to copy</param> public static void Copy(VertexUnit source, int sourceIndex, VertexUnit dest, int destIndex, int length) { if (source.Format != dest.Format) { throw new GraphicsException("Copy requires to vertexUnits with the same format"); } for (int i = 0; i < source.StreamCount; i++) { IGraphicsStream sourceStream = source[i]; IGraphicsStream destStream = dest[i]; Array.Copy(sourceStream.Data, sourceIndex, destStream.Data, destIndex, length); } }
//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Reserves a new region in the physical buffer and returns the /// used (eventually newly created physical buffer). /// </summary> /// <remarks> /// Currently the <c>GetBuffer</c> method also ensures, that the space /// for all streams of a certain <see cref="VertexUnit"/> is reserved /// at the same time. This is because "older" cards like the Geforce3 and /// Radeon8500 don't support rendering multiple streams starting at a different index. /// </remarks> /// <param name="stream">To return physical buffer for.</param> /// <returns>Physical buffer.</returns> public override IPhysicalGraphicsBuffer GetBuffer(IGraphicsStream stream) { // reserve the space for all streams of the vertexunit at the same time // to ensure, they start with the same index. VertexUnit unit = (stream as IVertexStream).VertexUnit; if (!unit.HasOnlineData()) { for (int i = 0; i < unit.Count; i++) { if (!unit[i].IsSoftware) { unit[i].PhysicalBuffer = base.GetBuffer(unit[i]); } } return(stream.PhysicalBuffer); } return(null); }
/// <summary> /// creates an indexed vertexUnit and the indexStream from the current vertexUnit /// </summary> /// <param name="vertexUnit">created vertexUnit</param> /// <param name="indexStream">created indexStream</param> public void Indexify(out VertexUnit vertexUnit, out VertexStreams.IndexStream indexStream) { object[] currentVertex = new object[StreamCount]; Hashtable vertices = new Hashtable(); int vertexNum = 0; int currentIndex = 0; indexStream = new VertexStreams.IndexStream16(Size); // TODO: Size is much too high for vertexUnit // calc real size vertexUnit = new VertexUnit(format, Size); for (int i = 0; i < Size; i++) { // fill vertex for (int j = 0; j < StreamCount; j++) { currentVertex[j] = this[j].Data.GetValue(i); } // calc current index if (vertices.Contains(currentVertex)) { currentIndex = (int)vertices[currentVertex]; } else { vertices.Add(currentVertex, vertexNum); currentIndex = vertexNum; vertexNum++; // add new vertex to new streams for (int j = 0; j < StreamCount; j++) { vertexUnit[j].Data.SetValue(currentVertex[j], j); } } indexStream[i] = currentIndex; } }