… | |
… | |
2 | |
2 | |
3 | #include <vector> |
3 | #include <vector> |
4 | |
4 | |
5 | using namespace std; |
5 | using namespace std; |
6 | |
6 | |
7 | #define GL_GLEXT_PROTOTYPES |
|
|
8 | #include <GL/gl.h> |
7 | #include <GL/gl.h> |
9 | #include <GL/glext.h> |
|
|
10 | |
8 | |
11 | #include "oct.h" |
9 | #include "oct.h" |
12 | #include "view.h" |
10 | #include "view.h" |
13 | #include "entity.h" |
11 | #include "entity.h" |
14 | |
|
|
15 | vector<GLuint> occ_query_objects; |
|
|
16 | |
|
|
17 | static GLuint begin_occ_query () |
|
|
18 | { |
|
|
19 | GLuint id; |
|
|
20 | |
|
|
21 | if (occ_query_objects.size ()) |
|
|
22 | { |
|
|
23 | id = *(occ_query_objects.end () - 1); |
|
|
24 | occ_query_objects.pop_back (); |
|
|
25 | } |
|
|
26 | else |
|
|
27 | glGenQueriesARB (1, &id); |
|
|
28 | |
|
|
29 | glBeginQueryARB (GL_SAMPLES_PASSED, id); |
|
|
30 | return id; |
|
|
31 | } |
|
|
32 | |
|
|
33 | #define end_occ_query() glEndQueryARB (GL_SAMPLES_PASSED) |
|
|
34 | |
|
|
35 | GLuint occ_query_result (GLuint id) |
|
|
36 | { |
|
|
37 | GLuint count; |
|
|
38 | |
|
|
39 | glGetQueryObjectuivARB (id, GL_QUERY_RESULT, &count); |
|
|
40 | occ_query_objects.push_back (id); |
|
|
41 | |
|
|
42 | return count; |
|
|
43 | } |
|
|
44 | |
12 | |
45 | octant world(0, sector (SOFFS_MIN, SOFFS_MIN, SOFFS_MIN), MAXEXTENT); |
13 | octant world(0, sector (SOFFS_MIN, SOFFS_MIN, SOFFS_MIN), MAXEXTENT); |
46 | |
14 | |
47 | octant::octant (octant *parent, const sector &orig, uoffs extent) |
15 | octant::octant (octant *parent, const sector &orig, uoffs extent) |
48 | : parent(parent), orig(orig), extent(extent) |
16 | : parent(parent), orig(orig), extent(extent) |
… | |
… | |
117 | vs.visibility = visibility_state::PARTIAL; |
85 | vs.visibility = visibility_state::PARTIAL; |
118 | vs.generation = ctx.generation; |
86 | vs.generation = ctx.generation; |
119 | } |
87 | } |
120 | else |
88 | else |
121 | { |
89 | { |
122 | sector center_s (orig + extent / 2 - ctx.orig); |
90 | GLfloat extent2 = 0.5F * (GLfloat)extent; |
123 | point center (center_s.x, center_s.y, center_s.z); |
91 | point center = point (orig) + extent2 - point (ctx.orig); |
124 | |
92 | |
125 | GLfloat dia = sqrtf (3) * (GLfloat)extent; |
93 | GLfloat rad = ctx.diagfact * extent2; |
126 | GLfloat rad = dia * 0.5; |
|
|
127 | |
94 | |
128 | if (ctx.frustum.t.distance (center) < -rad) return; |
95 | if (ctx.frustum.t.distance (center) < -rad) return; |
129 | if (ctx.frustum.b.distance (center) < -rad) return; |
96 | if (ctx.frustum.b.distance (center) < -rad) return; |
130 | if (ctx.frustum.l.distance (center) < -rad) return; |
97 | if (ctx.frustum.l.distance (center) < -rad) return; |
131 | if (ctx.frustum.r.distance (center) < -rad) return; |
98 | if (ctx.frustum.r.distance (center) < -rad) return; |
… | |
… | |
133 | |
100 | |
134 | GLfloat fd = ctx.frustum.f.distance (center); |
101 | GLfloat fd = ctx.frustum.f.distance (center); |
135 | |
102 | |
136 | if (fd < -rad) |
103 | if (fd < -rad) |
137 | { |
104 | { |
138 | if (fd < -dia) |
105 | if (fd < -rad * 3.F) |
139 | return; |
106 | return; |
140 | |
107 | |
141 | ctx.farlist.push_back (this); |
108 | ctx.farlist.push_back (this); |
142 | return; |
109 | return; |
143 | } |
110 | } |
… | |
… | |
191 | s.z + !!(j & 4) * extent); |
158 | s.z + !!(j & 4) * extent); |
192 | } |
159 | } |
193 | } |
160 | } |
194 | |
161 | |
195 | glEnd (); |
162 | glEnd (); |
196 | glDisable(GL_COLOR_MATERIAL); |
|
|
197 | #endif |
163 | #endif |
198 | |
164 | |
199 | for (iterator i = end (); i != begin (); ) |
165 | for (iterator i = end (); i != begin (); ) |
200 | (*--i)->display (ctx); |
166 | (*--i)->display (ctx); |
201 | } |
167 | } |
202 | |
168 | |
203 | void |
|
|
204 | octant::draw_bbox (view &ctx) |
169 | void octant::draw_bbox (view &ctx) |
205 | { |
170 | { |
206 | sector s = orig - ctx.orig; |
171 | sector s = orig - ctx.orig; |
207 | |
172 | |
208 | gl::draw_box (ctx, s, s + extent); |
173 | gl::draw_box (ctx, s, s + extent); |
209 | } |
174 | } |
210 | |
175 | |
|
|
176 | void octant::event (occ_query &ev) |
|
|
177 | { |
|
|
178 | if (ev.r <= 5) |
|
|
179 | return; |
211 | |
180 | |
|
|
181 | ev.v.vismap[this].visibility = visibility_state::FULL; |
|
|
182 | ev.v.far = ev.v.near + ev.v.frustum.n.distance (orig); |
|
|
183 | printf ("OCT(%x,%x,%x+%x) samples %d\n", orig.x, orig.y, orig.z, extent, ev.r); |
|
|
184 | } |
|
|
185 | |