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
  • 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

Reply
  • 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

Children