Skip to main content
GameDev.net gamedev.net
🔒 Locked

Vertex Buffers

Started by Laroche Jul 22, 2002 at 4:05 PM 3 replies 400+ views
Original Post
Laroche
Laroche
I''ve gotten to the point where I can use vertex buffers, but I have a question regarding the number of verts it can hold. Lets say I have Sprite objects, which are just 4 verts with a texture (from focus on 2d with direct 3d). How do I make the amount of vertices in the vertex buffer variable? Since the game is going to have a lot of temporary particle type things and sprites, what am I supposed to put as the size of the vertex buffer? Just a big number and leave it at that?
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
zngb
zngb
well i''m no master but maybe i can help

if i would have to make a nice game with 2d stuff i would probably have several vertex buffers.
one for particles one for units and ugly things and stuff.

the size can be determined by the maximum number of particles or units you allow in your game or anything.

to change these values constantly you have to lock and unlock the buffer all day and that may be time consuming on static vertex buffers. if you create the vertex buffer with the nice D3DUSAGE_DYNAMIC flag locking will be much faster and amazingier.

now all of this is probably pure bullshit so let''s hope a master will come and fix my false sentences.

btw what is the icon i chose for my post? it''s a hat? what is it????

May The Gzoo Be With You!
~Lord Gzoo
--Amir
cheez_keeper
cheez_keeper
"master" ... well lets just say i don''t stink at DX8

i like to give many solutions to a problem so you can "go your own way" (gotta like the Mac)

#1> Make lots of variables, i.e.
LPDIRECT3DVERTEXBUFFER8 sprite = NULL;
LPDIRECT3DVERTEXBUFFER8 particle[99] = NULL;
LPDIRECT3DVERTEXBUFFER8 thing1 = NULL;
LPDIRECT3DVERTEXBUFFER8 thing2 = NULL;
LPDIRECT3DVERTEXBUFFER8 thing3 = NULL;
LPDIRECT3DVERTEXBUFFER8 thing4 = NULL;

yes, it is static like you mentioned, but much easier to manage so do it where you can (my advice for beginners anyway)

#2> make a dynamic array (crack open that C++ book) of buffers
LPDIRECT3DVERTEXBUFFER8 *sprite;

this one is fun. i do it a lot if i have a bunch of fairly identical (like making little 2d boxes out of triangles...) buffers. by identical i mean the same number of verts, this become really hard to manage if you cant use array style indexing to jump around in your memory.
p.s. - don''t forget "delete"

#3> wait for DX9, they brought back all the old 2D stuff from pre-DX8 days (yea!). i tried it out it worked just like the good old days (gotta go find those nice howto sites in 2D again). so you can look forward to blitting blissfully without worry about where the blazes the memory is coming from.

#4> this one is tricky. did it once; got good performance and memory usage, nearly committed suicide a dozen times and went through 93 bottles of asprian because it made my head ache (dont tell me i didnt tell you so)... create the buffers on the fly. that is right, actually call CreateVertexBuffer in the middle of your program FOR SPECIAL OCCASIONS. it is SLOW but if you only call it when you NEED it and multi-thread your game so the creation takes place on the AI/GameUpdate thread instead of the graphics thread you will find that you can create them faster than your computer can lock/unlock a piece of memory already existing... that isnt a theory i actually put in the leg work and tried it ONCE. The real tricky here is the memcopy you have to do after creation. so there is some limit (it was a buffer of about 80 verts for me on this dinosaur) to your performance gains over maintaining an array in the heap (see option #2)

my 2 cents

Brett Lynnes
cheez_keeper@hotmail.com
Brett Lynnescheez_keeper@hotmail.com
Laroche
Laroche
So every sprite object can have it's own vertex buffer? I suppose during render i just SetStreamSource then?

[edited by - laroche on July 24, 2002 2:36:32 PM]
Check out my music at: http://zed.cbc.ca/go.ZeD?user_id=41947&user=Laroche&page=content
lor3
lor3
I have been thinking the same thing a little. If you are doing nothing but "2d" quads, using 4 verts (in a tri strip or whatever), why not just create a single vertex buf with the following:

pVertices[0].x = pVertices[1].x = 0;
pVertices[2].x = pVertices[3].x = 1;
pVertices[0].y = pVertices[2].y = 1;
pVertices[1].y = pVertices[3].y = 0;

and the add (multiply) a scale matrix (to that sprite's size) with any translating/rotation translation you want to do...

??? I'm a newbie too though (nearly finished my first "engine") .. so no idea if changing vertex buffers is any slower than multiplying matricies.



[edited by - lor3 on July 24, 2002 3:42:50 PM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.