Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/task/DrawSpan.cc @ 1047:6a80ca9a65d9
broken texure ( h/w != 2^n ) protection
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 08 Dec 2010 05:38:45 +0900 |
parents | 7fafe412c28f |
children |
rev | line source |
---|---|
507 | 1 #include <stdlib.h> |
2 #include <string.h> | |
3 #include "DrawSpan.h" | |
4 #include "polygon_pack.h" | |
860 | 5 #include "task_texture.h" |
507 | 6 #include "viewer_types.h" |
7 #include "Func.h" | |
8 #include "sys.h" | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
9 #include "SchedTask.h" |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
10 #include "Tapestry.h" |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
11 #include "SpanPack.h" |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
12 |
623 | 13 #if (__LITTLE_ENDIAN__) |
14 #define LITTLEENDIAN 1 | |
15 #else | |
16 #define LITTLEENDIAN 0 | |
17 #endif | |
507 | 18 |
19 SchedDefineTask(DrawSpan); | |
20 | |
21 #define TEX_LOAD1 0 | |
22 #define TEX_LOAD2 1 | |
23 #define SPAN_PACK_LOAD 2 | |
24 #define FB_STORE 3 | |
25 | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
26 typedef struct { |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
27 int **linebuf; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
28 float *zRow; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
29 TileListPtr tileList; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
30 int doneWrite; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
31 } G, *Gptr; |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
32 |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
33 static int** linebuf_init(SchedTask *smanager, int width, int height, int rgb); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
34 static float* zRow_init(SchedTask *smanager, int width, int height); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
35 // static TilePtr set_rgb(memaddr addr, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
36 // static void set_rgbs(memaddr addr, uint32 *max_addr, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
37 static uint32 get_rgb(int tx, int ty, TilePtr tile); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
38 // static TilePtr isAvailableTile(memaddr addr); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
39 static memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
40 static int getTexBlock(int tx, int ty, int twidth); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
41 |
738 | 42 static void updateBuffer(Gptr g, float zpos, int rangex, int loaclx, int localy, |
43 int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, | |
44 TilePtr tile, int world_x, int world_y, float world_z,SchedTask *smanager); | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
45 |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
46 // static void reboot(SpanPackPtr spack, int cur_span_x); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
47 |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
48 static int drawDot1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
49 //static void drawDot2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
50 static int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
51 // static void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag); |
738 | 52 |
53 static int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z, | |
54 SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z); | |
55 | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
56 |
621 | 57 static float |
58 innerProduct1(float *v0, float *v1) | |
59 { | |
845 | 60 return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]); |
621 | 61 } |
62 | |
507 | 63 |
64 /** | |
65 * テクスチャは、TEXTURE_SPLIT_PIXEL^2 のブロックに分割する | |
66 * | |
67 * +---+---+---+---+---+---+ | |
68 * | 0 | 1 | 2 | 3 | 4 | 5 | | |
69 * +---+---+---+---+---+---+ | |
70 * | | | | | |11 | | |
71 * +---+---+---+---+---+---+ | |
72 * | | | | | |17 | | |
73 * +---+---+---+---+---+---+ | |
74 * | | | | | |23 | | |
75 * +---+---+---+---+---+---+ | |
76 * | | | | | |29 | | |
77 * +---+---+---+---+---+---+ | |
78 * | | | | | |35 | | |
79 * +---+---+---+---+---+---+ | |
80 * | |
81 * 一辺を TEXTURE_SPLIT とする | |
82 * 各ブロックの数字がブロックIDとなる。 | |
83 */ | |
84 | |
85 /** | |
86 * テクスチャの座標から、 | |
87 * テクスチャのどのブロックかを求める | |
88 * | |
89 * @param[in] tx X coordinates of texture | |
90 * @param[in] tx Y coordinates of texture | |
91 * @param[in] twidth Width of texture | |
92 * @return block ID | |
93 */ | |
94 static int | |
95 getTexBlock(int tx, int ty, int twidth) | |
96 { | |
97 int blockX, blockY; | |
98 | |
99 blockX = tx / TEXTURE_SPLIT_PIXEL; | |
100 blockY = ty / TEXTURE_SPLIT_PIXEL; | |
101 | |
102 return blockX + (twidth/TEXTURE_SPLIT_PIXEL)*blockY; | |
103 } | |
104 | |
105 /** | |
106 * block ID と、テクスチャの TOP address から | |
107 * (tx,ty) で使われるテクスチャの Tile addres を求める | |
108 * | |
109 * @param[in] tx X coordinates of texture | |
110 * @param[in] tx Y coordinates of texture | |
111 * @param[in] tw Width of texture | |
112 * @param[in] tex_addr_top (tx,ty) で使うテクスチャの先頭address | |
113 * @return block ID | |
114 */ | |
115 static memaddr | |
116 getTile(int tx, int ty, int tw, memaddr tex_addr_top) | |
117 { | |
118 int block = getTexBlock(tx, ty, tw); | |
119 return tex_addr_top + block * TEXTURE_BLOCK_SIZE * sizeof(uint32); | |
120 } | |
121 | |
122 /** | |
123 * FrameBuffer に書き込む rgb の領域初期化 | |
124 * | |
125 * @param width Width of Buffer | |
126 * @param height Height of Buffer | |
127 * @param rgb Initial value of RGB at Buffer | |
128 * @return Buffer | |
129 */ | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
130 static int ** |
507 | 131 linebuf_init(SchedTask *smanager, int width, int height, int rgb) |
132 { | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
133 int **linebuf = (int**)smanager->allocate(height*sizeof(int*)); |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
134 for(int h = 0;h<height;h++) { |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
135 int *buf = linebuf[h] = (int*)smanager->get_output(h); |
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
136 for (int i = 0; i < width; i++) { |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
137 buf[i] = rgb; |
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
138 } |
507 | 139 } |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
140 return linebuf; |
507 | 141 } |
142 | |
143 /** | |
144 * Z-Buffer の初期化 | |
145 * | |
146 * @param width Width of Z-Buffer | |
147 * @param height Height of Z-Buffer | |
148 * @return Z-Buffer | |
149 */ | |
150 static float* | |
151 zRow_init(SchedTask *smanager, int width, int height) | |
152 { | |
153 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); | |
154 float def = 65535.0f; | |
155 | |
156 for (int i = 0; i < width*height; i++) { | |
157 buf[i] = def; | |
158 } | |
159 | |
160 return buf; | |
161 } | |
162 | |
163 | |
164 static uint32 | |
165 get_rgb(int tx, int ty, TilePtr tile) | |
166 { | |
167 uint32 *data = (uint32 *)tile->data; | |
168 return data[(TEXTURE_SPLIT_PIXEL)*ty+tx]; | |
169 } | |
170 | |
171 | |
172 | |
173 /** | |
174 * zRow と Linebuf を更新する | |
175 * | |
176 * @param zpos 更新する pixel のZ座標 | |
177 * @param rangex このタスクが処理する描画領域の x の長さ | |
178 * @param x pixel の、描画領域内での x 座標 | |
179 * @param y 〃 の、y 座標 | |
180 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 | |
181 * @param tex_y 〃 の y 座標 | |
182 * @param tex_addr テクスチャのアドレス(MainMemory) | |
183 */ | |
184 static void | |
738 | 185 updateBuffer(Gptr g, float zpos, int rangex, int localx, int localy, int tex_x, int tex_y, |
186 float normal_x, float normal_y, float normal_z, TilePtr tile, | |
187 int world_x, int world_y, float world_z, SchedTask *smanager) | |
507 | 188 { |
189 | |
190 int color = get_rgb(tex_x, tex_y, tile); | |
191 /*下位4bitを抽出*/ | |
623 | 192 #if LITTLEENDIAN |
599 | 193 int alpha = color & 0x000000ff; |
619 | 194 #else |
195 int alpha = color & 0xff000000; | |
196 #endif | |
845 | 197 |
882 | 198 //int *light_sysswitch = (int*)smanager->global_get(LightSysSwitch); |
845 | 199 |
855 | 200 |
201 /*完全に透けているか判断, 法線ベクトルが奥を向いてるかどうか*/ | |
1031 | 202 //int flag = (alpha != 0 && normal_z < 0); |
203 int flag = (alpha != 0); | |
507 | 204 |
845 | 205 //printf("light_sysswitch %d\n",light_sysswitch); |
206 | |
207 //if ( *light_sysswitch == 1) { | |
855 | 208 if (flag) { |
209 color = infinity_light_calc(color,normal_x,normal_y,normal_z, | |
210 smanager,localx,localy,zpos, | |
211 world_x,world_y,world_z); | |
212 } | |
845 | 213 //} |
507 | 214 |
738 | 215 g->zRow[localx + (rangex*localy)] = zpos*flag + g->zRow[localx + (rangex*localy)]*(1-flag); |
216 int *point = &g->linebuf[localy][localx] ; | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
217 *point = color*flag + *point *(1-flag); |
507 | 218 |
738 | 219 |
220 | |
507 | 221 } |
222 | |
223 /** | |
224 * 長さが 1 の Span の描画 (要するに 1 pixel) | |
225 * | |
226 * @param span Span | |
227 * @param startx 描画開始範囲 | |
228 * @param endx 描画終了範囲 | |
229 */ | |
230 static int | |
231 drawDot1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) | |
232 { | |
233 int rangex = endx - startx + 1; | |
234 | |
235 float normal_x = span->normal_x; | |
236 float normal_y = span->normal_y; | |
237 float normal_z = span->normal_z; | |
238 | |
239 | |
240 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
241 int tex_xpos, tex_ypos; | |
242 | |
243 // span の始点に対応する Texture の座標 (tex1, tey1) | |
244 float tex = span->tex_x1; | |
245 float tey = span->tex_y1; | |
246 | |
247 // span の始点に対応する z 座標 | |
248 float zpos = span->start_z; | |
249 | |
250 /* Tile 内での座標 */ | |
251 int localx = getLocalX(span->x-1); | |
252 int localy = getLocalY(span->y-1); | |
253 | |
254 /** | |
255 * (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
256 * そのブロックのアドレス(MainMemory) | |
257 */ | |
258 int tex_localx; | |
259 int tex_localy; | |
260 memaddr tex_addr; | |
261 | |
262 if (span->x < startx || endx < span->x) { | |
263 return -1; | |
264 } | |
265 | |
266 tex_xpos = (int)((span->tex_width-1) * tex); | |
267 tex_ypos = (int)((span->tex_height-1) * tey); | |
268 | |
269 if (zpos < g->zRow[localx + (rangex*localy)]) { | |
1047
6a80ca9a65d9
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1031
diff
changeset
|
270 if (!span->tex_addr) return -1; // broken case, I'd like to write some thing... |
507 | 271 tex_addr = getTile(tex_xpos, tex_ypos, |
272 span->tex_width, (memaddr)span->tex_addr); | |
273 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
274 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
275 | |
276 TilePtr tile = smanager->get_segment(tex_addr,g->tileList); | |
277 smanager->wait_segment(tile); | |
278 | |
279 updateBuffer(g, zpos, rangex, localx, localy, | |
280 tex_localx, tex_localy, | |
738 | 281 normal_x,normal_y,normal_z,tile, |
282 span->x, span->y, zpos, smanager); | |
507 | 283 } |
284 | |
285 return -1; | |
286 } | |
287 | |
288 #if 0 | |
289 static void | |
290 drawDot2(SchedTask *smanager, SpanPtr span, int startx, int end, int js, int wait_tag) | |
291 { | |
292 //printf("%d\n", js); | |
293 } | |
294 #endif | |
295 | |
296 /** | |
297 * 長さが 1 より大きい Span の描画 | |
298 * | |
299 * 本来の目的として、この関数(drawLine1) では | |
300 * : 既に SPE 上に Tile のある pixel だけ描画 | |
301 * : それ以外は、ここで予め DMA load しておき、 | |
302 * : drawLine2 で一気に描画する | |
303 * ってものだったんだけど、どうも上手く行かなかったので | |
304 * 今は drawLine1 で load -> wait -> rendering を全部やってます | |
305 * (rendering といっても、rendering buffer に書き込むだけで | |
306 * まだ main memory (frame buffer) に dma store してるわけではない) | |
307 * | |
308 * @param span Span | |
309 * @param startx 描画開始範囲 | |
310 * @param endx 描画終了範囲 | |
311 * @return 「span のどの位置まで rendering が終わったか」の x 座標 | |
312 */ | |
313 static int | |
314 drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag) | |
315 { | |
316 int x = span->x; | |
317 int rangex = endx - startx + 1; | |
318 int x_len = span->length_x; | |
319 | |
320 float normal_x = span->normal_x; | |
321 float normal_y = span->normal_y; | |
322 float normal_z = span->normal_z; | |
323 | |
324 | |
325 int js = (x < startx) ? startx - x : 0; | |
326 int je = (x + x_len > endx) ? endx - x : x_len; | |
327 | |
328 /* span->x に対応する Texture の座標 (tex_xpos, tex_ypos) */ | |
329 int tex_xpos, tex_ypos; | |
330 | |
331 // span の始点に対応する座標 (tex1, tey1) | |
332 float tex1 = span->tex_x1; | |
333 float tey1 = span->tex_y1; | |
334 | |
335 // span の終点に対応する座標 (tex2, tey2) | |
336 float tex2 = span->tex_x2; | |
337 float tey2 = span->tex_y2; | |
338 | |
339 // span の始点、終点に対応する z 座標 | |
340 float zpos1 = span->start_z; | |
341 float zpos2 = span->end_z; | |
342 | |
738 | 343 //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。 |
344 float z_inclination = (zpos1 - zpos2) / x_len; | |
345 float world_z = zpos2; | |
346 | |
507 | 347 // Tile 内での座標 |
348 int localx, localy = getLocalY(span->y-1); | |
349 | |
350 int ret = je+1; | |
351 | |
352 //for (int j = js; j <= je; j++) { | |
353 for (int j = je; j >= js; j--) { | |
354 float tex_x, tex_y, tex_z; | |
355 | |
738 | 356 world_z += z_inclination; |
357 | |
507 | 358 localx = getLocalX(x-1+j); |
359 | |
360 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); | |
361 | |
362 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); | |
363 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
364 if (tex_x > 1) tex_x = 1; | |
365 if (tex_x < 0) tex_x = 0; | |
366 if (tex_y > 1) tex_y = 1; | |
367 if (tex_y < 0) tex_y = 0; | |
368 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
369 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
370 | |
371 if (tex_z < g->zRow[localx + (rangex*localy)]) { | |
372 // (tex_xpos, tex_ypos) の、Tile 内(上の図参照)での座標と | |
373 // そのブロックのアドレス(MainMemory) | |
374 memaddr tex_addr; | |
375 int tex_localx; | |
376 int tex_localy; | |
377 | |
1047
6a80ca9a65d9
broken texure ( h/w != 2^n ) protection
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
1031
diff
changeset
|
378 if (!span->tex_addr) continue; // broken case, I'd like to write some thing... |
507 | 379 tex_addr = getTile(tex_xpos, tex_ypos, |
380 span->tex_width, (memaddr)span->tex_addr); | |
381 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
382 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
383 TilePtr tile = smanager->get_segment(tex_addr,g->tileList); | |
384 smanager->wait_segment(tile); | |
385 | |
386 updateBuffer(g, tex_z, rangex, localx, localy, | |
387 tex_localx, tex_localy, | |
738 | 388 normal_x, normal_y, normal_z, tile, |
389 span->x+j, span->y, world_z, smanager); | |
507 | 390 } |
391 } | |
392 | |
393 return ret; | |
394 } | |
395 | |
396 static int | |
738 | 397 infinity_light_calc(int color,float normal_x, float normal_y, |
398 float normal_z, SchedTask *smanager, int x, int y, float z, | |
399 int world_x, int world_y, float world_z) | |
400 | |
507 | 401 { |
766 | 402 |
403 | |
507 | 404 unsigned char rgb[4]; |
405 int light_rgb; | |
406 int flag; | |
407 float normal_vector[4] = {normal_x,normal_y,normal_z,0}; | |
766 | 408 float light_vector[4]; |
507 | 409 float inner_product; |
766 | 410 float *light_xyz = (float*)smanager->global_get(Light); |
411 | |
412 normalize(normal_vector, normal_vector); | |
507 | 413 |
414 // 引数で受け取った color の rgb 情報の抜き出し | |
623 | 415 #if LITTLEENDIAN |
507 | 416 rgb[0] = (color & 0xff000000) >> 24; |
417 rgb[1] = (color & 0x00ff0000) >> 16; | |
418 rgb[2] = (color & 0x0000ff00) >> 8; | |
419 rgb[3] = (color & 0x000000ff); | |
619 | 420 #else |
421 rgb[3] = (color & 0xff000000) >> 24; | |
422 rgb[2] = (color & 0x00ff0000) >> 16; | |
423 rgb[1] = (color & 0x0000ff00) >> 8; | |
424 rgb[0] = (color & 0x000000ff); | |
425 #endif | |
507 | 426 |
766 | 427 int tmp_rgb[3] = {0,0,0}; |
428 int light_num = 4; | |
429 for (int i = 0; i < light_num; i++) { | |
430 | |
845 | 431 |
766 | 432 light_vector[0] = world_x - light_xyz[i*4]; |
433 light_vector[1] = world_y - light_xyz[i*4+1]; | |
434 light_vector[2] = light_xyz[i*4+2] - world_z; | |
435 light_vector[3] = light_xyz[i*4+3]; | |
436 | |
437 normalize(light_vector, light_vector); | |
438 | |
439 // 法線ベクトルと光源ベクトルとの内積をとる | |
440 inner_product = innerProduct1(normal_vector,light_vector); | |
441 | |
442 //printf("inner_product %f\n",inner_product); | |
507 | 443 |
766 | 444 // 内積がマイナスの場合は色がない。 |
845 | 445 flag = (inner_product > 0); |
766 | 446 |
447 // 内積を rgb にかけていく | |
845 | 448 |
766 | 449 tmp_rgb[0] += (unsigned char)(rgb[0]*inner_product*flag); |
450 tmp_rgb[1] += (unsigned char)(rgb[1]*inner_product*flag); | |
451 tmp_rgb[2] += (unsigned char)(rgb[2]*inner_product*flag); | |
452 | |
453 } | |
454 | |
455 int rgb_flag[3]; | |
456 for (int i = 0; i < 3; i++) { | |
457 rgb_flag[i] = (tmp_rgb[i] > 255); | |
458 } | |
459 | |
460 rgb[0] = tmp_rgb[0]*(1 - rgb_flag[0]) + 255*(rgb_flag[0]); | |
461 rgb[1] = tmp_rgb[1]*(1 - rgb_flag[1]) + 255*(rgb_flag[1]); | |
462 rgb[2] = tmp_rgb[2]*(1 - rgb_flag[2]) + 255*(rgb_flag[2]); | |
463 | |
507 | 464 |
465 //計算した rgb を light_rgb にまとめる。 | |
623 | 466 #if LITTLEENDIAN |
507 | 467 light_rgb = (rgb[0] << 24) + (rgb[1] << 16) + (rgb[2] << 8) + (rgb[3]); |
619 | 468 #else |
469 light_rgb = (rgb[3] << 24) + (rgb[2] << 16) + (rgb[1] << 8) + (rgb[0]); | |
470 #endif | |
507 | 471 |
472 return light_rgb; | |
766 | 473 |
507 | 474 } |
475 | |
476 | |
477 static int | |
478 run(SchedTask *smanager, void *rbuf, void *wbuf) | |
479 { | |
838 | 480 |
845 | 481 //get_param(5) is spack->info.size |
846 | 482 if ((long)smanager->get_param(5) == 0) { |
838 | 483 |
484 int rangex_start = (long)smanager->get_param(2); | |
485 int rangex_end = (long)smanager->get_param(3); | |
486 | |
487 int rangex = rangex_end - rangex_start + 1; | |
488 int rangey = (long)smanager->get_param(4); | |
489 | |
914 | 490 for(int h = 0; h < rangey; h++) { |
491 int *buf = (int*)smanager->get_output(h); | |
492 for (int i = 0; i < rangex; i++) { | |
493 buf[i] = 0; | |
494 } | |
495 } | |
838 | 496 |
497 return 0; | |
498 | |
499 } | |
500 | |
501 | |
623 | 502 G g0; |
503 Gptr g = &g0; | |
507 | 504 |
505 SpanPackPtr spack = (SpanPackPtr)smanager->get_input(0); | |
506 SpanPackPtr next_spack = (SpanPackPtr)smanager->allocate(sizeof(SpanPack)); | |
507 SpanPackPtr free_spack = next_spack; // next_spack の free() 用 | |
508 Span *span; | |
509 | |
510 Span nop_span; | |
511 nop_span.length_x = 1; | |
512 | |
738 | 513 // uint32 display = (long)smanager->get_param(0); |
514 // int screen_width = (long)smanager->get_param(1); | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
623
diff
changeset
|
515 int rangex_start = (long)smanager->get_param(2); |
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
623
diff
changeset
|
516 int rangex_end = (long)smanager->get_param(3); |
507 | 517 |
518 // このタスクが担当する x の範囲 | |
519 int rangex = rangex_end - rangex_start + 1; | |
520 | |
521 // y の範囲 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
623
diff
changeset
|
522 int rangey = (long)smanager->get_param(4); |
507 | 523 g->tileList = (TileListPtr)smanager->global_get(GLOBAL_TILE_LIST); |
524 | |
525 g->zRow = zRow_init(smanager, rangex, rangey); | |
526 g->linebuf = linebuf_init(smanager, rangex, rangey, 0); | |
527 | |
528 int tl_tag[2] = {TEX_LOAD1, TEX_LOAD2}; | |
529 int tl_tag_flg1 = 0; | |
530 int tl_tag_flg2 = 1; | |
531 | |
532 do { | |
533 /** | |
534 * SpanPack->next が存在する場合、 | |
535 * 現在の SpanPack を処理してる間に | |
536 * 次の SpanPack の DMA 転送を行う | |
537 */ | |
538 if (spack->next != NULL) { | |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
539 smanager->dma_load(next_spack, (memaddr)spack->next, |
507 | 540 sizeof(SpanPack), SPAN_PACK_LOAD); |
541 } else { | |
542 next_spack = NULL; | |
543 } | |
544 | |
545 SpanPtr resume_span = &nop_span; | |
546 | |
547 for (int t = 0; t < spack->info.size; t++) { | |
548 SpanPtr next_span; | |
549 | |
550 span = &spack->span[t]; | |
551 | |
622
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
552 if (span->length_x != 1) { |
845 | 553 drawLine1( |
554 smanager, g, | |
555 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
622
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
556 } else { |
845 | 557 drawDot1( |
558 smanager, g, | |
559 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); | |
622
6a5e88112ed9
remove non relocatable funcion call.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
621
diff
changeset
|
560 } |
507 | 561 next_span = span; |
562 | |
563 resume_span = next_span; | |
564 | |
565 tl_tag_flg1 ^= 1; | |
566 tl_tag_flg2 ^= 1; | |
567 } | |
568 | |
569 smanager->dma_wait(SPAN_PACK_LOAD); | |
570 | |
571 SpanPackPtr tmp_spack = spack; | |
572 spack = next_spack; | |
573 next_spack = tmp_spack; | |
574 } while (spack); | |
575 | |
576 | |
577 free(g->zRow); | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
578 free(g->linebuf); |
507 | 579 |
580 //FINISH: | |
581 /** | |
582 * goto FINISH; の時は reboot なので | |
583 * linebuf, zRow は free() しない | |
584 */ | |
585 | |
586 free(free_spack); | |
587 | |
588 | |
589 return 0; | |
590 } | |
591 | |
592 /* end */ |