annotate TaskManager/Test/simple_render/viewer.cpp @ 51:c964110017c8

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 19:44:23 +0900
parents 7927e00fb8e2
children 90523ccc4dff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
1 #include <iostream>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
2 #include <SDL.h>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
3 #include <SDL_opengl.h>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
4 #include <math.h>
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
5 #include <unistd.h>
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
6 #include "polygon.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
7 #include "viewer.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
8 #include "sys.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
9 using namespace std;
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
10
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
11 #define redMask 0x00ff0000
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
12 #define greenMask 0x0000ff00
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
13 #define blueMask 0x000000ff
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
14 #define alphaMask 0
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
15
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
16 extern int create_sgp(Polygon *sg, SceneGraphPack *sgp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
17 extern int update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp);
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
18 extern int create_pp(SceneGraphPack *sgp, PolygonPack *pp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
19
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
20 Viewer::Viewer(int b, int w, int h)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
21 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
22 bpp = b;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
23 width = w;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
24 height = h;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
25 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
27
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
28 void Viewer::sdl_init()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
29 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
30 if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
31 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
32 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
33 exit( 1 );
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
34 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
35 screen = SDL_SetVideoMode( width, height, bpp, SDL_HWSURFACE );
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
36 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
37
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
38
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
39 int Viewer::get_ticks()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
40 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
41 int time;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
42 time = SDL_GetTicks();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
43 return time;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
44 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
45
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
46 bool Viewer::quit_check()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
47 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
48 bool quit = false;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
49 SDL_Event event;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
50 while(SDL_PollEvent(&event))
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
51 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
52 if(event.type==SDL_QUIT)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
53 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
54 quit = true;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
55 return quit;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
56 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
57 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
58 return quit;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
59 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
60
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
61 void Viewer::quit()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
62 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
63 SDL_Quit();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
64 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
65
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
66
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
67 void Viewer::swap_buffers()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
68 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
69 SDL_GL_SwapBuffers();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
70 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
71
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
72
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
73 void
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
74 Viewer::write_pixel(int x, int y,float z, Uint32 rgb)
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
75 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
76 SDL_PixelFormat *pf;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
77 pf = screen->format;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
78 x += width/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
79 y += height/2;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
80
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
81 static int diffz,diffz1;
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
82
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
83 diffz1 = diffz;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
84 diffz = (zRow[x][y]>z);
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
85 if (z < zRow[x][y]) {
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
86 if (x < width && x > 0 && y > 0 && y < height) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
87 zRow[x][y] = z;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
88 y = height - y;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
89 pixels[width*y + x] = rgb;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
90 }
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
91 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
92 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
93
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
94 void
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
95 Viewer::write_line(float x1, float y1, float x2, float y2, Uint32 rgb)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
96 {
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
97 if (x1 > x2) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
98 float x=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
99 float y=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
100 x=x1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
101 y=y1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
102 x1 = x2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
103 y1 = y2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
104 x2 = x;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
105 y2 = y;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
106 }
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
107
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
108 float s = y1;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
109
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
110 if ((int)x1 == (int)x2) {
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
111 if (y1 > y2) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
112 float y=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
113 y = y1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
114 y1 = y2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
115 y2 = y;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
116 }
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
117
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
118 for (float i=y1; i<y2; i++) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
119 //write_pixel((int)x1,(int)i);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
120 write_pixel((int)x1,(int)i,0,rgb);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
121 }
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
122 } else {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
123 float t = (y2 - y1)/(x2 - x1);
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
124 if (t < -1) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
125 float f = 0;
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
126 for (float i=x1; i<x2; i++) {
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
127 for (float a=(int)t; a<0; a++) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
128 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
129 s--;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
130 }
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
131
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
132 f += t-(int)t;
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
133
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
134 if (f <= -1) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
135 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
136 f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
137 s--;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
138 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
139 }
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
140 } else if (t <= 1) {
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
141 for(float i=x1; i<x2; i++) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
142 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
143 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
144 s += t;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
145 }
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
146 } else {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
147 float f = 0;
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
148 for (float i=x1; i<x2; i++) {
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
149 for (float a=0; a<(int)t; a++) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
150 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
151 s++;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
152 }
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
153
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
154 f += t-(int)t;
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
155
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
156 if (f >= 1) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
157 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
158 f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
159 s++;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
160 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
161 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
162 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
163 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
164 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
165
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
166 void Viewer::write_triangle(float x1, float y1, float x2, float y2, float x3, float y3, Uint32 rgb)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
167 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
168 write_line(x1,y1,x2,y2,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
169 write_line(x2,y2,x3,y3,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
170 write_line(x3,y3,x1,y1,rgb);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
171 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
172
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
173 void Viewer::clean_pixels()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
174 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
175 for(int i=0; i<width*height; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
176 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
177 pixels[i] = 0x00;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
178 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
179 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
180
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
181 void Viewer::graph_line()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
182 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
183 int xl = width*height/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
184 int yl = width/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
185 for(int i=0; i<width; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
186 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
187 for(int t=0; t<height; t+=20)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
188 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
189 pixels[width*t+i] = 0x5a;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
190 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
191 pixels[xl +i] = 0xff;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
192 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
193 for(int i=0; i<height; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
194 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
195 for(int t=0; t<width; t+=20)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
196 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
197 pixels[i*width+t] = 0x5a;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
198 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
199 pixels[i*width+yl] = 0xff;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
200 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
201 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
202
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
203
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
204 struct run_arg_t {
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
205 int start_time;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
206 int this_time;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
207 int frames;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
208 SDL_Surface *bitmap;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
209 SDL_PixelFormat *pf;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
210 Uint32 background;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
211 Polygon *p;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
212 SceneGraphPack *sgp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
213 PolygonPack *pp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
214 };
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
215
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
216 struct run_arg_t *arg;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
217
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
218 void
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
219 Viewer::run_init()
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
220 {
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
221 arg = new run_arg_t;
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
222 HTaskPtr task;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
223 int fd;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
224
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
225 arg->start_time = get_ticks();
51
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
226 arg->this_time = 0;
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
227 arg->frames = 0;
c964110017c8 *** empty log message ***
gongo
parents: 50
diff changeset
228
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
229 arg->pf = screen->format;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
230 arg->background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
231 arg->p = new Polygon;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
232 arg->p->set_data("cube.xml");
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
233 arg->p->viewer = this;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
234 arg->sgp = new SceneGraphPack;
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
235 create_sgp(arg->p, arg->sgp);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
236 arg->pp = new PolygonPack;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
237
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
238 pixels = new Uint32[width*height];
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
239
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
240 graph_line();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
241
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
242 arg->bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32,
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
243 width*4, redMask, greenMask,
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
244 blueMask, alphaMask);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
245
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
246 fd = manager->open("ViewerRunLoop");
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
247 task = manager->create_task(fd, 0, 0, 0, NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
248 manager->spawn_task(task);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
249 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
250
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
251 void
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
252 Viewer::run_loop(void)
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
253 {
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
254 HTaskPtr task_update_sgp = NULL;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
255 HTaskPtr task_create_pp = NULL;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
256 HTaskPtr task_finish = NULL;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
257 int fd_update_sgp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
258 int fd_create_pp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
259 int fd_finish;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
260
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
261 HTaskPtr task;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
262 int fd;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
263
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
264 if (quit_check()) {
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
265 arg->this_time = get_ticks();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
266 fd_finish = manager->open("ViewerRunFinish");
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
267 task_finish = manager->create_task(fd_finish, 0, 0, 0, NULL);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
268 manager->spawn_task(task_finish);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
269 return;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
270 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
271
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
272 clean_pixels();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
273
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
274 zRow_init();
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
275 graph_line();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
276
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
277 fd_update_sgp = manager->open("UpdateSGP");
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
278 fd_create_pp = manager->open("CreatePP");
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
279 fd = manager->open("ViewerRunDraw");
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
280 task_update_sgp = manager->create_task(fd_update_sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
281 sizeof(SceneGraphPack),
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
282 (unsigned int)arg->sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
283 (unsigned int)arg->sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
284 NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
285 task_create_pp = manager->create_task(fd_create_pp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
286 sizeof(SceneGraphPack),
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
287 (unsigned int)arg->sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
288 (unsigned int)arg->pp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
289 NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
290 task = manager->create_task(fd, 0, 0, 0, NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
291
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
292 manager->set_task_depend(task_update_sgp, task);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
293 manager->set_task_depend(task_create_pp, task);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
294
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
295 manager->spawn_task(task_update_sgp);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
296 manager->spawn_task(task_create_pp);
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
297 manager->spawn_task(task);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
298 }
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
299
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
300 void
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
301 Viewer::run_draw(void)
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
302 {
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
303 HTaskPtr task;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
304 int fd;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
305
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
306 arg->p->draw(arg->pp); // test draw of PolygonPack
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
307
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
308 SDL_BlitSurface(arg->bitmap, NULL, screen, NULL);
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
309 SDL_UpdateRect(screen, 0, 0, 0, 0);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
310
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
311 arg->frames++;
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
312
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
313 fd = manager->open("ViewerRunLoop");
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
314 task = manager->create_task(fd, 0, 0, 0, NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
315 manager->spawn_task(task);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
316 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
317
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
318 void
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
319 Viewer::run_finish(void)
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
320 {
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
321 if (arg->this_time != arg->start_time) {
50
7927e00fb8e2 *** empty log message ***
gongo
parents: 49
diff changeset
322 cout<< (((float)arg->frames)/(arg->this_time-arg->start_time))*1000.0 << " FPS\n";
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
323 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
324
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
325 SDL_FreeSurface(arg->bitmap);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
326 delete [] pixels;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
327 arg->p->delete_data();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
328 delete arg->p;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
329 delete arg->sgp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
330 delete arg->pp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
331 quit();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
332
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
333 delete arg;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
334 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
335
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
336 void
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
337 Viewer::zRow_init()
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
338 {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
339 for (int i = 0; i < width; i++) {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
340 for (int j = 0; j < height; j++) {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
341 zRow[i][j] = 65535;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
342 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
343 }
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
344 }