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