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