Mercurial > hg > Members > kono > Cerium
annotate Renderer/Engine/viewer.cc @ 986:ac437c3cf766 akira
double buffering of spanpack/polgonpack
not yet worked.
author | root@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 01 Oct 2010 03:42:25 +0900 |
parents | e40dd2384357 |
children | 0b6f8c82625a |
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 |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
118 data_load->set_param(0,(memaddr)(sizeof(float)*4*light_num)); // 1st allocate size |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
119 data_load->set_param(1,(memaddr)Light); // 1st id |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
120 data_load->set_param(0,(memaddr)(light_num * sizeof(int))); // 2nd size |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
121 data_load->set_param(1,(memaddr)LightSwitch); // 2nd id |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
122 data_load->set_param(0,(memaddr)16); // 3rd size |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
123 data_load->set_param(1,(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)); |
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 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
179 for (int j = 0; i < r[i].spackList_length; i++) { |
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 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
183 for (int j = 1; j <= r[i].spackList_length; i++) { |
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 | |
514 | 295 task_next->set_post(&post2runLoop, (void *)this, 0); // 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(); | |
981
a193a851b5e3
add double buffering frame device
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
969
diff
changeset
|
313 pixels = dev->flip_screen(pixels); |
748 | 314 |
969
9a53faae88d8
add new function for dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
965
diff
changeset
|
315 /* ここでGameTaskの終了を待つTaskを生成しておく */ |
9a53faae88d8
add new function for dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
965
diff
changeset
|
316 sgroot->wait_game_task = manager->create_task(Dummy,0,0,0,0); |
748 | 317 sgroot->updateControllerState(); |
318 sgroot->allExecute(width, height); | |
319 light_xyz_stock = sgroot->getLightVector(); | |
792 | 320 light_switch_stock = sgroot->getLightSwitch(); |
793 | 321 light_sysswitch_stock = sgroot->getLightSysSwitch(); |
748 | 322 //sgroot->checkRemove(); |
323 | |
324 // ここから下は Rendering という関数にする | |
325 rendering(task_next); | |
507 | 326 } |
327 | |
328 | |
329 | |
330 void | |
331 Viewer::run_collision() | |
332 { | |
333 } | |
334 | |
335 void | |
514 | 336 post2rendering(SchedTask *s, void *viewer_, void *arg) |
507 | 337 { |
338 Viewer *viewer = (Viewer *)viewer_; | |
826 | 339 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 340 viewer->rendering(task_next); |
341 } | |
342 | |
343 void | |
344 Viewer::rendering(HTaskPtr task_next) | |
345 { | |
748 | 346 common_rendering(task_next, sgroot); |
507 | 347 |
348 // Barrier 同期 | |
349 // run_draw() を呼ぶ post2runDraw | |
514 | 350 task_next->set_post(post2runDraw, (void*)this, 0); // set_post(function(this->run_draw()), NULL) |
507 | 351 task_next->spawn(); |
352 | |
353 // TASK_CREATE_SPAN が全て終わったら DUMMY_TASK が Viewer::run_draw() を呼ぶ | |
354 } | |
355 | |
356 static void | |
514 | 357 post2runLoop(SchedTask *s, void *viewer_, void *arg) |
507 | 358 { |
359 Viewer *viewer = (Viewer*)viewer_; | |
826 | 360 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 361 viewer->run_loop(task_next); |
575
0f13810d4492
Linda API worked. (slightly unreliable)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
572
diff
changeset
|
362 psx_sync_n(); |
507 | 363 } |
364 | |
365 static void | |
514 | 366 post2runDraw(SchedTask *s, void *viewer_, void *arg) |
507 | 367 { |
368 Viewer *viewer = (Viewer*)viewer_; | |
826 | 369 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 370 viewer->run_draw(task_next); |
371 | |
372 } | |
373 | |
374 void | |
375 Viewer::run_draw(HTaskPtr task_next) // 引数に post2runLoop を入れるようにする | |
376 { | |
377 common_draw(task_next); | |
378 | |
514 | 379 task_next->set_post(post2runLoop, (void*)this, 0); // set_post(function(this->run_loop()), NULL) |
507 | 380 task_next->spawn(); |
381 // TASK_DRAW_SPAN が全て終わったら DUMMY_TASK が Viewer::run_loop() を呼ぶ | |
382 | |
383 frames++; | |
384 } | |
385 | |
386 | |
387 static void | |
514 | 388 post2speRendering(SchedTask *s, void *viewer_, void *arg) |
507 | 389 { |
390 Viewer *viewer = (Viewer*)viewer_; | |
826 | 391 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 392 viewer->spe_rendering(task_next); |
393 } | |
394 | |
395 void | |
396 Viewer::spe_rendering(HTaskPtr task_next) | |
397 { | |
748 | 398 common_rendering(task_next, sgroot); |
507 | 399 |
400 this->draw_dummy->wait_for(task_next); | |
514 | 401 task_next->set_post(post2speDraw, (void*)this, 0); |
507 | 402 task_next->spawn(); |
403 | |
404 } | |
405 | |
406 static void | |
514 | 407 post2speDraw(SchedTask *s, void *viewer_, void *arg) |
507 | 408 { |
409 Viewer *viewer = (Viewer*)viewer_; | |
826 | 410 HTaskPtr task_next = viewer->manager->create_task(Dummy,0,0,0,0); |
507 | 411 viewer->spe_draw(task_next); |
412 } | |
413 | |
414 void | |
415 Viewer::spe_draw(HTaskPtr task_next) | |
416 { | |
417 common_draw(task_next); | |
418 | |
419 this->draw_dummy->wait_for(task_next); | |
420 task_next->spawn(); | |
421 this->draw_dummy->spawn(); | |
422 | |
423 frames++; | |
424 } | |
425 | |
907 | 426 |
908 | 427 // 完全にMac仕様。。sg_matrix を allocate してやらないといけないよ。 |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
428 float* |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
429 copy_matrix(SceneGraphPtr sg, TaskManager *manager) { |
908 | 430 |
431 float *matrix = sg->matrix; | |
432 float *real_matrix = sg->real_matrix; | |
433 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
434 //変換行列は4x4 なんで、16。が二つで32.と言い訳を書いてみる。 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
435 float *sg_matrix = (float*)manager->allocate(sizeof(float)*32); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
436 |
908 | 437 for (int i = 0; i < 16; i++) { |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
438 sg_matrix[i] = matrix[i]; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
439 sg_matrix[i+16] = real_matrix[i]; |
908 | 440 } |
441 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
442 return sg_matrix; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
443 |
908 | 444 } |
445 | |
446 void | |
447 print_matrix(float *matrix) { | |
448 | |
449 for (int i = 0; i < 32; i++) { | |
450 printf("%f\n",matrix[i]); | |
451 } | |
452 | |
453 } | |
907 | 454 |
455 void | |
456 add_matrix_list(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) { | |
457 | |
458 MatrixList *matrix_list = (MatrixList*)manager->allocate(sizeof(MatrixList)); | |
908 | 459 |
460 #if SPE_CREATE_POLYGON_CHECK | |
461 print_matrix(sg->sg_matrix); | |
462 #endif | |
463 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
464 matrix_list->matrix = copy_matrix(sg, manager);; |
907 | 465 matrix_list->next = NULL; |
908 | 466 |
907 | 467 |
468 if (info->last != NULL) { | |
469 info->last->next = matrix_list; | |
470 } | |
471 | |
472 info->last = matrix_list; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
473 info->list_length += 1; |
907 | 474 |
475 } | |
476 | |
477 void | |
478 new_matrix_info(SceneGraphPtr sg, TaskManager *manager, MatrixListInfo* info) { | |
479 | |
480 MatrixListInfo *next = NULL; | |
481 | |
482 if (info->id == -1) { | |
483 | |
484 info->id = sg->sgid; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
485 info->list_length = 1; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
486 info->coord_pack = sg->coord_pack; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
487 info->coord_pack_size = sg->coord_pack_size; |
907 | 488 next = info; |
489 | |
490 } else { | |
491 | |
492 MatrixListInfo* t; | |
493 | |
494 for (t = info; t->next != NULL; t = t->next) { | |
495 } | |
496 | |
497 next = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo)); | |
498 next->id = sg->sgid; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
499 next->list_length = 1; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
500 next->coord_pack = sg->coord_pack; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
501 next->coord_pack_size = sg->coord_pack_size; |
907 | 502 next->next = NULL; |
503 t->next = next; | |
504 | |
505 } | |
506 | |
507 MatrixList *new_list = (MatrixList*)manager->allocate(sizeof(MatrixList)); | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
508 new_list->matrix = copy_matrix(sg, manager); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
509 |
908 | 510 #if SPE_CREATE_POLYGON_CHECK |
511 print_matrix(sg->sg_matrix); | |
512 #endif | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
513 |
907 | 514 new_list->next = NULL; |
515 | |
516 next->first = new_list; | |
517 next->last = new_list; | |
518 | |
519 } | |
520 | |
521 void | |
522 collect_matrix(SceneGraphPtr sg, MatrixListInfo *matrix_info, TaskManager *manager) { | |
523 | |
524 matrix_info->id = -1; | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
525 matrix_info->list_length = 0; |
907 | 526 matrix_info->next = NULL; |
527 matrix_info->first = NULL; | |
528 matrix_info->last = NULL; | |
529 | |
530 while (sg) { | |
531 | |
532 if (sg->flag_drawable) { | |
533 | |
534 int flag = 0; | |
535 | |
536 for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) { | |
537 if (sg->sgid == t->id) { | |
538 add_matrix_list(sg, manager, t); | |
539 flag = 1; | |
540 } | |
541 } | |
542 | |
543 if (flag != 1) { | |
544 new_matrix_info(sg, manager, matrix_info); | |
545 } | |
546 | |
547 // search SceneGraph. でも、ただのリストがあったハズだから、あとでそれに直す。はず・・ | |
548 if (sg->children != NULL) { | |
549 sg = sg->children; | |
550 } else if (sg->brother != NULL) { | |
551 sg = sg->brother; | |
552 } else { | |
553 while (sg) { | |
554 if (sg->brother != NULL) { | |
555 sg = sg->brother; | |
556 break; | |
557 } else { | |
558 if (sg->parent == NULL) { | |
559 sg = NULL; | |
560 break; | |
561 } else { | |
562 sg = sg->parent; | |
563 } | |
564 } | |
565 } | |
566 } | |
567 } | |
568 } | |
569 } | |
570 | |
908 | 571 void |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
572 check_matrix(MatrixListInfo *matrix_info,SceneGraphPtr sg) { |
908 | 573 |
574 for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) { | |
575 for (MatrixList* u = t->first; u != NULL; u = u->next) { | |
576 print_matrix(u->matrix); | |
577 } | |
578 } | |
579 | |
580 } | |
581 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
582 |
908 | 583 void |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
584 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
|
585 int alloc_size, HTaskPtr alloc_wait, TaskManager *manager) |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
586 { |
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 for (int i = 0; i < spe_num; i++) { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
589 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
590 HTaskPtr data_alloc = manager->create_task(DataAllocate); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
591 //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
|
592 data_alloc->set_param(0,(memaddr)alloc_size); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
593 data_alloc->set_param(1,(memaddr)SG_COORD); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
594 data_alloc->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
595 alloc_wait->wait_for(data_alloc); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
596 data_alloc->spawn(); |
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 } |
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 cur_point += alloc_size / sizeof(float); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
601 |
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 void |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
605 coord_free(int spe_num, TaskManager *manager, HTaskPtr alloc_wait) |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
606 { |
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 for (int i = 0; i < spe_num; i++) { |
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 HTaskPtr data_free = manager->create_task(DataFree); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
611 data_free->set_param(0,(memaddr)SG_COORD); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
612 data_free->set_cpu((CPU_TYPE)((int)SPE_0 + i)); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
613 data_free->wait_for(alloc_wait); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
614 data_free->spawn(); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
615 |
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 void |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
621 create_pp_task(SceneGraphPtr sg, TaskManager *manager, int spe_num, HTaskPtr task_next) |
907 | 622 { |
623 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
624 MatrixListInfo *matrix_info = (MatrixListInfo*)manager->allocate(sizeof(MatrixListInfo)); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
625 collect_matrix(sg, matrix_info, manager); |
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 //HTaskPtr phase_wait = manager->create_task(Dummy); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
629 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
630 for (MatrixListInfo* t = matrix_info; t != NULL; t = t->next) { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
631 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
632 printf("list_length %d \n", t->list_length); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
633 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
634 int alloc_size = 16*1024; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
635 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
636 if (t->coord_pack_size < alloc_size) { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
637 alloc_size = t->coord_pack_size; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
638 } |
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 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
|
642 int phase_num = (division_num + spe_num -1) / spe_num; |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
643 int cur_point = 0; |
907 | 644 |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
645 for (int i = 0; i < phase_num; i++) { |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
646 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
647 HTaskPtr alloc_wait = manager->create_task(Dummy); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
648 coord_allocate(cur_point, t->coord_pack, spe_num, |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
649 alloc_size, alloc_wait, manager); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
650 |
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 for (MatrixList* u = t->first; u != NULL; u = u->next) { |
907 | 653 |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
654 //HTaskPtr free_wait = manager->create_task(Dummy); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
655 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
656 //phase_wait = manager->create_task(Dummy); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
657 |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
658 } |
907 | 659 |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
660 coord_free(spe_num, manager, alloc_wait); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
661 alloc_wait->spawn(); |
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
662 } |
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 printf("-----------------------\n"); |
908 | 666 //return create_pp_wait; |
907 | 667 |
668 } | |
669 | |
860 | 670 void |
748 | 671 Viewer::common_rendering(HTaskPtr task_next, SceneGraphRoot *sgroot) |
507 | 672 { |
860 | 673 |
674 #if SPE_CREATE_POLYGON | |
675 | |
907 | 676 SceneGraphPtr sg = sgroot->getDrawSceneGraph(); |
677 | |
915
ad10d6d39ca6
create_polygon_task ..not worked yet.
yutaka@localhost.localdomain
parents:
914
diff
changeset
|
678 create_pp_task(sg, manager, spe_num, task_next); |
907 | 679 |
908 | 680 #if SPE_CREATE_POLYGON_CHECK |
681 check_matrix(matrix_info,sg); | |
682 #endif | |
683 | |
907 | 684 |
909 | 685 |
686 #else | |
907 | 687 |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
688 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
|
689 HTaskPtr game_task = sgroot->wait_game_task; |
507 | 690 // SceneGraph(木構造) -> PolygonPack |
691 | |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
692 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
|
693 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
|
694 /* GameTaskの終了を待ってからポリゴンを作る */ |
9a53faae88d8
add new function for dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
965
diff
changeset
|
695 task_create_pp->wait_for(game_task); |
507 | 696 |
697 task_next->wait_for(task_create_pp); | |
748 | 698 |
909 | 699 #endif |
700 | |
748 | 701 int range_base = spe_num; |
702 | |
507 | 703 // 切り上げのつもり |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
704 int range = (r[spi].spackList_length + range_base - 1) / range_base; |
507 | 705 |
706 for (int i = 0; i < range_base; i++) { | |
707 int index_start = range*i; | |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
708 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
|
709 ? r[spi].spackList_length : index_start + range; |
507 | 710 |
652 | 711 HTaskPtr task_create_sp = manager->create_task(CreateSpan); |
507 | 712 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
713 task_create_sp->set_param(0,index_start); |
748 | 714 |
507 | 715 /** |
716 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 | |
717 * [ 1.. 80] [ 81..160] [161..240] | |
718 * [241..320] [321..400] [401..480] | |
719 * | |
720 * ex. screen_height が 1080, spenum が 5 の場合、 | |
721 * [ 1..216] [217..432] [433..648] | |
722 * [649..864] [865..1080] | |
723 */ | |
748 | 724 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
725 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
|
726 task_create_sp->set_param(2,index_end*split_screen_h); |
507 | 727 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
728 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
|
729 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
|
730 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
|
731 task_create_sp->add_inData(&r[spi].spackList[index_start], sizeof(SpanPack)); |
652 | 732 |
507 | 733 task_next->wait_for(task_create_sp); |
734 task_create_sp->wait_for(task_create_pp); | |
735 | |
748 | 736 task_create_sp->set_cpu(SPE_ANY); |
507 | 737 task_create_sp->spawn(); |
738 } | |
739 | |
860 | 740 task_create_pp->spawn(); |
969
9a53faae88d8
add new function for dandy.
koba <koba@cr.ie.u-ryukyu.ac.jp>
parents:
965
diff
changeset
|
741 game_task->spawn(); |
507 | 742 } |
743 | |
792 | 744 |
507 | 745 void |
746 Viewer::common_draw(HTaskPtr task_next) | |
747 { | |
748 | |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
749 //task_next = manager->create_task(Dummy); |
507 | 750 //task_next->set_post(post2runLoop, (void*)this); |
751 | |
792 | 752 //Light info update |
748 | 753 |
792 | 754 int light_num = 4; |
755 int size = sizeof(float)*4*light_num; //xyz+alpha(4) * light_num(4) | |
762 | 756 int light_size = size / sizeof(float); |
748 | 757 |
762 | 758 for (int i = 0; i < light_size; i++) { |
792 | 759 light_xyz[i] = light_xyz_stock[i]; |
762 | 760 } |
792 | 761 |
762 for (int i = 0; i < light_num; i++) { | |
763 light_switch[i] = light_switch_stock[i]; | |
764 } | |
793 | 765 |
766 light_sysswitch[0] = light_sysswitch_stock; | |
985 | 767 |
768 | |
769 HTask *data_update_wait = 0; | |
770 for (int i = 0; i < spe_num; i++) { | |
771 data_update_wait = manager->create_task(DataUpdate); | |
772 data_update_wait->set_param(0,3); | |
773 data_update_wait->set_param(1,Light); // GlobalSet ID base | |
774 data_update_wait->set_inData(0,light_xyz,size); // Light | |
775 data_update_wait->set_inData(1,light_switch,light_num * sizeof(int)); // LightSwitch = Light+1 | |
776 data_update_wait->set_inData(2,light_sysswitch,16); // LightSysSwitch = Light+2 | |
777 data_update_wait->set_cpu((CPU_TYPE)(SPE_0+i)); | |
778 data_update_wait->spawn(); | |
792 | 779 } |
780 | |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
781 ppi ^= 1; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
782 r[ppi].ppack->clear(); |
914 | 783 |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
784 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
|
785 SpanPack *spack = &r[spi].spackList[i]; |
507 | 786 int startx = 1; |
787 int endx = split_screen_w; | |
788 | |
789 int starty = spack->info.y_top - split_screen_h + 1; | |
790 //int endy = spack->info.y_top; | |
791 int rangey = (starty + split_screen_h - 1 > this->height) | |
792 ? this->height - starty + 1 : split_screen_h; | |
793 | |
889
b150914f5976
minor fix. Redering Engine not worked yet.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
885
diff
changeset
|
794 #if 1 |
857 | 795 |
914 | 796 // mem_flag は spe 側で黒い部分を 0 で埋めるフラグ |
797 if(spack->info.size > 0 || mem_flag == 1) { | |
838 | 798 |
857 | 799 int array_task_num = (this->width + split_screen_w - 1) / split_screen_w; |
800 HTaskPtr task_draw_array = manager->create_task_array(DrawSpan, array_task_num, 6, 1, rangey); | |
801 Task *task_draw = 0; | |
802 | |
803 while (startx < this->width) { | |
804 | |
839 | 805 // Draw SpanPack |
857 | 806 |
839 | 807 task_draw = task_draw_array->next_task_array(DrawSpan,task_draw); |
808 task_draw->set_param(0,(memaddr)&pixels[(startx-1) + this->width*(starty-1)]); | |
809 task_draw->set_param(1,this->width); | |
810 task_draw->set_param(2,startx); | |
811 task_draw->set_param(3,endx); | |
812 task_draw->set_param(4,rangey); | |
813 task_draw->set_param(5,spack->info.size); | |
838 | 814 |
839 | 815 task_draw->set_inData(0,spack, sizeof(SpanPack)); |
816 | |
817 for (int i = 0; i < rangey; i++) { | |
857 | 818 task_draw->set_outData(i, |
819 &pixels[(startx-1) + this->width*(starty-1 + i) ], | |
820 (endx-startx+1)*sizeof(int)); | |
839 | 821 } |
822 | |
823 startx += split_screen_w; | |
824 endx += split_screen_w; | |
825 | |
826 if (endx > this->width) { | |
827 endx = this->width; | |
828 } | |
829 | |
857 | 830 } |
831 | |
832 task_draw_array->spawn_task_array(task_draw->next()); | |
833 task_draw_array->set_cpu(SPE_ANY); | |
834 task_next->wait_for(task_draw_array); | |
835 task_draw_array->spawn(); | |
854 | 836 |
857 | 837 |
914 | 838 |
839 } else { | |
840 | |
857 | 841 memset(&pixels[(startx-1)+this->width*(starty-1)], |
842 0, (this->width)*sizeof(int)*rangey); | |
838 | 843 |
914 | 844 } |
845 | |
857 | 846 |
847 #else | |
838 | 848 |
849 HTaskPtr task_draw; | |
850 | |
507 | 851 while (startx < this->width) { |
857 | 852 if (spack->info.size > 0) { |
507 | 853 // Draw SpanPack |
614
4e44147d78ee
remove uncessary Task Name definision
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
603
diff
changeset
|
854 task_draw = manager->create_task(DrawSpan); |
507 | 855 |
625
60aa3f241b10
64bit mode worked on Mac OS X.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
616
diff
changeset
|
856 task_draw->set_param(0, |
603
42c94f85c779
long -> memaddr (64 or 32)
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
602
diff
changeset
|
857 (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
|
858 task_draw->set_param(1,this->width); |
652 | 859 task_draw->set_param(2,startx); |
860 task_draw->set_param(3,endx); | |
861 task_draw->set_param(4,rangey); | |
838 | 862 task_draw->set_param(5,spack->info.size); |
652 | 863 |
864 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
|
865 |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
866 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
|
867 task_draw->add_outData( |
616
f21603a335aa
Rendering not yet worked.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
615
diff
changeset
|
868 &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
|
869 (endx-startx+1)*sizeof(int)); |
615
f7d78b3c1106
First addOutput rendering try failed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
614
diff
changeset
|
870 } |
838 | 871 |
857 | 872 } else { |
507 | 873 // 7.7.3 SL1 Data Cache Range Set to Zero コマンド |
874 // を使って、DMAでclearするべき... ということは、 | |
875 // それもSPEでやる方が良い? | |
857 | 876 memset(&pixels[(startx-1)+this->width*(starty-1)], |
877 0, (this->width)*sizeof(int)*rangey); | |
878 break; | |
879 } | |
507 | 880 |
748 | 881 task_draw->set_cpu(SPE_ANY); |
507 | 882 task_next->wait_for(task_draw); |
883 task_draw->spawn(); | |
884 | |
885 startx += split_screen_w; | |
886 endx += split_screen_w; | |
887 | |
888 if (endx > this->width) { | |
889 endx = this->width; | |
890 } | |
891 } | |
838 | 892 #endif |
893 | |
792 | 894 } |
986
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
895 spi ^= 1; |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
896 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
|
897 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
|
898 } |
ac437c3cf766
double buffering of spanpack/polgonpack
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
985
diff
changeset
|
899 |
792 | 900 |
925
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
901 if (profile) { |
983 | 902 if (frames % 50 == 49) { |
984 | 903 manager->show_profile(); |
983 | 904 this_time = get_ticks(); |
905 if (this_time != start_time) { | |
984 | 906 printf("\n%f FPS\n", ((((float)frames)*1000.0)/(this_time-start_time))); |
983 | 907 start_time = this_time; frames = 0; |
908 } | |
982
b29547a5b85b
avoid WAIT in virtual console
root@henri.cr.ie.u-ryukyu.ac.jp
parents:
981
diff
changeset
|
909 } |
925
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
910 } |
748 | 911 } |
912 | |
913 void | |
914 Viewer::run_finish() | |
915 { | |
916 dev->free_device(); | |
917 if (this_time != start_time) { | |
918 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
919 } | |
925
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
920 if (profile) { |
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
921 manager->show_profile(); |
9da903858400
add profile in Redering Engine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
918
diff
changeset
|
922 } |
748 | 923 |
924 delete sgroot; | |
925 // delete sgroot_2; | |
926 quit(); | |
507 | 927 } |
928 | |
929 /* end */ |