Archived

This topic is now archived and is closed to further replies.

Vertex buffer question

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

Alright, I''m using texture quads to render 2d sprites in my engine and a lot of sprites tend to share the same texture, so I''d like to pump them all into a vertex buffer and draw them at once with one call to DrawPrimitive. The problem is that the number of sprites I have is constantly changing and from what I can tell, when you create a vertex buffer, you have to allocate a certain amount of memory for the vertexes. Should I remake the vertex buffer every time a new sprite sharing that texture is added? Is this impractical and would it slow me down even more than having each sprite use its own DrawPrimitive no matter how many times the texture is recycled? Is there a better way alltogether? Any help would be appreciated.

Share this post


Link to post
Share on other sites
Do NOT create a vertex buffer every frame. The performance hit is huge.

I''d recommend setting some cap number of quads you can have. Lock the buffer every frame (you should also create it with the D3DUSAGE_DYNAMIC flag), fill it with your sprites, unlock, and render. If you''re doing a lot of sprites, try batching for a performance boost.

Share this post


Link to post
Share on other sites
Since you are using 2D sprites, look at the ID3DXSprite interface. It encapsulates all the vertex buffer stuff that you want. If you need help, try searching this forum. You''ll get a lot of hits.

Share this post


Link to post
Share on other sites
timmay314, I think you misunderstood my question... I don''t want to recreate the vertex buffer on every frame, just every time a new sprite is added to the system or removed which won''t happen anywhere near every frame.

circlesoft, I''ve already seen many topics on using ID3DXSprite and texture quads, but none that specifically answered my question. Also, I already made an engine using ID3DXSprite and it is good and pretty fast, but it would be faster if I optimized a texture quad engine myself and I want more control over playing with the u and v texture coordinates for some of the features I want to add.

Share this post


Link to post
Share on other sites
Alright, after reading that article and finding the gamedev article on vertex buffers, the problem is that I didn''t realize how exactly to use "dynamic" vertex buffers. Someone told me to use them and for some reason I thought all it involved was setting the D3DUSAGE_DYNAMIC flag when creating it. Nevermind, it makes a lot more sense now

Share this post


Link to post
Share on other sites