Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/viewer.cpp @ 138:3fd24be89d02
オブジェクトを増やして複数の表示に成功。
TODO:オブジェクトの削除
author | gongo@charles.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Fri, 28 Nov 2008 12:16:24 +0900 |
parents | 6cf991f28c6c |
children | 861271089c43 |
rev | line source |
---|---|
109 | 1 #include "viewer.h" |
120 | 2 #include "viewer_types.h" |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
3 #include "SceneGraph.h" |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
4 #include "scene_graph_pack.h" |
109 | 5 #include "sys.h" |
6 #include "Func.h" | |
7 #include "error.h" | |
8 #include "TaskManager.h" | |
9 | |
10 extern void post2runLoop(void *); | |
11 extern void post2runDraw(void *); | |
12 | |
13 /* measure for FPS (Frame Per Second) */ | |
14 int start_time; | |
15 int this_time; | |
16 int frames; | |
17 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
18 SceneGraph *scene_graph; |
109 | 19 |
20 /* Data Pack */ | |
21 SceneGraphPack *sgpack; | |
22 PolygonPack *ppack; | |
23 SpanPackPtr spackList; | |
24 SpanPackPtr *spackList_ptr; | |
25 int spackList_length; | |
26 int spackList_length_align; | |
27 | |
28 void *__texture; | |
29 | |
30 Viewer::Viewer(int b, int w, int h, int _num) | |
31 { | |
32 bpp = b; | |
33 width = w; | |
34 height = h; | |
35 spe_num = _num; | |
36 } | |
37 | |
38 int | |
39 Viewer::get_ticks() | |
40 { | |
41 int time; | |
42 time = SDL_GetTicks(); | |
43 return time; | |
44 } | |
45 | |
46 bool | |
47 Viewer::quit_check() | |
48 { | |
49 SDL_Event event; | |
50 | |
51 while(SDL_PollEvent(&event)) { | |
52 if (event.type==SDL_QUIT) { | |
53 return true; | |
54 } | |
55 } | |
56 | |
57 Uint8 *keys=SDL_GetKeyState(NULL); | |
58 | |
59 if (keys[SDLK_q] == SDL_PRESSED) { | |
60 return true; | |
61 } | |
62 | |
63 return false; | |
64 } | |
65 | |
66 void | |
67 Viewer::quit() | |
68 { | |
69 SDL_Quit(); | |
70 } | |
71 | |
72 void | |
73 Viewer::swap_buffers() | |
74 { | |
75 SDL_GL_SwapBuffers(); | |
76 } | |
77 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
78 extern void node_init(void); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
79 |
109 | 80 void |
81 Viewer::run_init(char *xml) | |
82 { | |
83 HTaskPtr task_next; | |
84 HTaskPtr task_init_tex; | |
85 | |
86 start_time = get_ticks(); | |
87 this_time = 0; | |
88 frames = 0; | |
89 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
90 scene_graph = SceneGraph::createFromXMLfile(xml); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
91 //polygon->viewer = this; |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
92 |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
93 node_init(); |
109 | 94 |
95 sgpack = (SceneGraphPack*)manager->malloc(sizeof(SceneGraphPack)); | |
96 sgpack->init(); | |
97 ppack = (PolygonPack*)manager->malloc(sizeof(PolygonPack)); | |
98 | |
99 spackList_length = (this->height + split_screen_h - 1) / split_screen_h; | |
100 spackList = (SpanPack*)manager->malloc(sizeof(SpanPack)*spackList_length); | |
101 | |
102 // SPU に送る address list は 16 倍数でないといけない。 | |
103 // spackList_length*sizeof(SpanPack*) が 16 倍数になるような | |
104 // length_align を求めている。 | |
105 spackList_length_align = (spackList_length + 3)&(~3); | |
106 | |
107 /* 各 SPU が持つ、SpanPack の address list */ | |
108 spackList_ptr = (SpanPack**)manager->malloc(sizeof(SpanPack*)*spackList_length_align); | |
109 | |
110 for (int i = 0; i < spackList_length; i++) { | |
111 spackList_ptr[i] = &spackList[i]; | |
112 } | |
113 | |
126
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
114 for (int i = 1; i <= spackList_length; i++) { |
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
115 spackList[i-1].init(i*split_screen_h); |
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
116 } |
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
117 |
109 | 118 task_next = manager->create_task(TASK_DUMMY); |
119 task_next->set_post(&post2runLoop, NULL); | |
120 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
121 #if 0 |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
122 // 諸事情で、今は SceneGraphPack を作らずに |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
123 // そのまま SceneGraph でやっています |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
124 HTaskPtr task_sgp; |
109 | 125 task_sgp = manager->create_task(TASK_CREATE_SGP); |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
126 task_sgp->add_param((uint32)scene_graph); |
109 | 127 task_sgp->add_param((uint32)sgpack); |
128 task_next->wait_for(task_sgp); | |
129 task_sgp->spawn(); | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
130 #endif |
109 | 131 |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
132 int tex_width = scene_graph->texture_image->w; |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
133 int tex_height = scene_graph->texture_image->h; |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
134 int tex_blocksize = tex_width*tex_height*4; |
120 | 135 |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
136 __texture = (void*)manager->malloc(tex_blocksize); |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
137 memcpy(__texture, scene_graph->texture_image->pixels, tex_blocksize); |
120 | 138 |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
139 uint32 *tex_src = (uint32*)scene_graph->texture_image->pixels; |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
140 uint32 *tex_dest = (uint32*)manager->malloc(tex_blocksize); |
120 | 141 int tile_size = TEXTURE_SPLIT_PIXEL*TEXTURE_SPLIT_PIXEL; |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
142 int tile_num = tex_width*tex_height/tile_size; |
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
143 tile_num = (tile_num + 15)&(~15); |
120 | 144 void **tex_addrList = (void**)manager->malloc(sizeof(void*)*tile_num); |
145 | |
146 { | |
147 int t = 0; | |
148 | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
149 for (int y = 0; y < tex_height; y += TEXTURE_SPLIT_PIXEL) { |
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
150 for (int x = 0; x < tex_width; x += TEXTURE_SPLIT_PIXEL) { |
120 | 151 for (int j = 0; j < TEXTURE_SPLIT_PIXEL; j++) { |
152 for (int i = 0; i < TEXTURE_SPLIT_PIXEL; i++) { | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
153 tex_dest[t++] = tex_src[(x+i) + tex_width*(y+j)]; |
120 | 154 } |
155 } | |
156 } | |
157 } | |
158 | |
159 t = 0; | |
160 | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
161 for (int i = 0, t = 0; i < tex_width*tex_height; i += tile_size, t++) { |
120 | 162 tex_addrList[t] = (void*)&tex_dest[i]; |
163 } | |
164 } | |
165 | |
109 | 166 for (int i = 0; i < spe_num; i++) { |
167 task_init_tex = manager->create_task(TASK_INIT_TEXTURE); | |
120 | 168 task_init_tex->add_inData(tex_addrList, sizeof(void*)*tile_num); |
169 task_init_tex->add_param(tile_num); | |
109 | 170 task_init_tex->set_cpu(SPE_ANY); |
171 task_next->wait_for(task_init_tex); | |
172 task_init_tex->spawn(); | |
173 } | |
174 | |
175 task_next->spawn(); | |
176 } | |
177 | |
178 void | |
179 Viewer::run_loop(void) | |
180 { | |
181 HTaskPtr task_create_pp = NULL; | |
182 HTaskPtr task_create_sp = NULL; | |
183 HTaskPtr task_next; | |
184 bool quit_flg; | |
185 | |
186 quit_flg = quit_check(); | |
187 | |
188 if (quit_flg == true) { | |
189 this_time = get_ticks(); | |
190 run_finish(); | |
191 return; | |
192 } | |
193 | |
194 clean_pixels(); | |
195 | |
196 for (int i = 1; i <= spackList_length; i++) { | |
126
7635f223fc7d
fix RGBA mask (bgr -> rgba)
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
123
diff
changeset
|
197 spackList[i-1].reinit(i*split_screen_h); |
109 | 198 } |
199 | |
200 task_next = manager->create_task(TASK_DUMMY); | |
201 task_next->set_post(post2runDraw, NULL); | |
202 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
203 #if 0 |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
204 HTaskPtr task_update_sgp = NULL; |
109 | 205 task_update_sgp = manager->create_task(TASK_UPDATE_SGP); |
206 task_update_sgp->add_inData(sgpack, sizeof(SceneGraphPack)); | |
207 task_update_sgp->add_outData(sgpack, sizeof(SceneGraphPack)); | |
208 task_update_sgp->add_param(width); | |
209 task_update_sgp->add_param(height); | |
210 task_next->wait_for(task_update_sgp); | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
211 task_update_sgp->spawn(); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
212 #else |
138 | 213 scene_graph->all_execute(width, height); |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
214 #endif |
109 | 215 |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
216 #if 0 |
109 | 217 task_create_pp = manager->create_task(TASK_CREATE_PP); |
218 task_create_pp->add_inData(sgpack, sizeof(SceneGraphPack)); | |
219 task_create_pp->add_param((uint32)ppack); | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
220 #else |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
221 task_create_pp = manager->create_task(TASK_CREATE_PP2); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
222 task_create_pp->add_param((uint32)scene_graph); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
223 task_create_pp->add_param((uint32)ppack); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
224 #endif |
109 | 225 task_next->wait_for(task_create_pp); |
226 | |
227 int range_base = spe_num; | |
228 // 切り上げのつもり | |
229 int range = (spackList_length + range_base - 1) / range_base; | |
230 | |
231 for (int i = 0; i < range_base; i++) { | |
232 int index_start = range*i; | |
233 int index_end = (index_start + range >= spackList_length) | |
234 ? spackList_length : index_start + range; | |
235 | |
236 task_create_sp = manager->create_task(TASK_CREATE_SPAN); | |
237 task_create_sp->add_inData(ppack, sizeof(PolygonPack)); | |
238 task_create_sp->add_inData(spackList_ptr, | |
239 sizeof(SpanPack*)*spackList_length_align); | |
240 task_create_sp->add_inData(&spackList[index_start], sizeof(SpanPack)); | |
241 | |
242 task_create_sp->add_param(index_start); | |
243 | |
244 /** | |
133
435e0d24db39
DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
245 * ex. screen_height が 480, spenum が 6 の場合、各SPEのy担当範囲 |
109 | 246 * [ 1.. 80] [ 81..160] [161..240] |
247 * [241..320] [321..400] [401..480] | |
248 * | |
249 * ex. screen_height が 1080, spenum が 5 の場合、 | |
250 * [ 1..216] [217..432] [433..648] | |
251 * [649..864] [865..1080] | |
252 */ | |
253 task_create_sp->add_param(index_start*split_screen_h + 1); | |
254 task_create_sp->add_param(index_end*split_screen_h); | |
255 | |
256 task_next->wait_for(task_create_sp); | |
257 task_create_sp->wait_for(task_create_pp); | |
258 | |
259 task_create_sp->set_cpu(SPE_ANY); | |
260 task_create_sp->spawn(); | |
261 } | |
262 | |
263 task_create_pp->spawn(); | |
264 task_next->spawn(); | |
265 } | |
266 | |
267 void | |
268 Viewer::run_draw(void) | |
269 { | |
270 HTaskPtr task_next; | |
271 HTaskPtr task_draw; | |
272 | |
273 task_next = manager->create_task(TASK_DUMMY); | |
274 task_next->set_post(post2runLoop, NULL); | |
275 | |
276 ppack->clear(); | |
277 | |
278 for (int i = 0; i < spackList_length; i++) { | |
279 SpanPack *spack = &spackList[i]; | |
280 int startx = 1; | |
281 int endx = split_screen_w; | |
282 | |
283 int start_y = spack->info.y_top - split_screen_h + 1; | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
284 //int end_y = spack->info.y_top; |
109 | 285 int rangey = (start_y + split_screen_h - 1 > this->height) |
286 ? this->height - start_y + 1 : split_screen_h; | |
287 | |
288 while (startx < this->width) { | |
289 if (spack->info.size > 0) { | |
290 // Draw SpanPack | |
291 task_draw = manager->create_task(TASK_DRAW_SPAN); | |
292 task_draw->add_inData(spack, sizeof(SpanPack)); | |
293 } else { | |
294 // Draw Background (現在は塗りつぶし) | |
295 task_draw = manager->create_task(TASK_DRAW_BACK); | |
133
435e0d24db39
DrawSpan のテクスチャ座標を求める部分で、width と height が逆に使われてた。
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
130
diff
changeset
|
296 task_draw->add_param(0xffffff); |
109 | 297 } |
298 | |
299 for (int k = 0; k < rangey; k++) { | |
300 task_draw->add_outData( | |
128
776eca0daa02
texture load use hash table
gongo@charles.cr.ie.u-ryukyu.ac.jp
parents:
126
diff
changeset
|
301 &pixels[(startx-1)+this->width*(k+start_y-1)], |
109 | 302 (endx - startx + 1)*sizeof(int)); |
303 } | |
304 | |
305 task_draw->add_param(startx); | |
306 task_draw->add_param(endx); | |
307 task_draw->add_param(rangey); | |
308 task_draw->set_cpu(SPE_ANY); | |
309 task_next->wait_for(task_draw); | |
310 task_draw->spawn(); | |
311 | |
312 startx += split_screen_w; | |
313 endx += split_screen_w; | |
314 | |
315 if (endx > this->width) { | |
316 endx = this->width; | |
317 } | |
318 } | |
319 } | |
320 | |
321 task_next->spawn(); | |
322 | |
323 frames++; | |
324 } | |
325 | |
326 void | |
327 Viewer::run_finish(void) | |
328 { | |
329 if (this_time != start_time) { | |
330 printf("%f FPS\n", (((float)frames)/(this_time-start_time))*1000.0); | |
331 } | |
332 | |
137
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
333 scene_graph->delete_data(); |
6cf991f28c6c
SceneGraphPack の代わりに、今は SceneGraph をそのまま使う様に設定。
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
133
diff
changeset
|
334 delete scene_graph; |
109 | 335 |
336 free(__texture); | |
337 quit(); | |
338 } |