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