Jump to content
  • Advertisement
Sign in to follow this  
Maxim Skachkov

[MDX] Dream code for CustomVertex

This topic is 4492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I want that in the code of creation and initialisation of VertexBuffer the type's structure of the CustomVertex was not duplicated! Code i want to refactoring:
public override void InitGraphVB( Device ADevice )
{
	int count = 100;
	System.Type vertType = typeof( CustomVertex.PositionNormalColored );

	VertexFormats vertFormat = CustomVertex.PositionNormalColored.Format;

			
	VertexBuffer vb = new VertexBuffer( vertType, count, ADevice, Usage.WriteOnly, vertFormat, Pool.Managed );

	CustomVertex.PositionNormalColored[] verts = ( CustomVertex.PositionNormalColored[] ) vb.Lock( 0, 0 ); 
	
	for ( int i = 0; i < count; i++ )
	{	
		Vector3 pos = ...;
		Vector3 norm = ...;
		System.Drawing.Color color = ...;
		verts[ i ] = new CustomVertex.PositionNormalColored( pos, norm, color );
	}
	vb.Unlock();
}


Dream code to illustrate the idea:
public override void InitGraphVB( Device ADevice )
{
	int count = 100;
	System.Type vertType = typeof( CustomVertex.PositionNormalColored );

	VertexFormats vertFormat = ( VertexFormats ) ( classof( vertType ).GetField( "Format" ) );

			
	VertexBuffer vb = new VertexBuffer( vertType, count, ADevice, Usage.WriteOnly, vertFormat, Pool.Managed );

	classof( vertType )[] verts = ( classof( vertType )[] ) vb.Lock( 0, 0 ); 

	for ( int i = 0; i < count ; i++ )
	{	
		Vector3 pos = ...;
		Vector3 norm = ...;
		System.Drawing.Color color = ...;

		object[] constrParams = { ( object )pos, ( object )norm , ( object )color };

		verts[ i ] = Activator.CreateInstance( vertType, constrParams );
	}
	vb.Unlock();
}


The main difficulty for me how get class by his type: classof( vertType )? Also i don't know how get access to class members knowing his name like this: classof( vertType ).GetField( "Format" )? [Edited by - Maxim Skachkov on April 4, 2006 2:06:01 PM]

Share this post


Link to post
Share on other sites
Advertisement
Hi,duhroach!
No problem in the Constructor(). The constructors for a vertex buffer are identical for both samples of the code.

I mean the "CustomVertex.PositionNormalColored" code fragment should appeared only once.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!