I can’t say enough good things about Jonathan Harris (Marginal) — his work on X-Plane has been fantastic, he is one of the most advanced third party scenery authors I know of, and when he sends us a bug report, it is usually so perfectly patched up that I’m looking at the bad line of code in minutes! (One of these days I’ll post one of his bug reports — he always isolates the bug in a simple package that makes it very clear, with no extra “stuff”.)

He emailed me a while ago with some questions about layer groups, and I saved them to rewrite into a blog entry. A little bit of background:

X-Plane 850 and 860 introduce the concept of “layer groups”, which provide a way to control the draw order of scenery to some extent. Objects naturally fall into a layer group based on their type (e.g. objects go into the “object” layer group by default, and runways always go into the runway layer group). However, some scenery elements let you customize their layer-group placement in two ways:

  • By changing which layer group the element goes to entirely, or
  • By providing a “bias number”, which indicates that within the catagory of scenery elements, this one must be drawn early or late.

Layer groups let you do a number of useful things:

  • Make sure that polygons and objects are drawn under runways or over taxiways when needed.
  • Make sure that runway markings with polygon offset are drawn before 3-d objects.

Simply changing the order of objects in the DSF is not a reliable way to control draw order! Layer groups are. You can read about layer groups in the OBJ8 spec.

With that in mind, some Q and A. (I will elaborate on my answers from what I originally sent Jonathan.)

J: I assume that objects and polygons within a single layer can be drawn in any order – ie there’s no defined drawing order between different scenery types.

B: You assume correctly! Within a layer group, X-plane is free to reorder to improve fps. So you cannot rely on the draw order of any two scenery elements without assuring that they are in different layer groups, either by using different group names, or different relative offsets.

J: But is there are defined drawing order between objects/polygons and apt.dat-generated scenery?

B: Yes because airport scenery goes into specific layer groups! (In fact, all scenery has a “default” layer it goes into, and they usually vary by type of scenery element.)

J: eg if I have an object or polygon with ATTR_layer_group runways 0 will it be guaranteed to be drawn after the runway?

B: You’re close. The runways go into the runways group so

ATTR_layer_group runways -1

will always be before runways and

ATTR_layer_group runways 1

will always be after.

ATTR_layer_group runways 0

is the default layer group for runways, so your object or polygon would be in the layer group with all of the other runways, and X-Plane would be free to change the order amongst your object and runways in any way that would optimize framerate.

J: If not, is there any other way to insert objects and/or polygons between the taxiways and the runways?

B: The numeric offset is provided for this. The “spacing” of the layer group numbers is such that you can have up to 5 groups before and after each “named” group. So anything from runways -5 to runways +5 is fair game. (In other words, you can separately control up to 5 different “layers” of elements with a well-defined order for any layer group name.)

About Ben Supnik

Ben is a software engineer who works on X-Plane; he spends most of his days drinking coffee and swearing at the computer -- sometimes at the same time.