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

Setting a dynamic index buffer

Started by Valor Knight Jan 22, 2006 at 11:12 PM 4 replies 850+ views
Original Post
Valor Knight
Valor Knight
RESOLVED I was currently using a dynamic index buffer, or so I though, until today when I was adding in degeneative triangles to my terrain, and noticed, much to my dismay that my index buffer broke: http://photobucket.com/albums/c305/biohaz1/?action=view&current=INDEXBUFFERISFed.gif I have no idea on what happened, but using the settings I had, I was getting triangles every direction if I did not use the entire buffer (I do not remember if I was working on the lod with the dynamic flag or not, so I may have triggered it when I was trying to clean up my code). Now this is the current working buffer, with the defunct one commented out.

if(FAILED(_pDevice->CreateIndexBuffer(numindicesperpatch * sizeof(WORD),
/*D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY*/0, D3DFMT_INDEX16,
D3DPOOL_MANAGED/*DEFAULT*/, &_vecpIndexBuffers[patchindex], 0)))
How would I do one dynamically correctly? Does the Index buffer need the DYMANIC flag or is it just for the vertex buffer? Thanks EDIT: Broke up the long line of code - it was messing up the way your post was displayed. [Edited by - Valor Knight on January 29, 2006 4:09:01 PM]
There is no life without honor
jollyjeffers
jollyjeffers
Technically speaking you don't REQUIRE the dynamic flag - but performance can really suck if you don't use it. It's basically a hint to the runtime/driver so that it can place the resource somewhere that it's easy to change.

What is your code for locking/updating the buffer? It is possible to trip-up using those - particularly if you have nooverwrite/discard flags specified. Some older hardware tends to have odd behaviour with various combinations of these flags.

Also, that mess of triangles - do they actually correspond to locations of vertices in any way? I've had that sort of "noise" created when I mis-match the format/alignment/stride of data - causing the GPU to address the wrong data with the wrong semantic..

hth
Jack
<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ |
jamesw
jamesw
If you're not using the entire buffer remember to only render the number of primitives you are using in your call to DrawPrimitive().
Valor Knight
Valor Knight
This is my buffer creation / locking

if(FAILED(_pDevice->CreateIndexBuffer(numindicesperpatch * sizeof(WORD), D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &_vecpIndexBuffers[patchindex], 0)))..//LockWORD *indices = 0;_vecpIndexBuffers[patch]->Lock(0, 0, (void**)&indices, D3DLOCK_DISCARD);


Do I need the D3DUSAGE_DYNAMIC flag? If so, what is the correct pool setting?

Quote:
Original post by jollyjeffers
Also, that mess of triangles - do they actually correspond to locations of vertices in any way? I've had that sort of "noise" created when I mis-match the format/alignment/stride of data - causing the GPU to address the wrong data with the wrong semantic..

I guess it could have, but not anything that I was drawing ( I was only drawing one patch of land). It was doing that if I used an empty index buffer as well, so it must have been memory thing, I dont think I had the pool correct for dynamic.
_________________________

I am only calling DrawIndexedPrimitive with the correct number of triangles, But in the past it did not matter (at least for the extra triangles showing up - now that I think about it, it was before I added DYNAMIC flag)
There is no life without honor
jamesw
jamesw
If you lock the buffer every frame then yes, you should use the dynamic flag. Here's some relevant docs:

Quote:
index buffers and vertex buffers cannot be created using D3DPOOL_MANAGED together with D3DUSAGE_DYNAMIC.

For dynamic textures, it is sometimes desirable to use a pair of video memory and system memory textures, allocating the video memory using D3DPOOL_DEFAULT and the system memory using D3DPOOL_SYSTEMMEM. You can lock and modify the bits of the system memory texture using a locking method. Then you can update the video memory texture using UpdateTexture.


If that seems like too much trouble, you can just use a D3DPOOL_DEFAULT version and lock that. Also I found this:

Quote:
The D3DLOCK_DISCARD and D3DLOCK_NOOVERWRITE flags are valid only on buffers created with D3DUSAGE_DYNAMIC.


That may very well be the source of your problem when using the managed buffer.
Valor Knight
Valor Knight
Thanks, I figured it out a while ago and works fine now (I was telling it too many triangles to draw).
There is no life without honor

Topic Locked

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

Sign in to reply to this topic.