But if you’re saying that (by default/“Nez way”), Nez will sort the draw calls based on depth, then shouldn’t my draw calls be sorted then?
You have two calls happening one after another and you are overriding the layer depth. Nez can’t sort that. Do your two draws in separate RenderableComponents and then it can sort it. Have a look at the Nez.samples repo for lots of examples of sorted calls based on layerDepth and renderOrder.
So what you're saying is that multiple layerDepth don't work inside one RenderableComponent?
I was trying to render all of my tiles on one RenderableComponent to avoid creating entities for each tile. Is that just not possible then?
I guess what I could do it is to write some sort of wrapper that takes all of the "draw calls," sorts them by layer, then actually calls the batcher.draw(). Would that be the only way?
By default, DepthStencilState is set to None. Nez doesn't use or need a depth buffer because it sorts everything itself. What you are trying to do by just rendering stuff with no specific order requires the depth buffer to be enabled. You can of course make your own Renderer that doesnt sort and enables depth testing. The "Nez way" of doing this would be to just add multiple RenderableComponents on a single Entity if they are all related. Just let Nez handle the sorting and render order for you by setting RenderableComponent.layerDepth/renderLayer.
Alright, finally got it working. I ended up using one RenderableComponent for each layer, and have a main Component that sends the tiles to be rendered to their corresponding layer.
Thanks for all the help (and sorry if I was kind of pushy).
After looking more into the rendering code, I found a much simpler way to fix this issue. The only reason why Nez can't handle the depth layer is that DefaultRenderer uses Material.defaultMaterial, which has its DepthStencilState set to None.
that was enough to fix all of the issues and for the Batcher.draw() method to accept/use the depthLayer.
I was wondering, do you want me to submit a Pull Request to add this to the DefaultRenderer? Or perhaps add a new Renderer that fixes that issue? Or maybe add it to the docs? Just think it might be useful for others in the future.