Axiom.Graphics.AnyBuilder.AddObject C# (CSharp) Method

AddObject() public method

Populate with data as obtained from an IRenderable.
Will share the buffers. In case there are no index data associated with the IRenderable, i.e. RenderOperation.useIndices is false, custom software index buffer is created to provide default index data to the builder. This makes it possible for derived classes to handle the data in a convenient way.
public AddObject ( IRenderable obj ) : void
obj IRenderable
return void
		public void AddObject( IRenderable obj )
		{
			if ( obj == null )
				throw new ArgumentNullException();

			RenderOperation renderOp = obj.RenderOperation;

			IndexData indexData;
			if ( renderOp.useIndices )
			{
				indexData = renderOp.indexData;
			}
			else
			{
				//Create custom index buffer
				int vertexCount = renderOp.vertexData.vertexCount;
				IndexType itype = vertexCount > UInt16.MaxValue ?
				IndexType.Size32 : IndexType.Size16;

				DefaultHardwareIndexBuffer ibuf = new DefaultHardwareIndexBuffer( itype, vertexCount, BufferUsage.Static );
				customIndexBufferList.Add( ibuf ); //to be disposed later

				indexData = new IndexData();
				indexData.indexBuffer = ibuf;
				indexData.indexCount = vertexCount;
				indexData.indexStart = 0;

				//Fill buffer with indices
				IntPtr ibuffer =
				indexData.indexBuffer.Lock( BufferLocking.Normal );
				try
				{
					unsafe
					{
						Int16* ibuf16 = (Int16*)ibuffer;
						Int32* ibuf32 = (Int32*)ibuffer;
						for ( int i = 0; i < indexData.indexCount; i++ )
						{
							if ( itype == IndexType.Size16 )
							{
								ibuf16[ i ] = (Int16)i;
							}
							else
							{
								ibuf32[ i ] = i;
							}
						}
					} //unsafe
				}
				finally
				{
					indexData.indexBuffer.Unlock();
				}
			}

			AddVertexData( renderOp.vertexData );
			AddIndexData( indexData, vertexDataList.Count - 1,
			renderOp.operationType );
		}

Same methods

AnyBuilder::AddObject ( Axiom.Core.Mesh mesh, int lodIndex ) : void