The Render extension tries to draw triangles by effectively sorting the
three points by their Y coordinates, and drawing two degenerate trapezoids
that meet at the horizontal line passing through the middle point.
(see miRasterizeTriangle() in xserver/render/mitri.c)
The tricky part of this technique is figuring out which edge of the triangle is
the left edge of the trapezoid and which is the right. The current code does
this by comparing the X coordinates of the two non-top points, but this doesn't
work in general: there are cases where the non-top points have the same X
coordinate, but which edge of the triangle is left and which is right depends
on the X coordinate of the top point. I think the "two cases" described in
a comment should really be whether the three points, in top-down order, go
around the triangle clockwise or counterclockwise. (Which could be determined
for instance by looking at the sign of cross-product of two edge vectors of
I'll attach a C program that demonstrates this bug (for me using Xsdl from
last night's CVS, but I think the problem is hardware independent). The
program's expected behavior is to draw two symmetric triangles (making a
downward-pointing chevron), but only the right triangle draws correctly;
the left one fills in only an area to the left of what should be the left edge
of the top half (trapezoid) of the triangle.
(Also reported to XFree86 as their bug #1275)
Created attachment 157 [details]
C program to demonstrate Render triangle bug
Created attachment 160 [details] [review]
Proposed patch to mitri.c
This proposed patch implements the modified algorithm I referred to above.
It fixes the supplied test case and deals correctly with a number of other
triangles I tried.
Cool. Thanks for the fix. As you might have guessed, the triangle code hasn't
seen a lot of testing. And, we've also proved that the trapezoid spec is
broken, so we'll be reimplementing that at some point. So many bugs, so little
I'll see if I can't manage to get this patch tested and committed in the next
couple of days.
Has this been resolved?
(In reply to comment #4)
> Has this been resolved?
Either that or it is of no bother to anyone any more. Setting to REMIND status.
Mass reopen. The "REMIND" resolution is lame, I'm deleting it. Consider yourself reminded.
will close as invalid in September unless somebody speaks up
This looks like it was resolved when Keith rewrote the trap rendering code:
Author: Keith Packard <firstname.lastname@example.org>
Date: Fri Aug 6 23:42:10 2004 +0000
Add RenderAddTraps. Rewrite trapezoid rendering code.
At any rate the testcase given here renders correctly in in xserver 1.6.