Mercurial > hg > Game > Cerium
comparison TaskManager/Test/test_render/spe/DrawSpan.cpp @ 200:efd7e4712342 draft
fix run_draw
author | gongo@localhost.localdomain |
---|---|
date | Mon, 26 Jan 2009 14:27:45 +0900 |
parents | b56fb6ac2fc4 |
children | 1eba8570808c |
comparison
equal
deleted
inserted
replaced
199:1fd0107ebb25 | 200:efd7e4712342 |
---|---|
1 #include <stdlib.h> | 1 #include <stdlib.h> |
2 #include <string.h> | 2 #include <string.h> |
3 #include <spu_intrinsics.h> | |
3 #include "DrawSpan.h" | 4 #include "DrawSpan.h" |
4 #include "polygon_pack.h" | 5 #include "polygon_pack.h" |
5 #include "texture.h" | 6 #include "texture.h" |
6 #include "viewer_types.h" | 7 #include "viewer_types.h" |
7 #include "Func.h" | 8 #include "Func.h" |
113 DrawSpan::zRow_init(int width, int height) | 114 DrawSpan::zRow_init(int width, int height) |
114 { | 115 { |
115 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); | 116 float *buf = (float*)smanager->allocate(sizeof(float)*width*height); |
116 float def = 65535.0f; | 117 float def = 65535.0f; |
117 | 118 |
119 #if 1 | |
118 for (int i = 0; i < width*height; i++) { | 120 for (int i = 0; i < width*height; i++) { |
119 buf[i] = def; | 121 buf[i] = def; |
120 } | 122 } |
123 #else | |
124 vector float init = {0.0f, 0.0f, 0.0f, 0.0f}; | |
125 vector float defi = {def, def, def, def}; | |
126 | |
127 for (int i = 0; i < width*height; i += 4) { | |
128 vector float *out = (vector float *)&buf[i]; | |
129 | |
130 *out = spu_add(init, defi); | |
131 } | |
132 #endif | |
121 | 133 |
122 return buf; | 134 return buf; |
123 } | 135 } |
124 | 136 |
125 | 137 |
420 } | 432 } |
421 } | 433 } |
422 } | 434 } |
423 } | 435 } |
424 | 436 |
437 for (int t = 0; t < spack->info.size; t++) { | |
438 span = &spack->span[t]; | |
439 | |
440 uint32 rgb = 0x0000ff00; | |
441 float tex1 = span->tex_x1; | |
442 float tex2 = span->tex_x2; | |
443 float tey1 = span->tex_y1; | |
444 float tey2 = span->tex_y2; | |
445 | |
446 /** | |
447 * Span が持つ 1 pixel 毎の | |
448 * テクスチャの座標 | |
449 */ | |
450 int tex_xpos; | |
451 int tex_ypos; | |
452 | |
453 /** | |
454 * (tex_xpos, tex_ypos) の、ブロック内(上の図参照)での座標と | |
455 * そのブロックのアドレス(MainMemory) | |
456 */ | |
457 int tex_localx; | |
458 int tex_localy; | |
459 uint32 *tex_addr; | |
460 | |
461 int x = span->x; | |
462 int y = span->y; | |
463 int x_len = span->length_x; | |
464 float z = span->start_z; | |
465 float zpos = span->end_z; | |
466 | |
467 // 座標が [0 .. split_screen_w-1] に入るように x,y を -1 | |
468 int localx = getLocalX(x-1); | |
469 int localy = getLocalY(y-1); | |
470 | |
471 if (x_len == 1) { | |
472 if (x < rangex_start || rangex_end < x) { | |
473 continue; | |
474 } | |
475 | |
476 flag = 1; | |
477 tex_xpos = (int)((span->tex_width-1) * tex1); | |
478 tex_ypos = (int)((span->tex_height-1) * tey1); | |
479 | |
480 if (zpos < zRow[localx + (rangex*localy)]) { | |
481 tex_addr = getTile(tex_xpos, tex_ypos, | |
482 span->tex_width, span->tex_addr); | |
483 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
484 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
485 | |
486 if (!isAvailableTile(tex_addr)) { | |
487 # if defined(PROFILE) | |
488 printf("%d %u start load tile\n", | |
489 smanager->get_cpuid(), spu_read_decrementer()); | |
490 # endif | |
491 set_rgb(tex_addr); | |
492 smanager->dma_wait(TEX_LOAD); | |
493 # if defined(PROFILE) | |
494 printf("%d %u end load tile\n", | |
495 smanager->get_cpuid(), spu_read_decrementer()); | |
496 # endif | |
497 tileNum++; | |
498 } | |
499 | |
500 rgb = get_rgb(tex_localx, tex_localy, tex_addr); | |
501 | |
502 zRow[localx + (rangex*localy)] = zpos; | |
503 linebuf[localx + (rangex*localy)] = rgb; | |
504 } | |
505 } else { | |
506 int js = (x < rangex_start) ? rangex_start - x : 0; | |
507 int je = (x + x_len > rangex_end) ? rangex_end - x : x_len; | |
508 float tex_x, tex_y, tex_z; | |
509 | |
510 for (int j = js; j <= je; j++) { | |
511 flag = 1; | |
512 localx = getLocalX(x-1+j); | |
513 | |
514 tex_z = z*(x_len-1-j)/(x_len-1) + zpos*j/(x_len-1); | |
515 | |
516 tex_x = tex1*(x_len-1-j)/(x_len-1) + tex2*j/(x_len-1); | |
517 tex_y = tey1*(x_len-1-j)/(x_len-1) + tey2*j/(x_len-1); | |
518 if (tex_x > 1) tex_x = 1; | |
519 if (tex_x < 0) tex_x = 0; | |
520 if (tex_y > 1) tex_y = 1; | |
521 if (tex_y < 0) tex_y = 0; | |
522 tex_xpos = (int)((span->tex_width-1) * tex_x); | |
523 tex_ypos = (int)((span->tex_height-1) * tex_y); | |
524 | |
525 if (tex_z < zRow[localx + (rangex*localy)]) { | |
526 tex_addr = getTile(tex_xpos, tex_ypos, | |
527 span->tex_width, span->tex_addr); | |
528 tex_localx = tex_xpos % TEXTURE_SPLIT_PIXEL; | |
529 tex_localy = tex_ypos % TEXTURE_SPLIT_PIXEL; | |
530 | |
531 /** | |
532 * Tile が無い場合、一旦タスクはここで中断し、 | |
533 * Tile をロードするタスクを走らせた後に再起動する | |
534 */ | |
535 if (!isAvailableTile(tex_addr)) { | |
536 spack->info.start = t; | |
537 #if 0 | |
538 set_rgbs(tex_addr, | |
539 getTile(span->tex_width-1, tex_ypos, | |
540 span->tex_width, span->tex_addr)); | |
541 //smanager->dma_wait(TEX_LOAD); | |
542 reboot(spack, j); | |
543 goto FINISH; | |
544 #else | |
545 | |
546 # if defined(PROFILE) | |
547 printf("%d %u start load tile\n", | |
548 smanager->get_cpuid(), | |
549 spu_read_decrementer()); | |
550 # endif | |
551 | |
552 set_rgb(tex_addr); | |
553 smanager->dma_wait(TEX_LOAD); | |
554 tileNum++; | |
555 | |
556 # if defined(PROFILE) | |
557 printf("%d %u end load tile\n", | |
558 smanager->get_cpuid(), | |
559 spu_read_decrementer()); | |
560 # endif | |
561 #endif | |
562 } | |
563 | |
564 rgb = get_rgb(tex_localx, tex_localy, tex_addr); | |
565 | |
566 zRow[localx + (rangex*localy)] = tex_z; | |
567 linebuf[localx + (rangex*localy)] = rgb; | |
568 } | |
569 } | |
570 } | |
571 } | |
572 | |
573 | |
425 smanager->dma_wait(SPAN_PACK_LOAD); | 574 smanager->dma_wait(SPAN_PACK_LOAD); |
426 | 575 |
427 SpanPackPtr tmp_spack = spack; | 576 SpanPackPtr tmp_spack = spack; |
428 spack = next_spack; | 577 spack = next_spack; |
429 next_spack = tmp_spack; | 578 next_spack = tmp_spack; |