1 | /* |
---|
2 | |
---|
3 | Homan Igehy |
---|
4 | |
---|
5 | Computer Graphics Laboratory |
---|
6 | Stanford University |
---|
7 | |
---|
8 | --------------------------------------------------------------------- |
---|
9 | |
---|
10 | Copyright (1997) The Board of Trustees of the Leland Stanford Junior |
---|
11 | University. Except for commercial resale, lease, license or other |
---|
12 | commercial transactions, permission is hereby given to use, copy, |
---|
13 | modify this software for academic purposes only. No part of this |
---|
14 | software or any derivatives thereof may be used in the production of |
---|
15 | computer models for resale or for use in a commercial |
---|
16 | product. STANFORD MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND |
---|
17 | CONCERNING THIS SOFTWARE. No support is implied or provided. |
---|
18 | |
---|
19 | */ |
---|
20 | |
---|
21 | |
---|
22 | /* |
---|
23 | * sl_common.I |
---|
24 | * |
---|
25 | */ |
---|
26 | |
---|
27 | #ifndef SL_COMMON_I |
---|
28 | #define SL_COMMON_I |
---|
29 | |
---|
30 | //#include <iostream.h> |
---|
31 | #include <assert.h> |
---|
32 | |
---|
33 | #include "sl_val.H" |
---|
34 | #include "sl_vertex.H" |
---|
35 | #include "sl_texture.H" |
---|
36 | #include "sl_hack.H" |
---|
37 | #include "sl_common.H" |
---|
38 | #include "sl_framebuffer.H" |
---|
39 | #include "sl_framebuffer.I" |
---|
40 | |
---|
41 | |
---|
42 | |
---|
43 | ///////////////////////////////////////////////////// |
---|
44 | // routines for scan converting given structures // |
---|
45 | ///////////////////////////////////////////////////// |
---|
46 | |
---|
47 | #define PartialIncrement(i) { IN_Index(cur, i) += xf * IN_Index(ddx, i); } |
---|
48 | #define IncrementX(i) { IN_Index(cur, i) += IN_Index(ddx, i); } |
---|
49 | #define DecrementX(i) { IN_Index(cur, i) -= IN_Index(ddx, i); } |
---|
50 | |
---|
51 | #define SetSample(i) \ |
---|
52 | FB_Index(FB_Sample, i) FB_Index(*sample, i) = \ |
---|
53 | FB_Index(buffer->sample, i) + begin; |
---|
54 | |
---|
55 | #define LastSample(i) \ |
---|
56 | FB_Index(FB_Sample, i) *last_sample = FB_Index(buffer->sample, i) + end; |
---|
57 | |
---|
58 | #define IncrementSample(i) FB_Index(sample, i)++ |
---|
59 | #define DecrementSample(i) FB_Index(sample, i)-- |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | static inline void |
---|
64 | SL_ScanXLeftToRight(Real lx, Real rx, |
---|
65 | #ifdef SampleCalc_Dda |
---|
66 | IN_FormalArgs(cur) |
---|
67 | #endif |
---|
68 | #ifdef SampleCalc_Ddx |
---|
69 | IN_FormalConstArgs(cur) |
---|
70 | #endif |
---|
71 | IN_FormalConstArgs(ddx) |
---|
72 | CA_FormalConstArgs(cur) |
---|
73 | #ifdef LevelOfDetail |
---|
74 | const Real numParX, Real *numParYArray, |
---|
75 | #endif |
---|
76 | const FB_Buffer *buffer, const Integer offset) |
---|
77 | { |
---|
78 | |
---|
79 | Integer xr = CeilR2I(rx); |
---|
80 | Integer xl = CeilR2I(lx); |
---|
81 | |
---|
82 | if (xl >= xr) |
---|
83 | return; |
---|
84 | |
---|
85 | Real xf = (Real) xl - lx; |
---|
86 | |
---|
87 | #ifdef SampleCalc_Dda |
---|
88 | IN_DoForEach(PartialIncrement); |
---|
89 | #endif |
---|
90 | |
---|
91 | Integer begin = offset + xl; |
---|
92 | Integer end = offset + xr - 1; |
---|
93 | |
---|
94 | #ifdef LevelOfDetail |
---|
95 | numParYArray += xl; |
---|
96 | #endif |
---|
97 | |
---|
98 | FB_DoForEach(SetSample); |
---|
99 | FB_DoForFirst(LastSample); |
---|
100 | |
---|
101 | while (FB_FirstIndex(sample) != last_sample) { |
---|
102 | |
---|
103 | #ifdef SampleCalc_Dda |
---|
104 | BufferSample(IN_ListArgs(cur) |
---|
105 | CA_ListArgs(cur) |
---|
106 | #ifdef LevelOfDetail |
---|
107 | numParX, *numParYArray, |
---|
108 | #endif |
---|
109 | FB_ListArgs(sample)); |
---|
110 | IN_DoForEach(IncrementX); |
---|
111 | #endif |
---|
112 | |
---|
113 | #ifdef SampleCalc_Ddx |
---|
114 | BufferSample(xf, |
---|
115 | IN_ListArgs(cur) |
---|
116 | IN_ListArgs(ddx) |
---|
117 | CA_ListArgs(cur) |
---|
118 | #ifdef LevelOfDetail |
---|
119 | numParX, *numParYArray, |
---|
120 | #endif |
---|
121 | FB_ListArgs(sample)); |
---|
122 | xf += REAL_ONE; |
---|
123 | #endif |
---|
124 | |
---|
125 | #ifdef LevelOfDetail |
---|
126 | numParYArray++; |
---|
127 | #endif |
---|
128 | |
---|
129 | FB_DoForEach(IncrementSample); |
---|
130 | } |
---|
131 | |
---|
132 | #ifdef SampleCalc_Dda |
---|
133 | BufferSample(IN_ListArgs(cur) |
---|
134 | CA_ListArgs(cur) |
---|
135 | #ifdef LevelOfDetail |
---|
136 | numParX, *numParYArray, |
---|
137 | #endif |
---|
138 | FB_ListArgs(sample)); |
---|
139 | #endif |
---|
140 | |
---|
141 | #ifdef SampleCalc_Ddx |
---|
142 | BufferSample(xf, |
---|
143 | IN_ListArgs(cur) |
---|
144 | IN_ListArgs(ddx) |
---|
145 | CA_ListArgs(cur) |
---|
146 | #ifdef LevelOfDetail |
---|
147 | numParX, *numParYArray, |
---|
148 | #endif |
---|
149 | FB_ListArgs(sample)); |
---|
150 | #endif |
---|
151 | |
---|
152 | } |
---|
153 | |
---|
154 | |
---|
155 | |
---|
156 | |
---|
157 | |
---|
158 | static inline void |
---|
159 | SL_ScanXRightToLeft(Real lx, Real rx, |
---|
160 | #ifdef SampleCalc_Dda |
---|
161 | IN_FormalArgs(cur) |
---|
162 | #endif |
---|
163 | #ifdef SampleCalc_Ddx |
---|
164 | IN_FormalConstArgs(cur) |
---|
165 | #endif |
---|
166 | IN_FormalArgs(ddx) |
---|
167 | CA_FormalArgs(cur) |
---|
168 | #ifdef LevelOfDetail |
---|
169 | const Real numParX, Real *numParYArray, |
---|
170 | #endif |
---|
171 | const FB_Buffer *buffer, Integer offset) |
---|
172 | { |
---|
173 | Integer xl = CeilR2I(lx); |
---|
174 | Integer xr = CeilR2I(rx); |
---|
175 | |
---|
176 | if (xl >= xr) |
---|
177 | return; |
---|
178 | |
---|
179 | Real xf = (Real) (xr - 1) - rx; |
---|
180 | |
---|
181 | #ifdef SampleCalc_Dda |
---|
182 | IN_DoForEach(PartialIncrement); |
---|
183 | #endif |
---|
184 | |
---|
185 | Integer begin = offset + (xr - 1); |
---|
186 | Integer end = offset + xl; |
---|
187 | |
---|
188 | #ifdef LevelOfDetail |
---|
189 | numParYArray += (xr - 1); |
---|
190 | #endif |
---|
191 | |
---|
192 | FB_DoForEach(SetSample); |
---|
193 | FB_DoForFirst(LastSample); |
---|
194 | |
---|
195 | while (FB_FirstIndex(sample) != last_sample) { |
---|
196 | |
---|
197 | #ifdef SampleCalc_Dda |
---|
198 | BufferSample(IN_ListArgs(cur) |
---|
199 | CA_ListArgs(cur) |
---|
200 | #ifdef LevelOfDetail |
---|
201 | numParX, *numParYArray, |
---|
202 | #endif |
---|
203 | FB_ListArgs(sample)); |
---|
204 | IN_DoForEach(DecrementX); |
---|
205 | #endif |
---|
206 | |
---|
207 | #ifdef SampleCalc_Ddx |
---|
208 | BufferSample(xf, |
---|
209 | IN_ListArgs(cur) |
---|
210 | IN_ListArgs(ddx) |
---|
211 | CA_ListArgs(cur) |
---|
212 | #ifdef LevelOfDetail |
---|
213 | numParX, *numParYArray, |
---|
214 | #endif |
---|
215 | FB_ListArgs(sample)); |
---|
216 | xf -= REAL_ONE; |
---|
217 | #endif |
---|
218 | |
---|
219 | #ifdef LevelOfDetail |
---|
220 | numParYArray--; |
---|
221 | #endif |
---|
222 | |
---|
223 | FB_DoForEach(DecrementSample); |
---|
224 | } |
---|
225 | |
---|
226 | |
---|
227 | #ifdef SampleCalc_Dda |
---|
228 | BufferSample(IN_ListArgs(cur) |
---|
229 | CA_ListArgs(cur) |
---|
230 | #ifdef LevelOfDetail |
---|
231 | numParX, *numParYArray, |
---|
232 | #endif |
---|
233 | FB_ListArgs(sample)); |
---|
234 | #endif |
---|
235 | |
---|
236 | #ifdef SampleCalc_Ddx |
---|
237 | BufferSample(xf, |
---|
238 | IN_ListArgs(cur) |
---|
239 | IN_ListArgs(ddx) |
---|
240 | CA_ListArgs(cur) |
---|
241 | #ifdef LevelOfDetail |
---|
242 | numParX, *numParYArray, |
---|
243 | #endif |
---|
244 | FB_ListArgs(sample)); |
---|
245 | #endif |
---|
246 | |
---|
247 | |
---|
248 | } |
---|
249 | |
---|
250 | |
---|
251 | |
---|
252 | #endif /* SL_COMMON_I */ |
---|
253 | |
---|
254 | |
---|
255 | |
---|
256 | |
---|
257 | |
---|