Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/viewer.cc @ 1020:360f8eba78f1
create_pp_task fix. not done.
author | tkaito |
---|---|
date | Sun, 07 Nov 2010 04:24:24 +0900 |
parents | 736a833db108 |
children | 55f3c5976959 |
rev | line source |
---|---|
507 | 1 #include <SDL.h> |
2 #include "viewer.h" | |
3 #include "viewer_types.h" | |
4 #include "SceneGraph.h" | |
5 #include "SceneGraphRoot.h" | |
6 #include "scene_graph_pack.h" | |
7 #include "sys.h" | |
8 #include "Func.h" | |
9 #include "error.h" | |
10 #include "TaskManager.h" | |
11 #include <wchar.h> | |
12 #include "Pad.h" | |
511 | 13 #include "Application.h" |
575
0f13810d4492
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
14 #include "lindaapi.h" |
507 | 15 |
523 | 16 static void post2runLoop(SchedTask *s,void *viewer,void *s1); |
17 static void post2runDraw(SchedTask *s,void *viewer,void *s1); | |
18 static void post2speRendering(SchedTask *s,void *viewer,void *s1); | |
19 static void post2speDraw(SchedTask *s,void *viewer,void *s1); | |
20 static void post2runMoveDrawLoop(SchedTask *s,void *viewer,void *s1); | |
507 | 21 |
22 /* measure for FPS (Frame Per Second) */ | |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
23 static int start_time; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
24 static int this_time; |
507 | 25 int frames; |
514 | 26 // static void post2speRunLoop(void *viewer); |
27 //static void post2runMove(void *viewer); | |
28 //static void post2exchange_sgroot(void *viewer); | |
29 //static void post2speRunLoop(void *viewer); | |
507 | 30 |
31 //SceneGraphRootPtr sgroot_2; | |
32 | |
33 /* Data Pack sent to Other CPUs (ex. SPE) */ | |
34 | |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
35 RederingData r[2]; |
507 | 36 |
994 | 37 int ppi, spi = 0; |
907 | 38 |
507 | 39 /** |
40 * | |
41 */ | |
42 | |
748 | 43 Viewer::Viewer(TaskManager *m, ViewerDevice *vd, int b, int w, int h, int _num) |
507 | 44 { |
45 spe_num = _num; | |
748 | 46 manager = m; |
895
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
47 |
748 | 48 dev = vd; |
49 pixels = dev->video_init(manager, b, w, h); | |
50 | |
895
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
51 width = dev->width; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
52 height = dev->height; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
53 bpp = dev->bpp; |
bed529c55eda
add alignment of classes in SPU
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
891
diff
changeset
|
54 |
507 | 55 } |
56 | |
57 int | |
58 Viewer::get_ticks(void) | |
59 { | |
60 int time; | |
61 time = SDL_GetTicks(); | |
62 return time; | |
63 } | |
64 | |
65 bool | |
66 Viewer::quit_check(void) | |
67 { | |
68 SDL_Event event; | |
69 | |
70 while(SDL_PollEvent(&event)) { | |
71 if (event.type==SDL_QUIT) { | |
72 return true; | |
73 } | |
74 } | |
75 | |
76 Uint8 *keys=SDL_GetKeyState(NULL); | |
77 | |
78 if (keys[SDLK_q] == SDL_PRESSED) { | |
79 return true; | |
80 } | |
81 | |
82 return false; | |
83 } | |
84 | |
85 void | |
86 Viewer::quit(void) | |
87 { | |
88 SDL_Quit(); | |
89 } | |
90 | |
91 | |
92 void | |
509
8148c81d2660
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
93 Viewer::run_init(TaskManager *manager, Application *app) |
507 | 94 { |
95 this->manager = manager; | |
96 | |
748 | 97 if (spe_num == 0) spe_num = 1; |
98 | |
507 | 99 sgroot = new SceneGraphRoot(this->width, this->height); |
572 | 100 sgroot->tmanager = manager; |
792 | 101 |
102 int light_num = 4; | |
103 int size = sizeof(float)*4*light_num; //xyz+alfa(4) * light_num(4) | |
762 | 104 int light_size = size / sizeof(float); |
748 | 105 |
760
24a37fe8419a
first of all commit, not work Rendering/Test/create_task
hiroki
parents:
748
diff
changeset
|
106 light_xyz_stock = (float *)manager->allocate(size); |
748 | 107 light_xyz = (float *)manager->allocate(size); |
762 | 108 |
109 for (int i = 0; i < light_size ; i++) { | |
110 light_xyz[i] = 0.0f; | |
111 } | |
748 | 112 |
907 | 113 |
792 | 114 for(int i = 0; i < spe_num; i++) { |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
115 HTaskPtr data_load = manager->create_task(DataAllocate); |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
116 data_load->set_param(0,(memaddr)3); // num of allocate block |
988 | 117 data_load->set_param(1,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size |
118 data_load->set_param(2,(memaddr)Light); // 1st id | |
119 data_load->set_param(3,(memaddr)(light_num * sizeof(int))); // 2nd size | |
120 data_load->set_param(4,(memaddr)LightSwitch); // 2nd id | |
121 data_load->set_param(5,(memaddr)16); // 3rd size | |
122 data_load->set_param(6,(memaddr)LightSysSwitch); // 3rd id | |
748 | 123 data_load->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
124 data_load->spawn(); | |
125 } | |
509
8148c81d2660
Cerium Rendering Library
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
507
diff
changeset
|
126 |
792 | 127 light_switch = (int*)manager->allocate(size); |
793 | 128 |
792 | 129 for (int i = 0; i < light_num; i++) { |
130 light_switch[i] = 0; | |
131 } | |
132 | |
133 size = 16; // LightSysSwitch は 4byte. 残り 12byte は DMA転送の為のパディング | |
134 | |
793 | 135 light_sysswitch = (int*)manager->allocate(size); |
136 | |
843
0c7d885f0c92
cleanup unused variables and fix warning.
kazz <kazz@cr.ie.u-ryukyu.ac.jp>
parents:
842
diff
changeset
|
137 for (unsigned int i = 0; i < size / sizeof(int); i++) { |
793 | 138 light_sysswitch[i] = 0; |
139 } | |
140 | |
984 | 141 start_time = get_ticks(); |
142 this_time = 0; | |
143 frames = 0; | |
144 | |
511 | 145 MainLoop *mainloop = app->init(this, this->width, this->height); |
146 mainloop->mainLoop(); | |
507 | 147 } |
148 | |
149 | |
150 HTaskPtr | |
151 Viewer::initLoop() | |
152 { | |
153 HTaskPtr task_next; | |
154 HTaskPtr task_tex; | |
155 | |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
156 for(int i=0;i<2;i++) { |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
157 r[i].ppack = (PolygonPack*)manager->allocate(sizeof(PolygonPack)); |
989 | 158 r[i].ppack->next = 0; |
507 | 159 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
160 r[i].spackList_length = (this->height + split_screen_h - 1) / split_screen_h; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
161 r[i].spackList = (SpanPack*)manager->allocate(sizeof(SpanPack)*r[i].spackList_length); |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
162 // printf("spackList %0lx height %d\n",(unsigned long)r[i].spackList, this->height); |
507 | 163 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
164 /** |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
165 * SPU に送る address list は 16 バイト倍数でないといけない。 |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
166 * spackList_length*sizeof(SpanPack*) が 16 バイト倍数になるような |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
167 * length_align を求めている。はみ出した部分は使われない |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
168 * (ex) spackList_length が 13 の場合 |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
169 * spackList_length_align = 16; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
170 * 実際に送るデータは64バイトになるのでOK |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
171 * 14,15,16 の部分は何も入らない。 |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
172 */ |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
173 r[i].spackList_length_align = (r[i].spackList_length + 3)&(~3); |
507 | 174 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
175 /* 各 SPU が持つ、SpanPack の address list */ |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
176 r[i].spackList_ptr = |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
177 (SpanPack**)manager->allocate(sizeof(SpanPack*)*r[i].spackList_length_align); |
507 | 178 |
988 | 179 for (int j = 0; j < r[i].spackList_length; j++) { |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
180 r[i].spackList_ptr[j] = &r[i].spackList[j]; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
181 } |
507 | 182 |
988 | 183 for (int j = 1; j <= r[i].spackList_length; j++) { |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
184 r[i].spackList[j-1].init(j*split_screen_h); |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
185 } |
507 | 186 } |
187 | |
826 | 188 task_next = manager->create_task(Dummy,0,0,0,0); |
507 | 189 |
652 | 190 // ここは、Iterator を用意するべきだよね |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
191 for (int j = 0; j < spe_num; j++) { |
826 | 192 task_tex = manager->create_task(LoadTexture,0,0,0,0); |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
193 task_tex->set_cpu((CPU_TYPE)((int)SPE_0 + j)); |
826 | 194 task_next->wait_for(task_tex); |
748 | 195 task_tex->spawn(); |
507 | 196 } |
197 | |
792 | 198 |
507 | 199 return task_next; |
200 } | |
201 | |
202 | |
203 void | |
204 Viewer::getKey() | |
205 { | |
206 Pad *pad = sgroot->getController(); | |
207 if (pad->right.isHold()) { | |
208 keyPtr->right = HOLD; | |
209 } else if (pad->right.isPush()) { | |
210 keyPtr->right = PUSH; | |
211 } else { | |
212 keyPtr->right = NONE; | |
213 } | |
214 | |
215 if (pad->left.isHold()) { | |
216 keyPtr->left = HOLD; | |
217 } else if (pad->left.isPush()) { | |
218 keyPtr->left = PUSH; | |
219 } else { | |
220 keyPtr->left = NONE; | |
221 } | |
222 | |
223 if (pad->up.isHold()) { | |
224 keyPtr->up = HOLD; | |
225 } else if (pad->up.isPush()) { | |
226 keyPtr->up = PUSH; | |
227 } else { | |
228 keyPtr->up = NONE; | |
229 } | |
230 | |
231 if (pad->down.isHold()) { | |
232 keyPtr->down = HOLD; | |
233 } else if (pad->down.isPush()) { | |
234 keyPtr->down = PUSH; | |
235 } else { | |
236 keyPtr->down = NONE; | |
237 } | |
238 | |
239 if (pad->circle.isHold()) { | |
240 keyPtr->circle = HOLD; | |
241 } else if (pad->circle.isPush()) { | |
242 keyPtr->circle = PUSH; | |
243 } else { | |
244 keyPtr->circle = NONE; | |
245 } | |
246 } | |
247 | |
248 static void | |
514 | 249 post2runMoveDrawLoop(SchedTask *m, void *viewer_, void *arg) |
507 | 250 { |
251 Viewer *viewer = (Viewer*)viewer_; | |
252 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
253 // 同じ PPE 上なので sgroot(ポインタ) を set_param で送る。 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
254 //HTaskPtr send_key_task = viewer->manager->create_task(SendKey); |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
255 //send_key_task->set_param((int)sgroot); |
507 | 256 // set input data -> viewer keyPtr |
257 viewer->getKey(); | |
826 | 258 //HTaskPtr update_key = viewer->manager->create_task(UpdateKey,viewer->keyPtr, sizeof(key_stat),0,0); |
259 HTaskPtr update_key = viewer->manager->create_task(UpdateKey,0,0,0,0); | |
507 | 260 update_key->add_inData(viewer->keyPtr, sizeof(key_stat)); |
748 | 261 //update_key->set_cpu(SPE_0); |
507 | 262 update_key->spawn(); |
263 | |
264 /* TASK_MOVE は外から引数で取ってくるべき */ | |
265 //HTaskPtr move_task = viewer->manager->create_task(viewer->app->move_taskid); | |
965
1089f24bc86a
removing user task from Renderer Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
926
diff
changeset
|
266 // HTaskPtr move_task = viewer->manager->create_task(Move,0,0,0,0); |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
267 //move_task->set_param(sgroot); |
507 | 268 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
269 //HTaskPtr draw_task = viewer->manager->create_task(Draw); |
507 | 270 |
271 /* rendering task test */ | |
826 | 272 HTaskPtr draw_task = viewer->manager->create_task(Dummy,0,0,0,0); |
273 HTaskPtr draw_dummy = viewer->manager->create_task(Dummy,0,0,0,0); | |
507 | 274 |
826 | 275 HTaskPtr switch_task = viewer->manager->create_task(Switch,0,0,0,0); |
507 | 276 viewer->draw_dummy = draw_dummy; |
277 switch_task->wait_for(draw_dummy); | |
514 | 278 draw_task->set_post(post2speRendering, (void*)viewer, 0); |
507 | 279 |
965
1089f24bc86a
removing user task from Renderer Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
926
diff
changeset
|
280 // switch_task->wait_for(move_task); |
507 | 281 switch_task->wait_for(draw_task); |
965
1089f24bc86a
removing user task from Renderer Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
926
diff
changeset
|
282 // move_task->spawn(); |
507 | 283 draw_task->spawn(); |
284 | |
514 | 285 switch_task->set_post(post2runMoveDrawLoop, (void*)viewer, 0); |
507 | 286 switch_task->spawn(); |
287 | |
288 } | |
289 | |
290 void | |
291 Viewer::mainLoop() | |
292 { | |
293 HTaskPtr task_next = initLoop(); | |
294 | |
994 | 295 task_next->set_post(&post2runLoop, (void *)this, (void*)pixels); // set_post(function(this->run_loop()), NULL) |
507 | 296 task_next->spawn(); |
297 } | |
298 | |
299 void | |
748 | 300 Viewer::run_loop(HTaskPtr task_next) |
507 | 301 { |
748 | 302 dev->clear_screen(); |
303 | |
304 bool quit_flg; | |
305 quit_flg = quit_check(); | |
306 if (quit_flg == true) { | |
307 this_time = get_ticks(); | |
308 run_finish(); | |
309 return; | |
310 } | |
311 | |
312 dev->clean_pixels(); | |
994 | 313 |
981
a193a851b5e3
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
969
diff
changeset
|
314 pixels = dev->flip_screen(pixels); |
748 | 315 |
316 sgroot->updateControllerState(); | |
1003
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
317 |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
318 //TaskArray を使うか使わないか |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
319 if (sgroot->gtask_array != NULL) { |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
320 sgroot->create_task_array(); |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
321 sgroot->allExecute(width, height); |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
322 sgroot->task_array_finish(); |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
323 } else { |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
324 sgroot->allExecute(width, height); |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
325 } |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
326 |
748 | 327 light_xyz_stock = sgroot->getLightVector(); |
792 | 328 light_switch_stock = sgroot->getLightSwitch(); |
793 | 329 light_sysswitch_stock = sgroot->getLightSysSwitch(); |
748 | 330 //sgroot->checkRemove(); |
331 | |
332 // ここから下は Rendering という関数にする | |
333 rendering(task_next); | |
507 | 334 } |
335 | |
336 | |
337 | |
338 void | |
339 Viewer::run_collision() | |
340 { | |
341 } | |
342 | |
343 void | |
514 | 344 post2rendering(SchedTask *s, void *viewer_, void *arg) |
507 | 345 { |
346 Viewer *viewer = (Viewer *)viewer_; | |
826 | 347 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 348 viewer->rendering(task_next); |
349 } | |
350 | |
351 void | |
352 Viewer::rendering(HTaskPtr task_next) | |
353 { | |
748 | 354 common_rendering(task_next, sgroot); |
507 | 355 |
356 // Barrier 同期 | |
357 // run_draw() を呼ぶ post2runDraw | |
514 | 358 task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL) |
507 | 359 task_next->spawn(); |
360 | |
361 // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ | |
362 } | |
363 | |
364 static void | |
514 | 365 post2runLoop(SchedTask *s, void *viewer_, void *arg) |
507 | 366 { |
994 | 367 |
368 | |
507 | 369 Viewer *viewer = (Viewer*)viewer_; |
826 | 370 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 371 viewer->run_loop(task_next); |
575
0f13810d4492
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
372 psx_sync_n(); |
507 | 373 } |
374 | |
375 static void | |
514 | 376 post2runDraw(SchedTask *s, void *viewer_, void *arg) |
507 | 377 { |
378 Viewer *viewer = (Viewer*)viewer_; | |
826 | 379 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 380 viewer->run_draw(task_next); |
381 | |
382 } | |
383 | |
384 void | |
385 Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする | |
386 { | |
387 common_draw(task_next); | |
388 | |
994 | 389 task_next->set_post(post2runLoop, (void*)this, (void*)pixels); // set_post(function(this->run_loop()), NULL) |
507 | 390 task_next->spawn(); |
391 // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ | |
392 | |
393 frames++; | |
394 } | |
395 | |
396 | |
397 static void | |
514 | 398 post2speRendering(SchedTask *s, void *viewer_, void *arg) |
507 | 399 { |
400 Viewer *viewer = (Viewer*)viewer_; | |
826 | 401 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 402 viewer->spe_rendering(task_next); |
403 } | |
404 | |
405 void | |
406 Viewer::spe_rendering(HTaskPtr task_next) | |
407 { | |
748 | 408 common_rendering(task_next, sgroot); |
507 | 409 |
410 this->draw_dummy->wait_for(task_next); | |
514 | 411 task_next->set_post(post2speDraw, (void*)this, 0); |
507 | 412 task_next->spawn(); |
413 | |
414 } | |
415 | |
416 static void | |
514 | 417 post2speDraw(SchedTask *s, void *viewer_, void *arg) |
507 | 418 { |
419 Viewer *viewer = (Viewer*)viewer_; | |
826 | 420 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 421 viewer->spe_draw(task_next); |
422 } | |
423 | |
424 void | |
425 Viewer::spe_draw(HTaskPtr task_next) | |
426 { | |
427 common_draw(task_next); | |
428 | |
429 this->draw_dummy->wait_for(task_next); | |
430 task_next->spawn(); | |
431 this->draw_dummy->spawn(); | |
432 | |
433 frames++; | |
434 } | |
435 | |
907 | 436 |
908 | 437 // 完全にMac仕様。。sg_matrix を allocate してやらないといけないよ。 |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
438 float* |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
439 copy_matrix(SceneGraphPtr sg, TaskManager *manager) { |
908 | 440 |
441 float *matrix = sg->matrix; | |
442 float *real_matrix = sg->real_matrix; | |
443 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
444 //変換行列は4x4 なんで、16。が二つで32.と言い訳を書いてみる。 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
445 float *sg_matrix = (float*)manager->allocate(sizeof(float)*32); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
446 |
908 | 447 for (int i = 0; i < 16; i++) { |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
448 sg_matrix[i] = matrix[i]; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
449 sg_matrix[i+16] = real_matrix[i]; |
908 | 450 } |
451 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
452 return sg_matrix; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
453 |
908 | 454 } |
455 | |
456 void | |
457 print_matrix(float *matrix) { | |
458 | |
459 for (int i = 0; i < 32; i++) { | |
460 printf("%f\n",matrix[i]); | |
461 } | |
462 | |
463 } | |
907 | 464 |
465 void | |
466 add_matrix_list(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) { | |
467 | |
468 MatrixList *matrix_list = (MatrixList*)manager->allocate(sizeof(MatrixList)); | |
908 | 469 |
470 #if SPE_CREATE_POLYGON_CHECK | |
471 print_matrix(sg->sg_matrix); | |
472 #endif | |
473 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
474 matrix_list->matrix = copy_matrix(sg, manager);; |
907 | 475 matrix_list->next = NULL; |
908 | 476 |
907 | 477 |
478 if (info->last != NULL) { | |
479 info->last->next = matrix_list; | |
480 } | |
481 | |
482 info->last = matrix_list; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
483 info->list_length += 1; |
907 | 484 |
485 } | |
486 | |
487 void | |
488 new_matrix_info(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) { | |
489 | |
490 MatrixListInfo *next = NULL; | |
491 | |
492 if (info->id == -1) { | |
493 | |
494 info->id = sg->sgid; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
495 info->list_length = 1; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
496 info->coord_pack = sg->coord_pack; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
497 info->coord_pack_size = sg->coord_pack_size; |
907 | 498 next = info; |
499 | |
500 } else { | |
501 | |
502 MatrixListInfo* t; | |
503 | |
504 for (t = info; t->next != NULL; t = t->next) { | |
505 } | |
506 | |
507 next = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo)); | |
508 next->id = sg->sgid; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
509 next->list_length = 1; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
510 next->coord_pack = sg->coord_pack; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
511 next->coord_pack_size = sg->coord_pack_size; |
907 | 512 next->next = NULL; |
513 t->next = next; | |
514 | |
515 } | |
516 | |
517 MatrixList *new_list = (MatrixList*)manager->allocate(sizeof(MatrixList)); | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
518 new_list->matrix = copy_matrix(sg, manager); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
519 |
908 | 520 #if SPE_CREATE_POLYGON_CHECK |
521 print_matrix(sg->sg_matrix); | |
522 #endif | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
523 |
907 | 524 new_list->next = NULL; |
525 | |
526 next->first = new_list; | |
527 next->last = new_list; | |
528 | |
529 } | |
530 | |
531 void | |
532 collect_matrix(SceneGraphPtr sg, MatrixListInfo *matrix_info, TaskManager *manager) { | |
533 | |
534 matrix_info->id = -1; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
535 matrix_info->list_length = 0; |
907 | 536 matrix_info->next = NULL; |
537 matrix_info->first = NULL; | |
538 matrix_info->last = NULL; | |
539 | |
540 while (sg) { | |
541 | |
542 if (sg->flag_drawable) { | |
543 | |
544 int flag = 0; | |
545 | |
546 for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) { | |
547 if (sg->sgid == t->id) { | |
548 add_matrix_list(sg, manager, t); | |
549 flag = 1; | |
550 } | |
551 } | |
552 | |
553 if (flag != 1) { | |
554 new_matrix_info(sg, manager, matrix_info); | |
555 } | |
556 | |
557 // search SceneGraph. でも、ただのリストがあったハズだから、あとでそれに直す。はず・・ | |
558 if (sg->children != NULL) { | |
559 sg = sg->children; | |
560 } else if (sg->brother != NULL) { | |
561 sg = sg->brother; | |
562 } else { | |
563 while (sg) { | |
564 if (sg->brother != NULL) { | |
565 sg = sg->brother; | |
566 break; | |
567 } else { | |
568 if (sg->parent == NULL) { | |
569 sg = NULL; | |
570 break; | |
571 } else { | |
572 sg = sg->parent; | |
573 } | |
574 } | |
575 } | |
576 } | |
577 } | |
578 } | |
579 } | |
580 | |
908 | 581 void |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
582 check_matrix(MatrixListInfo *matrix_info,SceneGraphPtr sg) { |
908 | 583 |
584 for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) { | |
585 for (MatrixList* u = t->first; u != NULL; u = u->next) { | |
586 print_matrix(u->matrix); | |
587 } | |
588 } | |
589 | |
590 } | |
591 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
592 |
908 | 593 void |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
594 coord_allocate(int &cur_point, float *coord_pack, int spe_num, |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
595 int alloc_size, HTaskPtr alloc_wait, TaskManager *manager) |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
596 { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
597 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
598 for (int i = 0; i < spe_num; i++) { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
599 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
600 HTaskPtr data_alloc = manager->create_task(DataAllocate); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
601 //data_alloc->set_inData(0, &coord_pack[cur_point], alloc_size); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
602 data_alloc->set_param(0,(memaddr)alloc_size); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
603 data_alloc->set_param(1,(memaddr)SG_COORD); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
604 data_alloc->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
605 alloc_wait->wait_for(data_alloc); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
606 data_alloc->spawn(); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
607 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
608 } |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
609 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
610 cur_point += alloc_size / sizeof(float); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
611 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
612 } |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
613 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
614 void |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
615 coord_free(int spe_num, TaskManager *manager, HTaskPtr alloc_wait) |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
616 { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
617 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
618 for (int i = 0; i < spe_num; i++) { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
619 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
620 HTaskPtr data_free = manager->create_task(DataFree); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
621 data_free->set_param(0,(memaddr)SG_COORD); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
622 data_free->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
623 data_free->wait_for(alloc_wait); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
624 data_free->spawn(); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
625 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
626 } |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
627 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
628 } |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
629 |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
630 /* flag_drawable な Scenegraph の総数を求める */ |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
631 int |
1020 | 632 sg_drawable_num(SceneGraphPtr scenegraph) |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
633 { |
1020 | 634 SceneGraphPtr sg = scenegraph; |
635 | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
636 int sg_count = 0; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
637 while (sg) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
638 if (sg->flag_drawable) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
639 sg_count++; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
640 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
641 if (sg->children != NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
642 sg = sg->children; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
643 } else if (sg->brother != NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
644 sg = sg->brother; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
645 } else { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
646 while (sg) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
647 if (sg->brother != NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
648 sg = sg->brother; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
649 break; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
650 } else { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
651 if (sg->parent == NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
652 sg = NULL; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
653 break; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
654 } else { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
655 sg = sg->parent; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
656 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
657 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
658 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
659 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
660 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
661 return sg_count; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
662 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
663 |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
664 void |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
665 create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next) |
907 | 666 { |
667 | |
1013 | 668 /* |
669 * SceneGraph を辿って coord_xyz, coord_tex, normal, matrix, real_matrix 及び、 | |
670 * PolygonPack の TrianglePack (空) を送る。pp->info.size の計算もここで。 | |
671 * | |
672 */ | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
673 //int spe_num = 6; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
674 |
1020 | 675 PolygonPackPtr pp = (PolygonPackPtr)manager->allocate(sizeof(PolygonPack)); |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
676 |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
677 int sg_num = sg_drawable_num(sg); |
1020 | 678 int sg_division = sg_num / spe_num; |
679 int residue = sg_num % spe_num; | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
680 |
1020 | 681 HTask **task_array = (HTask**)manager->allocate(sizeof(HTask*)*spe_num); |
682 Task **pptask = (Task**)manager->allocate(sizeof(Task*)*spe_num); | |
683 | |
684 for (int k = 0; k < spe_num-1; k++) { | |
685 task_array[k] = manager->create_task_array(CreatePolygonFromSceneGraph,sg_division,4,6,1); | |
686 pptask[k] = 0; | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
687 } |
1020 | 688 |
689 task_array[spe_num] = manager->create_task_array(CreatePolygonFromSceneGraph, | |
690 sg_division+residue,4,6,1); | |
691 pptask[spe_num] = 0; | |
692 | |
693 int count= 0; | |
694 int k = 0; | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
695 |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
696 while (sg) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
697 if (sg->flag_drawable) { |
1020 | 698 if(count < spe_num * sg_division) { |
699 k %= spe_num-1; | |
700 } else { | |
701 k = spe_num; | |
702 } | |
703 pptask[k] = task_array[k]->next_task_array(CreatePolygonFromSceneGraph,pptask[k]); | |
704 pptask[k]->set_inData(0, &sg->coord_xyz, sizeof(float)*sg->size/3); | |
705 pptask[k]->set_inData(1, &sg->coord_tex, sizeof(float)*sg->size/3); | |
706 pptask[k]->set_inData(2, &sg->normal , sizeof(float)*sg->size/3); | |
707 pptask[k]->set_inData(3, &sg->matrix , sizeof(float)*12); | |
708 pptask[k]->set_inData(4, &sg->real_matrix, sizeof(float)*8); | |
709 pptask[k]->set_inData(5, &sg->texture_info.pixels, sizeof(uint32)); | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
710 |
1020 | 711 pptask[k]->set_param(0,(memaddr)sg->size); |
712 pptask[k]->set_param(1,(memaddr)sg->texture_info.t_w); | |
713 pptask[k]->set_param(2,(memaddr)sg->texture_info.t_h); | |
714 pptask[k]->set_param(3,(memaddr)sg->texture_info.scale_max); | |
715 | |
716 pptask[k]->set_outData(0, &pp->tri[pp->info.size++], sizeof(TrianglePack)); | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
717 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
718 if (sg->children != NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
719 sg = sg->children; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
720 } else if (sg->brother != NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
721 sg = sg->brother; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
722 } else { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
723 while (sg) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
724 if (sg->brother != NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
725 sg = sg->brother; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
726 break; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
727 } else { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
728 if (sg->parent == NULL) { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
729 sg = NULL; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
730 break; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
731 } else { |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
732 sg = sg->parent; |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
733 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
734 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
735 } |
1020 | 736 } |
737 count++; | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
738 } |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
739 |
907 | 740 } |
741 | |
860 | 742 void |
748 | 743 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) |
507 | 744 { |
860 | 745 |
746 #if SPE_CREATE_POLYGON | |
747 | |
907 | 748 SceneGraphPtr sg = sgroot->getDrawSceneGraph(); |
749 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
750 create_pp_task(sg, manager, spe_num, task_next); |
907 | 751 |
908 | 752 #if SPE_CREATE_POLYGON_CHECK |
753 check_matrix(matrix_info,sg); | |
754 #endif | |
755 | |
907 | 756 |
909 | 757 |
758 #else | |
1018
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
759 //SceneGraphPtr sg = sgroot->getDrawSceneGraph(); |
736a833db108
sg_drawable_num add. CreatePolygonFromSceneGraph not done.
tkaito
parents:
1013
diff
changeset
|
760 //printf("sg->size = %lld\n", sg->size); |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
761 HTaskPtr task_create_pp = manager->create_task(CreatePolygonFromSceneGraph); |
507 | 762 // SceneGraph(木構造) -> PolygonPack |
763 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
764 task_create_pp->set_param(0,(memaddr)sgroot->getDrawSceneGraph()); |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
765 task_create_pp->set_param(1,(memaddr)r[ppi].ppack); |
1003
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
766 |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
767 /* GameTask の処理の終了を待ってからポリゴンを作る */ |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
768 if (sgroot->gtask_array != NULL) { |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
769 HTaskPtr game_task_array = sgroot->gtask_array->get_task_array(); |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
770 task_create_pp->wait_for(game_task_array); |
295b3c79fb44
game_task keep up with task_array.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
1002
diff
changeset
|
771 } |
507 | 772 task_next->wait_for(task_create_pp); |
748 | 773 |
909 | 774 #endif |
775 | |
748 | 776 int range_base = spe_num; |
777 | |
507 | 778 // 切り上げのつもり |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
779 int range = (r[spi].spackList_length + range_base - 1) / range_base; |
507 | 780 |
781 for (int i = 0; i < range_base; i++) { | |
782 int index_start = range*i; | |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
783 int index_end = (index_start + range >= r[spi].spackList_length) |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
784 ? r[spi].spackList_length : index_start + range; |
507 | 785 |
652 | 786 HTaskPtr task_create_sp = manager->create_task(CreateSpan); |
507 | 787 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
788 task_create_sp->set_param(0,index_start); |
748 | 789 |
507 | 790 /** |
791 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 | |
792 * [ 1.. 80] [ 81..160] [161..240] | |
793 * [241..320] [321..400] [401..480] | |
794 * | |
795 * ex. screen_height が 1080, spenum が 5 の場合、 | |
796 * [ 1..216] [217..432] [433..648] | |
797 * [649..864] [865..1080] | |
798 */ | |
748 | 799 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
800 task_create_sp->set_param(1,index_start*split_screen_h + 1); |
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
801 task_create_sp->set_param(2,index_end*split_screen_h); |
507 | 802 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
803 task_create_sp->add_inData(r[ppi].ppack, sizeof(PolygonPack)); |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
804 task_create_sp->add_inData(r[spi].spackList_ptr, |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
805 sizeof(SpanPack*)*r[spi].spackList_length_align); |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
806 task_create_sp->add_inData(&r[spi].spackList[index_start], sizeof(SpanPack)); |
652 | 807 |
507 | 808 task_next->wait_for(task_create_sp); |
809 task_create_sp->wait_for(task_create_pp); | |
810 | |
748 | 811 task_create_sp->set_cpu(SPE_ANY); |
507 | 812 task_create_sp->spawn(); |
813 } | |
814 | |
860 | 815 task_create_pp->spawn(); |
507 | 816 } |
817 | |
792 | 818 |
507 | 819 void |
820 Viewer::common_draw(HTaskPtr task_next) | |
821 { | |
822 | |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
823 //task_next = manager->create_task(Dummy); |
507 | 824 //task_next->set_post(post2runLoop, (void*)this); |
825 | |
792 | 826 //Light info update |
748 | 827 |
792 | 828 int light_num = 4; |
829 int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) | |
762 | 830 int light_size = size / sizeof(float); |
748 | 831 |
762 | 832 for (int i = 0; i < light_size; i++) { |
792 | 833 light_xyz[i] = light_xyz_stock[i]; |
762 | 834 } |
792 | 835 |
836 for (int i = 0; i < light_num; i++) { | |
837 light_switch[i] = light_switch_stock[i]; | |
838 } | |
793 | 839 |
840 light_sysswitch[0] = light_sysswitch_stock; | |
985 | 841 |
842 | |
843 HTask *data_update_wait = 0; | |
844 for (int i = 0; i < spe_num; i++) { | |
845 data_update_wait = manager->create_task(DataUpdate); | |
846 data_update_wait->set_param(0,3); | |
847 data_update_wait->set_param(1,Light); // GlobalSet ID base | |
848 data_update_wait->set_inData(0,light_xyz,size); // Light | |
849 data_update_wait->set_inData(1,light_switch,light_num * sizeof(int)); // LightSwitch = Light+1 | |
850 data_update_wait->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2 | |
851 data_update_wait->set_cpu((CPU_TYPE)(SPE_0+i)); | |
852 data_update_wait->spawn(); | |
792 | 853 } |
854 | |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
855 ppi ^= 1; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
856 r[ppi].ppack->clear(); |
914 | 857 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
858 for (int i = 0; i < r[spi].spackList_length; i++) { |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
859 SpanPack *spack = &r[spi].spackList[i]; |
507 | 860 int startx = 1; |
861 int endx = split_screen_w; | |
862 | |
863 int starty = spack->info.y_top - split_screen_h + 1; | |
864 //int endy = spack->info.y_top; | |
865 int rangey = (starty + split_screen_h - 1 > this->height) | |
866 ? this->height - starty + 1 : split_screen_h; | |
867 | |
889
b150914f5976
minor fix. Redering Engine not worked yet.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
885
diff
changeset
|
868 #if 1 |
857 | 869 |
914 | 870 // mem_flag は spe 側で黒い部分を 0 で埋めるフラグ |
871 if(spack->info.size > 0 || mem_flag == 1) { | |
838 | 872 |
857 | 873 int array_task_num = (this->width + split_screen_w - 1) / split_screen_w; |
874 HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey); | |
875 Task *task_draw = 0; | |
876 | |
877 while (startx < this->width) { | |
878 | |
839 | 879 // Draw SpanPack |
857 | 880 |
839 | 881 task_draw = task_draw_array->next_task_array(DrawSpan,task_draw); |
882 task_draw->set_param(0,(memaddr)&pixels[(startx-1) + this->width*(starty-1)]); | |
883 task_draw->set_param(1,this->width); | |
884 task_draw->set_param(2,startx); | |
885 task_draw->set_param(3,endx); | |
886 task_draw->set_param(4,rangey); | |
887 task_draw->set_param(5,spack->info.size); | |
838 | 888 |
839 | 889 task_draw->set_inData(0,spack, sizeof(SpanPack)); |
890 | |
891 for (int i = 0; i < rangey; i++) { | |
857 | 892 task_draw->set_outData(i, |
893 &pixels[(startx-1) + this->width*(starty-1 + i) ], | |
894 (endx-startx+1)*sizeof(int)); | |
839 | 895 } |
896 | |
897 startx += split_screen_w; | |
898 endx += split_screen_w; | |
899 | |
900 if (endx > this->width) { | |
901 endx = this->width; | |
902 } | |
903 | |
857 | 904 } |
905 | |
906 task_draw_array->spawn_task_array(task_draw->next()); | |
907 task_draw_array->set_cpu(SPE_ANY); | |
908 task_next->wait_for(task_draw_array); | |
909 task_draw_array->spawn(); | |
854 | 910 |
857 | 911 |
914 | 912 |
913 } else { | |
914 | |
857 | 915 memset(&pixels[(startx-1)+this->width*(starty-1)], |
916 0, (this->width)*sizeof(int)*rangey); | |
838 | 917 |
914 | 918 } |
919 | |
857 | 920 |
921 #else | |
838 | 922 |
923 HTaskPtr task_draw; | |
924 | |
507 | 925 while (startx < this->width) { |
857 | 926 if (spack->info.size > 0) { |
507 | 927 // Draw SpanPack |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
928 task_draw = manager->create_task(DrawSpan); |
507 | 929 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
930 task_draw->set_param(0, |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
931 (memaddr)&pixels[(startx-1) + this->width*(starty-1)]); |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
932 task_draw->set_param(1,this->width); |
652 | 933 task_draw->set_param(2,startx); |
934 task_draw->set_param(3,endx); | |
935 task_draw->set_param(4,rangey); | |
838 | 936 task_draw->set_param(5,spack->info.size); |
652 | 937 |
938 task_draw->add_inData(spack, sizeof(SpanPack)); | |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
939 |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
940 for (int i = 0; i < rangey; i++) { |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
941 task_draw->add_outData( |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
942 &pixels[(startx-1) + this->width*(starty-1 + i) ], |
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
943 (endx-startx+1)*sizeof(int)); |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
944 } |
838 | 945 |
857 | 946 } else { |
507 | 947 // 7.7.3 SL1 Data Cache Range Set to Zero コマンド |
948 // を使って、DMAでclearするべき... ということは、 | |
949 // それもSPEでやる方が良い? | |
857 | 950 memset(&pixels[(startx-1)+this->width*(starty-1)], |
951 0, (this->width)*sizeof(int)*rangey); | |
952 break; | |
953 } | |
507 | 954 |
748 | 955 task_draw->set_cpu(SPE_ANY); |
507 | 956 task_next->wait_for(task_draw); |
957 task_draw->spawn(); | |
958 | |
959 startx += split_screen_w; | |
960 endx += split_screen_w; | |
961 | |
962 if (endx > this->width) { | |
963 endx = this->width; | |
964 } | |
965 } | |
838 | 966 #endif |
967 | |
792 | 968 } |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
969 spi ^= 1; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
970 for (int i = 1; i <= r[spi].spackList_length; i++) { |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
971 r[spi].spackList[i-1].reinit(i*split_screen_h); |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
972 } |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
973 |
792 | 974 |
925
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
975 if (profile) { |
983 | 976 if (frames % 50 == 49) { |
998 | 977 manager->show_profile(); |
983 | 978 this_time = get_ticks(); |
979 if (this_time != start_time) { | |
984 | 980 printf("\n%f FPS\n", ((((float)frames)*1000.0)/(this_time-start_time))); |
983 | 981 start_time = this_time; frames = 0; |
982 } | |
982
b29547a5b85b
avoid WAIT in virtual console
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
981
diff
changeset
|
983 } |
925
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
984 } |
748 | 985 } |
986 | |
987 void | |
988 Viewer::run_finish() | |
989 { | |
990 dev->free_device(); | |
991 if (this_time != start_time) { | |
992 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
993 } | |
925
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
994 if (profile) { |
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
995 manager->show_profile(); |
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
996 } |
748 | 997 |
998 delete sgroot; | |
999 // delete sgroot_2; | |
1000 quit(); | |
507 | 1001 } |
1002 | |
1003 /* end */ |