Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/task/DrawSpan.cc @ 625:60aa3f241b10
64bit mode worked on Mac OS X.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 16 Nov 2009 10:59:55 +0900 |
parents | f35a9bee38a6 |
children | 510424e175ae |
rev | line source |
---|---|
507 | 1 #include <stdlib.h> |
2 #include <string.h> | |
3 #include "DrawSpan.h" | |
4 #include "polygon_pack.h" | |
5 #include "texture.h" | |
6 #include "viewer_types.h" | |
7 #include "Func.h" | |
8 #include "sys.h" | |
9 #include "global_alloc.h" | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
10 #include "SchedTask.h" |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
11 #include "Tapestry.h" |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
12 #include "SpanPack.h" |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
13 |
623 | 14 #if (__LITTLE_ENDIAN__) |
15 #define LITTLEENDIAN 1 | |
16 #else | |
17 #define LITTLEENDIAN 0 | |
18 #endif | |
507 | 19 |
20 SchedDefineTask(DrawSpan); | |
21 | |
22 #define TEX_LOAD1 0 | |
23 #define TEX_LOAD2 1 | |
24 #define SPAN_PACK_LOAD 2 | |
25 #define FB_STORE 3 | |
26 | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
27 typedef struct { |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
28 int **linebuf; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
29 float *zRow; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
30 TileListPtr tileList; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
31 int doneWrite; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
32 } G, *Gptr; |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
33 |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
34 static int** linebuf_init(SchedTask *smanager, int width, int height, int rgb); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
35 static float* zRow_init(SchedTask *smanager, int width, int height); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
36 // static TilePtr set_rgb(memaddr addr, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
37 // static void set_rgbs(memaddr addr, uint32 *max_addr, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
38 static uint32 get_rgb(int tx, int ty, TilePtr tile); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
39 // static TilePtr isAvailableTile(memaddr addr); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
40 static memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
41 static int getTexBlock(int tx, int ty, int twidth); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
42 static void updateBuffer(Gptr g, float zpos, int rangex, int x, int y, |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
43 int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, TilePtr tile); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
44 |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
45 |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
46 // static void reboot(SpanPackPtr spack, int cur_span_x); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
47 |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
48 static int drawDot1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
49 //static void drawDot2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
50 static int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
51 // static void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
52 static int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
53 |
621 | 54 static float |
55 innerProduct1(float *v0, float *v1) | |
56 { | |
57 return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]); | |
58 } | |
59 | |
507 | 60 |
61 /** | |
62 * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する | |
63 * | |
64 * +---+---+---+---+---+---+ | |
65 * | 0 | 1 | 2 | 3 | 4 | 5 | | |
66 * +---+---+---+---+---+---+ | |
67 * | | | | | |11 | | |
68 * +---+---+---+---+---+---+ | |
69 * | | | | | |17 | | |
70 * +---+---+---+---+---+---+ | |
71 * | | | | | |23 | | |
72 * +---+---+---+---+---+---+ | |
73 * | | | | | |29 | | |
74 * +---+---+---+---+---+---+ | |
75 * | | | | | |35 | | |
76 * +---+---+---+---+---+---+ | |
77 * | |
78 * 一辺を TEXTURE_SPLIT とする | |
79 * 各ブロックの数字がブロックIDとなる。 | |
80 */ | |
81 | |
82 /** | |
83 * テクスチャの座標から、 | |
84 * テクスチャのどのブロックかを求める | |
85 * | |
86 * @param[in] tx X coordinates of texture | |
87 * @param[in] tx Y coordinates of texture | |
88 * @param[in] twidth Width of texture | |
89 * @return block ID | |
90 */ | |
91 static int | |
92 getTexBlock(int tx, int ty, int twidth) | |
93 { | |
94 int blockX, blockY; | |
95 | |
96 blockX = tx / TEXTURE_SPLIT_PIXEL; | |
97 blockY = ty / TEXTURE_SPLIT_PIXEL; | |
98 | |
99 return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; | |
100 } | |
101 | |
102 /** | |
103 * block ID と、テクスチャの TOP address から | |
104 * (tx,ty) で使われるテクスチャの Tile addres を求める | |
105 * | |
106 * @param[in] tx X coordinates of texture | |
107 * @param[in] tx Y coordinates of texture | |
108 * @param[in] tw Width of texture | |
109 * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address | |
110 * @return block ID | |
111 */ | |
112 static memaddr | |
113 getTile(int tx, int ty, int tw, memaddr tex_addr_top) | |
114 { | |
115 int block = getTexBlock(tx, ty, tw); | |
116 return tex_addr_top + block * TEXTURE_BLOCK_SIZE * sizeof(uint32); | |
117 } | |
118 | |
119 /** | |
120 * FrameBuffer に書き込む rgb の領域初期化 | |
121 * | |
122 * @param width Width of Buffer | |
123 * @param height Height of Buffer | |
124 * @param rgb Initial value of RGB at Buffer | |
125 * @return Buffer | |
126 */ | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
127 static int ** |
507 | 128 linebuf_init(SchedTask *smanager, int width, int height, int rgb) |
129 { | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
130 int **linebuf = (int**)smanager->allocate(height*sizeof(int*)); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
131 for(int h = 0;h<height;h++) { |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
132 int *buf = linebuf[h] = (int*)smanager->get_output(h); |
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
133 for (int i = 0; i < width; i++) { |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
134 buf[i] = rgb; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
135 } |
507 | 136 } |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
137 return linebuf; |
507 | 138 } |
139 | |
140 /** | |
141 * Z-Buffer の初期化 | |
142 * | |
143 * @param width Width of Z-Buffer | |
144 * @param height Height of Z-Buffer | |
145 * @return Z-Buffer | |
146 */ | |
147 static float* | |
148 zRow_init(SchedTask *smanager, int width, int height) | |
149 { | |
150 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); | |
151 float def = 65535.0f; | |
152 | |
153 for (int i = 0; i < width*height; i++) { | |
154 buf[i] = def; | |
155 } | |
156 | |
157 return buf; | |
158 } | |
159 | |
160 | |
161 static uint32 | |
162 get_rgb(int tx, int ty, TilePtr tile) | |
163 { | |
164 uint32 *data = (uint32 *)tile->data; | |
165 return data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; | |
166 } | |
167 | |
168 | |
169 | |
170 /** | |
171 * zRow と Linebuf を更新する | |
172 * | |
173 * @param zpos 更新する pixel のZ座標 | |
174 * @param rangex このタスクが処理する描画領域の x の長さ | |
175 * @param x pixel の、描画領域内での x 座標 | |
176 * @param y 〃 の、y 座標 | |
177 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 | |
178 * @param tex_y 〃 の y 座標 | |
179 * @param tex_addr テクスチャのアドレス(MainMemory) | |
180 */ | |
181 static void | |
182 updateBuffer(Gptr g, float zpos, int rangex, int x, int y, int tex_x, int tex_y, | |
183 float normal_x, float normal_y, float normal_z, TilePtr tile) | |
184 { | |
185 | |
186 int color = get_rgb(tex_x, tex_y, tile); | |
187 /*下位4bitを抽出*/ | |
623 | 188 #if LITTLEENDIAN |
599 | 189 int alpha = color & 0x000000ff; |
619 | 190 #else |
191 int alpha = color & 0xff000000; | |
192 #endif | |
507 | 193 /*完全に透けているか判断*/ |
194 int flag = (alpha != 0); | |
195 | |
196 color = infinity_light_calc(color,normal_x,normal_y,normal_z); | |
197 | |
198 g->zRow[x + (rangex*y)] = zpos*flag + g->zRow[x + (rangex*y)]*(1-flag); | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
199 int *point = &g->linebuf[y][x] ; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
200 *point = color*flag + *point *(1-flag); |
507 | 201 |
202 } | |
203 | |
204 /** | |
205 * 長さが 1 の Span の描画 (要するに 1 pixel) | |
206 * | |
207 * @param span Span | |
208 * @param startx 描画開始範囲 | |
209 * @param endx 描画終了範囲 | |
210 */ | |
211 static int | |
212 drawDot1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) | |
213 { | |
214 int rangex = endx - startx + 1; | |
215 | |
216 float normal_x = span->normal_x; | |
217 float normal_y = span->normal_y; | |
218 float normal_z = span->normal_z; | |
219 | |
220 | |
221 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
222 int tex_xpos, tex_ypos; | |
223 | |
224 // span の始点に対応する Texture の座標 (tex1, tey1) | |
225 float tex = span->tex_x1; | |
226 float tey = span->tex_y1; | |
227 | |
228 // span の始点に対応する z 座標 | |
229 float zpos = span->start_z; | |
230 | |
231 /* Tile 内での座標 */ | |
232 int localx = getLocalX(span->x-1); | |
233 int localy = getLocalY(span->y-1); | |
234 | |
235 /** | |
236 * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
237 * そのブロックのアドレス(MainMemory) | |
238 */ | |
239 int tex_localx; | |
240 int tex_localy; | |
241 memaddr tex_addr; | |
242 | |
243 if (span->x < startx || endx < span->x) { | |
244 return -1; | |
245 } | |
246 | |
247 tex_xpos = (int)((span->tex_width-1) * tex); | |
248 tex_ypos = (int)((span->tex_height-1) * tey); | |
249 | |
250 if (zpos < g->zRow[localx + (rangex*localy)]) { | |
251 tex_addr = getTile(tex_xpos, tex_ypos, | |
252 span->tex_width, (memaddr)span->tex_addr); | |
253 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
254 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
255 | |
256 TilePtr tile = smanager->get_segment(tex_addr,g->tileList); | |
257 smanager->wait_segment(tile); | |
258 | |
259 updateBuffer(g, zpos, rangex, localx, localy, | |
260 tex_localx, tex_localy, | |
261 normal_x,normal_y,normal_z,tile); | |
262 } | |
263 | |
264 return -1; | |
265 } | |
266 | |
267 #if 0 | |
268 static void | |
269 drawDot2(SchedTask *smanager, SpanPtr span, int startx, int end, int js, int wait_tag) | |
270 { | |
271 //printf("%d\n", js); | |
272 } | |
273 #endif | |
274 | |
275 /** | |
276 * 長さが 1 より大きい Span の描画 | |
277 * | |
278 * 本来の目的として、この関数(drawLine1) では | |
279 * : 既に SPE 上に Tile のある pixel だけ描画 | |
280 * : それ以外は、ここで予め DMA load しておき、 | |
281 * : drawLine2 で一気に描画する | |
282 * ってものだったんだけど、どうも上手く行かなかったので | |
283 * 今は drawLine1 で load -> wait -> rendering を全部やってます | |
284 * (rendering といっても、rendering buffer に書き込むだけで | |
285 * まだ main memory (frame buffer) に dma store してるわけではない) | |
286 * | |
287 * @param span Span | |
288 * @param startx 描画開始範囲 | |
289 * @param endx 描画終了範囲 | |
290 * @return 「span のどの位置まで rendering が終わったか」の x 座標 | |
291 */ | |
292 static int | |
293 drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) | |
294 { | |
295 int x = span->x; | |
296 int rangex = endx - startx + 1; | |
297 int x_len = span->length_x; | |
298 | |
299 float normal_x = span->normal_x; | |
300 float normal_y = span->normal_y; | |
301 float normal_z = span->normal_z; | |
302 | |
303 | |
304 int js = (x < startx) ? startx - x : 0; | |
305 int je = (x + x_len > endx) ? endx - x : x_len; | |
306 | |
307 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
308 int tex_xpos, tex_ypos; | |
309 | |
310 // span の始点に対応する座標 (tex1, tey1) | |
311 float tex1 = span->tex_x1; | |
312 float tey1 = span->tex_y1; | |
313 | |
314 // span の終点に対応する座標 (tex2, tey2) | |
315 float tex2 = span->tex_x2; | |
316 float tey2 = span->tex_y2; | |
317 | |
318 // span の始点、終点に対応する z 座標 | |
319 float zpos1 = span->start_z; | |
320 float zpos2 = span->end_z; | |
321 | |
322 // Tile 内での座標 | |
323 int localx, localy = getLocalY(span->y-1); | |
324 | |
325 int ret = je+1; | |
326 | |
327 //for (int j = js; j <= je; j++) { | |
328 for (int j = je; j >= js; j--) { | |
329 float tex_x, tex_y, tex_z; | |
330 | |
331 localx = getLocalX(x-1+j); | |
332 | |
333 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); | |
334 | |
335 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); | |
336 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
337 if (tex_x > 1) tex_x = 1; | |
338 if (tex_x < 0) tex_x = 0; | |
339 if (tex_y > 1) tex_y = 1; | |
340 if (tex_y < 0) tex_y = 0; | |
341 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
342 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
343 | |
344 if (tex_z < g->zRow[localx + (rangex*localy)]) { | |
345 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
346 // そのブロックのアドレス(MainMemory) | |
347 memaddr tex_addr; | |
348 int tex_localx; | |
349 int tex_localy; | |
350 | |
351 tex_addr = getTile(tex_xpos, tex_ypos, | |
352 span->tex_width, (memaddr)span->tex_addr); | |
353 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
354 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
355 TilePtr tile = smanager->get_segment(tex_addr,g->tileList); | |
356 smanager->wait_segment(tile); | |
357 | |
358 updateBuffer(g, tex_z, rangex, localx, localy, | |
359 tex_localx, tex_localy, | |
360 normal_x, normal_y, normal_z, tile); | |
361 } | |
362 } | |
363 | |
364 return ret; | |
365 } | |
366 | |
367 static int | |
368 infinity_light_calc(int color,float normal_x, float normal_y, float normal_z) | |
369 { | |
370 unsigned char rgb[4]; | |
371 int light_rgb; | |
372 int flag; | |
373 float normal_vector[4] = {normal_x,normal_y,normal_z,0}; | |
374 // 光のベクトル,きめうちしちゃった。どうにかする | |
375 float light_vector[4] = {0,0,-1,0}; | |
376 float inner_product; | |
377 | |
378 // 引数で受け取った color の rgb 情報の抜き出し | |
623 | 379 #if LITTLEENDIAN |
507 | 380 rgb[0] = (color & 0xff000000) >> 24; |
381 rgb[1] = (color & 0x00ff0000) >> 16; | |
382 rgb[2] = (color & 0x0000ff00) >> 8; | |
383 rgb[3] = (color & 0x000000ff); | |
619 | 384 #else |
385 rgb[3] = (color & 0xff000000) >> 24; | |
386 rgb[2] = (color & 0x00ff0000) >> 16; | |
387 rgb[1] = (color & 0x0000ff00) >> 8; | |
388 rgb[0] = (color & 0x000000ff); | |
389 #endif | |
507 | 390 |
391 // 法線ベクトルと光源ベクトルとの内積をとる | |
621 | 392 inner_product = innerProduct1(normal_vector,light_vector); |
507 | 393 // 内積がマイナスの場合は色がない。 |
394 flag = (inner_product > 0); | |
395 | |
396 // 内積を rgb にかけていく | |
397 rgb[0] = (unsigned char)(rgb[0]*inner_product*flag); | |
398 rgb[1] = (unsigned char)(rgb[1]*inner_product*flag); | |
399 rgb[2] = (unsigned char)(rgb[2]*inner_product*flag); | |
400 | |
401 //計算した rgb を light_rgb にまとめる。 | |
623 | 402 #if LITTLEENDIAN |
507 | 403 light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]); |
619 | 404 #else |
405 light_rgb = (rgb[3] << 24) + (rgb[2] << 16) + (rgb[1] << 8) + (rgb[0]); | |
406 #endif | |
507 | 407 |
408 return light_rgb; | |
409 } | |
410 | |
411 | |
412 static int | |
413 run(SchedTask *smanager, void *rbuf, void *wbuf) | |
414 { | |
623 | 415 G g0; |
416 Gptr g = &g0; | |
507 | 417 |
418 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); | |
419 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
420 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
421 Span *span; | |
422 | |
423 Span nop_span; | |
424 nop_span.length_x = 1; | |
425 | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
426 // uint32 display = smanager->get_param(0); |
619 | 427 // int screen_width = smanager->get_param(1); |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
623
diff
changeset
|
428 int rangex_start = (long)smanager->get_param(2); |
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
623
diff
changeset
|
429 int rangex_end = (long)smanager->get_param(3); |
507 | 430 |
431 // このタスクが担当する x の範囲 | |
432 int rangex = rangex_end - rangex_start + 1; | |
433 | |
434 // y の範囲 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
623
diff
changeset
|
435 int rangey = (long)smanager->get_param(4); |
507 | 436 g->tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
437 | |
438 g->zRow = zRow_init(smanager, rangex, rangey); | |
439 g->linebuf = linebuf_init(smanager, rangex, rangey, 0); | |
440 | |
441 int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; | |
442 int tl_tag_flg1 = 0; | |
443 int tl_tag_flg2 = 1; | |
444 | |
445 do { | |
446 /** | |
447 * SpanPack->next が存在する場合、 | |
448 * 現在の SpanPack を処理してる間に | |
449 * 次の SpanPack の DMA 転送を行う | |
450 */ | |
451 if (spack->next != NULL) { | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
452 smanager->dma_load(next_spack, (memaddr)spack->next, |
507 | 453 sizeof(SpanPack), SPAN_PACK_LOAD); |
454 } else { | |
455 next_spack = NULL; | |
456 } | |
457 | |
458 SpanPtr resume_span = &nop_span; | |
459 int resume_span_x = 0; | |
460 | |
461 for (int t = 0; t < spack->info.size; t++) { | |
462 SpanPtr next_span; | |
463 int next_span_x; | |
464 | |
465 span = &spack->span[t]; | |
466 | |
622
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
467 if (span->length_x != 1) { |
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
468 drawLine1( |
507 | 469 smanager, g, |
470 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
622
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
471 } else { |
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
472 drawDot1( |
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
473 smanager, g, |
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
474 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); |
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
475 } |
507 | 476 next_span = span; |
477 | |
478 resume_span = next_span; | |
479 resume_span_x = next_span_x; | |
480 | |
481 tl_tag_flg1 ^= 1; | |
482 tl_tag_flg2 ^= 1; | |
483 } | |
484 | |
485 smanager->dma_wait(SPAN_PACK_LOAD); | |
486 | |
487 SpanPackPtr tmp_spack = spack; | |
488 spack = next_spack; | |
489 next_spack = tmp_spack; | |
490 } while (spack); | |
491 | |
492 | |
493 free(g->zRow); | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
494 free(g->linebuf); |
507 | 495 |
496 //FINISH: | |
497 /** | |
498 * goto FINISH; の時は reboot なので | |
499 * linebuf, zRow は free() しない | |
500 */ | |
501 | |
502 free(free_spack); | |
503 | |
504 | |
505 return 0; | |
506 } | |
507 | |
508 /* end */ |