source: golgotha/src/render/software/span_buffer.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: 4.6 KB
RevLine 
[80]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
9#ifndef SPAN_BUFFER_HH
10#define SPAN_BUFFER_HH
11
12#include "time/profile.hh"
13
14union span_entry;
15struct span_tri_info;
16
17union span_entry //needs to be 8 byte aligned
18{
19  struct
20  {
21  //dont reorder these, the position of the x and y are required for a special amd3d mmx data load
22  sw32  x;
23  sw32  y;
24  sw32  width; 
25 
26  w32   next_tri_span; //index into the global span list of the next span 
27 
28  float ooz; //this ooz will be the ooz at the spans start
29             //since this is non-intersecting span sorting,
30             //this is all we need
31  w16   *scanline_ptr;
32  } s;
33  double alignment_dummy;
34}; //should be 16 bytes
35
36struct span_tri_info //needs to be 8 byte aligned
37{
38  tri_gradients grads;
39 
40  w16           *texture;
41 
42  union
43  {
44    sw32        texture_width;
45    w32         color;
46  };
47 
48  sw32          texture_height;
49 
50  float         cur_span_start_ooz;
51 
52  span_tri_info *next_stack;
53  span_tri_info *last_stack;
54 
55  sw16          cur_span_start_x;  //used when creating spans
56  w16           span_list_head; 
57  w8            twidth_log2;
58  w8            has_leader; 
59  w8            type;
60  w8            color_tint;
61}; //including the tri_gradients structure, this should be 104 bytes
62
63enum {MAX_TRIS = 20000};
64
65extern span_tri_info global_tri_list[]; //sized of max_tris
66extern int num_global_tris;
67
68inline span_tri_info *new_span_tri()
69{
70  if (num_global_tris < MAX_TRIS)
71  {
72    num_global_tris++;
73    span_tri_info *t = &global_tri_list[num_global_tris-1];
74    t->span_list_head=0;
75    t->next_stack=0;
76    t->last_stack=0;
77    t->has_leader=0;
78    return t;
79  }
80#ifdef DEBUG
81  i4_warning("out of span_tri_info memory");
82#endif
83  return 0;
84}
85
86enum {MAX_SPANS = 30000};
87
88extern span_entry global_span_list[]; //sized to max_spans
89extern int num_global_spans;
90
91enum {MAX_VERTICAL_RESOLUTION = 768};
92enum {MAX_NUM_EDGES           = 10000};
93
94struct span_edge //needs to be 4 byte aligned
95
96  sw32 x;
97  sw32 dxdy;
98   
99  span_tri_info *tri_1;
100
101  span_edge *next_remove; //in setup and when generating spans, this is the next remove edge (ends on the same scanline as this)
102  span_edge *next_active; //when generating the spans, this is the next active span in the active span list
103  union
104  {
105    span_edge *last_active;//when generating the spans, this is the previous active span in the active span list 
106    span_edge *next; //in setup, this is the next new edge (starts on the same scanline as this)
107  };
108 
109  w8 flags;
110  //flags & LEADING_1 means its a leading edge
111  //lower 7 bits define the type (see mappers.hh)
112
113  w8 pad1;
114  w8 pad2;
115  w8 pad3; //pad it to 28 bytes
116};
117
118extern span_edge *new_edges[];
119extern span_edge *remove_edges[];
120extern span_edge global_edges[];
121extern span_edge *active_list;
122
123extern int num_global_edges;
124
125inline span_edge *new_span_edge()
126{
127  if (num_global_edges < MAX_NUM_EDGES)
128  {
129    num_global_edges++;
130    span_edge *e = &global_edges[num_global_edges-1];
131    e->next_active = 0;
132    e->last_active = 0;   
133    return e;
134  }
135#ifdef DEBUG
136  //i4_warning("out of span_edge memory");
137#endif
138  return 0;
139}
140
141extern i4_profile_class pf_software_add_start_edge;
142extern sw32 shared_edges;
143extern sw32 total_edges;
144
145inline void add_start_edge(span_edge *e,sw32 scanline)
146{
147  pf_software_add_start_edge.start();
148
149  span_edge *compare_here = new_edges[scanline];
150  span_edge *last_compare = 0;
151
152  while (compare_here && e->x > compare_here->x)
153  {
154    last_compare = compare_here;
155    compare_here = compare_here->next;
156  }
157 
158  e->next = compare_here;
159 
160  //total_edges++;
161
162  if (last_compare)
163  {
164    last_compare->next = e;
165    /*
166    if (compare_here && (compare_here->x == e->x) && (compare_here->dxdy==e->dxdy))
167    {
168      shared_edges++;
169    }
170    */
171  }
172  else
173    new_edges[scanline] = e;
174 
175  pf_software_add_start_edge.stop();
176}
177
178inline void add_remove_edge(span_edge *e,sw32 scanline)
179{
180  e->next_remove = remove_edges[scanline];
181  remove_edges[scanline] = e;
182}
183
184void init_span_buffer();
185void clear_spans();
186void flush_spans();
187
188#endif
Note: See TracBrowser for help on using the repository browser.