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