Optimising the drawing of overlapping rectangles

后端 未结 4 566
余生分开走
余生分开走 2021-01-30 08:33

I have a large number of rectangles, and some overlap others; each rectangle has an absolute z-order and a colour. (Each \'rectangle\' is actually the axis-aligned bou

4条回答
  •  一向
    一向 (楼主)
    2021-01-30 09:25

    You are making the very wrong assumption that the performance you will be getting on the desktop browser will somehow determine the performance on your iPhone. You need to understand that the iPhone hardware implements tile-based deferred rendering which means that the fragment shader is used very late in the pipeline anyway. As Apple themselves say (“Do not waste CPU time sorting objects front to back”), Z-sorting your primitives will get you little performance gain.

    But here’s my suggestion: if changing the colour is expensive, just don’t change the colour: pass it as a vertex attribute, and merge the behaviours into one super shader so you can draw everything in one or a few batches without even sorting. Then benchmark and determine the optimal batch size for your platform.

提交回复
热议问题