opengl - Should I sort by buffer use when rendering? -


i'm designing sorting part of rendering engine. know changing render target, shader program, texture bindings, , more expensive , therefore 1 should sort draw order based on them reduce state changes. however, sorting based on index buffer bound, , vertex buffers used attributes?

i'm confused these because vaos mandatory , encapsulate of state. should peek behind scenes of vertex array objects (vaos), see state set , sort based on it? or should not care in order vaos called?

this confuses me vertex array objects. makes sense me not switching buffers in use on , on , yet vaos seem force 1 not care that.

is there general vague or not agreed on order on sort stuff rendering/game engines?

i know binding buffer changes global state surely must beneficial hardware draw same buffer multiple times, maybe small cache coherency?

while vaos mandated in gl 3.1 without gl_arb_compatibility or core 3.2+, not have use them way intended... say, can bind single vao duration of application's lifetime , continue bind , unbind vbos, etc. traditional way if somehow makes life easier. valve famous advocating doing in their presentation on porting source engine d3d gl... tend disagree them on points though. lot of things mention in presentation make me cringe has years of experience both d3d , opengl; making suggestions on how port api have minimal working knowledge of.

getting performance concern though, there can validation overhead changing bound resources frequently, more "simply changing global state." gl commands have validation in order determine if need set error state. validate input parameters (which pretty trivial), state of resource command needs use (this can complicated).

other types of gl objects fbos, textures , glsl programs have more rigorous validation , more complicated memory dependencies buffer objects , vertex arrays do. swapping vertex pointer should cheaper in grand scheme of things other kinds of object bindings, since lot of stuff can deferred implementation until issue gldrawelements (...) command.

nevertheless, best way tackle problem increase reuse of vertex buffers. object reuse pretty high begin vertex buffers, if have 200 instances of same opaque model in scene can potentially draw 200 of them back-to-back , never have change vertex pointer. materials tend change far more actual vertex buffers, , sort drawing first , foremost material (sub-sorted associated states opaque/translucent, texture(s), shader(s), etc.). can add level batch sorting draw batches share same vertex data after have been sorted material. ultimate goal minimize number of draw commands necessary complete frame, , using priority/hierarchy-based sorting emphasis on material delivers best results.

furthermore, if can fit multiple lods of model single vertex buffer, instead of swapping between different vertex buffers can draw different sets of indices or different range of indices single index buffer. in similar way, texture swapping pressure can alleviated using packed texture atlases / sprite sheets instead of single texture object each texture.

you can squeeze out performance reducing number of changes vertex array state, takeaway message here vertex array state pretty cheap compared lot of other states change frequently. if can implement secondary sort reduce vertex state changes go it, not invest lot of time in more sophisticated unless know bottleneck. prioritize texture, shader , framebuffer state first general rule.


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -