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