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