Jump to content
  • Advertisement
Sign in to follow this  

Combining glLoadName & glDrawArrays

This topic is 4711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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)

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

Share this post

Link to post
Share on other sites
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.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!