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