Jump to content
  • Advertisement
Sign in to follow this  
steg

Vertex structures

This topic is 5468 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

Hi all, I have been wondering what is the best way to design a 'shape' class which will render itself using Direct3D. I am confused with the vertex structure to use, as some shapes would require texture co-ordinates, normals while others won't. Example : struct Vertex { float x,y,z; D3DXVECTOR3 Normal; }; // Main parent class class CShape { public: virtual ~CShape(); virtual void Render() = 0; virtual void Init() = 0; protected: float m_XPos; // world position of object float m_YPos; IDirect3DVertexBuffer9* m_pVB; IDirect3DIndexBuffer9* m_pVB; }; // A Box object class CBox : public CShape { public: Vertex* m_pVertex; void Render(); void Init(); }; The CBox object derives from CShape and thus has to implement the two pure virtual functions Render and Init. Now I was thinking in the Init method this would create the vertex buffer, objects world position and in the Render, it would render itself. Ok, all seems well and good (at least I think ?), now I have a pointer to a Vertex structure, now my problem is, should I have multiple Vertex structures, i.e. one which just has x,y,z, another which has texture coordinates, another which has texture coordinates and normals, OR, just one vertex structure with all this information in ? Any help, advice is much appreciated. Kind regards, Steve

Share this post


Link to post
Share on other sites
Advertisement
As for the vertex structure, I'd suggest something like this:
 struct vertex{
p as D3DVECTOR; //position
n as D3DVECTOR; //normal
t as D3DVECTOR2; //texture coordinates
};

I'd put everything in there just to keep things simple. It only takes up a couple (<50) bytes to keep everything in there, so why not take it? Unless you're going for insane memory optimization, there shouldn't be a problem.

And in your CShape class, don't forget about a m_Zpos... you might just need it even if you think you don't [grin]

...Next time you post lots of code, use [source] tags so that it all fits in the forum nicely. Thanks!
Other than that, everything looks fine to me!

Share this post


Link to post
Share on other sites
Use two types of vertex description. One that has tex coords and one that does not. There is a performance hit though.

Share this post


Link to post
Share on other sites
Yeah i ran into a similar issue. my static meshes use a typical XYZ | UV | NORMAL but my skeletal meshes use a custom vertex declaration for shaders. so in my base I store the data inside of a byte array and use C-style casting to convert to the required vertex type. There is a cost for this cast I guess. I've noticed a small bit of slowdown but can;t say for certain that's the issue 4 sure yet.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!