I'm drawing a lot of rectangles, thus I'm using the WebGL2RenderingContext.drawArraysInstanced() for it. I'm also using a lot of buffers to control shaders per instance (containing such data as position, colors, state, etc). I want now to affect the order in which my instances are being drawn (for example, to bring to the front the instance clicked by the user) and I'm looking for something like INSTANCE_ARRAY_BUFFER
, something similar to ELEMENT_ARRAY_BUFFER
, but for instances instead of vertices. Something that would allow me to tell "draw instances in the following order: 3,1,2,0,...". Is there any API which would allow me to control the order of the drawn instances without modifying the order of elements of all the data buffers?
Based on my research so far I suspect the answer will be "no", but maybe I missed some hidden WebGL API. Moreover, as a bonus question – was something like that introduced maybe in recent OpenGL versions or the WebGPU?