glLoadName() using vertex arrays?

Hey all, I broke my picking by putting placing vertex arrays in my project and now trying to figure out how to do this w/ vertex arrays.

I have a wire frame mesh and I’m trying to have each element of my mesh highlighted by hovering the mouse over that triangle. I think my problem is that I’m using vertex arrays. I set the vertex arrays up just as soon as my application reads in an input file, parses the coord values, and loads them into vertex arrays.

I think I need to call glLoadName(int) for each drawing command (each triangle) while on the MODELVIEW matrix during render mode SELECT so that I can process the hits. But I don’t know how since all my triangles are now one big vertex array where I then make a call like the following to draw them.


gl.glVertexPointer(3, GL.GL_FLOAT, 0, vElementsBuffer[index]);
gl.glDrawArrays(GL.GL_TRIANGLES, 0, vElementsBuffer[index].capacity() / 3);

Is there a way to assign a name to each triangle when using vertex arrays? Does that make sense? Any help much appreciated.

You can only set 1 name per vertex-array.

glPushName();

glLoadName(…);
glDrawArrays(…);

glPopName();

Ugh, your kidding? No way around that? I had to use vertex arrays because my performance any other way was so bad. But now it looks as if I’ve traded highlighting my elements for speed.

I’ve got to find another way.

Try displaylists, you can insert ‘any’ gl-call in it.

Downside is that your geometry must be static, but if it is, it’ll be very fast.

Hi,
Alternatively can’t you have your vertex arrays for normal rendering and a cheap rendering version on the neighbourhood of the mouse to retrieve the picked / selected object.?

Yeah, but as I understand it, I can’t do that because highlighting elements in my mesh makes it not static.

I’m not sure I understand this. You mean, use vertex arrays in one mode, then switch to an edit mode where the performance sucks and not use vertex arrays so that I can select an object?

In fact my point was to try to use a reduced version of your mesh and try to use this simplified version for the picking.
But if you have to highlight a part of your mesh “on the fly” when the mouse moves over it certainly can be hard to do.

You can also try to renderer your mesh with a different color for each polygon and try a glReadPixel to simulate a picking… but once again it can be hard to implement depending on your specific concerns.

Edit and adding : You can also try to pick on a “raw version” of your mesh (quad tree or something like that) then narrow down the search, that will allow you find the picked polygon in multiple passes, but quite fast ones…

You mean something like, click on an area of the model and drag to make an outlined rectangle, release the mouse, and it automatically zooms in on only the selected group of elements where I then do picking on those? That could possibly work if I understand you correctly. Wouldn’t happen to know of any example code, would you?

Can’t do that, I use grouped elements w/ specific colors.

I sort of understand quad trees, but not sure what you mean by making multiple passes and narrowing it down.

Now that I think about it more, wouldn’t I have to be doing picking in the first place in order to detected which lines collide when I draw the rectangle to select elements of my mesh?

Hi, I don’t know how you will handle your mesh in the end but.

If I understand you well, your problem is that you have poor performance when using picking and immediate mode.
On the other hand, when using advanced techniques as vertex arrays or VBOs you can use picking (or only one name per array).

My suggestion, but once again it may not suit your needs, is to use 2 seperates rendering routines.

On the standard one you are using vertex arrays to draw as fast as possible.

Here I see multiple options when your mouse moves :

  1. you try to find (with a quad tree, or some decimation algorithm) the smallest subset of your mesh you have to draw to peform the picking.

  2. You “draw” (i fact you don’t draw it but you use it in selection mode) a very simplified version of your mesh, perform the picking and find the subsection of your mesh that is concerned and go on like this.

  3. You add a special color vertex array to your mesh, let us say that each triangle have a color, and you perform a draw on the back buffer with the colored mesh, you use glReadPixel to find the color under the mouse with a good performance, at least you have to try if 2 draws with vertex arrays is quicker than your hold method…

I may not be clear, and i certainly don’t give you straight answers but I think that these are good tracks to follow…

Hope it helps

Just to clarify, I have great performance when in RENDER mode and using my vertex arrays (a single vertex array per group of triangles, currently on avg of 4 - 8 vertex arrays (groups) to draw the model). Problem here is that I can only assign one name per vertex array and not per mesh triangle.

I have terrible performance when in SELECT mode because I assign a name to each triangle and have a vertex array for each individual triangle of my mesh (which is not hard to understand I guess since my mesh’s have 10,000 - 100,000 trianlges on average).

  1. That’s an idea.
  2. Sounds a bit like 1, an idea.
  3. My triangles must be groups by specific colors and cannot be different colors.

So, I guess I’m down to ideas like 1 or 2. Something that could have been so easy, because of performance has just gotten really tedious. :frowning:

Having a zillion vertex-arrays is realy bad for performance.

Try to upload only one vertex-array and render individual triangles with glDrawElements() instead of glDrawArrays()

Not that that is the solution, it only makes it less bad. I think you have a design-problem here. SELECT mode is just not meant for stuff like this, and it will certainly crawl. color coding would be best, each triangle has its own color (all 3 vertices have the same color), just add a GL_COLOR_ARRAY and disable texturing/lighting/shaders.

frame-rendering-loop:

  1. clear depth/color-buffer
  2. render color-coded
  3. read color of pixel of mouse with glReadPixels();
  4. clear depth/color-buffer
  5. render model

to further improve performance you might want to only perform step 1+2+3 once a second, while always performing 4+5.