Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/task/DrawSpan.cpp @ 360:716b87bce32a
add vacuum "-sg 16"
author | aaa |
---|---|
date | Fri, 17 Jul 2009 22:50:06 +0900 |
parents | 953811245b63 |
children | f88744ee9350 |
rev | line source |
---|---|
109 | 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" | |
184 | 7 #include "Func.h" |
315 | 8 #include "sys.h" |
352 | 9 #include "global_alloc.h" |
109 | 10 |
210 | 11 SchedDefineTask(DrawSpan); |
109 | 12 |
210 | 13 #define TEX_LOAD1 0 |
14 #define TEX_LOAD2 1 | |
15 #define SPAN_PACK_LOAD 2 | |
16 #define FB_STORE 3 | |
109 | 17 |
193 | 18 DrawSpan::~DrawSpan(void) |
19 { | |
20 smanager->dma_wait(FB_STORE); | |
21 free((void*)((int)linebuf*doneWrite)); | |
22 } | |
23 | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
24 /** |
193 | 25 * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
26 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
27 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
28 * | 0 | 1 | 2 | 3 | 4 | 5 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
29 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
30 * | | | | | |11 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
31 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
32 * | | | | | |17 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
33 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
34 * | | | | | |23 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
35 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
36 * | | | | | |29 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
37 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
38 * | | | | | |35 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
39 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
40 * |
193 | 41 * 一辺を TEXTURE_SPLIT とする |
42 * 各ブロックの数字がブロックIDとなる。 | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
43 */ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
44 |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
45 /** |
193 | 46 * テクスチャの座標から、 |
47 * テクスチャのどのブロックかを求める | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
48 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
49 * @param[in] tx X coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
50 * @param[in] tx Y coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
51 * @param[in] twidth Width of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
52 * @return block ID |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
53 */ |
184 | 54 int |
55 DrawSpan::getTexBlock(int tx, int ty, int twidth) | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
56 { |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
57 int blockX, blockY; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
58 |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
59 blockX = tx / TEXTURE_SPLIT_PIXEL; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
60 blockY = ty / TEXTURE_SPLIT_PIXEL; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
61 |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
62 return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
63 } |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
64 |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
65 /** |
193 | 66 * block ID と、テクスチャの TOP address から |
67 * (tx,ty) で使われるテクスチャの Tile addres を求める | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
68 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
69 * @param[in] tx X coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
70 * @param[in] tx Y coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
71 * @param[in] tw Width of texture |
193 | 72 * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
73 * @return block ID |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
74 */ |
184 | 75 uint32* |
76 DrawSpan::getTile(int tx, int ty, int tw, uint32 *tex_addr_top) | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
77 { |
184 | 78 int block = getTexBlock(tx, ty, tw); |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
79 return tex_addr_top + block*TEXTURE_BLOCK_SIZE; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
80 } |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
81 |
193 | 82 /** |
83 * FrameBuffer に書き込む rgb の領域初期化 | |
84 * | |
85 * @param width Width of Buffer | |
86 * @param height Height of Buffer | |
87 * @param rgb Initial value of RGB at Buffer | |
88 * @return Buffer | |
89 */ | |
90 int* | |
91 DrawSpan::linebuf_init(int width, int height, int rgb) | |
109 | 92 { |
193 | 93 int *buf = (int*)smanager->allocate(sizeof(int)*width*height); |
94 | |
95 for (int i = 0; i < width*height; i++) { | |
352 | 96 buf[i] = rgb; |
109 | 97 } |
193 | 98 |
99 return buf; | |
109 | 100 } |
101 | |
184 | 102 /** |
193 | 103 * Z-Buffer の初期化 |
184 | 104 * |
193 | 105 * @param width Width of Z-Buffer |
106 * @param height Height of Z-Buffer | |
107 * @return Z-Buffer | |
108 */ | |
109 float* | |
110 DrawSpan::zRow_init(int width, int height) | |
111 { | |
112 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); | |
113 float def = 65535.0f; | |
114 | |
115 for (int i = 0; i < width*height; i++) { | |
352 | 116 buf[i] = def; |
193 | 117 } |
118 | |
119 return buf; | |
120 } | |
121 | |
122 | |
123 /** | |
124 * Span が使う Texture Tile があるか | |
125 * | |
126 * @retval != NULL 存在する | |
127 * @retval NULL 存在しない | |
184 | 128 */ |
129 TilePtr | |
130 DrawSpan::isAvailableTile(uint32 *addr) | |
131 { | |
132 return hash->get(addr); | |
133 } | |
134 | |
360 | 135 TilePtr |
210 | 136 DrawSpan::set_rgb(uint32 *addr, int tag) |
184 | 137 { |
138 TilePtr tile; | |
139 | |
210 | 140 |
193 | 141 tile = tileList->nextTile(); |
360 | 142 uint32 *old_addr = tile->texture_addr; |
143 smanager->dma_load(tile->pixel, (uint32)addr, | |
144 sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); | |
193 | 145 /** |
146 * FIFO なので、もし前のが残っていれば削除 | |
147 */ | |
360 | 148 |
149 hash->remove(old_addr); | |
352 | 150 |
193 | 151 tile->texture_addr = addr; |
352 | 152 |
238 | 153 hash->put(tile->texture_addr, tile); |
360 | 154 |
155 return tile; | |
184 | 156 } |
157 | |
360 | 158 uint32 |
159 DrawSpan::get_rgb(int tx, int ty, TilePtr tile) | |
184 | 160 { |
168 | 161 return tile->pixel[(TEXTURE_SPLIT_PIXEL)*ty+tx]; |
109 | 162 } |
163 | |
184 | 164 /** |
193 | 165 * DrawSpan の再起動 (DrawSpanRenew 生成) |
184 | 166 * |
193 | 167 * @param[in] spack 現在処理している SpanPack |
168 * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で | |
169 * どこまで進んでいるか | |
184 | 170 */ |
171 void | |
172 DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) | |
173 { | |
193 | 174 DrawSpanArgPtr args = |
352 | 175 (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); |
184 | 176 TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); |
193 | 177 |
178 // 数が多いので構造体で渡す | |
179 args->display = smanager->get_param(0); | |
180 args->screen_width = smanager->get_param(1); | |
181 args->rangex_start = smanager->get_param(2); | |
182 args->rangex_end = smanager->get_param(3); | |
183 args->rangey = smanager->get_param(4); | |
184 renew_task->add_param((int)args); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
185 |
184 | 186 /** |
193 | 187 * SpanPack は続きから開始するので、 |
188 * 現在の状態をコピーしておく。 | |
189 * spack は rbuf から取得してる可能性があり | |
190 * rbuf はシステムが自動的に free() するため | |
191 * アドレスだけ渡すのはNG | |
352 | 192 */ |
184 | 193 SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); |
194 memcpy(curr, spack, sizeof(SpanPack)); | |
195 renew_task->add_param((int)curr); | |
196 renew_task->add_param(cur_span_x); | |
197 | |
193 | 198 // linebuf と zRow も引き継がせる |
199 renew_task->add_param((int)linebuf); | |
200 renew_task->add_param((int)zRow); | |
201 | |
184 | 202 /** |
193 | 203 * 再起動したタスクを待つ |
352 | 204 */ |
184 | 205 smanager->wait_task(renew_task); |
206 | |
193 | 207 // next_spack は free() するので wait する |
184 | 208 smanager->dma_wait(SPAN_PACK_LOAD); |
209 } | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
210 |
193 | 211 void |
212 DrawSpan::writebuffer(unsigned int display, int buf_width, int height, | |
352 | 213 int screen_width) |
193 | 214 { |
215 for (int i = 0; i < height; i++) { | |
352 | 216 smanager->dma_store(&linebuf[i*buf_width], |
217 display + (sizeof(int)*screen_width*i), | |
218 sizeof(int)*buf_width, FB_STORE); | |
193 | 219 } |
220 | |
221 doneWrite = 1; | |
222 } | |
223 | |
210 | 224 /** |
225 * zRow と Linebuf を更新する | |
226 * | |
227 * @param zpos 更新する pixel のZ座標 | |
228 * @param rangex このタスクが処理する描画領域の x の長さ | |
229 * @param x pixel の、描画領域内での x 座標 | |
230 * @param y 〃 の、y 座標 | |
231 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 | |
232 * @param tex_y 〃 の y 座標 | |
233 * @param tex_addr テクスチャのアドレス(MainMemory) | |
234 */ | |
235 void | |
352 | 236 DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, int tex_x, int tex_y, |
360 | 237 float normal_x, float normal_y, float normal_z, TilePtr tile) |
210 | 238 { |
262 | 239 |
360 | 240 int color = get_rgb(tex_x, tex_y, tile); |
262 | 241 /*下位4bitを抽出*/ |
315 | 242 int alpha = color & 0x000F; |
262 | 243 /*完全に透けているか判断*/ |
244 int flag = (alpha != 0); | |
245 | |
315 | 246 color = infinity_light_calc(color,normal_x,normal_y,normal_z); |
247 | |
262 | 248 zRow[x + (rangex*y)] = zpos*flag + zRow[x + (rangex*y)]*(1-flag); |
315 | 249 linebuf[x + (rangex*y)] = color*flag + linebuf[x + (rangex*y)]*(1-flag); |
262 | 250 |
210 | 251 } |
252 | |
253 /** | |
254 * 長さが 1 の Span の描画 (要するに 1 pixel) | |
255 * | |
256 * @param span Span | |
257 * @param startx 描画開始範囲 | |
258 * @param endx 描画終了範囲 | |
259 */ | |
260 int | |
261 DrawSpan::drawDot1(SpanPtr span, int startx, int endx, int wait_tag) | |
262 { | |
263 int rangex = endx - startx + 1; | |
264 | |
315 | 265 float normal_x = span->normal_x; |
266 float normal_y = span->normal_y; | |
267 float normal_z = span->normal_z; | |
268 | |
269 | |
210 | 270 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ |
271 int tex_xpos, tex_ypos; | |
272 | |
273 // span の始点に対応する Texture の座標 (tex1, tey1) | |
274 float tex = span->tex_x1; | |
275 float tey = span->tex_y1; | |
276 | |
277 // span の始点に対応する z 座標 | |
278 float zpos = span->start_z; | |
279 | |
280 /* Tile 内での座標 */ | |
281 int localx = getLocalX(span->x-1); | |
282 int localy = getLocalY(span->y-1); | |
283 | |
284 /** | |
285 * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
286 * そのブロックのアドレス(MainMemory) | |
287 */ | |
288 int tex_localx; | |
289 int tex_localy; | |
290 uint32 *tex_addr; | |
291 | |
292 if (span->x < startx || endx < span->x) { | |
352 | 293 return -1; |
210 | 294 } |
295 | |
296 tex_xpos = (int)((span->tex_width-1) * tex); | |
297 tex_ypos = (int)((span->tex_height-1) * tey); | |
298 | |
233 | 299 if (zpos < zRow[localx + (rangex*localy)]) { |
352 | 300 tex_addr = getTile(tex_xpos, tex_ypos, |
301 span->tex_width, span->tex_addr); | |
302 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
303 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
210 | 304 |
360 | 305 TilePtr tile; |
306 if (!(tile = isAvailableTile(tex_addr))) { | |
307 tile = set_rgb(tex_addr, wait_tag); | |
352 | 308 smanager->dma_wait(wait_tag); |
309 //return startx; | |
310 } | |
210 | 311 |
352 | 312 updateBuffer(zpos, rangex, localx, localy, |
313 tex_localx, tex_localy, | |
360 | 314 normal_x,normal_y,normal_z,tile); |
210 | 315 } |
316 | |
317 return -1; | |
318 } | |
319 | |
320 void | |
321 DrawSpan::drawDot2(SpanPtr span, int startx, int end, int js, int wait_tag) | |
322 { | |
323 //printf("%d\n", js); | |
324 } | |
325 | |
233 | 326 /** |
327 * 長さが 1 より大きい Span の描画 | |
328 * | |
329 * 本来の目的として、この関数(drawLine1) では | |
330 * : 既に SPE 上に Tile のある pixel だけ描画 | |
331 * : それ以外は、ここで予め DMA load しておき、 | |
332 * : drawLine2 で一気に描画する | |
333 * ってものだったんだけど、どうも上手く行かなかったので | |
334 * 今は drawLine1 で load -> wait -> rendering を全部やってます | |
335 * (rendering といっても、rendering buffer に書き込むだけで | |
336 * まだ main memory (frame buffer) に dma store してるわけではない) | |
352 | 337 * |
233 | 338 * @param span Span |
339 * @param startx 描画開始範囲 | |
340 * @param endx 描画終了範囲 | |
341 * @return 「span のどの位置まで rendering が終わったか」の x 座標 | |
342 */ | |
210 | 343 int |
344 DrawSpan::drawLine1(SpanPtr span, int startx, int endx, int wait_tag) | |
345 { | |
346 int x = span->x; | |
347 int rangex = endx - startx + 1; | |
348 int x_len = span->length_x; | |
349 | |
315 | 350 float normal_x = span->normal_x; |
351 float normal_y = span->normal_y; | |
352 float normal_z = span->normal_z; | |
353 | |
354 | |
210 | 355 int js = (x < startx) ? startx - x : 0; |
356 int je = (x + x_len > endx) ? endx - x : x_len; | |
357 | |
358 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
359 int tex_xpos, tex_ypos; | |
360 | |
361 // span の始点に対応する座標 (tex1, tey1) | |
362 float tex1 = span->tex_x1; | |
363 float tey1 = span->tex_y1; | |
364 | |
365 // span の終点に対応する座標 (tex2, tey2) | |
366 float tex2 = span->tex_x2; | |
367 float tey2 = span->tex_y2; | |
368 | |
369 // span の始点、終点に対応する z 座標 | |
370 float zpos1 = span->start_z; | |
371 float zpos2 = span->end_z; | |
372 | |
373 // Tile 内での座標 | |
374 int localx, localy = getLocalY(span->y-1); | |
375 | |
376 int ret = je+1; | |
377 | |
378 //for (int j = js; j <= je; j++) { | |
379 for (int j = je; j >= js; j--) { | |
352 | 380 float tex_x, tex_y, tex_z; |
210 | 381 |
352 | 382 localx = getLocalX(x-1+j); |
233 | 383 |
352 | 384 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); |
233 | 385 |
352 | 386 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); |
387 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
388 if (tex_x > 1) tex_x = 1; | |
389 if (tex_x < 0) tex_x = 0; | |
390 if (tex_y > 1) tex_y = 1; | |
391 if (tex_y < 0) tex_y = 0; | |
392 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
393 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
394 | |
395 if (tex_z < zRow[localx + (rangex*localy)]) { | |
396 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
397 // そのブロックのアドレス(MainMemory) | |
398 uint32 *tex_addr; | |
399 int tex_localx; | |
400 int tex_localy; | |
210 | 401 |
352 | 402 tex_addr = getTile(tex_xpos, tex_ypos, |
403 span->tex_width, span->tex_addr); | |
404 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
405 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
210 | 406 |
360 | 407 TilePtr tile; |
408 if (!(tile = isAvailableTile(tex_addr))) { | |
409 tile = set_rgb(tex_addr, wait_tag); | |
352 | 410 smanager->dma_wait(wait_tag); |
411 } | |
210 | 412 |
352 | 413 updateBuffer(tex_z, rangex, localx, localy, |
414 tex_localx, tex_localy, | |
360 | 415 normal_x, normal_y, normal_z, tile); |
352 | 416 } |
210 | 417 } |
418 | |
419 return ret; | |
420 } | |
421 | |
109 | 422 int |
315 | 423 DrawSpan::infinity_light_calc(int color,float normal_x, float normal_y, float normal_z) |
424 { | |
425 unsigned char rgb[4]; | |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
426 int light_rgb; |
315 | 427 int flag; |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
428 float normal_vector[4] = {normal_x,normal_y,normal_z,0}; |
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
429 // 光のベクトル,きめうちしちゃった。どうにかする |
338
2964ed8fd321
add normal vector rotate
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
325
diff
changeset
|
430 float light_vector[4] = {0,0,-1,0}; |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
431 float inner_product; |
315 | 432 |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
433 // 引数で受け取った color の rgb 情報の抜き出し |
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
434 rgb[0] = (color & 0xff000000) >> 24; |
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
435 rgb[1] = (color & 0x00ff0000) >> 16; |
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
436 rgb[2] = (color & 0x0000ff00) >> 8; |
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
437 rgb[3] = (color & 0x000000ff); |
315 | 438 |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
439 // 法線ベクトルと光源ベクトルとの内積をとる |
315 | 440 inner_product = innerProduct(normal_vector,light_vector); |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
441 // 内積がマイナスの場合は色がない。 |
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
442 flag = (inner_product > 0); |
315 | 443 |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
444 // 内積を rgb にかけていく |
357
953811245b63
fix spe/DrawSpan.{cpp, h} spe/DrawSpanRenew.cpp
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
356
diff
changeset
|
445 rgb[0] = (unsigned char)(rgb[0]*inner_product*flag); |
953811245b63
fix spe/DrawSpan.{cpp, h} spe/DrawSpanRenew.cpp
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
356
diff
changeset
|
446 rgb[1] = (unsigned char)(rgb[1]*inner_product*flag); |
953811245b63
fix spe/DrawSpan.{cpp, h} spe/DrawSpanRenew.cpp
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
356
diff
changeset
|
447 rgb[2] = (unsigned char)(rgb[2]*inner_product*flag); |
352 | 448 |
325
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
449 //計算した rgb を light_rgb にまとめる。 |
f79cacba09b1
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
450 light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]); |
315 | 451 |
452 return light_rgb; | |
453 } | |
454 | |
455 | |
456 int | |
109 | 457 DrawSpan::run(void *rbuf, void *wbuf) |
458 { | |
193 | 459 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); |
460 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
461 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
462 Span *span; | |
463 | |
210 | 464 Span nop_span; |
465 nop_span.length_x = 1; | |
466 | |
467 int (DrawSpan::*drawFunc1[2])(SpanPtr, int, int, int) = { | |
352 | 468 &DrawSpan::drawDot1, &DrawSpan::drawLine1 |
210 | 469 }; |
470 | |
193 | 471 uint32 display = smanager->get_param(0); |
472 int screen_width = smanager->get_param(1); | |
473 int rangex_start = smanager->get_param(2); | |
352 | 474 int rangex_end = smanager->get_param(3); |
475 | |
193 | 476 // このタスクが担当する x の範囲 |
477 int rangex = rangex_end - rangex_start + 1; | |
478 | |
479 // y の範囲 | |
480 int rangey = smanager->get_param(4); | |
210 | 481 |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
482 hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); |
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
483 tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
130
8a33f4859ed8
テクスチャの大きさを128x128以外にも使えるように。(若干バグ有り)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
484 |
193 | 485 zRow = zRow_init(rangex, rangey); |
233 | 486 //linebuf = linebuf_init(rangex, rangey, 0x00ffffff); |
229 | 487 linebuf = linebuf_init(rangex, rangey, 0); |
184 | 488 |
193 | 489 doneWrite = 0; |
184 | 490 |
210 | 491 int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; |
492 int tl_tag_flg1 = 0; | |
493 int tl_tag_flg2 = 1; | |
352 | 494 |
109 | 495 do { |
352 | 496 /** |
497 * SpanPack->next が存在する場合、 | |
498 * 現在の SpanPack を処理してる間に | |
499 * 次の SpanPack の DMA 転送を行う | |
500 */ | |
501 if (spack->next != NULL) { | |
502 smanager->dma_load(next_spack, (uint32)spack->next, | |
503 sizeof(SpanPack), SPAN_PACK_LOAD); | |
504 } else { | |
505 next_spack = NULL; | |
506 } | |
109 | 507 |
352 | 508 SpanPtr resume_span = &nop_span; |
509 int resume_span_x = 0; | |
210 | 510 |
352 | 511 for (int t = 0; t < spack->info.size; t++) { |
512 SpanPtr next_span; | |
513 int next_span_x; | |
210 | 514 |
352 | 515 span = &spack->span[t]; |
109 | 516 |
352 | 517 /** |
518 * span の長さによって、drawLine か drawDot を選択している | |
519 */ | |
520 next_span_x | |
521 = (this->*drawFunc1[(span->length_x != 1)])( | |
522 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
523 next_span = span; | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
524 |
352 | 525 resume_span = next_span; |
526 resume_span_x = next_span_x; | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
527 |
352 | 528 //smanager->dma_wait(tl_tag[tl_tag_flg1]); |
529 | |
530 tl_tag_flg1 ^= 1; | |
531 tl_tag_flg2 ^= 1; | |
532 } | |
184 | 533 |
352 | 534 // 現在 drawLine2、drawDot2 は機能してないので |
535 //(this->*drawFunc2[(resume_span->length_x != 1)])( | |
536 //resume_span, rangex_start, rangex_end, resume_span_x, | |
537 //tl_tag[tl_tag_flg1]); | |
148
9642aeef298d
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
134
diff
changeset
|
538 |
352 | 539 smanager->dma_wait(SPAN_PACK_LOAD); |
109 | 540 |
352 | 541 SpanPackPtr tmp_spack = spack; |
542 spack = next_spack; | |
543 next_spack = tmp_spack; | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
544 } while (spack); |
109 | 545 |
193 | 546 writebuffer(display, rangex, rangey, screen_width); |
547 | |
548 // linebuf は、writebuffer() の dma_store を wait する | |
549 // DrawSpan::~DrawSpan() 内で free する。 | |
550 //free(linebuf); | |
551 free(zRow); | |
184 | 552 |
210 | 553 //FINISH: |
193 | 554 /** |
555 * goto FINISH; の時は reboot なので | |
556 * linebuf, zRow は free() しない | |
557 */ | |
210 | 558 |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
559 free(free_spack); |
109 | 560 return 0; |
561 } |