This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Any tips when using Scissor tests and glReadPixels to detect clicked areas ?

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 :

  • Apply a scissor test of a 1x1 rectangle at the clicked location
  • Redraw of the scene objects in a buffer, painting each object with a unique colour
  • Use glReadPixels on that buffer and infer the clicked element from its colour

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 ?

Parents Reply Children
  • 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 ?