-1

I'm trying to implement picking routine using transform feedback. Currently it works ok, but the problem is very low speed (slower than GL_SELECT).

How it works now:

  1. Bind TBO using glBindBufferRange() with offset (0 in the beginning).
  2. Reset memory(size of TF varyings structure) using glBufferSubData() (to be sure picking will be correct). The main problem is here.
  3. Draw objects with geometry shader that checks intersection with picking ray. If intersection has been found, shader writes this to TF varying (initially it has no intersection, see step 2).
  4. Increase offset and go to step 1 with the next object.

So, at the end I have an array of picking data for each object.

The question is how to avoid calling glBufferSubData() on each iteration? Possible solutions (but I don't know how to implement them) are:

  • Write only one TF varying. So it is not necessary to reset others
  • Reset data with any other way

Any ideas?

genpfault
  • 51,148
  • 11
  • 85
  • 139
  • It's been a while since I've used openGL, but couldn't you process all the objects in one go and have the geometry filter write out the IDs of all intersecting primitives? you would then have to find a way to associate the primitives with the objects they belong to, but that should be possible. – Knoep Oct 23 '17 at 17:26

1 Answers1

1

If all you want to do is clear a region of a buffer, use glClearBufferSubData. That being said, it's not clear why you need to clear it, instead of just overwriting what's there.

FYI: Picking is best implemented by rendering the scene, assigning objects different "colors", and reading the pixel of interest back. Your method is always going to be slower.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • Not all primitives can intersect the ray. My shader writes varyings only in case it does. Because I don't know count of the primitives, I use only the first varying and do offset for the next object. But the memory of the next first varying has been already affected by previous object. That's why I need to clear it. – Vetal B Oct 24 '17 at 15:21
  • Color-based method is not appropriate for me, because of rectangle selection and big-zoom posibility. Objects just could be degenerated and after zooming in there will be no selected objects – Vetal B Oct 24 '17 at 15:32
  • @VetalB: If you're zooming, then that zoom should be part of your picking render. If the user can see the object, then they can click on it. Box selection can work simply by reading all of the pixels within that box. "*That's why I need to clear it.*" It's still not clear why you have to clear the buffer. Feedback operations remember which data they've written. So if you do another feedback render, so long as you haven't *stopped* the feedback operation, then the data written will not overwrite previous data. It'll just move to the next location in the buffer. – Nicol Bolas Oct 24 '17 at 16:18
  • User may not see the object. Whole model may be rendered as one pixel(big zoom). Model can contain a lot of objects and the user must have posibility to pick each one. – Vetal B Oct 25 '17 at 08:48
  • Let me explain my way in more details. 1) Reserve TBO buffer. And bind buffer range from 0 2) Picking of the first object. Lets imagine it has 10 primitives. 5 of them intersect the ray, so 5 varyings are written 3) Increase bind offset on size of one varying element. This is because I don't know count of written primitives + saving the memory. 4) Picking of the second object. Because second object has already been written by the first object (as well as all the first 5) I need to clear it – Vetal B Oct 25 '17 at 08:50
  • @VetalB: If the entire model is that small, how could they possibly select it with the mouse? If multiple models share the same pixel, how can they select it? They can only click on a single pixel. What you want is impossible, even with your method, since each pixel will only generate a single ray. – Nicol Bolas Oct 25 '17 at 13:59
  • I mean the case of a large zoom out (one pixel on the display) + rectangle-selection of the whole model. With color-based method, there will be only one selected object (because of one pixel). With my method it is possible to check each object (simple math). – Vetal B Oct 25 '17 at 15:27