Mercurial > hg > Game > Cerium
annotate TaskManager/Test/test_render/task/DrawSpan.cpp @ 406:da48fe13a459 draft
add task/SendKey
author | game@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Wed, 23 Sep 2009 13:00:03 +0900 (2009-09-23) |
parents | 492e60453124 |
children | e2f29e912d0b |
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" |
352 | 9 #include "global_alloc.h" |
109 | 10 |
210 | 11 SchedDefineTask(DrawSpan); |
109 | 12 |
210 | 13 #define TEX_LOAD1 0 |
14 #define TEX_LOAD2 1 | |
15 #define SPAN_PACK_LOAD 2 | |
16 #define FB_STORE 3 | |
109 | 17 |
193 | 18 DrawSpan::~DrawSpan(void) |
19 { | |
20 smanager->dma_wait(FB_STORE); | |
21 free((void*)((int)linebuf*doneWrite)); | |
22 } | |
23 | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
24 /** |
193 | 25 * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
26 * |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
27 * +---+---+---+---+---+---+ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
28 * | 0 | 1 | 2 | 3 | 4 | 5 | |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
29 * +---+---+---+---+---+---+ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
30 * | | | | | |11 | |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
31 * +---+---+---+---+---+---+ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
32 * | | | | | |17 | |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
33 * +---+---+---+---+---+---+ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
34 * | | | | | |23 | |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
35 * +---+---+---+---+---+---+ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
36 * | | | | | |29 | |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
37 * +---+---+---+---+---+---+ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
38 * | | | | | |35 | |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
39 * +---+---+---+---+---+---+ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
40 * |
193 | 41 * 一辺を TEXTURE_SPLIT とする |
42 * 各ブロックの数字がブロックIDとなる。 | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
43 */ |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
44 |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
45 /** |
193 | 46 * テクスチャの座標から、 |
47 * テクスチャのどのブロックかを求める | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
48 * |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
49 * @param[in] tx X coordinates of texture |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
50 * @param[in] tx Y coordinates of texture |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
51 * @param[in] twidth Width of texture |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
52 * @return block ID |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
53 */ |
184 | 54 int |
55 DrawSpan::getTexBlock(int tx, int ty, int twidth) | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
56 { |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
57 int blockX, blockY; |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
58 |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
59 blockX = tx / TEXTURE_SPLIT_PIXEL; |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
60 blockY = ty / TEXTURE_SPLIT_PIXEL; |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
61 |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
62 return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
63 } |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
64 |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
65 /** |
193 | 66 * block ID と、テクスチャの TOP address から |
67 * (tx,ty) で使われるテクスチャの Tile addres を求める | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
68 * |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
69 * @param[in] tx X coordinates of texture |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
70 * @param[in] tx Y coordinates of texture |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
71 * @param[in] tw Width of texture |
193 | 72 * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
73 * @return block ID |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
74 */ |
373 | 75 memaddr |
76 DrawSpan::getTile(int tx, int ty, int tw, memaddr tex_addr_top) | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
77 { |
184 | 78 int block = getTexBlock(tx, ty, tw); |
373 | 79 return tex_addr_top + block * TEXTURE_BLOCK_SIZE * sizeof(uint32); |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
80 } |
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
81 |
193 | 82 /** |
83 * FrameBuffer に書き込む rgb の領域初期化 | |
84 * | |
85 * @param width Width of Buffer | |
86 * @param height Height of Buffer | |
87 * @param rgb Initial value of RGB at Buffer | |
88 * @return Buffer | |
89 */ | |
90 int* | |
91 DrawSpan::linebuf_init(int width, int height, int rgb) | |
109 | 92 { |
193 | 93 int *buf = (int*)smanager->allocate(sizeof(int)*width*height); |
94 | |
95 for (int i = 0; i < width*height; i++) { | |
352 | 96 buf[i] = rgb; |
109 | 97 } |
193 | 98 |
99 return buf; | |
109 | 100 } |
101 | |
184 | 102 /** |
193 | 103 * Z-Buffer の初期化 |
184 | 104 * |
193 | 105 * @param width Width of Z-Buffer |
106 * @param height Height of Z-Buffer | |
107 * @return Z-Buffer | |
108 */ | |
109 float* | |
110 DrawSpan::zRow_init(int width, int height) | |
111 { | |
112 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); | |
113 float def = 65535.0f; | |
114 | |
115 for (int i = 0; i < width*height; i++) { | |
352 | 116 buf[i] = def; |
193 | 117 } |
118 | |
119 return buf; | |
120 } | |
121 | |
184 | 122 |
360 | 123 uint32 |
124 DrawSpan::get_rgb(int tx, int ty, TilePtr tile) | |
184 | 125 { |
373 | 126 uint32 *data = (uint32 *)tile->data; |
127 return data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; | |
109 | 128 } |
129 | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
130 |
193 | 131 void |
132 DrawSpan::writebuffer(unsigned int display, int buf_width, int height, | |
352 | 133 int screen_width) |
193 | 134 { |
135 for (int i = 0; i < height; i++) { | |
352 | 136 smanager->dma_store(&linebuf[i*buf_width], |
137 display + (sizeof(int)*screen_width*i), | |
138 sizeof(int)*buf_width, FB_STORE); | |
193 | 139 } |
140 | |
141 doneWrite = 1; | |
142 } | |
143 | |
210 | 144 /** |
145 * zRow と Linebuf を更新する | |
146 * | |
147 * @param zpos 更新する pixel のZ座標 | |
148 * @param rangex このタスクが処理する描画領域の x の長さ | |
149 * @param x pixel の、描画領域内での x 座標 | |
150 * @param y 〃 の、y 座標 | |
151 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 | |
152 * @param tex_y 〃 の y 座標 | |
153 * @param tex_addr テクスチャのアドレス(MainMemory) | |
154 */ | |
155 void | |
352 | 156 DrawSpan::updateBuffer(float zpos, int rangex, int x, int y, int tex_x, int tex_y, |
360 | 157 float normal_x, float normal_y, float normal_z, TilePtr tile) |
210 | 158 { |
262 | 159 |
360 | 160 int color = get_rgb(tex_x, tex_y, tile); |
262 | 161 /*下位4bitを抽出*/ |
315 | 162 int alpha = color & 0x000F; |
262 | 163 /*完全に透けているか判断*/ |
164 int flag = (alpha != 0); | |
165 | |
315 | 166 color = infinity_light_calc(color,normal_x,normal_y,normal_z); |
167 | |
262 | 168 zRow[x + (rangex*y)] = zpos*flag + zRow[x + (rangex*y)]*(1-flag); |
315 | 169 linebuf[x + (rangex*y)] = color*flag + linebuf[x + (rangex*y)]*(1-flag); |
262 | 170 |
210 | 171 } |
172 | |
173 /** | |
174 * 長さが 1 の Span の描画 (要するに 1 pixel) | |
175 * | |
176 * @param span Span | |
177 * @param startx 描画開始範囲 | |
178 * @param endx 描画終了範囲 | |
179 */ | |
180 int | |
181 DrawSpan::drawDot1(SpanPtr span, int startx, int endx, int wait_tag) | |
182 { | |
183 int rangex = endx - startx + 1; | |
184 | |
315 | 185 float normal_x = span->normal_x; |
186 float normal_y = span->normal_y; | |
187 float normal_z = span->normal_z; | |
188 | |
189 | |
210 | 190 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ |
191 int tex_xpos, tex_ypos; | |
192 | |
193 // span の始点に対応する Texture の座標 (tex1, tey1) | |
194 float tex = span->tex_x1; | |
195 float tey = span->tex_y1; | |
196 | |
197 // span の始点に対応する z 座標 | |
198 float zpos = span->start_z; | |
199 | |
200 /* Tile 内での座標 */ | |
201 int localx = getLocalX(span->x-1); | |
202 int localy = getLocalY(span->y-1); | |
203 | |
204 /** | |
205 * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
206 * そのブロックのアドレス(MainMemory) | |
207 */ | |
208 int tex_localx; | |
209 int tex_localy; | |
373 | 210 memaddr tex_addr; |
210 | 211 |
212 if (span->x < startx || endx < span->x) { | |
352 | 213 return -1; |
210 | 214 } |
215 | |
216 tex_xpos = (int)((span->tex_width-1) * tex); | |
217 tex_ypos = (int)((span->tex_height-1) * tey); | |
218 | |
233 | 219 if (zpos < zRow[localx + (rangex*localy)]) { |
352 | 220 tex_addr = getTile(tex_xpos, tex_ypos, |
373 | 221 span->tex_width, (memaddr)span->tex_addr); |
352 | 222 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; |
223 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
210 | 224 |
387
b6fce69839b5
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
225 TilePtr tile = smanager->get_segment(tex_addr,tileList); |
b6fce69839b5
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
226 smanager->wait_segment(tile); |
210 | 227 |
352 | 228 updateBuffer(zpos, rangex, localx, localy, |
229 tex_localx, tex_localy, | |
360 | 230 normal_x,normal_y,normal_z,tile); |
210 | 231 } |
232 | |
233 return -1; | |
234 } | |
235 | |
236 void | |
237 DrawSpan::drawDot2(SpanPtr span, int startx, int end, int js, int wait_tag) | |
238 { | |
239 //printf("%d\n", js); | |
240 } | |
241 | |
233 | 242 /** |
243 * 長さが 1 より大きい Span の描画 | |
244 * | |
245 * 本来の目的として、この関数(drawLine1) では | |
246 * : 既に SPE 上に Tile のある pixel だけ描画 | |
247 * : それ以外は、ここで予め DMA load しておき、 | |
248 * : drawLine2 で一気に描画する | |
249 * ってものだったんだけど、どうも上手く行かなかったので | |
250 * 今は drawLine1 で load -> wait -> rendering を全部やってます | |
251 * (rendering といっても、rendering buffer に書き込むだけで | |
252 * まだ main memory (frame buffer) に dma store してるわけではない) | |
352 | 253 * |
233 | 254 * @param span Span |
255 * @param startx 描画開始範囲 | |
256 * @param endx 描画終了範囲 | |
257 * @return 「span のどの位置まで rendering が終わったか」の x 座標 | |
258 */ | |
210 | 259 int |
260 DrawSpan::drawLine1(SpanPtr span, int startx, int endx, int wait_tag) | |
261 { | |
262 int x = span->x; | |
263 int rangex = endx - startx + 1; | |
264 int x_len = span->length_x; | |
265 | |
315 | 266 float normal_x = span->normal_x; |
267 float normal_y = span->normal_y; | |
268 float normal_z = span->normal_z; | |
269 | |
270 | |
210 | 271 int js = (x < startx) ? startx - x : 0; |
272 int je = (x + x_len > endx) ? endx - x : x_len; | |
273 | |
274 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
275 int tex_xpos, tex_ypos; | |
276 | |
277 // span の始点に対応する座標 (tex1, tey1) | |
278 float tex1 = span->tex_x1; | |
279 float tey1 = span->tex_y1; | |
280 | |
281 // span の終点に対応する座標 (tex2, tey2) | |
282 float tex2 = span->tex_x2; | |
283 float tey2 = span->tex_y2; | |
284 | |
285 // span の始点、終点に対応する z 座標 | |
286 float zpos1 = span->start_z; | |
287 float zpos2 = span->end_z; | |
288 | |
289 // Tile 内での座標 | |
290 int localx, localy = getLocalY(span->y-1); | |
291 | |
292 int ret = je+1; | |
293 | |
294 //for (int j = js; j <= je; j++) { | |
295 for (int j = je; j >= js; j--) { | |
352 | 296 float tex_x, tex_y, tex_z; |
210 | 297 |
352 | 298 localx = getLocalX(x-1+j); |
233 | 299 |
352 | 300 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); |
233 | 301 |
352 | 302 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); |
303 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
304 if (tex_x > 1) tex_x = 1; | |
305 if (tex_x < 0) tex_x = 0; | |
306 if (tex_y > 1) tex_y = 1; | |
307 if (tex_y < 0) tex_y = 0; | |
308 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
309 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
310 | |
311 if (tex_z < zRow[localx + (rangex*localy)]) { | |
312 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
313 // そのブロックのアドレス(MainMemory) | |
373 | 314 memaddr tex_addr; |
352 | 315 int tex_localx; |
316 int tex_localy; | |
210 | 317 |
352 | 318 tex_addr = getTile(tex_xpos, tex_ypos, |
373 | 319 span->tex_width, (memaddr)span->tex_addr); |
352 | 320 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; |
321 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
387
b6fce69839b5
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
322 TilePtr tile = smanager->get_segment(tex_addr,tileList); |
b6fce69839b5
no compile error but not worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
386
diff
changeset
|
323 smanager->wait_segment(tile); |
210 | 324 |
352 | 325 updateBuffer(tex_z, rangex, localx, localy, |
326 tex_localx, tex_localy, | |
360 | 327 normal_x, normal_y, normal_z, tile); |
352 | 328 } |
210 | 329 } |
330 | |
331 return ret; | |
332 } | |
333 | |
109 | 334 int |
315 | 335 DrawSpan::infinity_light_calc(int color,float normal_x, float normal_y, float normal_z) |
336 { | |
337 unsigned char rgb[4]; | |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
338 int light_rgb; |
315 | 339 int flag; |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
340 float normal_vector[4] = {normal_x,normal_y,normal_z,0}; |
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
341 // 光のベクトル,きめうちしちゃった。どうにかする |
338
d2caa52c1828
add normal vector rotate
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
325
diff
changeset
|
342 float light_vector[4] = {0,0,-1,0}; |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
343 float inner_product; |
315 | 344 |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
345 // 引数で受け取った color の rgb 情報の抜き出し |
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
346 rgb[0] = (color & 0xff000000) >> 24; |
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
347 rgb[1] = (color & 0x00ff0000) >> 16; |
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
348 rgb[2] = (color & 0x0000ff00) >> 8; |
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
349 rgb[3] = (color & 0x000000ff); |
315 | 350 |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
351 // 法線ベクトルと光源ベクトルとの内積をとる |
315 | 352 inner_product = innerProduct(normal_vector,light_vector); |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
353 // 内積がマイナスの場合は色がない。 |
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
354 flag = (inner_product > 0); |
315 | 355 |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
356 // 内積を rgb にかけていく |
357
6602b9ba4bfd
fix spe/DrawSpan.{cpp, h} spe/DrawSpanRenew.cpp
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
356
diff
changeset
|
357 rgb[0] = (unsigned char)(rgb[0]*inner_product*flag); |
6602b9ba4bfd
fix spe/DrawSpan.{cpp, h} spe/DrawSpanRenew.cpp
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
356
diff
changeset
|
358 rgb[1] = (unsigned char)(rgb[1]*inner_product*flag); |
6602b9ba4bfd
fix spe/DrawSpan.{cpp, h} spe/DrawSpanRenew.cpp
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
356
diff
changeset
|
359 rgb[2] = (unsigned char)(rgb[2]*inner_product*flag); |
352 | 360 |
325
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
361 //計算した rgb を light_rgb にまとめる。 |
67e82512b15b
add inner_product is minus case.
e065725@yutaka.st.ie.u-ryukyu.ac.jp
parents:
321
diff
changeset
|
362 light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]); |
315 | 363 |
364 return light_rgb; | |
365 } | |
366 | |
367 | |
368 int | |
109 | 369 DrawSpan::run(void *rbuf, void *wbuf) |
370 { | |
193 | 371 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); |
372 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
373 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
374 Span *span; | |
375 | |
210 | 376 Span nop_span; |
377 nop_span.length_x = 1; | |
378 | |
379 int (DrawSpan::*drawFunc1[2])(SpanPtr, int, int, int) = { | |
352 | 380 &DrawSpan::drawDot1, &DrawSpan::drawLine1 |
210 | 381 }; |
382 | |
193 | 383 uint32 display = smanager->get_param(0); |
384 int screen_width = smanager->get_param(1); | |
385 int rangex_start = smanager->get_param(2); | |
352 | 386 int rangex_end = smanager->get_param(3); |
387 | |
193 | 388 // このタスクが担当する x の範囲 |
389 int rangex = rangex_end - rangex_start + 1; | |
390 | |
391 // y の範囲 | |
392 int rangey = smanager->get_param(4); | |
167
508beb59e0eb
DrawSpan で使う Tile の Hash の扱いは class TileHash を生成する事に。
gongo@localhost.localdomain
parents:
166
diff
changeset
|
393 tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
130
40978d4b608a
テクスチャの大きさを128x128以外にも使えるように。(若干バグ有り)
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
394 |
193 | 395 zRow = zRow_init(rangex, rangey); |
233 | 396 //linebuf = linebuf_init(rangex, rangey, 0x00ffffff); |
229 | 397 linebuf = linebuf_init(rangex, rangey, 0); |
184 | 398 |
193 | 399 doneWrite = 0; |
184 | 400 |
210 | 401 int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; |
402 int tl_tag_flg1 = 0; | |
403 int tl_tag_flg2 = 1; | |
352 | 404 |
109 | 405 do { |
352 | 406 /** |
407 * SpanPack->next が存在する場合、 | |
408 * 現在の SpanPack を処理してる間に | |
409 * 次の SpanPack の DMA 転送を行う | |
410 */ | |
411 if (spack->next != NULL) { | |
412 smanager->dma_load(next_spack, (uint32)spack->next, | |
413 sizeof(SpanPack), SPAN_PACK_LOAD); | |
414 } else { | |
415 next_spack = NULL; | |
416 } | |
109 | 417 |
352 | 418 SpanPtr resume_span = &nop_span; |
419 int resume_span_x = 0; | |
210 | 420 |
352 | 421 for (int t = 0; t < spack->info.size; t++) { |
422 SpanPtr next_span; | |
423 int next_span_x; | |
210 | 424 |
352 | 425 span = &spack->span[t]; |
109 | 426 |
352 | 427 /** |
428 * span の長さによって、drawLine か drawDot を選択している | |
429 */ | |
430 next_span_x | |
431 = (this->*drawFunc1[(span->length_x != 1)])( | |
432 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
433 next_span = span; | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
434 |
352 | 435 resume_span = next_span; |
436 resume_span_x = next_span_x; | |
164
dc7d10ae7460
TilePtr は SPE で計算した方がいいと判断して変更。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
161
diff
changeset
|
437 |
352 | 438 //smanager->dma_wait(tl_tag[tl_tag_flg1]); |
439 | |
440 tl_tag_flg1 ^= 1; | |
441 tl_tag_flg2 ^= 1; | |
442 } | |
184 | 443 |
352 | 444 // 現在 drawLine2、drawDot2 は機能してないので |
445 //(this->*drawFunc2[(resume_span->length_x != 1)])( | |
446 //resume_span, rangex_start, rangex_end, resume_span_x, | |
447 //tl_tag[tl_tag_flg1]); | |
148
74341c8bf935
Span への Texture List の渡し。じゃっかん texture がバグってるので
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
134
diff
changeset
|
448 |
352 | 449 smanager->dma_wait(SPAN_PACK_LOAD); |
109 | 450 |
352 | 451 SpanPackPtr tmp_spack = spack; |
452 spack = next_spack; | |
453 next_spack = tmp_spack; | |
182
8e9ada0c1ed0
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
454 } while (spack); |
109 | 455 |
193 | 456 writebuffer(display, rangex, rangey, screen_width); |
457 | |
458 // linebuf は、writebuffer() の dma_store を wait する | |
459 // DrawSpan::~DrawSpan() 内で free する。 | |
460 //free(linebuf); | |
461 free(zRow); | |
184 | 462 |
210 | 463 //FINISH: |
193 | 464 /** |
465 * goto FINISH; の時は reboot なので | |
466 * linebuf, zRow は free() しない | |
467 */ | |
210 | 468 |
182
8e9ada0c1ed0
add get_inputAddr, get_outputAddr
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
177
diff
changeset
|
469 free(free_spack); |
109 | 470 return 0; |
471 } | |
386 | 472 |
473 /* end */ |