Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/task/DrawSpan.cpp @ 193:102dad2949a0
fix
author | gongo@localhost.localdomain |
---|---|
date | Tue, 13 Jan 2009 19:06:13 +0900 |
parents | 7c800a5570f1 |
children | 204b03ca98f8 |
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 |
9 #define SPAN_PACK_LOAD 0 | |
120 | 10 #define TEX_LOAD 1 |
193 | 11 #define FB_STORE 2 |
109 | 12 |
13 SchedDefineTask(DrawSpan); | |
14 | |
193 | 15 DrawSpan::~DrawSpan(void) |
16 { | |
17 smanager->dma_wait(FB_STORE); | |
18 free((void*)((int)linebuf*doneWrite)); | |
19 } | |
20 | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
21 /** |
193 | 22 * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
23 * |
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 * | 0 | 1 | 2 | 3 | 4 | 5 | |
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 * | | | | | |11 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
28 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
29 * | | | | | |17 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
30 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
31 * | | | | | |23 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
32 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
33 * | | | | | |29 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
34 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
35 * | | | | | |35 | |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
36 * +---+---+---+---+---+---+ |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
37 * |
193 | 38 * 一辺を TEXTURE_SPLIT とする |
39 * 各ブロックの数字がブロックIDとなる。 | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
40 */ |
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 /** |
193 | 43 * テクスチャの座標から、 |
44 * テクスチャのどのブロックかを求める | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
45 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
46 * @param[in] tx X coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
47 * @param[in] tx Y coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
48 * @param[in] twidth Width of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
49 * @return block ID |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
50 */ |
184 | 51 int |
52 DrawSpan::getTexBlock(int tx, int ty, int twidth) | |
164
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 int blockX, blockY; |
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 blockX = tx / TEXTURE_SPLIT_PIXEL; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
57 blockY = ty / TEXTURE_SPLIT_PIXEL; |
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 return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
60 } |
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 /** |
193 | 63 * block ID と、テクスチャの TOP address から |
64 * (tx,ty) で使われるテクスチャの Tile addres を求める | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
65 * |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
66 * @param[in] tx X coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
67 * @param[in] tx Y coordinates of texture |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
68 * @param[in] tw Width of texture |
193 | 69 * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
70 * @return block ID |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
71 */ |
184 | 72 uint32* |
73 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
|
74 { |
184 | 75 int block = getTexBlock(tx, ty, tw); |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
76 return tex_addr_top + block*TEXTURE_BLOCK_SIZE; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
77 } |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
78 |
193 | 79 /** |
80 * FrameBuffer に書き込む rgb の領域初期化 | |
81 * | |
82 * @param width Width of Buffer | |
83 * @param height Height of Buffer | |
84 * @param rgb Initial value of RGB at Buffer | |
85 * @return Buffer | |
86 */ | |
87 int* | |
88 DrawSpan::linebuf_init(int width, int height, int rgb) | |
109 | 89 { |
193 | 90 int *buf = (int*)smanager->allocate(sizeof(int)*width*height); |
91 | |
92 for (int i = 0; i < width*height; i++) { | |
109 | 93 buf[i] = rgb; |
94 } | |
193 | 95 |
96 return buf; | |
109 | 97 } |
98 | |
184 | 99 /** |
193 | 100 * Z-Buffer の初期化 |
184 | 101 * |
193 | 102 * @param width Width of Z-Buffer |
103 * @param height Height of Z-Buffer | |
104 * @return Z-Buffer | |
105 */ | |
106 float* | |
107 DrawSpan::zRow_init(int width, int height) | |
108 { | |
109 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); | |
110 float def = 65535.0f; | |
111 | |
112 for (int i = 0; i < width*height; i++) { | |
113 buf[i] = def; | |
114 } | |
115 | |
116 return buf; | |
117 } | |
118 | |
119 | |
120 /** | |
121 * Span が使う Texture Tile があるか | |
122 * | |
123 * @retval != NULL 存在する | |
124 * @retval NULL 存在しない | |
184 | 125 */ |
126 TilePtr | |
127 DrawSpan::isAvailableTile(uint32 *addr) | |
128 { | |
129 return hash->get(addr); | |
130 } | |
131 | |
132 void | |
133 DrawSpan::set_rgb(uint32 *addr) | |
134 { | |
135 TilePtr tile; | |
136 | |
193 | 137 tile = tileList->nextTile(); |
138 /** | |
139 * FIFO なので、もし前のが残っていれば削除 | |
140 */ | |
141 hash->remove(tile->texture_addr); | |
142 | |
143 tile->texture_addr = addr; | |
144 | |
145 hash->put(tile->texture_addr, tile); | |
146 | |
147 smanager->dma_load(tile->pixel, (uint32)addr, | |
148 sizeof(uint32)*TEXTURE_BLOCK_SIZE, TEX_LOAD); | |
184 | 149 } |
150 | |
151 void | |
152 DrawSpan::set_rgbs(uint32 *addr, uint32 *max_addr) | |
153 { | |
154 uint32 start = (uint32)addr; | |
155 uint32 end = (uint32)max_addr; | |
193 | 156 int length = (int)end-start; |
157 int diff = sizeof(int)*TEXTURE_BLOCK_SIZE; | |
158 int max_tile = 16; | |
159 | |
160 for (int i = 0, j = 0; i <= length && j < max_tile; i += diff, j++) { | |
184 | 161 set_rgb((uint32*)(start + i)); |
162 } | |
163 } | |
164 | |
193 | 165 uint32 |
166 | 166 DrawSpan::get_rgb(int tx, int ty, uint32 *addr) |
109 | 167 { |
154 | 168 TilePtr tile; |
109 | 169 |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
170 tile = hash->get(addr); |
168 | 171 return tile->pixel[(TEXTURE_SPLIT_PIXEL)*ty+tx]; |
109 | 172 } |
173 | |
184 | 174 /** |
193 | 175 * DrawSpan の再起動 (DrawSpanRenew 生成) |
184 | 176 * |
193 | 177 * @param[in] spack 現在処理している SpanPack |
178 * @param[in] cur_span_x span->length_x != 1 の時の Span の処理で | |
179 * どこまで進んでいるか | |
184 | 180 */ |
181 void | |
182 DrawSpan::reboot(SpanPackPtr spack, int cur_span_x) | |
183 { | |
193 | 184 DrawSpanArgPtr args = |
185 (DrawSpanArgPtr)smanager->allocate(sizeof(DrawSpanArg)); | |
184 | 186 TaskPtr renew_task = smanager->create_task(TASK_DRAW_SPAN2); |
193 | 187 |
188 // 数が多いので構造体で渡す | |
189 args->display = smanager->get_param(0); | |
190 args->screen_width = smanager->get_param(1); | |
191 args->rangex_start = smanager->get_param(2); | |
192 args->rangex_end = smanager->get_param(3); | |
193 args->rangey = smanager->get_param(4); | |
194 renew_task->add_param((int)args); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
195 |
184 | 196 /** |
193 | 197 * SpanPack は続きから開始するので、 |
198 * 現在の状態をコピーしておく。 | |
199 * spack は rbuf から取得してる可能性があり | |
200 * rbuf はシステムが自動的に free() するため | |
201 * アドレスだけ渡すのはNG | |
184 | 202 */ |
203 SpanPackPtr curr = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
204 memcpy(curr, spack, sizeof(SpanPack)); | |
205 renew_task->add_param((int)curr); | |
206 renew_task->add_param(cur_span_x); | |
207 | |
193 | 208 // linebuf と zRow も引き継がせる |
209 renew_task->add_param((int)linebuf); | |
210 renew_task->add_param((int)zRow); | |
211 | |
184 | 212 /** |
193 | 213 * 再起動したタスクを待つ |
184 | 214 */ |
215 smanager->wait_task(renew_task); | |
216 | |
193 | 217 // next_spack は free() するので wait する |
184 | 218 smanager->dma_wait(SPAN_PACK_LOAD); |
219 } | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
220 |
193 | 221 void |
222 DrawSpan::writebuffer(unsigned int display, int buf_width, int height, | |
223 int screen_width) | |
224 { | |
225 for (int i = 0; i < height; i++) { | |
226 smanager->dma_store(&linebuf[i*buf_width], | |
227 display + (sizeof(int)*screen_width*i), | |
228 sizeof(int)*buf_width, FB_STORE); | |
229 } | |
230 | |
231 doneWrite = 1; | |
232 } | |
233 | |
109 | 234 int |
235 DrawSpan::run(void *rbuf, void *wbuf) | |
236 { | |
193 | 237 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); |
238 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
239 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
240 Span *span; | |
241 | |
242 uint32 display = smanager->get_param(0); | |
243 int screen_width = smanager->get_param(1); | |
244 int rangex_start = smanager->get_param(2); | |
245 int rangex_end = smanager->get_param(3); | |
246 | |
247 // このタスクが担当する x の範囲 | |
248 int rangex = rangex_end - rangex_start + 1; | |
249 | |
250 // y の範囲 | |
251 int rangey = smanager->get_param(4); | |
252 | |
167
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
253 hash = (TileHashPtr)smanager->global_get(GLOBAL_TEXTURE_HASH); |
c8b868871dce
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
254 tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
130
8a33f4859ed8
テクスチャの大きさを128x128以外にも使えるように。(若干バグ有り)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
255 |
193 | 256 zRow = zRow_init(rangex, rangey); |
257 linebuf = linebuf_init(rangex, rangey, 0xffffffff); | |
184 | 258 |
193 | 259 doneWrite = 0; |
184 | 260 |
109 | 261 do { |
262 /** | |
193 | 263 * SpanPack->next が存在する場合、 |
264 * 現在の SpanPack を処理してる間に | |
265 * 次の SpanPack の DMA 転送を行う | |
109 | 266 */ |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
267 if (spack->next != NULL) { |
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
268 smanager->dma_load(next_spack, (uint32)spack->next, |
109 | 269 sizeof(SpanPack), SPAN_PACK_LOAD); |
270 } else { | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
271 next_spack = NULL; |
109 | 272 } |
273 | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
274 for (int t = 0; t < spack->info.size; t++) { |
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
275 span = &spack->span[t]; |
109 | 276 |
193 | 277 uint32 rgb = 0x0000ff00; |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
278 float tex1 = span->tex_x1; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
279 float tex2 = span->tex_x2; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
280 float tey1 = span->tex_y1; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
281 float tey2 = span->tex_y2; |
148
9642aeef298d
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
134
diff
changeset
|
282 |
166 | 283 /** |
193 | 284 * Span が持つ 1 pixel 毎の |
285 * テクスチャの座標 | |
166 | 286 */ |
109 | 287 int tex_xpos; |
288 int tex_ypos; | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
289 |
166 | 290 /** |
193 | 291 * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と |
292 * そのブロックのアドレス(MainMemory) | |
166 | 293 */ |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
294 int tex_localx; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
295 int tex_localy; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
296 uint32 *tex_addr; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
297 |
109 | 298 int x = span->x; |
299 int y = span->y; | |
134
92fcce4330f3
CreateSpan で、三角形を二つに割る時、
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
300 int x_len = span->length_x; |
109 | 301 float z = span->start_z; |
302 float zpos = span->end_z; | |
303 | |
193 | 304 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 |
109 | 305 int localx = getLocalX(x-1); |
306 int localy = getLocalY(y-1); | |
130
8a33f4859ed8
テクスチャの大きさを128x128以外にも使えるように。(若干バグ有り)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
307 |
134
92fcce4330f3
CreateSpan で、三角形を二つに割る時、
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
308 if (x_len == 1) { |
109 | 309 if (x < rangex_start || rangex_end < x) { |
310 continue; | |
311 } | |
154 | 312 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
313 tex_xpos = (int)((span->tex_width-1) * tex1); |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
314 tex_ypos = (int)((span->tex_height-1) * tey1); |
109 | 315 |
193 | 316 if (zpos < zRow[localx + (rangex*localy)]) { |
166 | 317 tex_addr = getTile(tex_xpos, tex_ypos, |
318 span->tex_width, span->tex_addr); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
319 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
320 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; |
166 | 321 |
184 | 322 if (!isAvailableTile(tex_addr)) { |
193 | 323 set_rgb(tex_addr); |
324 smanager->dma_wait(TEX_LOAD); | |
184 | 325 } |
326 | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
327 rgb = get_rgb(tex_localx, tex_localy, tex_addr); |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
328 |
193 | 329 zRow[localx + (rangex*localy)] = zpos; |
330 linebuf[localx + (rangex*localy)] = rgb; | |
109 | 331 } |
332 } else { | |
333 int js = (x < rangex_start) ? rangex_start - x : 0; | |
134
92fcce4330f3
CreateSpan で、三角形を二つに割る時、
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
334 int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
335 float tex_x, tex_y, tex_z; |
109 | 336 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
337 for (int j = js; j <= je; j++) { |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
338 localx = getLocalX(x-1+j); |
154 | 339 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
340 tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); |
134
92fcce4330f3
CreateSpan で、三角形を二つに割る時、
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
341 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
342 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
343 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
344 if (tex_x > 1) tex_x = 1; |
166 | 345 if (tex_x < 0) tex_x = 0; |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
346 if (tex_y > 1) tex_y = 1; |
166 | 347 if (tex_y < 0) tex_y = 0; |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
348 tex_xpos = (int)((span->tex_width-1) * tex_x); |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
349 tex_ypos = (int)((span->tex_height-1) * tex_y); |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
350 |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
351 if (tex_z < zRow[localx + (rangex*localy)]) { |
166 | 352 tex_addr = getTile(tex_xpos, tex_ypos, |
353 span->tex_width, span->tex_addr); | |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
354 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
355 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; |
184 | 356 |
193 | 357 /** |
358 * Tile が無い場合、一旦タスクはここで中断し、 | |
359 * Tile をロードするタスクを走らせた後に再起動する | |
360 */ | |
184 | 361 if (!isAvailableTile(tex_addr)) { |
362 spack->info.start = t; | |
193 | 363 #if 1 |
184 | 364 set_rgbs(tex_addr, |
365 getTile(span->tex_width-1, tex_ypos, | |
366 span->tex_width, span->tex_addr)); | |
193 | 367 //smanager->dma_wait(TEX_LOAD); |
184 | 368 reboot(spack, j); |
369 goto FINISH; | |
193 | 370 #else |
371 set_rgb(tex_addr); | |
372 smanager->dma_wait(TEX_LOAD); | |
373 #endif | |
184 | 374 } |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
375 |
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
376 rgb = get_rgb(tex_localx, tex_localy, tex_addr); |
168 | 377 |
164
38cbb7aecc70
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
378 zRow[localx + (rangex*localy)] = tex_z; |
193 | 379 linebuf[localx + (rangex*localy)] = rgb; |
148
9642aeef298d
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
134
diff
changeset
|
380 } |
109 | 381 } |
382 } | |
383 } | |
148
9642aeef298d
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
134
diff
changeset
|
384 |
109 | 385 smanager->dma_wait(SPAN_PACK_LOAD); |
386 | |
184 | 387 SpanPackPtr tmp_spack = spack; |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
388 spack = next_spack; |
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
389 next_spack = tmp_spack; |
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
390 } while (spack); |
109 | 391 |
193 | 392 writebuffer(display, rangex, rangey, screen_width); |
393 | |
394 // linebuf は、writebuffer() の dma_store を wait する | |
395 // DrawSpan::~DrawSpan() 内で free する。 | |
396 //free(linebuf); | |
397 free(zRow); | |
184 | 398 |
399 FINISH: | |
193 | 400 /** |
401 * goto FINISH; の時は reboot なので | |
402 * linebuf, zRow は free() しない | |
403 */ | |
182
df3cfc04e796
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
404 free(free_spack); |
109 | 405 |
406 return 0; | |
407 } |