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

problem with indexbuffer

Started by billconan Nov 1, 2005 at 4:32 AM 2 replies 300+ views
Original Post
billconan
billconan
hi there guys, in my program(in c# code), the indexbuffer needs to be altered a lot. but i don't know how to do some of the operation. i mean it is easy to add new faces to the indexbuffer but how to delete faces? i lock the buffer and get a graphicsstream, but how to delete the data? another question is how if i add so many faces that the data exceeds the capacity of the indexbuffer? in some cases, i could not be sure about the number of faces in a model(the faces may be added randomly during the runtime). many thanks!
Skeleton_V@T
Skeleton_V@T
Quote:

how to delete the data ?


What do you mean ? Data can be replaced but never get deleted, what will it be after 'deleting' ?. A bunch of unused memory is just there but considerered rubbish.

Quote:

it is easy to add new faces to the indexbuffer.


As far as I concern, adding a new object (face) to render means overwriting the allocated index buffer with a significant value, so when we want to remove an object, just overwrite the index buffer (vertex buffer) with an incorrect value (i.e, a triangle with 3 vertices: (0, 0, 0) (0, 0, 0) and (0, 0, 0)) won't be rendered onto the screen.

But... Usually I don't remove an object that way, just bypass overwriting object's vertices order into the index buffer and count total number of faces the whole rendering process. Finally, pass that total faces number to Draw*Primitive* (). That way I can render only need-rendering objects.


Quote:

I could not be sure about the number of faces in a model(the faces may be added randomly during the runtime).



In my opinion, the amount of memory allocated for index and vertex buffer is faily small in comparison to another resources (textures, sounds ...). So you can freely allocate index buffer memory for an enormous number of objects but it'll still be quite small: 1,000,000 indices with 2 bytes (16 bits) each one with take you ~2MB of memory - equal to a 1024x768 (not exactly, just an example) bitmap. When will you be able to utilize such amount of indices for your objects :) ?.

An alternative, you can create multiple index/vertex buffer to use, but this takes quite some time to create/lock/unlock/swap each one so use it sparingly. Refer to the DXSDK documentations for more infos.

Hth
V@T
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--
billconan
billconan
hey thanks.
well, about the first question.
ok, here is the deal, my case is a 3d modeller. because the default vertexbuffer and indexbuffer do not fit for a 3d modeller, so i maintain my own datastructure. and in order to render the model, i convert it to a single indexbuffer model before the rendering. but the 3d modeller involves too many modification of the model, you know, like adding faces, deleting faces and if i updata the whole model everytime a tiny change happen to it, the proformance will be poor. so i'm thinking of only updating the changed part of the indexbuffer.

i ever thought of breaking the whole indexbuffer into lots of small ones, so i can make a better control over different model parts. but it is said that the performance of rendering Primitive is just the same regardless the complexity of the data, which means rendering lots of little indexbuffers may be a lag.

i have figured out some way to solve this, something like the "(0,0,0)" idea.
i can use an arraylist to keep the record of the idle space of the indexbuffer, everytime i delete a triangle from the buffer, i just overwrite it to 0,0,0, and it will not be rendered, and i add the idle position into the arraylist. if i want to add new faces, i will fill up the idle space first.

and i also find a way to expand the indexbuffer. i can use a reference to keep track of the indexbuffer i use. if it is full, i just create another larger indexbuffer and copy the content of the current one to the new one. and then change the reference so that it can point to the new larger indexbuffer.

these thought could be hard to implement, so i just ask for more professional solutions.
Skeleton_V@T
Skeleton_V@T
I don't get it, if you draw triangles using Triangle list then adding or removing a triangle shouldn't be a problem.
Or I'm completely take it wrong ?
--> The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones <--

Topic Locked

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

Sign in to reply to this topic.