|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| Designing a Flexible Vertex Element System for XNA Using Attributes |
|
![]() Takuan Daikon Member since: 9/27/2007 |
||||
|
|
||||
| Wow, I don't think this could have been more timely if you'd have been shoulder-surfing me this morning! I was *just* converting some custom vertex formats while in the process of cleaning up someone else's code which had accumulated a bunch of cruft, and was actually kind of thinking of whether there were some more unified and consistent way of doing this! I'll be trying this out today, thanks for the article! |
||||
|
||||
![]() Tape_Worm Member since: 4/21/2000 From: Calgary, Canada |
||||
|
|
||||
Nice article Mikey. The whole thing is a brilliant idea, I wish I had thought of it . I think I'm going to experiment with this system.Oh internet... so many idiots... so few bullets. Linky goodness: [journal] | [Gorgon] |
||||
|
||||
![]() Jorgon3d Member since: 12/12/2008 |
||||
|
|
||||
| I developed the exact same thing earlier in the year for an OpenGL engine I have been working on. I created a VertexBuffer<> class that handles the VBOs transparently. I am glad to see the implementation has enough merit to be a feature. |
||||
|
||||
![]() Ultrahead Member since: 12/20/2007 From: Montevideo |
||||
|
|
||||
| Great article! I'd change the signature of "CreateVertexDeclaration" to public static VertexDeclaration CreateVertexDeclaration<T>(this GraphicsDevice device) where T : struct and also I'd create a static dictionary to hold the vertex element format: static Dictionary<Type, VertexElementFormat> "cachedFormats" so that you can then replace all the "if, else if" statements as follows: if (attributes[0].Format == VertexElementFormat.Unused) attributes[0].Format = cachedFormats[field.FieldType]; ~Pete http://amapplease.blogspot.com |
||||
|
||||
![]() Mike.Popoloski GDNet+ Member since: 6/28/2004 From: West Milford, NJ, United States |
||||
|
|
||||
| Your first suggestion is mostly just a stylistic choice, but the second one of using a map is good. The type detection as a whole was basically thrown in at the end, I haven't really made use of it very much. Mike Popoloski | Journal | SlimDX |
||||
|
||||
![]() Ultrahead Member since: 12/20/2007 From: Montevideo |
||||
|
|
||||
| Exactly. |
||||
|
||||
![]() BLiTZWiNG Member since: 4/10/2006 From: Brisbane, Australia |
||||
|
|
||||
| Have you done any performance tests to see what effect the use of reflection has? |
||||
|
||||
![]() Codeka Member since: 10/19/2008 From: Sydney, Australia |
||||
|
|
||||
Quote: This code would not be called every frame - in fact, it's probably only called when you load your level/start the game - so performance is not an issue. |
||||
|
||||
![]() Mike.Popoloski GDNet+ Member since: 6/28/2004 From: West Milford, NJ, United States |
||||
|
|
||||
| Yes, the code is only used when your vertex declaration needs to be recreated, which should not be every frame. Even so, the reflected data is cached in a dictionary, so the reflection itself only occurs for the first creation of a particular vertex declaration; after that, recreating the declaration is a simple method call. Mike Popoloski | Journal | SlimDX |
||||
|
||||
![]() JeBuSBrian Member since: 6/3/2009 From: Chicago, IL, United States |
||||
|
|
||||
| Marshal.OffsetOf doesn't exist on the Xbox 360. Any suggested work-around? |
||||
|
||||
![]() Armigus2 Member since: 6/30/2009 From: Weston, MA, United States |
||||
|
|
||||
| #1. For completeness sake, some using statements are called for: using System.Reflection; using System.Runtime.InteropServices; #2. Most built-in vertices have an int SizeInBytes property. I can get that value for a custom vertex as well: int vertexSize = Marshal.SizeOf(vertexType); Can this property be added dynamically as well or am I stuck with the old "count the elements and their sizes" routine? |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|