PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Triangle Rasterization

Hey guys (and girls), I would like to get some opinions on triangle rasterization from the great minds that hang out here. Mainly what you found worked best and what to avoid. I'm currently writing a software triangle rasterizer for Windows Mobile running ARM CPU. Target surface is always a 16-bit RGB565 surface.

To start off, I had defined a few fixed point types which would be handy for different purposes. All are based on the standard 32-bit integer:

* fx24 - 8.24

* fx16 - 16.16

* fx10 - 22.10

* fx8 - 24.8

Starting with the vertex type, I was contemplating between a collection of different vertex types to handle different scenarios OR just one BIG vertex type that would suit all purposes. I'll go with the all in one.

The verticies will be fx10 which are nice to work with specifically with multiplication and division operations. UV's will use the fx24 type for precision when iterating a texture. But then I'm limiting myself to 256 x 256 textures but I don't see that as so bad. RAM is quite limited to begin with and 256 x 256 textures are so nice to work with. I use fx8 for the color and keep them individually stored rather than as a packed 16-bit word which makes them easy for interpolating.

Here is my fabulous data structure:

Code:

TVertex2D
{
fx10 fxX, fxY, fxZ;
fx24 fxU, fxV;
fx8 fxR, fxG, fxB;
};


For rasterization, I've chosen to stick to triangles as they are easier to manage. So given three verticies [v0, v1, v2] - I was thinking either to sort them such that v0.y > v1.y > v2.y which leads to v0 to v2 being the longest edge and v0 to v1 to v2 would be the other edge UNLESS it's a flat top or bottom type triangle in which case any of the y's are equal. So if that was the case, would it be better to split the triangles along the v2.y line and handle each case differently?

Then when it comes to scanning an edge I was thinking about the classic way of having an edge list that is the size of the screen height and storing the start and end x of each scanline for each y. But I don't like the idea of clearing out that list for each triangle to be rendered. So then I was thinking maybe a list that kept the x1, x2 and Y. The line raster function would take care of figuring out whether to draw from x2 to x1 or vice versa.

So... thoughts so far?