… | |
… | |
5 | #include "view.h" |
5 | #include "view.h" |
6 | #include "oct.h" |
6 | #include "oct.h" |
7 | |
7 | |
8 | using namespace gl; |
8 | using namespace gl; |
9 | |
9 | |
|
|
10 | pass pass_depth (0); |
|
|
11 | |
10 | vector<GLuint> occ_query_objects; |
12 | vector<GLuint> occ_query_objects; |
11 | |
13 | |
12 | static GLuint begin_occ_query () |
14 | static GLuint begin_occ_query () |
13 | { |
15 | { |
14 | GLuint id; |
16 | GLuint id; |
… | |
… | |
17 | { |
19 | { |
18 | id = *(occ_query_objects.end () - 1); |
20 | id = *(occ_query_objects.end () - 1); |
19 | occ_query_objects.pop_back (); |
21 | occ_query_objects.pop_back (); |
20 | } |
22 | } |
21 | else |
23 | else |
22 | glGenQueriesARB (1, &id); |
24 | glGenQueries (1, &id); |
23 | |
25 | |
24 | glBeginQueryARB (GL_SAMPLES_PASSED, id); |
26 | glBeginQuery (GL_SAMPLES_PASSED, id); |
25 | return id; |
27 | return id; |
26 | } |
28 | } |
27 | |
29 | |
28 | inline void end_occ_query () |
30 | inline void end_occ_query () |
29 | { |
31 | { |
30 | glEndQueryARB (GL_SAMPLES_PASSED); |
32 | glEndQuery (GL_SAMPLES_PASSED); |
31 | } |
33 | } |
32 | |
34 | |
33 | static GLuint occ_query_result (GLuint id) |
35 | static GLuint occ_query_result (GLuint id) |
34 | { |
36 | { |
35 | GLuint count; |
37 | GLuint count; |
36 | |
38 | |
37 | glGetQueryObjectuivARB (id, GL_QUERY_RESULT, &count); |
39 | glGetQueryObjectuiv (id, GL_QUERY_RESULT, &count); |
38 | occ_query_objects.push_back (id); |
40 | occ_query_objects.push_back (id); |
39 | |
41 | |
40 | return count; |
42 | return count; |
41 | } |
43 | } |
42 | |
44 | |
… | |
… | |
128 | diagfact = abs (rz.x) + abs (rz.y) + abs (rz.z); |
130 | diagfact = abs (rz.x) + abs (rz.y) + abs (rz.z); |
129 | //printf ("diagfact = %f\n", diagfact); |
131 | //printf ("diagfact = %f\n", diagfact); |
130 | diagfact = sqrtf (3.);//D WHY??? |
132 | diagfact = sqrtf (3.);//D WHY??? |
131 | |
133 | |
132 | glMultMatrixf (m); |
134 | glMultMatrixf (m); |
133 | glTranslatef (-p.x, -p.y, -p.z); |
|
|
134 | |
135 | |
135 | glGetFloatv (GL_PROJECTION_MATRIX, m); |
136 | glGetFloatv (GL_PROJECTION_MATRIX, m); |
136 | |
137 | |
137 | frustum.l = plane ( m(3,0) + m(0,0), m(3,1) + m(0,1), m(3,2) + m(0,2), m(3,3) + m(0,3) ); |
138 | frustum.l = plane ( m(3,0) + m(0,0), m(3,1) + m(0,1), m(3,2) + m(0,2), m(3,3) + m(0,3) ); |
138 | frustum.r = plane ( m(3,0) - m(0,0), m(3,1) - m(0,1), m(3,2) - m(0,2), m(3,3) - m(0,3) ); |
139 | frustum.r = plane ( m(3,0) - m(0,0), m(3,1) - m(0,1), m(3,2) - m(0,2), m(3,3) - m(0,3) ); |
… | |
… | |
157 | frustum.c = cone (p, d, atan (sqrt (GLdouble (w * w + h * h)) * ftan / h)); |
158 | frustum.c = cone (p, d, atan (sqrt (GLdouble (w * w + h * h)) * ftan / h)); |
158 | } |
159 | } |
159 | |
160 | |
160 | glMatrixMode (GL_MODELVIEW); |
161 | glMatrixMode (GL_MODELVIEW); |
161 | glLoadIdentity (); |
162 | glLoadIdentity (); |
|
|
163 | glTranslatef (-p.x, -p.y, -p.z); |
162 | } |
164 | } |
163 | |
165 | |
164 | void view::begin () |
166 | void view::begin () |
165 | { |
167 | { |
166 | generation++; |
168 | generation++; |
… | |
… | |
182 | vislist.clear (); |
184 | vislist.clear (); |
183 | } |
185 | } |
184 | |
186 | |
185 | #define DEPTH_OFFSET (1. / (GLdouble)(1L << 16)) |
187 | #define DEPTH_OFFSET (1. / (GLdouble)(1L << 16)) |
186 | |
188 | |
187 | void view::render (enum pass p) |
189 | void view::render (enum pass_type p, pass &data) |
188 | { |
190 | { |
189 | pass = p; |
191 | pass_type = p; |
|
|
192 | pass_data = &data; |
190 | |
193 | |
191 | switch (pass) |
194 | switch (pass_type) |
192 | { |
195 | { |
193 | case DEPTH: |
196 | case DEPTH: |
194 | glColorMask (1, 1, 1, 1); |
197 | glColorMask (1, 1, 1, 1); |
195 | glDepthMask (1); |
198 | glDepthMask (1); |
196 | |
199 | |
… | |
… | |
246 | } |
249 | } |
247 | |
250 | |
248 | for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i) |
251 | for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i) |
249 | (*i)->display (*this); |
252 | (*i)->display (*this); |
250 | |
253 | |
251 | if (pass == LIGHTED) |
254 | if (pass_type == DEPTH) |
252 | printf ("fps %f NF %f:%f vis %d CAM (%d,%d,%d)\n", timer.fps, z_near, z_far, drawn.size (), orig.x, orig.y, orig.z);//D |
255 | printf ("fps %f NF %f:%f vis %d CAM (%d,%d,%d)\n", timer.fps, z_near, z_far, drawn.size (), orig.x, orig.y, orig.z);//D |
253 | |
256 | |
254 | drawn.clear (); |
257 | drawn.clear (); |
255 | |
258 | |
256 | #if 0 |
259 | #if 0 |
… | |
… | |
270 | glDisable (GL_DEPTH_CLAMP_NV); |
273 | glDisable (GL_DEPTH_CLAMP_NV); |
271 | } |
274 | } |
272 | #endif |
275 | #endif |
273 | } |
276 | } |
274 | |
277 | |
|
|
278 | void light::enable () |
|
|
279 | { |
|
|
280 | lightpos->set (p); |
|
|
281 | } |
275 | |
282 | |
|
|
283 | void light::disable () |
|
|
284 | { |
|
|
285 | } |
|
|
286 | |
|
|
287 | static shader::varying_1f camdist; |
|
|
288 | static shader::varying_3f lightvec; |
|
|
289 | |
|
|
290 | void linear_light::vsh () |
|
|
291 | { |
|
|
292 | using namespace shader::compile; |
|
|
293 | |
|
|
294 | lightvec = xyz (lightpos - model_view_matrix * vin.vertex); |
|
|
295 | camdist = max (1 - length (lightvec) / radius, 0); |
|
|
296 | } |
|
|
297 | |
|
|
298 | shader::temp_3f linear_light::operator ()() |
|
|
299 | { |
|
|
300 | using namespace shader::compile; |
|
|
301 | |
|
|
302 | temp_3f res; |
|
|
303 | res = float3 (c.r / 255.F, c.g / 255.F, c.b / 255.F) * (min (intensity * camdist * 0.6F + 0.9F, 1.F)); |
|
|
304 | |
|
|
305 | return res; |
|
|
306 | } |
|
|
307 | |
|
|
308 | |