source: trunk/sys/TinyGL/src/zline.c @ 186

Last change on this file since 186 was 1, checked in by alain, 8 years ago

First import

File size: 1.9 KB
Line 
1#include <stdlib.h>
2#include "zbuffer.h"
3
4#define ZCMP(z,zpix) ((z) >= (zpix))
5
6void ZB_plot(ZBuffer * zb, ZBufferPoint * p)
7{
8    unsigned short *pz;
9    PIXEL *pp;
10    int zz;
11
12    pz = zb->zbuf + (p->y * zb->xsize + p->x);
13    pp = (PIXEL *) ((char *) zb->pbuf + zb->linesize * p->y + p->x * PSZB);
14    zz = p->z >> ZB_POINT_Z_FRAC_BITS;
15    if (ZCMP(zz, *pz)) {
16#if TGL_FEATURE_RENDER_BITS == 24
17        pp[0]=p->r>>8;
18        pp[1]=p->g>>8;
19        pp[2]=p->b>>8;
20#else
21        *pp = RGB_TO_PIXEL(p->r, p->g, p->b);
22#endif
23        *pz = zz;
24    }
25}
26
27#define INTERP_Z
28static void ZB_line_flat_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2, 
29                           int color)
30{
31#include "zline.h"
32}
33
34/* line with color interpolation */
35#define INTERP_Z
36#define INTERP_RGB
37static void ZB_line_interp_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
38{
39#include "zline.h"
40}
41
42/* no Z interpolation */
43
44static void ZB_line_flat(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2, 
45                             int color)
46{
47#include "zline.h"
48}
49
50#define INTERP_RGB
51static void ZB_line_interp(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
52{
53#include "zline.h"
54}
55
56void ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
57{
58    int color1, color2;
59
60    color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
61    color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
62
63    /* choose if the line should have its color interpolated or not */
64    if (color1 == color2) {
65        ZB_line_flat_z(zb, p1, p2, color1);
66    } else {
67        ZB_line_interp_z(zb, p1, p2);
68    }
69}
70
71void ZB_line(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2)
72{
73    int color1, color2;
74
75    color1 = RGB_TO_PIXEL(p1->r, p1->g, p1->b);
76    color2 = RGB_TO_PIXEL(p2->r, p2->g, p2->b);
77
78    /* choose if the line should have its color interpolated or not */
79    if (color1 == color2) {
80        ZB_line_flat(zb, p1, p2, color1);
81    } else {
82        ZB_line_interp(zb, p1, p2);
83    }
84}
Note: See TracBrowser for help on using the repository browser.