annotate TaskManager/Test/test_render/viewer.cpp @ 132:e7c80537b6aa

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