… | |
… | |
8 | using namespace std; |
8 | using namespace std; |
9 | |
9 | |
10 | #include "util.h" |
10 | #include "util.h" |
11 | #include "event.h" |
11 | #include "event.h" |
12 | |
12 | |
13 | struct visibility_state { |
13 | struct visibility_base |
14 | unsigned int generation; |
14 | { |
15 | enum { UNKNOWN, OCCLUDED, PARTIAL, FULL } visibility; |
15 | unsigned int generation; // freshness check |
16 | double last; |
|
|
17 | |
|
|
18 | visibility_state () : generation(0), last(0.), visibility(UNKNOWN) { }; |
|
|
19 | }; |
16 | }; |
20 | |
17 | |
21 | struct occ_query { |
18 | struct visible { |
22 | struct view &v; |
19 | visibility_base *get_visibility (view &ctx); |
23 | GLuint id; |
20 | virtual visibility_base *new_visibility () = 0; |
24 | GLuint r; |
21 | virtual void clear_visibility (visibility_base *vs) = 0; |
|
|
22 | }; |
25 | |
23 | |
26 | occ_query (view &v, GLuint id, GLuint r) : v(v), id(id), r(r) { }; |
24 | struct occ_query |
|
|
25 | { |
|
|
26 | struct view &ctx; |
|
|
27 | void *id; |
|
|
28 | GLuint count; |
|
|
29 | |
|
|
30 | occ_query (view &ctx, void *id, GLuint count) : ctx(ctx), id(id), count(count) { }; |
27 | }; |
31 | }; |
28 | |
32 | |
29 | typedef event_receiver<void, occ_query> recv_occ_query; |
33 | typedef event_receiver<void, occ_query> recv_occ_query; |
30 | |
34 | |
31 | struct view { |
35 | struct view |
|
|
36 | { |
32 | sector orig; |
37 | sector orig; |
33 | point p; |
38 | point p; |
34 | vec3 d, u; |
39 | vec3 d, u; |
35 | GLfloat fov; |
40 | GLfloat fov; |
36 | GLfloat near, far; |
41 | GLfloat z_near, z_far, c_far; |
37 | int w, h; |
42 | int w, h; |
|
|
43 | GLfloat pixfact; // how many pixels on screen are drawn by a unit length line, *roughly* |
38 | |
44 | |
39 | GLfloat gamma; |
45 | GLfloat gamma; |
40 | |
46 | |
41 | // only to be used by friends: TODO |
47 | // only to be used by friends: TODO |
42 | |
48 | |
43 | GLfloat nextfar; |
49 | GLfloat nz_far, nc_far; |
44 | GLfloat diagfact; // bounding box border to depth factor |
50 | GLfloat diagfact; // bounding box border to depth factor |
|
|
51 | GLfloat perspfact; // perspfact * (1/depth)=> pixels |
45 | |
52 | |
46 | matrix projection; |
53 | gl::matrix projection; |
47 | |
54 | |
48 | struct { |
55 | struct { |
49 | plane l, r, t, b, n, f; |
56 | plane l, r, t, b, n, f; |
50 | } frustum; |
57 | } frustum; |
51 | |
58 | |
52 | enum mode { DEPTH, LIGHTED } mode; |
59 | // the passes |
|
|
60 | enum pass { |
|
|
61 | DEPTH, // mandatory, render depth only |
|
|
62 | POSTDEPTH, // mandatory, occ tests or ignored |
|
|
63 | LIGHTED, // optional, render faces in full glory |
|
|
64 | } pass; |
|
|
65 | |
53 | light *l; |
66 | struct light *l; |
54 | set<const entity *> drawn; |
67 | set<const entity *> drawn; // TODO: put drawn info and octant+entity visibility info into vismap! |
55 | |
68 | |
56 | unsigned int generation; |
69 | unsigned int generation; |
57 | map<octant *, visibility_state> vismap; |
70 | typedef map<visible *, visibility_base *> visibility_map; |
|
|
71 | visibility_map vismap; |
58 | |
72 | |
59 | vector<octant *> vislist; // octants partially or fully visible in frustum |
73 | vector<octant *> vislist; // octants that want to be drawn |
60 | vector<octant *> farlist; // octants possibly visible |
|
|
61 | |
74 | |
62 | typedef pair<recv_occ_query *, GLint> oq_data; |
75 | struct oq_data { |
|
|
76 | recv_occ_query *recv; |
|
|
77 | GLint id; |
|
|
78 | void *data; |
|
|
79 | |
|
|
80 | oq_data (recv_occ_query *recv, GLint id, void *data) : recv(recv), id(id), data(data) { }; |
|
|
81 | }; |
63 | vector<oq_data> occ_queries; |
82 | vector<oq_data> occ_queries; |
64 | void begin_occ_query (recv_occ_query &recv); |
83 | void begin_occ_query (recv_occ_query &recv, void *id = 0); |
65 | void end_occ_query (); |
84 | void end_occ_query (); |
66 | |
85 | |
67 | void reset_projection (); |
86 | void reset_projection (); |
68 | |
87 | |
69 | // public |
88 | // public |
70 | |
89 | |
71 | void begin (); |
90 | void begin (); |
72 | void pass (enum mode m); |
91 | void render (enum pass p); |
73 | void end (); |
92 | void end (); |
74 | |
93 | |
75 | bool may_draw (const entity *e); |
94 | bool may_draw (const entity *e); |
76 | |
95 | |
77 | view (); |
96 | view (); |