Vertex buffer question
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.
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.
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.
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.
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.
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.
Never never never never never never never never never never never make a vertex buffer in anything but initialization!!!
How to use dynamic vertex buffers efficiently
How to use dynamic vertex buffers efficiently
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
You might be surprised how fast the newest D3DXSprite inmplementation goes. It does the batching and sorting by texture. You can''t play with the UVs though.
I like pie.
I like pie.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement