Custom Vertices

Started by
2 comments, last by enigmatix 16 years, 8 months ago
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?
Advertisement
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:
...
}

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.
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?

This topic is closed to new replies.

Advertisement