3d - Render multiple models in OpenGL with a single draw call -
i built 2d graphical engine, , created batching system it, so, if have 1000 sprites same texture, can draw them 1 single call opengl.
this achieved putting in single vbo vertex array vertices of sprites same texture.
instead of "print these vertices, print these vertices, print these vertices", "put vertices toghether, print", clear. easy enough, i'm trying achieve same thing in 3d, , i'm having big problem.
the problem i'm using model view projection matrix place , render models, common approach render model in 3d space.
for each model on screen, need pass mvp matrix shader, can use transform each vertex correct position.
if transformation outside shader, executed cpu, not idea, obvious reasons.
but problem lies there. need pass matrix shader, each model matrix different.
so cannot same did 2d sprites, because changing shader uniform requires draw every time.
i hope i've been clear, maybe have idea didn't have or had same problem. know fact there solution somewhere, because in engine unity, can use same shader multiple models, , away 1 draw call
there exists feature you're looking for, , it's called instancing. instancing, store n
matrices (or whatever else need) in uniform buffer , call gldrawelementsinstanced
draw n
copies. in shader, input gl_instanceid
, index uniform buffer fetch matrix need particular instance.
you can read more instancing here: https://www.opengl.org/wiki/vertex_rendering#instancing
Comments
Post a Comment