Jump to content
  • Advertisement
Sign in to follow this  

Seeking basic advice on rendering efficiency with vertex buffers

This topic is 3376 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'm building a 2D platformer, tiles of quads in D3D9. I remember once knowing what was said to be the most efficient way for storing and rendering your vertices, but now I can't remember it. Like any platformer, the game will have foreground and background layers taking different transformations, as well as the individual sprites all doing their individual things. What is the best way to store this data in the vertex buffer to avoid slowing down the rendering? If I should have more than 1 vertex buffer, what am I taking into account when I create more? Cheers.

Share this post

Link to post
Share on other sites
Mostly you just want to use as few draw calls as possible by batching sprites into single call when you can. The way that ID3DXSprite does things is fine for most cases: it transforms vertices on the CPU and then puts them into a dynamic VB, batching together sprites that use the same texture. I would say just use ID3DXSprite or a similar approach until you think you've run into a legitimate performance problem, and you'd have to be drawing a lot of sprites for that to be an issue.

Share this post

Link to post
Share on other sites
It is said that it's best to store all triangles in one single buffer if possible and sort them so all that use the same texture be close to each other, especially if you're using large amounts of quads. This way you can minimize the number of data packets sent to the GPU (you will render all triangles that use same texture at once).

If you change the vertices frequently (you probably will if you are using xyzrhw) then make sure you make the buffer dynamic and placed in the appropriate memory pool, read directx documentation, it's all there.

I would advice to hold all completely transparent quads in another buffer than those opaque, to handle them easier (render them after the opaques).

Also, instead of trying to create more buffers, just hold the quad data plus an index to where to write it in the buffer and some other stuff encapsulated in a structure so you don't mess with the buffer too much, something like this:

struct Quad
static D3DXVERTEXBUFFER9 *opaque; // one buffer for all opaques
static D3DXVERTEXBUFFER9 *transparent; // one for transp

CUSTOM_VERTEX vertex[6]; // or 4 if you use indexing
int position_in_the_buffer;

// other useful stuff
BOOL this_quad_is_transparent;

D3DXTEXTURE9 *texture;

void WriteQuadToBuffer();
// some other helper functions here, like locking and unlocking the buffer

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!