… | |
… | |
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 | { |
14 | { |
15 | unsigned int generation; |
15 | unsigned int generation; // freshness check |
16 | enum { UNKNOWN, OCCLUDED, PARTIAL, FULL } visibility; |
16 | }; |
17 | double last; |
|
|
18 | |
17 | |
19 | visibility_state () : generation(0), last(0.), visibility(UNKNOWN) { }; |
18 | struct visible { |
|
|
19 | visibility_base *get_visibility (view &ctx); |
|
|
20 | virtual visibility_base *new_visibility () = 0; |
|
|
21 | virtual void clear_visibility (visibility_base *vs) = 0; |
20 | }; |
22 | }; |
21 | |
23 | |
22 | struct occ_query |
24 | struct occ_query |
23 | { |
25 | { |
24 | struct view &v; |
26 | struct view &ctx; |
25 | GLuint id; |
27 | void *id; |
26 | GLuint r; |
28 | GLuint count; |
27 | |
29 | |
28 | occ_query (view &v, GLuint id, GLuint r) : v(v), id(id), r(r) { }; |
30 | occ_query (view &ctx, void *id, GLuint count) : ctx(ctx), id(id), count(count) { }; |
29 | }; |
31 | }; |
30 | |
32 | |
31 | typedef event_receiver<void, occ_query> recv_occ_query; |
33 | typedef event_receiver<void, occ_query> recv_occ_query; |
|
|
34 | |
|
|
35 | struct pass |
|
|
36 | { |
|
|
37 | struct light *l; |
|
|
38 | |
|
|
39 | pass (light *l) : l(l) { } |
|
|
40 | }; |
|
|
41 | |
|
|
42 | extern pass pass_depth; |
32 | |
43 | |
33 | struct view |
44 | struct view |
34 | { |
45 | { |
35 | sector orig; |
46 | sector orig; |
36 | point p; |
47 | point p; |
37 | vec3 d, u; |
48 | vec3 d, u; |
38 | GLfloat fov; |
49 | GLfloat fov; |
39 | GLfloat z_near, z_far, c_far; |
50 | GLfloat z_near, z_far, c_far; |
40 | int w, h; |
51 | int w, h; |
|
|
52 | GLfloat pixfact; // how many pixels on screen are drawn by a unit length line, *roughly* |
|
|
53 | sector eorig; // orig of currently-rendered entity in relation to the camera |
41 | |
54 | |
42 | GLfloat gamma; |
55 | GLfloat gamma; |
43 | |
56 | |
44 | // only to be used by friends: TODO |
57 | // only to be used by friends: TODO |
45 | |
58 | |
46 | GLfloat nz_far, nc_far; |
59 | GLfloat nz_far, nz_near, nc_far; |
47 | GLfloat diagfact; // bounding box border to depth factor |
60 | GLfloat diagfact; // bounding box border to depth factor |
|
|
61 | GLfloat perspfact; // perspfact * (1/depth)=> pixels |
48 | |
62 | |
49 | matrix projection; |
63 | gl::matrix projection; |
50 | |
64 | |
51 | struct { |
65 | struct { |
52 | plane l, r, t, b, n, f; |
66 | plane l, r, t, b, n, f; |
|
|
67 | cone c; |
|
|
68 | sphere s; |
53 | } frustum; |
69 | } frustum; |
54 | |
70 | |
55 | enum mode { DEPTH, LIGHTED } mode; |
71 | // the passes |
56 | struct light *l; |
72 | enum pass_type { |
57 | set<const entity *> drawn; |
73 | DEPTH, // mandatory, render depth only |
|
|
74 | POSTDEPTH, // mandatory, occ tests or ignored |
|
|
75 | LIGHTED, // optional, render faces in full glory |
|
|
76 | } pass_type; |
|
|
77 | |
|
|
78 | pass *pass_data; |
|
|
79 | |
|
|
80 | set<const entity *> drawn; // TODO: put drawn info and octant+entity visibility info into vismap! |
58 | |
81 | |
59 | unsigned int generation; |
82 | unsigned int generation; |
60 | map<octant *, visibility_state> vismap; |
83 | typedef map<visible *, visibility_base *> visibility_map; |
|
|
84 | visibility_map vismap; |
61 | |
85 | |
62 | vector<octant *> vislist; // octants partially or fully visible in frustum |
86 | vector<octant *> vislist; // octants that want to be drawn |
63 | vector<octant *> farlist; // octants possibly visible |
|
|
64 | |
87 | |
65 | typedef pair<recv_occ_query *, GLint> oq_data; |
88 | struct oq_data { |
|
|
89 | recv_occ_query *recv; |
|
|
90 | GLint id; |
|
|
91 | void *data; |
|
|
92 | |
|
|
93 | oq_data (recv_occ_query *recv, GLint id, void *data) : recv(recv), id(id), data(data) { }; |
|
|
94 | }; |
66 | vector<oq_data> occ_queries; |
95 | vector<oq_data> occ_queries; |
67 | void begin_occ_query (recv_occ_query &recv); |
96 | void begin_occ_query (recv_occ_query &recv, void *id = 0); |
68 | void end_occ_query (); |
97 | void end_occ_query (); |
69 | |
98 | |
70 | void reset_projection (); |
99 | void reset_projection (); |
71 | |
100 | |
72 | // public |
101 | // public |
73 | |
102 | |
74 | void begin (); |
103 | void begin (); |
75 | void pass (enum mode m); |
104 | void render (enum pass_type p, pass &data); |
76 | void end (); |
105 | void end (); |
77 | |
106 | |
78 | bool may_draw (const entity *e); |
107 | bool may_draw (const entity *e); |
79 | |
108 | |
80 | view (); |
109 | view (); |
81 | ~view (); |
110 | ~view (); |
82 | }; |
111 | }; |
83 | |
112 | |
|
|
113 | struct light : view |
|
|
114 | { |
|
|
115 | colour c; |
|
|
116 | GLfloat intensity; |
|
|
117 | GLfloat radius; |
|
|
118 | }; |
|
|
119 | |
84 | #endif |
120 | #endif |
85 | |
121 | |