changeset 907:62838c1cd4b0

collect matrix..
author Yutaka_Kinjyo
date Tue, 20 Jul 2010 02:33:48 +0900
parents 348b48db317e
children 830bcfbde3bc
files Renderer/Engine/RenderingGlobal.h Renderer/Engine/viewer.cc Renderer/Engine/viewer.h
diffstat 3 files changed, 155 insertions(+), 111 deletions(-) [+]
line wrap: on
line diff
--- a/Renderer/Engine/RenderingGlobal.h	Mon Jul 19 23:40:53 2010 +0900
+++ b/Renderer/Engine/RenderingGlobal.h	Tue Jul 20 02:33:48 2010 +0900
@@ -4,3 +4,7 @@
   Light,
   LightSwitch,
   LightSysSwitch,
+
+/*spe_create_polygon 用*/
+
+  SG_COORD,
--- a/Renderer/Engine/viewer.cc	Mon Jul 19 23:40:53 2010 +0900
+++ b/Renderer/Engine/viewer.cc	Tue Jul 20 02:33:48 2010 +0900
@@ -39,6 +39,7 @@
 int spackList_length;
 int spackList_length_align;
 
+
 /**
  *
  */
@@ -118,6 +119,7 @@
       light_xyz[i] = 0.0f;
     }
 
+
     for(int i = 0; i < spe_num; i++) {
 
 	HTaskPtr data_load = manager->create_task(DataLoad);
@@ -462,125 +464,165 @@
 
 #endif
 
+struct MatrixList {
+
+  float *matrix;
+  MatrixList *next;
+   
+};
+
+struct MatrixListInfo {
+  int id;
+  MatrixList *first;
+  MatrixList *last;
+  MatrixListInfo *next;
+};
+
+
+void
+add_matrix_list(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) {
+
+    MatrixList *matrix_list = (MatrixList*)manager->allocate(sizeof(MatrixList));
+    matrix_list->matrix = sg->sg_matrix;
+    matrix_list->next = NULL;
+    
+    if (info->last != NULL) {
+        info->last->next = matrix_list;
+    }
+
+    info->last = matrix_list;
+
+}
+
+void
+new_matrix_info(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) {
+
+    MatrixListInfo *next = NULL;
+
+  if (info->id == -1) {
+
+    info->id = sg->sgid;
+    next = info;
+
+  } else {
+
+    MatrixListInfo* t;
+
+    for (t = info; t->next != NULL; t = t->next) {
+    }
+
+    next = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo));
+    next->id = sg->sgid;
+    next->next = NULL;
+    t->next = next;
+
+  }
+
+    MatrixList *new_list = (MatrixList*)manager->allocate(sizeof(MatrixList));
+    new_list->matrix = sg->sg_matrix;
+    new_list->next = NULL;
+
+    next->first = new_list;
+    next->last = new_list;
+
+}
+
+void
+collect_matrix(SceneGraphPtr sg, MatrixListInfo *matrix_info, TaskManager *manager) {
+  
+  matrix_info->id = -1;
+  matrix_info->next = NULL;
+  matrix_info->first = NULL;
+  matrix_info->last = NULL;
+
+  while (sg) {
+    
+    if (sg->flag_drawable) {
+      
+      int flag = 0;
+      
+      for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) {
+	if (sg->sgid == t->id) {
+	  add_matrix_list(sg, manager, t);
+	  flag = 1;
+	}	    	    	    
+      }
+      
+      if (flag != 1) {
+	new_matrix_info(sg, manager, matrix_info);  
+      }
+      
+      // search SceneGraph. でも、ただのリストがあったハズだから、あとでそれに直す。はず・・
+      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;
+	    }
+	  }
+	}
+      } 
+    } 
+  }
+}
+
+HTaskPtr
+create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next,
+	       MatrixListInfo *matrix_info)
+{
+
+  HTaskPtr create_pp_wait = manager->create_task(Dummy);
+  // どれくらい allocate するかわ、よくわからないけど。
+  // とりあえず、16k ぐらいにしておく。
+  int sg_size = 16*1024;
+  
+  for (int i = 0; i < spe_num; i++) {
+    
+    HTaskPtr data_load = manager->create_task(DataLoad);
+    data_load->set_param(0,(memaddr)sg_size);
+    data_load->set_param(1,(memaddr)SG_COORD);
+    task_next->wait_for(data_load);
+    data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i));
+    data_load->spawn();
+	  
+  }
+
+  float *cur_coord_pack = sg->coord_pack;
+  int coord_pack_size = sg->coord_pack_size;
+
+  collect_matrix(sg, matrix_info, manager);  
+
+  return create_pp_wait;
+
+}
+
 void
 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot)
 {
 
 #if SPE_CREATE_POLYGON
 
-  SceneGraphPtr sg = sgroot->getDrawSceneGraph();
-  PolygonPackPtr pp_cur = ppack;
-  HTaskPtr create_pp_wait = manager->create_task(Dummy);
-  int pp_index = 0;
 
-  pp_cur->init();
-
-  task_next->wait_for(create_pp_wait);
-
-  while (sg) {
-    
-    if (sg->flag_drawable) {
-
-      int sum_size = sg->size;
-      int tri_cur_num = MAX_SIZE_TRIANGLE;
-      int sg_index = 0;
-
-      while (sum_size) {
-	
-	  tri_cur_num -= sg->size/3;
-	
-	  if (tri_cur_num < 0) {
-	    
-	      tri_cur_num = MAX_SIZE_TRIANGLE;
-	      create_pp_task(sg, pp_cur, create_pp_wait,
-			     pp_index, sg_index, tri_cur_num);
-	     
-	      PolygonPackPtr next = (PolygonPackPtr)manager->allocate(sizeof(PolygonPack));
-	      next->init();
-
-	      pp_cur->next = next;
-	      pp_cur       = next;
-	      pp_index = 0;
-	      
-	  } else {
-	  
-	      create_pp_task(sg, pp_cur, create_pp_wait,
-			     pp_index, sg_index, tri_cur_num);
-
-	  }
-
-	  sum_size -= tri_cur_num*3;
-
-      }
-      
-      
-    }
-    
-    
-    
-    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;
-	  }
-	}
-      }
-    } 
-  }
-  
-
-  int  range_base = spe_num;
-  
-    // 切り上げのつもり
-  int range = (spackList_length + range_base - 1) / range_base;
-  
-  for (int i = 0; i < range_base; i++) {
-    int index_start = range*i;
-    int index_end = (index_start + range >= spackList_length)
-      ? spackList_length : index_start + range;
-    
-    HTaskPtr task_create_sp = manager->create_task(CreateSpan);
-    
-    task_create_sp->set_param(0,index_start);
-    
-    /**
-     * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲
-     *   [  1.. 80] [ 81..160] [161..240]
-     *   [241..320] [321..400] [401..480]
-     *
-     * ex. screen_height が 1080, spenum が 5 の場合、
-     *   [  1..216] [217..432] [433..648]
-     *   [649..864] [865..1080]
-     */
-    
-    task_create_sp->set_param(1,index_start*split_screen_h + 1);
-    task_create_sp->set_param(2,index_end*split_screen_h);
-    
-    task_create_sp->add_inData(ppack, sizeof(PolygonPack));
-    task_create_sp->add_inData(spackList_ptr,
-			       sizeof(SpanPack*)*spackList_length_align);
-    task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack));
-    
-    task_next->wait_for(task_create_sp);
-    task_create_sp->wait_for(create_pp_wait);
-    
-    task_create_sp->set_cpu(SPE_ANY);
-    task_create_sp->spawn();
-  }
   
 #else
 
+    SceneGraphPtr sg = sgroot->getDrawSceneGraph();
+
+    MatrixListInfo *matrix_info = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo));
+    create_pp_task(sg, manager, spe_num, task_next, matrix_info);
+
+
+    
     HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph);
     
     // SceneGraph(木構造) -> PolygonPack
--- a/Renderer/Engine/viewer.h	Mon Jul 19 23:40:53 2010 +0900
+++ b/Renderer/Engine/viewer.h	Tue Jul 20 02:33:48 2010 +0900
@@ -69,8 +69,6 @@
     void run_collision();
     void rendering(HTaskPtr task_next);
     void common_draw(HTaskPtr task_next);
-    void create_pp_task(SceneGraphPtr sg, PolygonPackPtr pp_cur, HTaskPtr create_pp_wait,
-			int &pp_index, int &sg_index, int tri_num);
     void common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot);
 
     void spe_rendering(HTaskPtr task_next);