Greetings,
I'm trying to find different ways to detect which element was clicked on a rendered image with OpenGL ES 2.x.
It seems that the most common way to do this is to :
Giving a "unique colour" to each object efficiently seems a bit tricky.
However, is there any trick to speed up this dummy redraw ? Given that fragments will only be displayed in a 1x1 area, does the buffer resolution matter ?
Is there any OES extension that could speed up this process even more ?
Using glReadPixels will force the driver stack to drain the rendering pipeline and totally destroy your application's performance, so I would highly recommend not doing it this way. Ideally just find some means to do it purely in software; software nearly always has enough information to do this (e.g. if it is a 3D game you always need the geometry for collision detection and physics, if it is a 2D game you need to know layering and how things are stacked on screen). The only complication with the 2D games is sprites with transparencies, but it's solvable.
The scissor minimizes the cost, but you'll still end up draining the pipeline which is always bad news.
HTH, Pete
Ah, interesting information !
Would it also drain the whole pipeline if the whole scissor operation is done against a off-screen rendering buffer (like the ones used to do a render to texture) ?
In general yes, unless you are using an asynchronous glReadPixels from a second context, which would avoid the pipeline draining but which would also add quite a bit of latency for processing user events (so the clicks will be one extra frame behind what is on screen, rather than two frames behind).
Cheers,
Pete
Interesting... It never occurred to me that a second context could be used like this... Is there a blog article about how OpenGL contexts are implemented on Mali ? Wouldn't context switching stall the rendering pipeline ?
The OpenGL Wiki is far from being exhaustive on the subject.
Also, is there any page regrouping all the blog articles about OpenGL and Mali ?