Sign in to follow this  
enigmatix

Custom Vertices

Recommended Posts

I've been able to come up with a custom vertex struct and vertex declaration and I thought that it would be really convenient if i could extra variables to the vertex struct, such as visibility, id, etc. for management purposes. The only problem is with a struct, you cant have a constructor unless it encompasses all the variables, so i tried using a class. As soon as i did, the app failed on the SetData function of the vertex buffer. Is there no way to use a class instead of struct?

Share this post


Link to post
Share on other sites
The only difference between a class and a struct is default access. In a struct members are public by default. In a class members are private by default.

Did you forget to do this:

class vertex{
public:
...
}

Share this post


Link to post
Share on other sites
Quote:
Original post by enigmatix
I've been able to come up with a custom vertex struct and vertex declaration and I thought that it would be really convenient if i could extra variables to the vertex struct, such as visibility, id, etc. for management purposes. The only problem is with a struct, you cant have a constructor unless it encompasses all the variables, so i tried using a class. As soon as i did, the app failed on the SetData function of the vertex buffer. Is there no way to use a class instead of struct?

The reason SetData fails is because it expects a value-type, while classes in C# are reference types. I don't see any reason why you can't use a struct. Just initialize your extra parameters to default values in the constructor without actually passing values in through the parameter list, and instead expose them as properties. I'm not sure how the SetData function behaves with extra data in the struct - you might have to mess with the StrideSize property. Alternatively, you lock the vertex buffer as an array and write the vertices manually.

Share this post


Link to post
Share on other sites
Ok, well the struct isn't going to work. I tried initializing the properties in the constructor and the program freezes at that point. Not sure why. So let's just say I want to manually write data to the vertex buffer with a graphics stream. Would i have to do that in byte data? ...because the all the examples I've seen use the standard structs (PositionNormal, PositionColored, etc.) as the data they write to the vertex buffer. Is it possible to write the data just as it's setup in the vertex declaration without the use of struct?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this