| 1 |
#ifndef BOUNDARIES_H_INCLUDED |
| 2 |
#define BOUNDARIES_H_INCLUDED |
| 3 |
|
| 4 |
#include <stdbool.h> |
| 5 |
#include <stdint.h> |
| 6 |
|
| 7 |
#include "triangle.h" |
| 8 |
|
| 9 |
typedef struct boundary_info { |
| 10 |
/*---------------------------------------------------------------------------- |
| 11 |
Information about visible triangle rows' boundaries. Also see the |
| 12 |
"boundary buffer functions" below. |
| 13 |
|
| 14 |
A "visible" triangle row is one which: |
| 15 |
|
| 16 |
1. Corresponds to a frame buffer row whose index (from top to bottom) is |
| 17 |
equal to or greater than 0 and smaller than the image height; and |
| 18 |
|
| 19 |
2. Has at least some of its pixels between the frame buffer columns whose |
| 20 |
index (from left to right) is equal to or greater than 0 and smaller |
| 21 |
than the image width. |
| 22 |
-----------------------------------------------------------------------------*/ |
| 23 |
int16_t start_scanline; |
| 24 |
/* Index of the frame buffer scanline which contains the first visible |
| 25 |
row of the current triangle, if there is any such row. If not, it |
| 26 |
contains the value -1. |
| 27 |
*/ |
| 28 |
|
| 29 |
int16_t num_upper_rows; |
| 30 |
/* The number of visible rows in the upper part of the triangle. The |
| 31 |
upper part of a triangle is composed of all the rows starting from |
| 32 |
the top vertex down to the middle vertex, but not including this |
| 33 |
last one. |
| 34 |
*/ |
| 35 |
|
| 36 |
int16_t num_lower_rows; |
| 37 |
/* The number of visible rows in the lower part of the triangle. The |
| 38 |
lower part of a triangle is composed of all the rows from the |
| 39 |
middle vertex to the bottom vertex -- all inclusive. |
| 40 |
*/ |
| 41 |
|
| 42 |
int16_t * buffer; |
| 43 |
/* This is the "boundary buffer": a pointer to an array of int16_t's |
| 44 |
where each consecutive pair of values indicates, in this order, the |
| 45 |
columns of the left and right boundary pixels for a particular |
| 46 |
visible triangle row. Those boundaries are inclusive on both sides |
| 47 |
and may be outside the limits of the frame buffer. This field is |
| 48 |
initialized and freed by the functions "init_boundary_buffer" and |
| 49 |
"free_boundary_buffer", respectively. |
| 50 |
*/ |
| 51 |
} boundary_info; |
| 52 |
|
| 53 |
void |
| 54 |
init_boundary_buffer(boundary_info * const bdi, |
| 55 |
int16_t const height); |
| 56 |
|
| 57 |
void |
| 58 |
free_boundary_buffer(boundary_info *); |
| 59 |
|
| 60 |
bool |
| 61 |
gen_triangle_boundaries(Xy const xy, |
| 62 |
boundary_info * const bdi, |
| 63 |
int16_t const width, |
| 64 |
int16_t const height); |
| 65 |
|
| 66 |
void |
| 67 |
get_triangle_boundaries(uint16_t const row_index, |
| 68 |
int32_t * const left, |
| 69 |
int32_t * const right, |
| 70 |
const boundary_info * const bdi); |
| 71 |
|
| 72 |
#endif |