source: golgotha/src/render/software/r1_software_types.hh @ 80

Last change on this file since 80 was 80, checked in by Sam Hocevar, 11 years ago
  • Adding the Golgotha source code. Not sure what's going to be interesting in there, but since it's all public domain, there's certainly stuff to pick up.
File size: 5.3 KB
Line 
1/********************************************************************** <BR>
2  This file is part of Crack dot Com's free source code release of
3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
4  information about compiling & licensing issues visit this URL</a>
5  <PRE> If that doesn't help, contact Jonathan Clark at
6  golgotha_source@usa.net (Subject should have "GOLG" in it)
7***********************************************************************/
8
9typedef sw32 f16_16; //fixed point 16:16
10typedef sw32 f28_4;  //fixed point 28:4
11
12
13//if you change the struct below, adjust this to reflect
14//the proper offset
15#define TRI_AREA_STRUCT_AREA 16
16
17//stores the area of a triangle
18struct tri_area_struct
19{
20  float dx1x0; //tri.x1 - tri.x0
21  float dy1y0; //tri.y1 - tri.y0
22  float dx2x0; //tri.x2 - tri.x0
23  float dy2y0; //tri.y2 - tri.y0
24  float area;  //(float)((dx2x0 * dy1y0) - (dx1x0) * dy2y0));
25 
26  //calculates the area. uses asm
27
28  void  calc_area(sw32 x0, sw32 x1, sw32 x2,
29                  sw32 y0, sw32 y1, sw32 y2);
30 
31  void  calc_area(float x0, float x1, float x2,
32                  float y0, float y1, float y2);
33};
34
35//the rendering vertex structure used by most/all software routines
36struct s_vert //needs to be 4 byte aligned
37{
38  float px,py;   //screen x, screen y (floats)
39  sw32  ix,iy; //screen x, screen y (truncated ints)
40  w32   color; //the lower 16-bits are the color, the upper 16-bits might also be a duplicate
41  f28_4 l;     //the lighting value (fixed 24.8 interpolated)
42  float ooz;   //1/z value
43  float s,soz; //s value, s/z value
44  float t,toz; //t value, t/z value
45  i4_bool st_projected; //TRUE if soz and toz have been calculated (based on s, t, and z)
46  w8 pad1;
47  w8 pad2;
48  w8 pad3;
49};
50
51//used for simple rasterization of triangles
52struct tri_edge
53{
54  f16_16 px;         //fixed point representation of screen x
55 
56  float  dxdy;       //change in x per screen y
57  f16_16 dxdy_fixed; //i4_f_to_i(dxdy * 65536.f)
58
59  sw32   dy;         //total change in y
60};
61
62//simple primitive used for drawing lines
63typedef struct
64{
65  w16 start_color,end_color;
66  sw16 x0,x1,y0,y1;
67} software_line;
68
69
70//gradients used for texturemapping a triangle either affine or perspective correct
71//(hence the use of unions)
72struct tri_gradients //needs to be 8 byte aligned
73{
74  //DO NOT REORDER THESE
75
76  // 1/z gradient -- convert back to floats?
77  float doozdx;     //change in 1/z per screen x
78  float doozdy;     //change in 1/z per screen y
79
80  //t gradient
81  union
82  {
83    float dtozdx; //change in t/z per screen x
84    float dtdx;   //change in t   per screen x
85  };
86
87  union
88  {
89    float dtozdy; //change in t/z per screen y
90    float dtdy;   //change in t   per screen y
91  };
92
93  //s gradient
94  union
95  {
96    float dsozdx;     //change in s/z per x
97    float dsdx;       //change in s   per x
98  };
99
100  union
101  {
102    float dsozdy;      //change in s/z per screen y
103    float dsdy;        //change in s   per screen y
104  };
105
106  union
107  {
108    float dsozdxspan; //change in s/z per 8 pixel x span
109    float dsdxspan;   //change in s   per 8 pixel x span
110  };
111
112  union
113  {
114    float dtozdxspan; //change in t/z per 8 pixel span
115    float dtdxspan;   //change in t   per 8 pixel span
116  };
117
118  //lighting gradient 
119  float dldx;  //change in lighting value per screen x
120  float dldy;  //change in lighting value per screen y
121
122  union
123  {
124    float sozat00;  //this tri's soz value at screen point 0,0
125    float sat00;    //this tri's s   value at screen point 0,0
126  };
127 
128  union
129  {
130    float tozat00; //this tri's toz value at screen position (0,0)
131    float tat00;   //this tri's t   value at screen position (0,0)
132  };
133
134  //adjustment data (needed to ensure we dont step outside the texture boundary)
135  f16_16 s_adjust;
136  f16_16 t_adjust;
137
138  float doozdxspan; //change in 1/z per 8 pixel span
139  float oozat00;    //this tri's ooz value at screen position (0,0)
140
141  float lat00; //this tri's lighting value at screen position (0,0)
142  w32   pad; //ensures that the structure itself is 8-byte aligned, total of 72 bytes
143};
144
145//data passed to each scanline texturemapper
146//(the starting values for the indicated components)
147//other pertinant information is also passed (the width, the x offset)
148//in the function call, and textureing gradient information
149//is copied into a global variable
150
151//if you change these structures you must change the #defines below to correspond
152//with the correct offsets
153typedef struct //needs to be 8 byte aligned
154{
155  f16_16 s,t,l;
156  float ooz;
157} affine_span;
158
159#define AFFINE_SPAN_S 0
160#define AFFINE_SPAN_T 4
161#define AFFINE_SPAN_L 8
162
163typedef struct //needs to be 8 byte aligned
164{
165  float soz,toz,ooz;
166  f16_16 l; 
167} perspective_span;
168
169typedef struct
170{
171  float ooz;
172  w32   color;
173  f28_4 alpha;
174} solid_blend_span;
175
176//lighting table defines
177#define NUM_LIGHT_SHADES  (31)
178#define NUM_LIGHT_SHADES_LOG2 (5)
179#define ctable_size       (256*(NUM_LIGHT_SHADES+1))
180#define ctable_size_bytes (ctable_size*4)
181
182//the lighting lookup table structure
183struct software_color_table
184{
185  w32 table[ctable_size*2];
186  w32 *low_lookups()  { return table; }
187  w32 *high_lookups() { return &table[ctable_size]; }
188};
189
190extern software_color_table software_color_tables[];
Note: See TracBrowser for help on using the repository browser.