Instancing, Batching, and Conditional Rendering


I’ve been wondering how to combine these three techniques using OpenGL 3.2. Instancing and batching is not that hard, assuming one wants deferred shading, which factors out lighting. Then, all one needs to do is to render N instances M times (once for each material). By using texture layers etc. M can be decreased.

But conditional rendering? In OpenGL 3.2, I start and end it with glBegin/EndConditionalRendering. I would have to call this once per object. This already doesn’t fit with instancing, which would make little sense if one renders each object explicitely. And batching? I would have to call these two functions N*M times…

Of course it would be awesome if there is a connection between conditional rendering and instancing in OpenGL 3.2, but I don’t see any in the spec.

Any ideas?

They don’t go together because they aren’t meant to.

When you render an instance of something, the idea is that each instance is relatively negligible. It is small and takes up fairly few resources to render. The reason you render them as instances is because you have a lot of objects (thousands) that use the identical mesh data (how you process that data is up to you). The purpose of instanced rendering is to cut down on state changes between instances.

Conditional rendering is for a single object that takes a lot of rendering resources. That means you only want to render it if it is absolutely necessary.

This is the direct opposite of what you use instanced rendering for.

Great answer!

Indeed, great answer, thanks!