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