source: trunk/sys/TinyGL/src/zbuffer.h @ 64

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

First import

File size: 3.7 KB
RevLine 
[1]1#ifndef _tgl_zbuffer_h_
2#define _tgl_zbuffer_h_
3
4/*
5 * Z buffer
6 */
7
8#include "zfeatures.h"
9
10#define ZB_Z_BITS 16
11
12#define ZB_POINT_Z_FRAC_BITS 14
13
14#define ZB_POINT_S_MIN ( (1<<13) )
15#define ZB_POINT_S_MAX ( (1<<22)-(1<<13) )
16#define ZB_POINT_T_MIN ( (1<<21) )
17#define ZB_POINT_T_MAX ( (1<<30)-(1<<21) )
18
19#define ZB_POINT_RED_MIN ( (1<<10) )
20#define ZB_POINT_RED_MAX ( (1<<16)-(1<<10) )
21#define ZB_POINT_GREEN_MIN ( (1<<9) )
22#define ZB_POINT_GREEN_MAX ( (1<<16)-(1<<9) )
23#define ZB_POINT_BLUE_MIN ( (1<<10) )
24#define ZB_POINT_BLUE_MAX ( (1<<16)-(1<<10) )
25
26/* display modes */
27#define ZB_MODE_5R6G5B  1  /* true color 16 bits */
28#define ZB_MODE_INDEX   2  /* color index 8 bits */
29#define ZB_MODE_RGBA    3  /* 32 bit rgba mode */
30#define ZB_MODE_RGB24   4  /* 24 bit rgb mode */
31#define ZB_NB_COLORS    225 /* number of colors for 8 bit display */
32
33#if TGL_FEATURE_RENDER_BITS == 15
34
35#define RGB_TO_PIXEL(r,g,b) \
36  ((((r) >> 1) & 0x7c00) | (((g) >> 6) & 0x03e0) | ((b) >> 11))
37typedef unsigned short PIXEL;
38/* bytes per pixel */
39#define PSZB 2
40/* bits per pixel = (1 << PSZH) */
41#define PSZSH 4
42
43#elif TGL_FEATURE_RENDER_BITS == 16
44
45/* 16 bit mode */
46#define RGB_TO_PIXEL(r,g,b) \
47  (((r) & 0xF800) | (((g) >> 5) & 0x07E0) | ((b) >> 11))
48typedef unsigned short PIXEL;
49#define PSZB 2
50#define PSZSH 4
51
52#elif TGL_FEATURE_RENDER_BITS == 24
53
54#define RGB_TO_PIXEL(r,g,b) \
55  ((((r) << 8) & 0xff0000) | ((g) & 0xff00) | ((b) >> 8))
56typedef unsigned char PIXEL;
57#define PSZB 3
58#define PSZSH 5
59
60#elif TGL_FEATURE_RENDER_BITS == 32
61
62#define RGB_TO_PIXEL(r,g,b) \
63  ((((r) << 8) & 0xff0000) | ((g) & 0xff00) | ((b) >> 8))
64typedef unsigned int PIXEL;
65#define PSZB 4
66#define PSZSH 5
67
68#else
69
70#error Incorrect number of bits per pixel
71
72#endif
73
74typedef struct {
75    int xsize,ysize;
76    int linesize; /* line size, in bytes */
77    int mode;
78   
79    unsigned short *zbuf;
80    PIXEL *pbuf;
81    int frame_buffer_allocated;
82   
83    int nb_colors;
84    unsigned char *dctable;
85    int *ctable;
86    PIXEL *current_texture;
87} ZBuffer;
88
89typedef struct {
90  int x,y,z;     /* integer coordinates in the zbuffer */
91  int s,t;       /* coordinates for the mapping */
92  int r,g,b;     /* color indexes */
93 
94  float sz,tz;   /* temporary coordinates for mapping */
95} ZBufferPoint;
96
97/* zbuffer.c */
98
99ZBuffer *ZB_open(int xsize,int ysize,int mode,
100                 int nb_colors,
101                 unsigned char *color_indexes,
102                 int *color_table,
103                 void *frame_buffer);
104
105
106void ZB_close(ZBuffer *zb);
107
108void ZB_resize(ZBuffer *zb,void *frame_buffer,int xsize,int ysize);
109void ZB_clear(ZBuffer *zb,int clear_z,int z,
110              int clear_color,int r,int g,int b);
111/* linesize is in BYTES */
112void ZB_copyFrameBuffer(ZBuffer *zb,void *buf,int linesize);
113
114/* zdither.c */
115
116void ZB_initDither(ZBuffer *zb,int nb_colors,
117                   unsigned char *color_indexes,int *color_table);
118void ZB_closeDither(ZBuffer *zb);
119void ZB_ditherFrameBuffer(ZBuffer *zb,unsigned char *dest,
120                          int linesize);
121
122/* zline.c */
123
124void ZB_plot(ZBuffer *zb,ZBufferPoint *p);
125void ZB_line(ZBuffer *zb,ZBufferPoint *p1,ZBufferPoint *p2);
126void ZB_line_z(ZBuffer * zb, ZBufferPoint * p1, ZBufferPoint * p2);
127
128/* ztriangle.c */
129
130void ZB_setTexture(ZBuffer *zb, PIXEL *texture);
131
132void ZB_fillTriangleFlat(ZBuffer *zb,
133                 ZBufferPoint *p1,ZBufferPoint *p2,ZBufferPoint *p3);
134
135void ZB_fillTriangleSmooth(ZBuffer *zb,
136                   ZBufferPoint *p1,ZBufferPoint *p2,ZBufferPoint *p3);
137
138void ZB_fillTriangleMapping(ZBuffer *zb,
139                    ZBufferPoint *p1,ZBufferPoint *p2,ZBufferPoint *p3);
140
141void ZB_fillTriangleMappingPerspective(ZBuffer *zb,
142                    ZBufferPoint *p0,ZBufferPoint *p1,ZBufferPoint *p2);
143
144
145typedef void (*ZB_fillTriangleFunc)(ZBuffer  *,
146            ZBufferPoint *,ZBufferPoint *,ZBufferPoint *);
147
148/* memory.c */
149void gl_free(void *p);
150void *gl_malloc(int size);
151void *gl_zalloc(int size);
152
153#endif /* _tgl_zbuffer_h_ */
Note: See TracBrowser for help on using the repository browser.