Advertisement

Combining glLoadName & glDrawArrays

Started by June 16, 2005 05:37 AM
3 comments, last by ZMaster 19 years, 5 months ago
Hello everyone, does anybody know an effective way to assign object IDs when using Vertex Buffers? At the moment I do it manually by running through the VB sequentially like this:

for(long i=0;i<BufferCount;i+=6)
{
   if(i%6==0 || i==0)
	glLoadName(i/6);	// Assign Object A Name (ID)
   glDrawArrays(GL_TRIANGLES,i,6);
}

It works perfectly, but the larger the VB becomes, the more performance it eats (significally). Is there any way, to draw the buffer all at once (glDrawArrays(GL_TRIANGLES,0,BufferCount);) and also assign object IDs? Thanks for any help in advance Greets Chris
Anyone? :/

I just need to know a performance sensitive way to do picking out of a vertex buffer ;)
Advertisement
There are no ways to change the name in the middle of a vertex array, other than splitting the drawing into separate steps.
Ok, that's what I wanted to know.

Thanks ;)
I'm assuming you're using glLoadName to identify objects in your scene for selection mode.

However there's another way to do this:
Draw your scene in a first pass with only alpha testing, depth testing and color buffer writes enabled. Make sure that you use a pointer to a color array when drawing your scene. The color values should be a unique one for every object. Then just read the color value under your mouse pointer from the frame buffer and take the color value to identify the selected object.
In the second pass you can now draw your scene with "normal" colors and eye candy enabled.

I don't know if this is faster than using OpenGLs selection mode in your special case, but you can draw your arrays with only one call to glDrawArrays reducing overhead. Just try it, it's really not that hard to implement.

This topic is closed to new replies.

Advertisement