Axiom.Graphics.VertexData.Clone C# (CSharp) Method

Clone() public method

Clones this vertex data, potentially including replicating any vertex buffers.
public Clone ( bool copyData ) : VertexData
copyData bool /// If true, makes a copy the vertex buffer in addition to the definition. /// If false, the clone will refer to the same vertex buffer this object refers to. ///
return VertexData
		public VertexData Clone( bool copyData )
		{
			VertexData dest = new VertexData();

			// Copy vertex buffers in turn
			Dictionary<short, HardwareVertexBuffer> bindings = vertexBufferBinding.Bindings;

			foreach ( short source in bindings.Keys )
			{
				HardwareVertexBuffer srcbuf = bindings[ source ];
				HardwareVertexBuffer dstBuf;

				if ( copyData )
				{
					// create new buffer with the same settings
					dstBuf =
						HardwareBufferManager.Instance.CreateVertexBuffer( srcbuf.VertexDeclaration, srcbuf.VertexCount, srcbuf.Usage,	srcbuf.HasShadowBuffer );

					// copy data
					dstBuf.CopyData( srcbuf, 0, 0, srcbuf.Size, true );
				}
				else
				{
					// don't copy, point at existing buffer
					dstBuf = srcbuf;
				}

				// Copy binding
				dest.vertexBufferBinding.SetBinding( source, dstBuf );
			}

			// Basic vertex info
			dest.vertexStart = this.vertexStart;
			dest.vertexCount = this.vertexCount;

			// Copy elements
			for ( int i = 0; i < vertexDeclaration.ElementCount; i++ )
			{
				VertexElement element = vertexDeclaration.GetElement( i );

				dest.vertexDeclaration.AddElement( element.Source, element.Offset, element.Type, element.Semantic, element.Index );
			}

			// Copy hardware shadow buffer if set up
			if ( hardwareShadowVolWBuffer != null )
			{
				dest.hardwareShadowVolWBuffer =
					HardwareBufferManager.Instance.CreateVertexBuffer( hardwareShadowVolWBuffer.VertexDeclaration, hardwareShadowVolWBuffer.VertexCount, hardwareShadowVolWBuffer.Usage, hardwareShadowVolWBuffer.HasShadowBuffer );

				// copy data
				dest.hardwareShadowVolWBuffer.CopyData( hardwareShadowVolWBuffer, 0, 0, hardwareShadowVolWBuffer.Size,true );
			}

			// copy anim data
			dest.HWAnimationDataList = HWAnimationDataList;
			dest.HWAnimDataItemsUsed = HWAnimDataItemsUsed;

			return dest;
		}

Same methods

VertexData::Clone ( ) : VertexData

Usage Example

        public GeometryBucket(MaterialBucket parent, string formatString, 
                              VertexData vData, IndexData iData)
        {
            // Clone the structure from the example
            this.parent = parent;
            this.formatString = formatString;
            vertexData = vData.Clone(false);
            indexData = iData.Clone(false);
            vertexData.vertexCount = 0;
            vertexData.vertexStart = 0;
            indexData.indexCount = 0;
            indexData.indexStart = 0;
            indexType = indexData.indexBuffer.Type;
            queuedGeometry = new List<QueuedGeometry>();
            // Derive the max vertices
            if (indexType == IndexType.Size32)
                maxVertexIndex = int.MaxValue;
            else
                maxVertexIndex = ushort.MaxValue;

            // Check to see if we have blend indices / blend weights
            // remove them if so, they can try to blend non-existent bones!
            VertexElement blendIndices =
                vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.BlendIndices);
            VertexElement blendWeights =
                vertexData.vertexDeclaration.FindElementBySemantic(VertexElementSemantic.BlendWeights);
            if (blendIndices != null && blendWeights != null) {
                Debug.Assert(blendIndices.Source == blendWeights.Source,
                             "Blend indices and weights should be in the same buffer");
                // Get the source
                ushort source = blendIndices.Source;
                Debug.Assert(blendIndices.Size + blendWeights.Size ==
                    vertexData.vertexBufferBinding.GetBuffer(source).VertexSize,
                    "Blend indices and blend buffers should have buffer to themselves!");
                // Unset the buffer
                vertexData.vertexBufferBinding.UnsetBinding(source);
                // Remove the elements
                vertexData.vertexDeclaration.RemoveElement(VertexElementSemantic.BlendIndices);
                vertexData.vertexDeclaration.RemoveElement(VertexElementSemantic.BlendWeights);
            }
        }
All Usage Examples Of Axiom.Graphics.VertexData::Clone