Jump to content
  • Advertisement

Archived

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

carb

Buffer Updates - Question

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

Say I were doing a 2D tetris game in DirectX9 ... Every so often, I''d want to change the position of the blocks. Wouldn''t I need to update the vertex buffer with all the new coordinates? I''m confused about this, because several people on the forum have said, quite plainly, "this is bad" ... but if that''s true, what''s another way to go about it? Is there a way to translate just a _set_ of coordinates? - Ben

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Well tetris just happens to be an odd example, as everything is made up of small textured quads.

You could set the world transform, draw a quad, set the world transform, draw another quad, but this would be really slow.

You could keep all the blocks that have made it to the bottom be part of a static buffer, and update it only when another piece reaches the bottom, adding and/or removing bits as needed.

The best bet for a tetris game though, is to use a dyanamic buffer, and transform the coordinates yourself before putting them into the buffer and leave the world transform at identity.

Since it''s 2D, you probably want to put pre-transformed XYZRHW coordinates into your buffer. It''s easier to deal with for 2D, and will render faster.

Constantly updating a static buffer is bad, and will kill performance. Updating dynamic buffers is fine. That''s what they''re there for... Data that changes all the time.

Share this post


Link to post
Share on other sites
What is the difference between a static and dynamic buffer?

Basically, I''ve gone through a plethora of tutorials which do little more than show how to draw one shape, and rotate/texture/etc. onto it. I''m trying to figure out how to move from this to many shapes, some moving, some not, etc. So many tutorials give you the _absolute_ basics, and then that''s it - you''re left to fend for yourself from that point on.

Appreciate the reply, btw.
- Ben

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Read this for info on how to use dynamic buffers correctly.

http://www.gamedev.net/community/forums/topic.asp?topic_id=148414

Data that doesn''t change should go into a static buffer. Character models, terrain, houses, trees, rocks, etc. They can be placed, rotated, and scaled with a world transform, or animated via a shader, but the data in the buffer is never modified.

Data that does change should go into a dynamic buffer.

Static data is stored on the GPU once, and the GPU uses it whenever you ask it to. Dynamic data is transferred to the GPU everytime you draw. Each type of buffer has it''s uses.

Now, a tetris block never changes, it''s just translated and drawn, so you may think using a static buffer is the way to go... except that you want to reduce your draw calls to the bare minimum. Each one has tons of overhead.

How do we reduce the number of draw calls? By drawing more than one block at a time. Since placement of each block will constantly change, and because each block is very few polygons, it''s now more of a situation for a dynamic buffer.

Using a dynamic buffer will be slightly slower than using a static buffer, but this slowdown is more than outweighed by the overhead in drawing each block seperately.

Now you ask "But my blocks are going to have different textures or colors... how do you draw them all together. You can''t switch textures half way though a draw call."

Use one large texture, and use a portion of it for each block. In a 256x256 texture you can have 256 unique looking 16x16 blocks. Or 64 unique 32x32 blocks. Just adjust the UV coordinates to show only the part of the image you want.

If your blocks are just colored not textured, use vertex colors to draw each block in an appropriate color rather than material color.

Use these texture states for plain textures
0, D3DTSS_COLOROP, D3DTOP_SELECTARG1
0, D3DTSS_COLORARG1, D3DTA_TEXTURE
1, D3DTSS_COLOROP, D3DTOP_DISABLE


Or set these render states for colors:
D3DRS_COLORVERTEX, TRUE
D3DRS_DIFFUSEMATERIALSOURCE, D3DMCS_COLOR1
D3DRS_AMBIENTMATERIALSOURCE, D3DMCS_COLOR1

And these texture states for colors:
0, D3DTSS_COLOROP, D3DTOP_SELECTARG1
0, D3DTSS_COLORARG1, D3DTA_DIFFUSE
1, D3DTSS_COLOROP, D3DTOP_DISABLE

Share this post


Link to post
Share on other sites
So, basically, you can use as many buffers as you want? Is there some limit or any reason not to?

Can you perform world transformations on an indvidual buffer?
- Ben

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!