   Efficient way of handling lots of small meshes ?
  Hi,I'd like to know if any of you have experience in this kind of problem : I have a lot (from 100s to 1000s) of small objects (from 4 to a few 10s of triangles) to display. The list can change from frame to frame, so I can't really create a big static mesh.How do most engines deal with those kind of small props ? I thought I could create a bunch of dynamic buffers, and just before rendering I would parse the list of objects to render, and batch all the small ones into the big buffers. But that would mean a lot of locking / copying (and transforming the vertices) / unlocking ... so I'm not sure it would be very usefull ...Any idea ?   
Quote:Original post by paicHow do most engines deal with those kind of small props ? I thought I could create a bunch of dynamic buffers, and just before rendering I would parse the list of objects to render, and batch all the small ones into the big buffers. But that would mean a lot of locking / copying (and transforming the vertices) / unlocking ... so I'm not sure it would be very usefull ...That sounds reasonable enough to me. If all of your meshes have the same vertex format, and are all [indexed] triangle lists, you can then draw the entire buffer in one go. Dynamic buffers are pretty well optimised, and memcpy() is fast. Just make sure you Lock(), memcpy() and Unlock() as far before rendering as possible.   ;  Consider using 2 or 3 normal vertex buffers and cycle through them, rather than a single dynamic vertex buffer. That way it would work on the Xbox 360 as well and the locks are still instantaneous.   ;  Well, no one came saying this is the most ridiculous idea they ever heard, so I guess I will try this approach :)I hesitated mainly because of the transformation of vertices : to draw everything in one DIP, I need to transform each vertices before copying them. I hope it won't cost too much CPU :)Thx ! (and if anyone has another approach to this problem ... feel free to share :)   ;Quote:Original post by RottbottConsider using 2 or 3 normal vertex buffers and cycle through them, rather than a single dynamic vertex buffer. That way it would work on the Xbox 360 as well and the locks are still instantaneous.Locking a non-dynamic vertex buffer is fast, but it takes a long time for the data to get from the CPU to GPU.A dynamic vertex buffer normally goes in AGP or CPU/GPU shared memory, and a static one goes into video memory.When you Lock() a dynamic vertex buffer, the driver can give you a pointer directly to the shared memory. If you lock a non-dynamic vertex buffer, you're usually given a shadow copy of the data, which is then uploaded to the card - which is slow.If you have data that changes more often than once a second or so, use a dynamic vertex buffer - there's almost no exceptions to that rule.   ;  Only that you have to write entirely separate code for the 360 where all memory is shared. Just something to bear in mind.Edit: If you want to do the transformations on the GPU you could do it like boned animation, give the shader an array of transformation matrices and put the array index into your vertex structure.   ;  What you describe is solved best with hardware instancing. So if you can use pixelshader >=3.0 then I would recommend this.Here is a sample which shows different solutions to your problem, including hardware instancing:http://msdn.microsoft.com/en-us/library/bb174602(VS.85).aspx   ;  All your meshes are different, if the answer is no, try load only one,and make pointers to that one:LPD3DXMESH Box;Load the mesh, textures etc, then:LPD3DXMESH *Boxes[1000];for(...)Boxes =  &BoxTransform Boxes[0]Draw Boxes[0]Transform Boxes[1]Draw Boxes[1]