Triangle drawing order in DirectX/OpenGL
Asked Answered
M

1

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?

Midmost answered 10/7, 2012 at 10:50 Comment(0)
B
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.

Beginning answered 10/7, 2012 at 10:59 Comment(5)
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?Midmost
@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.Menace
@Menace 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."Midmost
@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.Menace
@Midmost sorry for been late, but is this answer still true and so i can rely on this?Photovoltaic

© 2022 - 2024 — McMap. All rights reserved.