Jump to content
  • Advertisement
Sign in to follow this  
rXpSwiss

OpenGL glDrawElements with glBufferSubData ? -> 2 or more indexes ?

This topic is 1507 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,

 

I was wondering, is there a way to use glDrawElements with glBufferSubData with multiple indexes ?

By that I mean : 

I parse an obj file and the faces definition tells me which normal goes with which vertex etc. A vertex can be used multiple times and a normal too but they can also be used separately.

I could duplicate the vertices put each vertex/normal/texCoord in a struct... But I would rather use , if that is possible, multiple indexes. Use them to tell OpenGL "use idVertices for the vertices, use idNormals for the normals, ...".

 

Is that possible or should I prepare the data in a single array of structs and draw it with glDrawArrays ?

 

rXp>!<

Edited by rXpSwiss

Share this post


Link to post
Share on other sites
Advertisement

In short, no. OpenGL takes one index for a vertex (including position and normal and whatever else is there). So you need to duplicate data in order to have "unique" vertices for the ones that share a normal or a texture coordinate in the OBJ file.

 

Although technically, you could do the multiple indices thing on recent hardware (by only sending indices to the vertex shader and reading from buffer textures manually). It is not very straightforward and thus not advisable, however. Simply duplicating vertices is sooooo much easier.

Share this post


Link to post
Share on other sites

Absolutely, you can in modern OpenGL. Google programmable vertex pulling. One way would be to store your incidences as vertex attributes. Then you store your actual vertex attributes in a SSBO. In your vertex shader you index the SSBO arrays using the incidences stored in the vertex attributes. The second way of handling it would be to forgo traditional vertex attributes all together. Just bind a blank VAO (must be using a core profile context) and store both your vertex attributes and incidences inside of SSBOs. In your vertex shader you index the arrays containing your incidences using gl_VertexID. Then you take those and use them to index the arrays containing your vertex attributes. In both cases you would be using glDrawArrays instead of glDrawElements.

 

You'll probably get better performance if you just stick to the traditional method, and you'll definitely get wider compatibility.

Edited by Chris_F

Share this post


Link to post
Share on other sites

Okey so it is possible but it would need some changes. So if I want, for example, compute things with the "original" data I just need to keep it stored in my model object while also having the "data to be drawn". (if I want to switch from flat shading to smooth shading, etc).

I guess I would not get better performance if in this case. I always fear that drawelements is better than drawarrays and vice versa depending in the situation.

 

Thank you for your answers.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!