In opengl, we can associate a vertex with several different normals. For example, three adjacent planes of a cube will have a common vertex, i.e., a vertex may belong to three different planes. Then when we specify each of these three polygons, the common vertex will be given three different normals. My question is, in the vertex shader, which normal will be returned by gl_Normal?

The vertex shader will be run 3 times, once for each normal.

Thanks. Does it mean that opengl will create a new vertex whenever it sees a glVertex command even in the case that the vertex may have the same coordinates as the one given before?


Vertices can only be re-used when you use indexed vertex arrays and access the same index twice.

Yes, each glVertex call will generate a new vertex and use the other currently set parameters (normal, color, tex coords) for this vertex.
You can only have vertex sharing if you use strips, fans or indexed vertex arrays. When using vertex arrays you would have to store your vertices three times though (once for each variation in the attributes). For large meshes preprocessing the models with a tool like nvtristrip might give the best performace.

[ | vector_math (3d math library) | software renderer ]

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.