Mercurial > hg > Members > kono > Cerium
comparison Renderer/Engine/viewer.cc @ 1034:a0faa0cfc271
merge.
author | koba <koba@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 26 Nov 2010 04:35:34 +0900 |
parents | 431936c0cc96 3191cae6f7a2 |
children | ff0e6d00c060 |
comparison
equal
deleted
inserted
replaced
1033:431936c0cc96 | 1034:a0faa0cfc271 |
---|---|
627 | 627 |
628 } | 628 } |
629 | 629 |
630 } | 630 } |
631 | 631 |
632 void | 632 /* flag_drawable な Scenegraph の総数を求める */ |
633 create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next) | 633 int |
634 { | 634 sg_drawable_num(SceneGraphPtr scenegraph) |
635 | 635 { |
636 MatrixListInfo *matrix_info = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo)); | 636 SceneGraphPtr sg = scenegraph; |
637 collect_matrix(sg, matrix_info, manager); | 637 |
638 | 638 int sg_count = 0; |
639 | 639 while (sg) { |
640 //HTaskPtr phase_wait = manager->create_task(Dummy); | 640 if (sg->flag_drawable) { |
641 | 641 sg_count++; |
642 for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) { | 642 } |
643 | 643 if (sg->children != NULL) { |
644 printf("list_length %d \n", t->list_length); | 644 sg = sg->children; |
645 | 645 } else if (sg->brother != NULL) { |
646 int alloc_size = 16*1024; | 646 sg = sg->brother; |
647 | 647 } else { |
648 if (t->coord_pack_size < alloc_size) { | 648 while (sg) { |
649 alloc_size = t->coord_pack_size; | 649 if (sg->brother != NULL) { |
650 } | 650 sg = sg->brother; |
651 | 651 break; |
652 | 652 } else { |
653 int division_num = (t->coord_pack_size + alloc_size - 1) / alloc_size; | 653 if (sg->parent == NULL) { |
654 int phase_num = (division_num + spe_num -1) / spe_num; | 654 sg = NULL; |
655 int cur_point = 0; | 655 break; |
656 | 656 } else { |
657 for (int i = 0; i < phase_num; i++) { | 657 sg = sg->parent; |
658 } | |
659 } | |
660 } | |
661 } | |
662 } | |
663 return sg_count; | |
664 } | |
665 | |
666 void | |
667 create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next, SceneGraphRootPtr sgroot) | |
668 { | |
669 | |
670 /* | |
671 * SceneGraph を辿って coord_xyz, coord_tex, normal, matrix, real_matrix 及び、 | |
672 * PolygonPack の TrianglePack (空) を送る。pp->info.size の計算もここで。 | |
673 * | |
674 */ | |
675 | |
676 int sg_num = sg_drawable_num(sg); | |
677 int sg_division = sg_num / spe_num; | |
678 int residue = sg_num % spe_num; | |
679 | |
680 HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num); | |
681 Task **pptask = (Task**)manager->allocate(sizeof(Task*)*spe_num); | |
682 | |
683 for (int k = 0; k < spe_num-1; k++) { | |
684 task_array[k] = manager->create_task_array(CreatePolygonFromSceneGraph,sg_division,4,6,1); | |
685 pptask[k] = 0; | |
686 } | |
687 | |
688 task_array[spe_num] = manager->create_task_array(CreatePolygonFromSceneGraph, | |
689 sg_division+residue,4,6,1); | |
690 pptask[spe_num] = 0; | |
691 | |
692 int k = 0; | |
693 | |
694 while (sg) { | |
695 if (sg->flag_drawable) { | |
696 if(k < spe_num * sg_division) { | |
697 k %= spe_num-1; | |
698 } else { | |
699 k = spe_num; | |
700 } | |
701 pptask[k] = task_array[k]->next_task_array(CreatePolygonFromSceneGraph,pptask[k]); | |
702 pptask[k]->set_inData(0, &sg->coord_xyz, sizeof(float)*sg->size/3); | |
703 pptask[k]->set_inData(1, &sg->coord_tex, sizeof(float)*sg->size/3); | |
704 pptask[k]->set_inData(2, &sg->normal , sizeof(float)*sg->size/3); | |
705 pptask[k]->set_inData(3, &sg->matrix , sizeof(float)*12); | |
706 pptask[k]->set_inData(4, &sg->real_matrix, sizeof(float)*8); | |
707 pptask[k]->set_inData(5, &sg->texture_info.pixels, sizeof(uint32)); | |
708 | |
709 pptask[k]->set_param(0,(memaddr)sg->size); | |
710 pptask[k]->set_param(1,(memaddr)sg->texture_info.t_w); | |
711 pptask[k]->set_param(2,(memaddr)sg->texture_info.t_h); | |
712 pptask[k]->set_param(3,(memaddr)sg->texture_info.scale_max); | |
658 | 713 |
659 HTaskPtr alloc_wait = manager->create_task(Dummy); | 714 } |
660 coord_allocate(cur_point, t->coord_pack, spe_num, | 715 if (sg->children != NULL) { |
661 alloc_size, alloc_wait, manager); | 716 sg = sg->children; |
662 | 717 } else if (sg->brother != NULL) { |
663 | 718 sg = sg->brother; |
664 for (MatrixList* u = t->first; u != NULL; u = u->next) { | 719 } else { |
665 | 720 while (sg) { |
666 //HTaskPtr free_wait = manager->create_task(Dummy); | 721 if (sg->brother != NULL) { |
667 | 722 sg = sg->brother; |
668 //phase_wait = manager->create_task(Dummy); | 723 break; |
669 | 724 } else { |
725 if (sg->parent == NULL) { | |
726 sg = NULL; | |
727 break; | |
728 } else { | |
729 sg = sg->parent; | |
730 } | |
731 } | |
670 } | 732 } |
671 | 733 } |
672 coord_free(spe_num, manager, alloc_wait); | 734 k++; |
673 alloc_wait->spawn(); | |
674 } | |
675 } | 735 } |
676 | 736 for (int k = 0; k < spe_num; k++) { |
677 printf("-----------------------\n"); | 737 task_array[k]->spawn_task_array(pptask[k]->next()); |
678 //return create_pp_wait; | 738 task_array[k]->set_cpu(SPE_ANY); |
679 | 739 task_array[k]->spawn(); |
740 if (sgroot->gtask_array != NULL) { | |
741 HTaskPtr game_task_array = sgroot->gtask_array->get_task_array(); | |
742 task_array[k]->wait_for(game_task_array); | |
743 } | |
744 task_next->wait_for(task_array[k]); | |
745 } | |
680 } | 746 } |
681 | 747 |
682 void | 748 void |
683 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) | 749 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) |
684 { | 750 { |
685 | 751 |
686 #if SPE_CREATE_POLYGON | 752 #if SPE_CREATE_POLYGON |
687 | 753 |
688 SceneGraphPtr sg = sgroot->getDrawSceneGraph(); | 754 SceneGraphPtr sg = sgroot->getDrawSceneGraph(); |
689 | 755 |
690 create_pp_task(sg, manager, spe_num, task_next); | 756 create_pp_task(sg, manager, spe_num, task_next, sgroot); |
691 | 757 |
692 #if SPE_CREATE_POLYGON_CHECK | 758 #if SPE_CREATE_POLYGON_CHECK |
693 check_matrix(matrix_info,sg); | 759 check_matrix(matrix_info,sg); |
694 #endif | 760 #endif |
695 | 761 |
696 | 762 |
697 | 763 |
698 #else | 764 #else |
699 | 765 //SceneGraphPtr sg = sgroot->getDrawSceneGraph(); |
766 //printf("sg->size = %lld\n", sg->size); | |
700 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); | 767 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); |
701 // SceneGraph(木構造) -> PolygonPack | 768 // SceneGraph(木構造) -> PolygonPack |
702 | 769 |
703 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); | 770 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); |
704 task_create_pp->set_param(1,(memaddr)r[ppi].ppack); | 771 task_create_pp->set_param(1,(memaddr)r[ppi].ppack); |
706 /* GameTask の処理の終了を待ってからポリゴンを作る */ | 773 /* GameTask の処理の終了を待ってからポリゴンを作る */ |
707 if (sgroot->gtask_array != NULL) { | 774 if (sgroot->gtask_array != NULL) { |
708 HTaskPtr game_task_array = sgroot->gtask_array->get_task_array(); | 775 HTaskPtr game_task_array = sgroot->gtask_array->get_task_array(); |
709 task_create_pp->wait_for(game_task_array); | 776 task_create_pp->wait_for(game_task_array); |
710 } | 777 } |
711 | |
712 task_next->wait_for(task_create_pp); | 778 task_next->wait_for(task_create_pp); |
713 | 779 |
714 #endif | 780 #endif |
715 | 781 |
716 int range_base = spe_num; | 782 int range_base = spe_num; |