glDrawElements with glBufferSubData ? -> 2 or more indexes ?

Started by
1 comment, last by rXpSwiss 9 years, 6 months ago

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>!<

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.

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.

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.

This topic is closed to new replies.

Advertisement