How does Blender implement flat shading non-planar polygons? Following up on my recent question on ComputerGraphics.SE — how is flat shading of non-planar polygons implemented in Blender?

If polygons are rendered using GL_TRIANGLE_FAN in OpenGL, one approach would be to upload a single normal vector for every individual polygon that's rendered. This might not be very efficient though.

On the other hand, if polygons are split into triangles before everything is rendered, then these triangles somehow  have to share a normal vector. This sounds more like glDrawArrays() than glDrawElements(), which again might not be the best solution.
Blender's face normals are calculated as follows:


For quads, we use the cross product of 2 edge vectors which don't share a vertex.
For polygons, we use Newell's Method.


To draw with these normals, we store the tessellated triangles and simply copy the normals calculated from the original faces, into each of the tessellation triangles normals (which is sent as a buffer to the GPU).

See: gpu_buffers.c for details (though you will probably want to see how this API is used by other files to see how it works).