diff 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
line wrap: on
line diff
--- a/Renderer/Engine/viewer.cc	Fri Nov 26 04:32:59 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Fri Nov 26 04:35:34 2010 +0900
@@ -629,54 +629,120 @@
 
 }
 
+/* flag_drawable な Scenegraph の総数を求める */
+int
+sg_drawable_num(SceneGraphPtr scenegraph)
+{
+  SceneGraphPtr sg = scenegraph;
+
+  int sg_count = 0;
+  while (sg) {
+    if (sg->flag_drawable) {
+      sg_count++;
+    }
+    if (sg->children != NULL) {
+      sg = sg->children;
+    } else if (sg->brother != NULL) {
+      sg = sg->brother;
+    } else {
+      while (sg) {
+	if (sg->brother != NULL) {
+	  sg = sg->brother;
+	  break;
+	} else {
+	  if (sg->parent == NULL) {
+	    sg = NULL;
+	    break;
+	  } else {
+	    sg = sg->parent;
+	  }
+	}
+      }
+    }  
+  }
+  return sg_count;
+}
+
 void
-create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next)
+create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next, SceneGraphRootPtr sgroot)
 {
 
-  MatrixListInfo *matrix_info = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo));
-  collect_matrix(sg, matrix_info, manager);
-
+  /*
+   * SceneGraph を辿って coord_xyz, coord_tex, normal, matrix, real_matrix 及び、
+   * PolygonPack の TrianglePack (空) を送る。pp->info.size の計算もここで。
+   * 
+   */
 
-  //HTaskPtr phase_wait = manager->create_task(Dummy);
-
-  for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) {
-
-    printf("list_length %d \n", t->list_length);
+  int sg_num = sg_drawable_num(sg);
+  int sg_division = sg_num / spe_num;
+  int residue = sg_num % spe_num;
 
-    int alloc_size = 16*1024;
+  HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num);
+  Task **pptask = (Task**)manager->allocate(sizeof(Task*)*spe_num);
+  
+  for (int k = 0; k < spe_num-1; k++) {
+    task_array[k] = manager->create_task_array(CreatePolygonFromSceneGraph,sg_division,4,6,1);
+    pptask[k] = 0;
+  }
+  
+  task_array[spe_num] = manager->create_task_array(CreatePolygonFromSceneGraph,
+						   sg_division+residue,4,6,1);
+  pptask[spe_num] = 0;
 
-    if (t->coord_pack_size < alloc_size) {
-      alloc_size = t->coord_pack_size;
-    }
-
-
-    int division_num = (t->coord_pack_size + alloc_size - 1) / alloc_size;
-    int phase_num = (division_num + spe_num -1) / spe_num;
-    int cur_point = 0;
+  int k = 0;
 
-    for (int i = 0; i < phase_num; i++) {
-      
-      HTaskPtr alloc_wait = manager->create_task(Dummy);
-      coord_allocate(cur_point, t->coord_pack, spe_num,
-		     alloc_size, alloc_wait, manager);
-
-
-      for (MatrixList* u = t->first; u != NULL; u = u->next) {
-
-	//HTaskPtr free_wait = manager->create_task(Dummy);
+  while (sg) {
+    if (sg->flag_drawable) {
+      if(k < spe_num * sg_division) {
+	k %= spe_num-1;
+      } else {
+	k = spe_num;
+      }
+      pptask[k] = task_array[k]->next_task_array(CreatePolygonFromSceneGraph,pptask[k]);
+      pptask[k]->set_inData(0, &sg->coord_xyz, sizeof(float)*sg->size/3);
+      pptask[k]->set_inData(1, &sg->coord_tex, sizeof(float)*sg->size/3);
+      pptask[k]->set_inData(2, &sg->normal   , sizeof(float)*sg->size/3);
+      pptask[k]->set_inData(3, &sg->matrix   , sizeof(float)*12);
+      pptask[k]->set_inData(4, &sg->real_matrix, sizeof(float)*8);
+      pptask[k]->set_inData(5, &sg->texture_info.pixels, sizeof(uint32));
 	
-	//phase_wait = manager->create_task(Dummy);
-	
+      pptask[k]->set_param(0,(memaddr)sg->size);
+      pptask[k]->set_param(1,(memaddr)sg->texture_info.t_w);
+      pptask[k]->set_param(2,(memaddr)sg->texture_info.t_h);
+      pptask[k]->set_param(3,(memaddr)sg->texture_info.scale_max);
+      
+    }
+    if (sg->children != NULL) {
+      sg = sg->children;
+    } else if (sg->brother != NULL) {
+      sg = sg->brother;
+    } else {
+      while (sg) {
+	if (sg->brother != NULL) {
+	  sg = sg->brother;
+	  break;
+	} else {
+	  if (sg->parent == NULL) {
+	    sg = NULL;
+	    break;
+	  } else {
+	    sg = sg->parent;
+	  }
+	}
       }
-
-      coord_free(spe_num, manager, alloc_wait);
-      alloc_wait->spawn();
     }
+    k++;
   }
-
-  printf("-----------------------\n");
-  //return create_pp_wait;
-
+  for (int k = 0; k < spe_num; k++) {
+    task_array[k]->spawn_task_array(pptask[k]->next());
+    task_array[k]->set_cpu(SPE_ANY);
+    task_array[k]->spawn();
+    if (sgroot->gtask_array != NULL) {
+      HTaskPtr game_task_array = sgroot->gtask_array->get_task_array();
+      task_array[k]->wait_for(game_task_array);
+    }
+    task_next->wait_for(task_array[k]);	
+  }
 }
 
 void
@@ -687,7 +753,7 @@
 
     SceneGraphPtr sg = sgroot->getDrawSceneGraph();
 
-    create_pp_task(sg, manager, spe_num, task_next);
+    create_pp_task(sg, manager, spe_num, task_next, sgroot);
 
 #if SPE_CREATE_POLYGON_CHECK
     check_matrix(matrix_info,sg);
@@ -696,7 +762,8 @@
 
   
 #else
-    
+    //SceneGraphPtr sg = sgroot->getDrawSceneGraph();
+    //printf("sg->size = %lld\n", sg->size);
     HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph);
     // SceneGraph(木構造) -> PolygonPack
 
@@ -708,7 +775,6 @@
 	HTaskPtr game_task_array = sgroot->gtask_array->get_task_array();
 	task_create_pp->wait_for(game_task_array);
     }
-
     task_next->wait_for(task_create_pp);
 
 #endif