comparison Renderer/Engine/task/DrawSpan.cc @ 748:b7376415fa5f

TaskManager changeset 683, Renderer changeset 746
author hiroki
date Mon, 25 Jan 2010 18:01:19 +0900
parents 60aa3f241b10
children 984e6aa17174
comparison
equal deleted inserted replaced
677:fd3492a767c7 748:b7376415fa5f
37 // static void set_rgbs(memaddr addr, uint32 *max_addr, int wait_tag); 37 // static void set_rgbs(memaddr addr, uint32 *max_addr, int wait_tag);
38 static uint32 get_rgb(int tx, int ty, TilePtr tile); 38 static uint32 get_rgb(int tx, int ty, TilePtr tile);
39 // static TilePtr isAvailableTile(memaddr addr); 39 // static TilePtr isAvailableTile(memaddr addr);
40 static memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top); 40 static memaddr getTile(int tx, int ty, int tw, memaddr tex_addr_top);
41 static int getTexBlock(int tx, int ty, int twidth); 41 static int getTexBlock(int tx, int ty, int twidth);
42 static void updateBuffer(Gptr g, float zpos, int rangex, int x, int y, 42
43 int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z, TilePtr tile); 43 static void updateBuffer(Gptr g, float zpos, int rangex, int loaclx, int localy,
44 44 int tex_x, int tex_y, float normal_x, float nomral_x, float normal_z,
45 TilePtr tile, int world_x, int world_y, float world_z,SchedTask *smanager);
45 46
46 // static void reboot(SpanPackPtr spack, int cur_span_x); 47 // static void reboot(SpanPackPtr spack, int cur_span_x);
47 48
48 static int drawDot1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag); 49 static int drawDot1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
49 //static void drawDot2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag); 50 //static void drawDot2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag);
50 static int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag); 51 static int drawLine1(SchedTask *smanager, Gptr g, SpanPtr span, int startx, int endx, int wait_tag);
51 // static void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag); 52 // static void drawLine2(SchedTask *smanager, SpanPtr span, int startx, int endx, int js, int wait_tag);
52 static int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z); 53
54 static int infinity_light_calc(int color,float normal_x, float normal_y, float normal_z,
55 SchedTask *smanager,int x, int y, float z, int world_x, int world_y, float world_z);
56
53 57
54 static float 58 static float
55 innerProduct1(float *v0, float *v1) 59 innerProduct1(float *v0, float *v1)
56 { 60 {
57 return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]); 61 return (v0[0]*v1[0] + v0[1]*v1[1] + v0[2]*v1[2]);
177 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標 181 * @param tex_x pixel が使用するテクスチャの、Tile (8x8) 内での x 座標
178 * @param tex_y 〃 の y 座標 182 * @param tex_y 〃 の y 座標
179 * @param tex_addr テクスチャのアドレス(MainMemory) 183 * @param tex_addr テクスチャのアドレス(MainMemory)
180 */ 184 */
181 static void 185 static void
182 updateBuffer(Gptr g, float zpos, int rangex, int x, int y, int tex_x, int tex_y, 186 updateBuffer(Gptr g, float zpos, int rangex, int localx, int localy, int tex_x, int tex_y,
183 float normal_x, float normal_y, float normal_z, TilePtr tile) 187 float normal_x, float normal_y, float normal_z, TilePtr tile,
188 int world_x, int world_y, float world_z, SchedTask *smanager)
184 { 189 {
185 190
186 int color = get_rgb(tex_x, tex_y, tile); 191 int color = get_rgb(tex_x, tex_y, tile);
187 /*下位4bitを抽出*/ 192 /*下位4bitを抽出*/
188 #if LITTLEENDIAN 193 #if LITTLEENDIAN
191 int alpha = color & 0xff000000; 196 int alpha = color & 0xff000000;
192 #endif 197 #endif
193 /*完全に透けているか判断*/ 198 /*完全に透けているか判断*/
194 int flag = (alpha != 0); 199 int flag = (alpha != 0);
195 200
196 color = infinity_light_calc(color,normal_x,normal_y,normal_z); 201 color = infinity_light_calc(color,normal_x,normal_y,normal_z,
197 202 smanager,localx,localy,zpos,
198 g->zRow[x + (rangex*y)] = zpos*flag + g->zRow[x + (rangex*y)]*(1-flag); 203 world_x,world_y,world_z);
199 int *point = &g->linebuf[y][x] ; 204
205 g->zRow[localx + (rangex*localy)] = zpos*flag + g->zRow[localx + (rangex*localy)]*(1-flag);
206 int *point = &g->linebuf[localy][localx] ;
200 *point = color*flag + *point *(1-flag); 207 *point = color*flag + *point *(1-flag);
208
209
201 210
202 } 211 }
203 212
204 /** 213 /**
205 * 長さが 1 の Span の描画 (要するに 1 pixel) 214 * 長さが 1 の Span の描画 (要するに 1 pixel)
256 TilePtr tile = smanager->get_segment(tex_addr,g->tileList); 265 TilePtr tile = smanager->get_segment(tex_addr,g->tileList);
257 smanager->wait_segment(tile); 266 smanager->wait_segment(tile);
258 267
259 updateBuffer(g, zpos, rangex, localx, localy, 268 updateBuffer(g, zpos, rangex, localx, localy,
260 tex_localx, tex_localy, 269 tex_localx, tex_localy,
261 normal_x,normal_y,normal_z,tile); 270 normal_x,normal_y,normal_z,tile,
271 span->x, span->y, zpos, smanager);
262 } 272 }
263 273
264 return -1; 274 return -1;
265 } 275 }
266 276
317 327
318 // span の始点、終点に対応する z 座標 328 // span の始点、終点に対応する z 座標
319 float zpos1 = span->start_z; 329 float zpos1 = span->start_z;
320 float zpos2 = span->end_z; 330 float zpos2 = span->end_z;
321 331
332 //spanを右から左に見ていくうちに、zが下がるのか、上がっていくのか。
333 float z_inclination = (zpos1 - zpos2) / x_len;
334 float world_z = zpos2;
335
322 // Tile 内での座標 336 // Tile 内での座標
323 int localx, localy = getLocalY(span->y-1); 337 int localx, localy = getLocalY(span->y-1);
324 338
325 int ret = je+1; 339 int ret = je+1;
326 340
327 //for (int j = js; j <= je; j++) { 341 //for (int j = js; j <= je; j++) {
328 for (int j = je; j >= js; j--) { 342 for (int j = je; j >= js; j--) {
329 float tex_x, tex_y, tex_z; 343 float tex_x, tex_y, tex_z;
344
345 world_z += z_inclination;
330 346
331 localx = getLocalX(x-1+j); 347 localx = getLocalX(x-1+j);
332 348
333 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1); 349 tex_z = zpos1*(x_len-1-j)/(x_len-1) + zpos2*j/(x_len-1);
334 350
355 TilePtr tile = smanager->get_segment(tex_addr,g->tileList); 371 TilePtr tile = smanager->get_segment(tex_addr,g->tileList);
356 smanager->wait_segment(tile); 372 smanager->wait_segment(tile);
357 373
358 updateBuffer(g, tex_z, rangex, localx, localy, 374 updateBuffer(g, tex_z, rangex, localx, localy,
359 tex_localx, tex_localy, 375 tex_localx, tex_localy,
360 normal_x, normal_y, normal_z, tile); 376 normal_x, normal_y, normal_z, tile,
377 span->x+j, span->y, world_z, smanager);
361 } 378 }
362 } 379 }
363 380
364 return ret; 381 return ret;
365 } 382 }
366 383
367 static int 384 static int
368 infinity_light_calc(int color,float normal_x, float normal_y, float normal_z) 385 infinity_light_calc(int color,float normal_x, float normal_y,
386 float normal_z, SchedTask *smanager, int x, int y, float z,
387 int world_x, int world_y, float world_z)
388
369 { 389 {
370 unsigned char rgb[4]; 390 unsigned char rgb[4];
371 int light_rgb; 391 int light_rgb;
372 int flag; 392 int flag;
373 float normal_vector[4] = {normal_x,normal_y,normal_z,0}; 393 float normal_vector[4] = {normal_x,normal_y,normal_z,0};
421 Span *span; 441 Span *span;
422 442
423 Span nop_span; 443 Span nop_span;
424 nop_span.length_x = 1; 444 nop_span.length_x = 1;
425 445
426 // uint32 display = smanager->get_param(0); 446 // uint32 display = (long)smanager->get_param(0);
427 // int screen_width = smanager->get_param(1); 447 // int screen_width = (long)smanager->get_param(1);
428 int rangex_start = (long)smanager->get_param(2); 448 int rangex_start = (long)smanager->get_param(2);
429 int rangex_end = (long)smanager->get_param(3); 449 int rangex_end = (long)smanager->get_param(3);
430 450
431 // このタスクが担当する x の範囲 451 // このタスクが担当する x の範囲
432 int rangex = rangex_end - rangex_start + 1; 452 int rangex = rangex_end - rangex_start + 1;
454 } else { 474 } else {
455 next_spack = NULL; 475 next_spack = NULL;
456 } 476 }
457 477
458 SpanPtr resume_span = &nop_span; 478 SpanPtr resume_span = &nop_span;
459 int resume_span_x = 0;
460 479
461 for (int t = 0; t < spack->info.size; t++) { 480 for (int t = 0; t < spack->info.size; t++) {
462 SpanPtr next_span; 481 SpanPtr next_span;
463 int next_span_x;
464 482
465 span = &spack->span[t]; 483 span = &spack->span[t];
466 484
467 if (span->length_x != 1) { 485 if (span->length_x != 1) {
468 drawLine1( 486 drawLine1(
474 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]); 492 span, rangex_start, rangex_end, tl_tag[tl_tag_flg1]);
475 } 493 }
476 next_span = span; 494 next_span = span;
477 495
478 resume_span = next_span; 496 resume_span = next_span;
479 resume_span_x = next_span_x;
480 497
481 tl_tag_flg1 ^= 1; 498 tl_tag_flg1 ^= 1;
482 tl_tag_flg2 ^= 1; 499 tl_tag_flg2 ^= 1;
483 } 500 }
484 501