9

Is the order of drawing triangles in a 3D API guaranteed to be the same as their order in the index buffer?

For example if I have two overlapping triangles in a single draw call, and depth testing is disabled, will the first or second triangle be visible in the end?

Or do I need to issue separate draw calls to be sure that the 2nd triangle appears on top of the 1st?

kaalus
  • 4,475
  • 3
  • 29
  • 39

1 Answers1

9

In OpenGL the order is indeed preserveed, so that painters algorithm can be used, for example when rendering semitransparent geometry.

Direct3D I don't know for sure, but I'd say the same applies there.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks! Do you have a link to some official doc that says that the order will be preserved? Will tiled architecture (like Adreno or Xbox GPU) where drawing is done separately in multiple tiles not affect that? – kaalus Jul 10 '12 at 11:01
  • 1
    @kaalus: I can vouch for the ordering, though I can't for the life of me find a reference in DX. GL has at least a reference in passing p115 of 4.2 Core profile. tiling will not affect it. – Bahbar Jul 10 '12 at 11:21
  • 1
    @Bahbar Indeed, it's only mentioned in passing. Here's the actual text: "The relative order of invocations of the same shader type are undefined. A store issued by a shader when working on primitive B might complete prior to a store for primitive A, even if primitive A is specified prior to primitive B. This applies even to fragment shaders; while fragment shader outputs are written to the framebuffer in primitive order, stores executed by fragment shader invocations are not." – kaalus Jul 10 '12 at 15:54
  • 3
    @kaalus: I found the initial mention. 2.1 GL fundamentals, last paragraph of p5:one primitive must be drawn completely before any subsequent one can affect the framebuffer. – Bahbar Jul 11 '12 at 05:29
  • @kaalus sorry for been late, but is this answer still true and so i can rely on this? – khokm Feb 18 '22 at 11:09