Is there a substitute for glPolygonMode in Open GL ES/WebGL?

Conceivably you could render the entire scene using GL_LINES


Unfortunately, you might have to actually completely convert your geometry to line primitives and render them using GL_LINES. However, it is of course not done by simply replacing GL_TRIANGLES (or whatever) with GL_LINES in your draw calls, you will have to entirely reorder your vertices to accomodate for the new primitive mode. This requires you to at least use different index arrays in glDrawElements... calls or, for non-indexed rendering (glDrawArrays...), different vertex arrays altogether (though, in case you really choose to do that, this might be the right moment to switch to indexed drawing instead).

If, however, you have Geometry Shaders available (though, it seems WebGL doesn't support them, OpenGL ES should since 3.2, as does desptop GL but that has good old glPolygonMode anyway) and don't already use them for something else, things get easier. In this case you can just install a rather simple geometry shader between the vertex and fragment processing that takes triangles and outputs 3 lines for each of them:

layout(triangles) in;
layout(line_strip, max_vertices=4) out;

void main()
{
    for(int i=0; i<4; ++i)
    {
        // and whatever other attributes of course
        gl_Position = gl_in[i%3].gl_Position;
        EmitVertex();
    }
}

If you use proper block-based shader interfacing, you should be able to use your existing vertex and fragment shaders for the rest and just hook that geometry shader in between them for the wireframe rendering of all kinds for triangle-based primitives.