1 |
#ifndef VIEW_H |
2 |
#define VIEW_H |
3 |
|
4 |
#include <set> |
5 |
#include <map> |
6 |
#include <utility> |
7 |
|
8 |
using namespace std; |
9 |
|
10 |
#include "util.h" |
11 |
#include "event.h" |
12 |
|
13 |
struct visibility_base |
14 |
{ |
15 |
unsigned int generation; // freshness check |
16 |
}; |
17 |
|
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; |
22 |
}; |
23 |
|
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) { }; |
31 |
}; |
32 |
|
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; |
43 |
|
44 |
struct view |
45 |
{ |
46 |
sector orig; |
47 |
point p; |
48 |
vec3 d, u; |
49 |
GLfloat fov; |
50 |
GLfloat z_near, z_far, c_far; |
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 |
54 |
|
55 |
GLfloat gamma; |
56 |
|
57 |
// only to be used by friends: TODO |
58 |
|
59 |
GLfloat nz_far, nz_near, nc_far; |
60 |
GLfloat diagfact; // bounding box border to depth factor |
61 |
GLfloat perspfact; // perspfact * (1/depth)=> pixels |
62 |
|
63 |
gl::matrix projection; |
64 |
|
65 |
struct { |
66 |
plane l, r, t, b, n, f; |
67 |
cone c; |
68 |
sphere s; |
69 |
} frustum; |
70 |
|
71 |
// the passes |
72 |
enum pass_type { |
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! |
81 |
|
82 |
unsigned int generation; |
83 |
typedef map<visible *, visibility_base *> visibility_map; |
84 |
visibility_map vismap; |
85 |
|
86 |
vector<octant *> vislist; // octants that want to be drawn |
87 |
|
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 |
}; |
95 |
vector<oq_data> occ_queries; |
96 |
void begin_occ_query (recv_occ_query &recv, void *id = 0); |
97 |
void end_occ_query (); |
98 |
|
99 |
void reset_projection (); |
100 |
|
101 |
// public |
102 |
|
103 |
void begin (); |
104 |
void render (enum pass_type p, pass &data); |
105 |
void end (); |
106 |
|
107 |
bool may_draw (const entity *e); |
108 |
|
109 |
view (); |
110 |
~view (); |
111 |
}; |
112 |
|
113 |
struct light : view |
114 |
{ |
115 |
colour c; |
116 |
GLfloat intensity; |
117 |
GLfloat radius; |
118 |
}; |
119 |
|
120 |
#endif |
121 |
|