Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/task/DrawSpan.cpp @ 221:d61fded0729e
Cameraの設定、Makefile 修正
author | gongo@gendarme.local |
---|---|
date | Tue, 10 Feb 2009 01:47:12 +0900 |
parents | 0f1ff7b06157 |
children | 401b55a4a4dd |
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); |
211 | 151 if (index < 0) { |
152 printf("haosa\n"); | |
153 } | |
193 | 154 smanager->dma_load(tile->pixel, (uint32)addr, |
210 | 155 sizeof(uint32)*TEXTURE_BLOCK_SIZE, tag); |
184 | 156 } |
157 | |
210 | 158 /** |
159 * | |
160 */ | |
184 | 161 void |
210 | 162 DrawSpan::set_rgbs(uint32 *cur_addr, uint32 *max_addr, int wait_tag) |
184 | 163 { |
210 | 164 uint32 curp = (uint32)cur_addr; |
165 uint32 maxp = (uint32)max_addr; | |
166 uint32 startp = curp; | |
167 uint32 diff = sizeof(int)*TEXTURE_BLOCK_SIZE; | |
168 int length = (int)maxp-(int)curp; | |
169 | |
170 int cmp = (length < 0); | |
193 | 171 |
210 | 172 #if 1 |
173 length += cmp*(-1)*length*2; | |
174 startp = cmp*maxp + !cmp*curp; | |
175 #else | |
176 if (length < 0) { | |
177 length = -length; | |
178 startp = maxp; | |
179 } | |
180 #endif | |
181 | |
182 for (int i = 0; i <= length; i += diff) { | |
183 set_rgb((uint32*)(startp + i), wait_tag); | |
184 | 184 } |
185 } | |
186 | |
193 | 187 uint32 |
166 | 188 DrawSpan::get_rgb(int tx, int ty, uint32 *addr) |
109 | 189 { |
154 | 190 TilePtr tile; |
215
7ca6a2ef5be9
fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents:
211
diff
changeset
|
191 |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
192 tile = hash->get(addr); |
168 | 193 return tile->pixel[(TEXTURE_SPLIT_PIXEL)*ty+tx]; |
109 | 194 } |
195 | |
184 | 196 /** |
193 | 197 * DrawSpan の再起動 (DrawSpanRenew 生成) |
184 | 198 * |
193 | 199 * @param[in] spack 現在処理している SpanPack |
200 * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で | |
201 * どこまで進んでいるか | |
184 | 202 */ |
203 void | |
204 DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) | |
205 { | |
193 | 206 DrawSpanArgPtr args = |
207 (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); | |
184 | 208 TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); |
193 | 209 |
210 // 数が多いので構造体で渡す | |
211 args->display = smanager->get_param(0); | |
212 args->screen_width = smanager->get_param(1); | |
213 args->rangex_start = smanager->get_param(2); | |
214 args->rangex_end = smanager->get_param(3); | |
215 args->rangey = smanager->get_param(4); | |
216 renew_task->add_param((int)args); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
217 |
184 | 218 /** |
193 | 219 * SpanPack は続きから開始するので、 |
220 * 現在の状態をコピーしておく。 | |
221 * spack は rbuf から取得してる可能性があり | |
222 * rbuf はシステムが自動的に free() するため | |
223 * アドレスだけ渡すのはNG | |
184 | 224 */ |
225 SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
226 memcpy(curr, spack, sizeof(SpanPack)); | |
227 renew_task->add_param((int)curr); | |
228 renew_task->add_param(cur_span_x); | |
229 | |
193 | 230 // linebuf と zRow も引き継がせる |
231 renew_task->add_param((int)linebuf); | |
232 renew_task->add_param((int)zRow); | |
233 | |
184 | 234 /** |
193 | 235 * 再起動したタスクを待つ |
184 | 236 */ |
237 smanager->wait_task(renew_task); | |
238 | |
193 | 239 // next_spack は free() するので wait する |
184 | 240 smanager->dma_wait(SPAN_PACK_LOAD); |
241 } | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
242 |
193 | 243 void |
244 DrawSpan::writebuffer(unsigned int display, int buf_width, int height, | |
245 int screen_width) | |
246 { | |
247 for (int i = 0; i < height; i++) { | |
248 smanager->dma_store(&linebuf[i*buf_width], | |
249 display + (sizeof(int)*screen_width*i), | |
250 sizeof(int)*buf_width, FB_STORE); | |
251 } | |
252 | |
253 doneWrite = 1; | |
254 } | |
255 | |
210 | 256 /** |
257 * zRow と Linebuf を更新する | |
258 * | |
259 * @param zpos 更新する pixel のZ座標 | |
260 * @param rangex このタスクが処理する描画領域の x の長さ | |
261 * @param x pixel の、描画領域内での x 座標 | |
262 * @param y 〃 の、y 座標 | |
263 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 | |
264 * @param tex_y 〃 の y 座標 | |
265 * @param tex_addr テクスチャのアドレス(MainMemory) | |
266 */ | |
267 void | |
268 DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, | |
269 int tex_x, int tex_y, uint32 *tex_addr) | |
270 { | |
271 int rgb = get_rgb(tex_x, tex_y, tex_addr); | |
272 | |
273 zRow[x + (rangex*y)] = zpos; | |
274 linebuf[x + (rangex*y)] = rgb; | |
275 } | |
276 | |
277 /** | |
278 * 長さが 1 の Span の描画 (要するに 1 pixel) | |
279 * | |
280 * @param span Span | |
281 * @param startx 描画開始範囲 | |
282 * @param endx 描画終了範囲 | |
283 */ | |
284 int | |
285 DrawSpan::drawDot1(SpanPtr span, int startx, int endx, int wait_tag) | |
286 { | |
287 int rangex = endx - startx + 1; | |
288 | |
289 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
290 int tex_xpos, tex_ypos; | |
291 | |
292 // span の始点に対応する Texture の座標 (tex1, tey1) | |
293 float tex = span->tex_x1; | |
294 float tey = span->tex_y1; | |
295 | |
296 // span の始点に対応する z 座標 | |
297 float zpos = span->start_z; | |
298 | |
299 /* Tile 内での座標 */ | |
300 int localx = getLocalX(span->x-1); | |
301 int localy = getLocalY(span->y-1); | |
302 | |
303 /** | |
304 * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
305 * そのブロックのアドレス(MainMemory) | |
306 */ | |
307 int tex_localx; | |
308 int tex_localy; | |
309 uint32 *tex_addr; | |
310 | |
311 if (span->x < startx || endx < span->x) { | |
312 return -1; | |
313 } | |
314 | |
315 tex_xpos = (int)((span->tex_width-1) * tex); | |
316 tex_ypos = (int)((span->tex_height-1) * tey); | |
317 | |
221 | 318 if (0 < zpos && zpos < zRow[localx + (rangex*localy)]) { |
319 //if (zpos < zRow[localx + (rangex*localy)]) { | |
210 | 320 tex_addr = getTile(tex_xpos, tex_ypos, |
321 span->tex_width, span->tex_addr); | |
322 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
323 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
324 | |
325 if (!isAvailableTile(tex_addr)) { | |
326 set_rgb(tex_addr, wait_tag); | |
327 smanager->dma_wait(wait_tag); | |
328 //return startx; | |
329 } | |
330 | |
331 updateBuffer(zpos, rangex, localx, localy, | |
332 tex_localx, tex_localy, tex_addr); | |
333 } | |
334 | |
335 return -1; | |
336 } | |
337 | |
338 void | |
339 DrawSpan::drawDot2(SpanPtr span, int startx, int end, int js, int wait_tag) | |
340 { | |
341 //printf("%d\n", js); | |
342 } | |
343 | |
344 int | |
345 DrawSpan::drawLine1(SpanPtr span, int startx, int endx, int wait_tag) | |
346 { | |
347 int x = span->x; | |
348 int rangex = endx - startx + 1; | |
349 int x_len = span->length_x; | |
350 | |
351 int js = (x < startx) ? startx - x : 0; | |
352 int je = (x + x_len > endx) ? endx - x : x_len; | |
353 | |
354 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
355 int tex_xpos, tex_ypos; | |
356 | |
357 // span の始点に対応する座標 (tex1, tey1) | |
358 float tex1 = span->tex_x1; | |
359 float tey1 = span->tex_y1; | |
360 | |
361 // span の終点に対応する座標 (tex2, tey2) | |
362 float tex2 = span->tex_x2; | |
363 float tey2 = span->tex_y2; | |
364 | |
365 // span の始点、終点に対応する z 座標 | |
366 float zpos1 = span->start_z; | |
367 float zpos2 = span->end_z; | |
368 | |
369 // Tile 内での座標 | |
370 int localx, localy = getLocalY(span->y-1); | |
371 | |
372 int ret = je+1; | |
373 | |
374 //for (int j = js; j <= je; j++) { | |
375 for (int j = je; j >= js; j--) { | |
376 float tex_x, tex_y, tex_z; | |
377 | |
378 localx = getLocalX(x-1+j); | |
379 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); | |
380 | |
221 | 381 if (0 < tex_z && tex_z < zRow[localx + (rangex*localy)]) { |
382 //if (tex_z < zRow[localx + (rangex*localy)]) { | |
210 | 383 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と |
384 // そのブロックのアドレス(MainMemory) | |
385 uint32 *tex_addr; | |
386 int tex_localx; | |
387 int tex_localy; | |
388 | |
211 | 389 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); |
390 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
391 if (tex_x > 1) tex_x = 1; | |
392 if (tex_x < 0) tex_x = 0; | |
393 if (tex_y > 1) tex_y = 1; | |
394 if (tex_y < 0) tex_y = 0; | |
395 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
396 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
397 | |
210 | 398 tex_addr = getTile(tex_xpos, tex_ypos, |
399 span->tex_width, span->tex_addr); | |
400 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
401 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
211 | 402 |
403 //set_rgb(tex_addr, wait_tag); | |
404 //ret = j; | |
405 //continue; | |
210 | 406 |
407 if (!isAvailableTile(tex_addr)) { | |
211 | 408 #if 0 |
210 | 409 tex_x = tex1*(x_len-1-js)/(x_len-1) + tex2*js/(x_len-1); |
410 if (tex_x > 1) tex_x = 1; | |
411 if (tex_x < 0) tex_x = 0; | |
412 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
413 | |
414 uint32 *max_addr = getTile(tex_xpos, tex_ypos, | |
415 span->tex_width, span->tex_addr); | |
416 | |
417 set_rgbs(tex_addr, max_addr, wait_tag); | |
418 return js; | |
419 #else | |
420 set_rgb(tex_addr, wait_tag); | |
215
7ca6a2ef5be9
fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents:
211
diff
changeset
|
421 //ret = j; |
7ca6a2ef5be9
fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents:
211
diff
changeset
|
422 smanager->dma_wait(wait_tag); |
7ca6a2ef5be9
fix SceneGraph Constructor, Destructor
gongo@gendarme.local
parents:
211
diff
changeset
|
423 //continue; |
210 | 424 #endif |
425 } | |
426 | |
427 updateBuffer(tex_z, rangex, localx, localy, | |
428 tex_localx, tex_localy, tex_addr); | |
429 } | |
430 } | |
431 | |
432 return ret; | |
433 } | |
434 | |
435 void | |
436 DrawSpan::drawLine2(SpanPtr span, int startx, int endx, int js, int wait_tag) | |
437 { | |
438 int x = span->x; | |
439 int rangex = endx - startx + 1; | |
440 int x_len = span->length_x; | |
441 | |
442 //int js = startx; | |
443 int je = (x + x_len > endx) ? endx - x : x_len; | |
444 | |
445 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
446 int tex_xpos, tex_ypos; | |
447 | |
448 // span の始点に対応する座標 (tex1, tey1) | |
449 float tex1 = span->tex_x1; | |
450 float tey1 = span->tex_y1; | |
451 | |
452 // span の終点に対応する座標 (tex2, tey2) | |
453 float tex2 = span->tex_x2; | |
454 float tey2 = span->tex_y2; | |
455 | |
456 // span の始点、終点に対応する z 座標 | |
457 float zpos1 = span->start_z; | |
458 float zpos2 = span->end_z; | |
459 | |
460 // Tile 内での座標 | |
461 int localx, localy = getLocalY(span->y-1); | |
462 | |
463 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
464 // そのブロックのアドレス(MainMemory) | |
465 int tex_localx; | |
466 int tex_localy; | |
467 uint32 *tex_addr; | |
468 | |
469 float tex_x, tex_y, tex_z; | |
470 | |
471 smanager->dma_wait(wait_tag); | |
472 | |
473 for (int j = js; j <= je; j++) { | |
474 localx = getLocalX(x-1+j); | |
475 | |
476 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); | |
477 | |
478 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); | |
479 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
480 if (tex_x > 1) tex_x = 1; | |
481 if (tex_x < 0) tex_x = 0; | |
482 if (tex_y > 1) tex_y = 1; | |
483 if (tex_y < 0) tex_y = 0; | |
484 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
485 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
486 | |
221 | 487 if (0 < tex_z && tex_z < zRow[localx + (rangex*localy)]) { |
488 //if (tex_z < zRow[localx + (rangex*localy)]) { | |
210 | 489 tex_addr = getTile(tex_xpos, tex_ypos, |
490 span->tex_width, span->tex_addr); | |
491 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
492 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
493 | |
494 updateBuffer(tex_z, rangex, localx, localy, | |
495 tex_localx, tex_localy, tex_addr); | |
496 } | |
497 } | |
498 } | |
499 | |
109 | 500 int |
501 DrawSpan::run(void *rbuf, void *wbuf) | |
502 { | |
193 | 503 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); |
504 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
505 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
506 Span *span; | |
507 | |
210 | 508 Span nop_span; |
509 nop_span.length_x = 1; | |
510 | |
511 int (DrawSpan::*drawFunc1[2])(SpanPtr, int, int, int) = { | |
512 &DrawSpan::drawDot1, &DrawSpan::drawLine1 | |
513 }; | |
514 | |
515 void (DrawSpan::*drawFunc2[2])(SpanPtr, int, int, int, int) = { | |
516 &DrawSpan::drawDot2, &DrawSpan::drawLine2 | |
517 }; | |
518 | |
193 | 519 uint32 display = smanager->get_param(0); |
520 int screen_width = smanager->get_param(1); | |
521 int rangex_start = smanager->get_param(2); | |
522 int rangex_end = smanager->get_param(3); | |
210 | 523 |
193 | 524 // このタスクが担当する x の範囲 |
525 int rangex = rangex_end - rangex_start + 1; | |
526 | |
527 // y の範囲 | |
528 int rangey = smanager->get_param(4); | |
210 | 529 |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
530 hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); |
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
531 tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
130
8a33f4859ed8
テクスチャの大きさを128x128以外にも使えるように。(若干バグ有り)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
532 |
193 | 533 zRow = zRow_init(rangex, rangey); |
211 | 534 linebuf = linebuf_init(rangex, rangey, 0xffffffff); |
184 | 535 |
193 | 536 doneWrite = 0; |
184 | 537 |
210 | 538 int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; |
539 int tl_tag_flg1 = 0; | |
540 int tl_tag_flg2 = 1; | |
541 | |
109 | 542 do { |
543 /** | |
193 | 544 * SpanPack->next が存在する場合、 |
545 * 現在の SpanPack を処理してる間に | |
546 * 次の SpanPack の DMA 転送を行う | |
109 | 547 */ |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
548 if (spack->next != NULL) { |
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
549 smanager->dma_load(next_spack, (uint32)spack->next, |
109 | 550 sizeof(SpanPack), SPAN_PACK_LOAD); |
551 } else { | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
552 next_spack = NULL; |
109 | 553 } |
554 | |
210 | 555 SpanPtr resume_span = &nop_span; |
556 int resume_span_x = 0; | |
557 | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
558 for (int t = 0; t < spack->info.size; t++) { |
210 | 559 SpanPtr next_span; |
560 int next_span_x; | |
561 | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
562 span = &spack->span[t]; |
109 | 563 |
210 | 564 next_span_x |
565 = (this->*drawFunc1[(span->length_x != 1)])( | |
566 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
567 next_span = span; | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
568 |
210 | 569 (this->*drawFunc2[(resume_span->length_x != 1)])( |
570 resume_span, rangex_start, rangex_end, resume_span_x, | |
571 tl_tag[tl_tag_flg2]); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
572 |
210 | 573 resume_span = next_span; |
574 resume_span_x = next_span_x; | |
575 | |
576 //smanager->dma_wait(tl_tag[tl_tag_flg1]); | |
184 | 577 |
210 | 578 tl_tag_flg1 ^= 1; |
579 tl_tag_flg2 ^= 1; | |
109 | 580 } |
210 | 581 |
582 (this->*drawFunc2[(resume_span->length_x != 1)])( | |
583 resume_span, rangex_start, rangex_end, resume_span_x, | |
584 tl_tag[tl_tag_flg1]); | |
148
9642aeef298d
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
134
diff
changeset
|
585 |
109 | 586 smanager->dma_wait(SPAN_PACK_LOAD); |
587 | |
184 | 588 SpanPackPtr tmp_spack = spack; |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
589 spack = next_spack; |
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
590 next_spack = tmp_spack; |
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
591 } while (spack); |
109 | 592 |
193 | 593 writebuffer(display, rangex, rangey, screen_width); |
594 | |
595 // linebuf は、writebuffer() の dma_store を wait する | |
596 // DrawSpan::~DrawSpan() 内で free する。 | |
597 //free(linebuf); | |
598 free(zRow); | |
184 | 599 |
210 | 600 //FINISH: |
193 | 601 /** |
602 * goto FINISH; の時は reboot なので | |
603 * linebuf, zRow は free() しない | |
604 */ | |
210 | 605 |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
606 free(free_spack); |
109 | 607 return 0; |
608 } |