Jump to content
  • Advertisement

Archived

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

Vertex Buffers in a 2D Engine

This topic is 5804 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! I''m working a on 2D graphics engine in DirectX 8 currently. I''m working on a CSprite class that uses a VertexBuffer8 object to store all location data(it''s a quad). Everytime I draw the sprite I use sprite.draw(); which sets the texture for the sprite object, creates an origin matrix based off of current rotation,translation, and scaling matrices, and finally makes a call to draw primitve. It works fine for about 100 sprites (I haven''t bothered trying more) on screen at one time but am I doing it in an ok way? I remeber reading somewhere that you want to make as few calls to SetTexture as you can (batching?). I tried creating a simple test where I call SetTexture only as many times as I needed to change textures(5 different textures = only 5 SetTexture calls) vs my current way of drawing and I didn''t see any difference in performance. Am I doing it the correct way or is it more important to batch the DrawPrimitive calls since I''m only sending 4 verticies? So, I guess my big question is what is the best way to go about organizing a scene when working with 2D-style graphics? -jon

Share this post


Link to post
Share on other sites
Advertisement
I can''t say anything particular for 2d but generally in DX the fastest way to do all drawing is to batch primitives, sending 4 vertices 100 is ALWAYS slower then sending 400 vertices one time, I''d suggest that you save all your vertices in a vertex buffer, that fastest way might be to use triangle lists instead of triangle strips and render all primitives that uses a texture then render all primtives that uses another texture and so on, using trilists (or indexed trilists) will probably ease up to process of batching by texture since your 2d sprites doesn''t have to use the same vertices.

Regards Shadows

PS. Where did I get tristrips from are you even using them, well whatever DS.

Share this post


Link to post
Share on other sites
Ok....So I need to batch all of my vertices together and draw them at one time. Now I can only batch vertices together that use the same texture, right? Which means if I have a specific sprite that uses a unique texture, I''m back to just sending 4 vertices to the DrawPrimitive call. I''m under the assumption that I can only use one base texture per each DrawPrimitive call.

Now, if I stuck as many different sprite graphics into a big (512x512) texture then just used that texture for a group of specific sprites, would that be a better way of drawing them?

-jon
PS. I am currently useing triangle strips

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!