annotate TaskManager/Test/test_render/viewer.cpp @ 130:40978d4b608a draft

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