Blending Lines and Polygons

I am developing a general 3D Simulator in JOGL which can render a wide range of Geographic data. The data can be in the form of points, lines and polygons.

But I am facing annoying problems while blending. If the data contains lines as well as polygons the blending goes for a toss as the depth test does not allow lines behind the polygon to be displayed.

Of course, ideally I should be sorting the primitives according to depth and render them from far to near. But since I am using both GL_TRIANGLE_STRIP and GL_LINE_STRIP primitives, in different functions calls this is not possible. Here is a snippet of my JOGL display() function:


if(polyLen > 0) {
    gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, polyStart, polyLen);
}
if(lnLen > 0) {
   gl.glMultiDrawArrays(GL.GL_LINE_STRIP, lineFirst, 0, lineCount, 0, lineFirst.length);
}
if(ptLen > 0) {
    gl.glDrawArrays(GL.GL_POINTS, ptStart, ptLen);
}

As you can see, each of the primitives are rendered using a separate function call. So any points or lines behind the polygons will be hidden by the depth test. All three primitives can be transparent/translucent. Worse, individual parts (some triangles in TRIANGLE_STRIP, some lines in LINE_STRIP) of each primitive may be transparent/translucent. So I am not sure if I can use the glDepthMask(false) trick.

How can blending between the different primitives be handled?

Perhaps you need to split the draw function up into lines and polys and also handle transparency separately.
I suggest you render in this order:

  1. solid polys
  2. ‘Solid’ lines - disable z writes/depth test
  3. Blend transparent polys
  4. blend transparent lines

This may not be the best way, but I don’t see why this would not work. You do need some way to break up/tag the data into different batches.