Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/spe/CreateSpan.cpp @ 131:805d27efafd8
fix
author | gongo@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Tue, 25 Nov 2008 17:24:18 +0900 |
parents | 6ba88fa28df6 |
children | 435e0d24db39 |
rev | line source |
---|---|
109 | 1 #include "CreateSpan.h" |
2 #include "viewer_types.h" | |
3 | |
4 static const int SPAN_PACK_LOAD = 5; | |
5 static const int SPAN_PACK_STORE = 6; | |
6 static const int POLYGON_PACK_LOAD = 7; | |
7 | |
8 static SpanPackPtr spack = NULL; | |
9 static SpanPackPtr send_spack = NULL; | |
10 static int prev_index = 0; | |
11 | |
12 SchedDefineTask(CreateSpan); | |
13 | |
14 static float | |
15 calc(float f1, float f2,int i, float base) | |
16 { | |
17 float ans; | |
18 ans = f1/f2*i + base; | |
19 return ans; | |
20 } | |
21 | |
22 | |
23 /** | |
24 * TrianglePack から、vMin, vMid, vMax を求める | |
25 * | |
26 * @param [triPack] TrianglePack | |
27 * @param [vMin] [vMid] [vMax] | |
28 */ | |
29 static void | |
30 make_vertex(TrianglePack *triPack, | |
31 VertexPackPtr *vMin, VertexPackPtr *vMid, VertexPackPtr *vMax) | |
32 { | |
33 if (triPack->ver1.y <= triPack->ver2.y) { | |
34 if (triPack->ver2.y <= triPack->ver3.y) { | |
35 *vMin = &triPack->ver1; | |
36 *vMid = &triPack->ver2; | |
37 *vMax = &triPack->ver3; | |
38 } else if (triPack->ver3.y <= triPack->ver1.y) { | |
39 *vMin = &triPack->ver3; | |
40 *vMid = &triPack->ver1; | |
41 *vMax = &triPack->ver2; | |
42 } else { | |
43 *vMin = &triPack->ver1; | |
44 *vMid = &triPack->ver3; | |
45 *vMax = &triPack->ver2; | |
46 } | |
47 } else { | |
48 if (triPack->ver1.y <= triPack->ver3.y) { | |
49 *vMin = &triPack->ver2; | |
50 *vMid = &triPack->ver1; | |
51 *vMax = &triPack->ver3; | |
52 } else if (triPack->ver3.y <= triPack->ver2.y) { | |
53 *vMin = &triPack->ver3; | |
54 *vMid = &triPack->ver2; | |
55 *vMax = &triPack->ver1; | |
56 } else { | |
57 *vMin = &triPack->ver2; | |
58 *vMid = &triPack->ver3; | |
59 *vMax = &triPack->ver1; | |
60 } | |
61 } | |
62 } | |
63 | |
64 static void | |
65 make_vMid10(VertexPack *v, VertexPack *vMin, | |
66 VertexPack *vMid, VertexPack *vMax) | |
67 { | |
68 int d, d1; | |
69 | |
70 d = (int)(vMax->y - vMin->y); | |
71 d1 = (int)(vMid->y - vMin->y); | |
72 | |
73 v->tex_x = calc(vMax->tex_x - vMin->tex_x, d, d1, vMin->tex_x); | |
74 v->tex_y = calc(vMax->tex_y - vMin->tex_y, d, d1, vMin->tex_y); | |
75 v->x = calc(vMax->x - vMin->x, d, d1, vMin->x); | |
76 v->y = vMid->y; | |
77 v->z = calc(vMax->z - vMin->z, d, d1, vMin->z); | |
78 } | |
79 | |
80 void | |
81 CreateSpan::half_triangle(SpanPackPtr *spackList, | |
82 int charge_y_top, int charge_y_end, | |
83 long *tex_addr, long tex_width, long tex_height, | |
84 VertexPack *vMin,VertexPack *vMid,VertexPack *vMid10) | |
85 { | |
86 float tmp_z,tmp_tex1, tmp_tex2 ,tmp_tey1,tmp_tey2; | |
87 float tmp_xpos,tmp_end,tmp_zpos; | |
88 float start_z, end_z; | |
89 float start_tex_x, end_tex_x, start_tex_y, end_tex_y; | |
90 int x, y, length; | |
91 | |
92 int start_y = (int)vMid->y; | |
93 int end_y = (int)vMin->y; | |
94 float div_y = start_y - end_y; | |
95 int k = 0; | |
96 int l = 1; | |
97 | |
98 SpanPackPtr tmp_spack; | |
99 | |
100 if (div_y < 0) { | |
101 div_y = -div_y; | |
102 k = 1; | |
103 l = -1; | |
104 } | |
105 | |
106 for (int i = k; i < div_y+1; i++) { | |
107 y = (int)vMin->y + i*l; | |
108 | |
109 /** | |
110 * 担当 y 範囲内 | |
111 */ | |
112 if (charge_y_top <= y && y <= charge_y_end) { | |
113 // 1..8 を index0, 9..16 を index1 にするために y を -1 | |
114 int index = (y-1) / split_screen_h; | |
115 | |
116 /** | |
117 * 違う SpanPack を扱う場合、 | |
118 * 現在の SpanPack をメインメモリに送り、 | |
119 * 新しい SpanPack を取ってくる | |
120 */ | |
121 if (index != prev_index) { | |
122 tmp_spack = spack; | |
123 spack = send_spack; | |
124 send_spack = tmp_spack; | |
125 | |
126 smanager->dma_wait(SPAN_PACK_STORE); | |
127 smanager->dma_store(send_spack, (uint32)spackList[prev_index], | |
128 sizeof(SpanPack), SPAN_PACK_STORE); | |
129 | |
130 smanager->dma_load(spack, (uint32)spackList[index], | |
131 sizeof(SpanPack), SPAN_PACK_LOAD); | |
132 prev_index = index; | |
133 smanager->dma_wait(SPAN_PACK_LOAD); | |
134 } | |
135 | |
136 /** | |
137 * 書き込む SpanPack が満杯だったら | |
138 * メインメモリで allocate した領域 (next) を持ってきて | |
139 * 現在の spack->next につなぎ、next を次の spack とする。 | |
140 */ | |
141 if (spack->info.size >= MAX_SIZE_SPAN) { | |
142 SpanPackPtr next; | |
143 | |
144 mainMem_alloc(0, sizeof(SpanPack)); | |
145 mainMem_wait(); | |
146 next = (SpanPackPtr)mainMem_get(0); | |
147 | |
148 spack->next = next; | |
149 | |
150 tmp_spack = spack; | |
151 spack = send_spack; | |
152 send_spack = tmp_spack; | |
153 | |
154 smanager->dma_wait(SPAN_PACK_STORE); | |
155 smanager->dma_store(send_spack, (uint32)spackList[index], | |
156 sizeof(SpanPack), SPAN_PACK_STORE); | |
157 | |
158 spackList[index] = next; | |
159 | |
160 smanager->dma_load(spack, (uint32)spackList[index], | |
161 sizeof(SpanPack), SPAN_PACK_LOAD); | |
162 smanager->dma_wait(SPAN_PACK_LOAD); | |
163 spack->init((index+1)*split_screen_h); | |
164 } | |
165 } else { | |
166 /** | |
167 * 担当範囲外だったら無視 | |
168 */ | |
169 continue; | |
170 } | |
171 | |
172 tmp_xpos = calc(vMid10->x - vMin->x ,div_y, i, vMin->x); | |
173 tmp_end = calc(vMid->x - vMin->x ,div_y, i, vMin->x); | |
174 tmp_z = calc(vMid10->z - vMin->z ,div_y, i, vMin->z); | |
175 tmp_zpos = calc(vMid->z - vMin->z ,div_y, i, vMin->z); | |
176 | |
177 tmp_tex1 =((i/(div_y)) * vMid10->tex_x) + | |
178 ( ((div_y - i)/(div_y)) * vMin->tex_x); | |
179 tmp_tex2 =( (i/(div_y)) * vMid->tex_x) + | |
180 ( ((div_y - i)/(div_y)) * vMin->tex_x); | |
181 | |
182 tmp_tey1 =( (i/(div_y)) * vMid10->tex_y) + | |
183 ( ((div_y - i)/(div_y)) * vMin->tex_y); | |
184 tmp_tey2 =( (i/(div_y)) * vMid->tex_y) + | |
185 ( ((div_y - i)/(div_y)) * vMin->tex_y); | |
186 | |
187 if (tmp_xpos > tmp_end) { | |
188 x = (int)tmp_end; | |
189 length = (int)(tmp_xpos)-(int)(tmp_end)+1; | |
190 start_z = tmp_zpos; | |
191 end_z = tmp_z; | |
192 start_tex_x = tmp_tex2; | |
193 end_tex_x = tmp_tex1; | |
194 start_tex_y = tmp_tey2; | |
195 end_tex_y = tmp_tey1; | |
196 } else { | |
197 x = (int)tmp_xpos; | |
198 length = (int)(tmp_end)-(int)(tmp_xpos)+1; | |
199 start_z = tmp_z; | |
200 end_z = tmp_zpos; | |
201 start_tex_x = tmp_tex1; | |
202 end_tex_x = tmp_tex2; | |
203 start_tex_y = tmp_tey1; | |
204 end_tex_y = tmp_tey2; | |
205 } | |
206 | |
207 smanager->dma_wait(SPAN_PACK_LOAD); | |
208 | |
209 Span *span = &spack->span[spack->info.size++]; | |
210 | |
211 span->tex_addr = tex_addr; | |
212 span->tex_width = tex_width; | |
213 span->tex_height = tex_height; | |
214 span->x = x; | |
215 span->y = y; | |
216 span->length_x = length; | |
217 span->start_z = start_z; | |
218 span->end_z = end_z; | |
219 span->tex_x1 = start_tex_x; | |
220 span->tex_x2 = end_tex_x; | |
221 span->tex_y1 = start_tex_y; | |
222 span->tex_y2 = end_tex_y; | |
113
6ba88fa28df6
Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
223 |
6ba88fa28df6
Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
224 // TilePtr の計算 |
6ba88fa28df6
Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
225 // tix, tiy (Tile 内での x, y) |
6ba88fa28df6
Define New Texture Data Structure
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
109
diff
changeset
|
226 // |
109 | 227 } |
228 } | |
229 | |
230 | |
231 int | |
232 CreateSpan::run(void *rbuf, void *wbuf) | |
233 { | |
234 PolygonPack *pp = (PolygonPack*)smanager->get_input(0); | |
235 PolygonPack *next_pp = | |
236 (PolygonPack*)smanager->allocate(sizeof(PolygonPack)); | |
237 PolygonPack *free_pp = next_pp; | |
238 PolygonPack *tmp_pp; | |
239 | |
240 TrianglePackPtr triPack; | |
241 VertexPackPtr vMin, vMid, vMax; | |
242 VertexPackPtr vMid10 | |
243 = (VertexPackPtr)smanager->allocate(sizeof(VertexPack)); | |
244 | |
245 SpanPackPtr *spackList = (SpanPackPtr*)smanager->get_input(1); | |
246 spack = (SpanPackPtr)smanager->get_input(2); | |
247 send_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
248 prev_index = get_param(0); | |
249 | |
250 // spack と send_spack は swap しながら DMA を繰り返すので | |
251 // 自分で allocate した send_spack を覚えてないといけない | |
252 SpanPackPtr free_spack = send_spack; | |
253 | |
254 int charge_y_top = get_param(1); | |
255 int charge_y_end = get_param(2); | |
256 | |
257 do { | |
258 if (pp->next != NULL) { | |
259 smanager->dma_load(next_pp, (uint32)pp->next, | |
260 sizeof(PolygonPack), POLYGON_PACK_LOAD); | |
261 } else { | |
262 next_pp = NULL; | |
263 } | |
264 | |
265 for (int i = 0; i < pp->info.size; i++) { | |
266 triPack = &pp->tri[i]; | |
267 | |
268 #if 0 | |
269 make_vertex(triPack, &vMin, &vMid, &vMax); | |
270 #else | |
271 if (triPack->ver1.y <= triPack->ver2.y) { | |
272 if (triPack->ver2.y <= triPack->ver3.y) { | |
273 vMin = &triPack->ver1; | |
274 vMid = &triPack->ver2; | |
275 vMax = &triPack->ver3; | |
276 } else if (triPack->ver3.y <= triPack->ver1.y) { | |
277 vMin = &triPack->ver3; | |
278 vMid = &triPack->ver1; | |
279 vMax = &triPack->ver2; | |
280 } else { | |
281 vMin = &triPack->ver1; | |
282 vMid = &triPack->ver3; | |
283 vMax = &triPack->ver2; | |
284 } | |
285 } else { | |
286 if (triPack->ver1.y <= triPack->ver3.y) { | |
287 vMin = &triPack->ver2; | |
288 vMid = &triPack->ver1; | |
289 vMax = &triPack->ver3; | |
290 } else if (triPack->ver3.y <= triPack->ver2.y) { | |
291 vMin = &triPack->ver3; | |
292 vMid = &triPack->ver2; | |
293 vMax = &triPack->ver1; | |
294 } else { | |
295 vMin = &triPack->ver2; | |
296 vMid = &triPack->ver3; | |
297 vMax = &triPack->ver1; | |
298 } | |
299 } | |
300 #endif | |
301 make_vMid10(vMid10, vMin, vMid, vMax); | |
302 | |
303 half_triangle(spackList, charge_y_top, charge_y_end, | |
304 triPack->tex_addr, triPack->tex_width, | |
305 triPack->tex_height, vMin, vMid, vMid10); | |
306 half_triangle(spackList, charge_y_top, charge_y_end, | |
307 pp->tri[0].tex_addr, pp->tri[0].tex_width, | |
308 pp->tri[0].tex_height, vMax, vMid, vMid10); | |
309 } | |
310 | |
311 smanager->dma_wait(POLYGON_PACK_LOAD); | |
312 | |
313 tmp_pp = pp; | |
314 pp = next_pp; | |
315 next_pp = tmp_pp; | |
316 } while (pp); | |
317 | |
318 smanager->dma_wait(SPAN_PACK_STORE); | |
319 smanager->dma_store(spack, (uint32)spackList[prev_index], | |
320 sizeof(SpanPack), SPAN_PACK_STORE); | |
321 smanager->dma_wait(SPAN_PACK_STORE); | |
322 | |
323 free(free_pp); | |
324 free(free_spack); | |
325 free(vMid10); | |
326 | |
327 return 0; | |
328 } |