Sign in to follow this  

DX: Best way to render any number of objects

This topic is 4713 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 want to know the best way of rendering an ever changing amount of objects. ie, say i created 10 objects of type CSquare on the fly, whats the best way of rendering them all? Im trying to get started with working on a simple engine, so obviously i cant hard code the number of objects ill need to render. Is it best to just copy all of the data into the vertex buffer each frame? Or will that be far too slow? What about passing a pointer to the vertex buffer when we create an object, so it can fill it with data when it gets created, but then change the VB if the object moves? Any help you can give will be much appreciated. Cheers

Share this post


Link to post
Share on other sites
What you're going to want to look at is called a Dynamic Vertex Buffer. It's in the D3D documentation. The basic idea is that you create one large dynamic vertex buffer during initialization time. Then each frame you fill this vertex buffer with the vertices you need to render however many triangles are necessary.

Notice that when you create any kind of vertex buffer (be it static or dynamic) you need to specify the vertex format and size. If your objects will have different vertex formats, then you'll need one dynamic vertex buffer per vertex format. However, you could decide on one vertex format and make all of the objects in your engine use this one format even if certain parts of the vertex go unused for a given object. It's up to you.

What happens if in one particular frame your application creates too many objects to fit in your dynamic vertex buffer? Then you render your objects in multiple passes. You fill in you dynamic vertex buffer until its full and then render it. If there's more objects left to render, then you do the same thing again until you've rendered all the objects you wanted to in the frame.

Dynamic vertex buffers come up pretty often in this forum. Do a search and you'll find lots of information.

Hope this helps,
neneboricua

Share this post


Link to post
Share on other sites
cheers thanks alot, certainly will give me alot to read up on :)
Ive heard of dynamic vertex buffers for, but was under the impression you just resized them to fit. Is it sensible to create a bunch of primative drawing classes? ie, CVertex, CLine (consists of 2 CVertex classes...), CTri (consists of 3 CVertex classes...) etc, or is there a better way of managing objects?

Cheers, much appreciated.

[Edit: As a quick after thought - whats a good size to initialise the VB to? Are we talking thousands / 10s of thousands / 100s of thousands of triangles into 1 VB?]

Share this post


Link to post
Share on other sites

This topic is 4713 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this