c++ - D3D9 drawing 100k cubes from Vertexbuffer is very slow -


i'm newbie in stuff. i'm working book shows me how use d3d9 , how create vertexbuffer , draw cube it. created class in c++ wraps needed stuff draw single cube. means every cube object creats own vertexbuffer , stores pointer vertexbuffer, pos, rotation , scaling values.

the problem drawing of 100k slow. ~2-3 fps if try draw 100k cubes (with nvidia gtx 970)

instead of writing long code here decided show current steps im doing draw cube because think there mistake. if code realy need add sure. k important steps:

//create vertexbuffer single cube obj object:

1.) pdevice->createvertexbuffer() //using: d3dusage_writeonly 2.) pvertexbuffer->lock() 3.) memcpy() //copy stuff vertexbuffer 4.) pvertexbuffer->unlock(); 

//drawing cube object (this stuff im called in for-loop runs trought 100k cubes):

1.) pdevice->setfvf() 2.) pdevice->setstreamsource() //to use cube's vertexbuffer 3.) create rotation-, translation- , scalingmatrix 4.) create world matrix matrix above 5.) pdevice->settransform() //use worldmatrix 6.) pdevice->drawprimitive() 

what found out if make vertexbuffer static (means 100k use same vertexbuffer) 10 times more fps (~30fps) idk.. 100k cubes sounds me still not (100k cubes , 30fps o_o?). think im doing totaly wrong :/

someone have idea whats mistake?

you should make vertex buffer static unless requires dynamic. gpu can use information optimise.

while graphics card can many millions of triangles, can't many millions of draw calls. single draw call quite expensive, , later on try , minimise state changes on graphics card.

as mentioned in comments instancing 1 way go render many of same thing. merge cubes , render in 1 shot (this minecraft degree).

there other methods depends on trying achieve. more involved others.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -