1 |
root |
1.1 |
#ifndef VIEW_H |
2 |
|
|
#define VIEW_H |
3 |
|
|
|
4 |
|
|
#include <set> |
5 |
root |
1.4 |
#include <map> |
6 |
root |
1.17 |
#include <utility> |
7 |
root |
1.1 |
|
8 |
|
|
using namespace std; |
9 |
|
|
|
10 |
|
|
#include "util.h" |
11 |
root |
1.17 |
#include "event.h" |
12 |
root |
1.1 |
|
13 |
root |
1.22 |
struct visibility_base |
14 |
root |
1.20 |
{ |
15 |
root |
1.22 |
unsigned int generation; // freshness check |
16 |
|
|
}; |
17 |
root |
1.12 |
|
18 |
root |
1.22 |
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 |
root |
1.12 |
}; |
23 |
|
|
|
24 |
root |
1.20 |
struct occ_query |
25 |
|
|
{ |
26 |
root |
1.26 |
struct view &ctx; |
27 |
root |
1.22 |
void *id; |
28 |
root |
1.26 |
GLuint count; |
29 |
root |
1.17 |
|
30 |
root |
1.26 |
occ_query (view &ctx, void *id, GLuint count) : ctx(ctx), id(id), count(count) { }; |
31 |
root |
1.17 |
}; |
32 |
|
|
|
33 |
|
|
typedef event_receiver<void, occ_query> recv_occ_query; |
34 |
|
|
|
35 |
root |
1.31 |
struct pass |
36 |
|
|
{ |
37 |
|
|
struct light *l; |
38 |
|
|
|
39 |
|
|
pass (light *l) : l(l) { } |
40 |
|
|
}; |
41 |
|
|
|
42 |
|
|
extern pass pass_depth; |
43 |
|
|
|
44 |
root |
1.20 |
struct view |
45 |
|
|
{ |
46 |
root |
1.2 |
sector orig; |
47 |
|
|
point p; |
48 |
|
|
vec3 d, u; |
49 |
root |
1.13 |
GLfloat fov; |
50 |
root |
1.19 |
GLfloat z_near, z_far, c_far; |
51 |
root |
1.2 |
int w, h; |
52 |
root |
1.21 |
GLfloat pixfact; // how many pixels on screen are drawn by a unit length line, *roughly* |
53 |
root |
1.30 |
sector eorig; // orig of currently-rendered entity in relation to the camera |
54 |
root |
1.2 |
|
55 |
root |
1.13 |
GLfloat gamma; |
56 |
root |
1.4 |
|
57 |
root |
1.17 |
// only to be used by friends: TODO |
58 |
root |
1.5 |
|
59 |
root |
1.28 |
GLfloat nz_far, nz_near, nc_far; |
60 |
root |
1.17 |
GLfloat diagfact; // bounding box border to depth factor |
61 |
root |
1.21 |
GLfloat perspfact; // perspfact * (1/depth)=> pixels |
62 |
root |
1.13 |
|
63 |
root |
1.25 |
gl::matrix projection; |
64 |
root |
1.9 |
|
65 |
root |
1.5 |
struct { |
66 |
|
|
plane l, r, t, b, n, f; |
67 |
root |
1.27 |
cone c; |
68 |
|
|
sphere s; |
69 |
root |
1.5 |
} frustum; |
70 |
root |
1.14 |
|
71 |
root |
1.26 |
// the passes |
72 |
root |
1.31 |
enum pass_type { |
73 |
root |
1.26 |
DEPTH, // mandatory, render depth only |
74 |
|
|
POSTDEPTH, // mandatory, occ tests or ignored |
75 |
|
|
LIGHTED, // optional, render faces in full glory |
76 |
root |
1.31 |
} pass_type; |
77 |
|
|
|
78 |
|
|
pass *pass_data; |
79 |
root |
1.26 |
|
80 |
|
|
set<const entity *> drawn; // TODO: put drawn info and octant+entity visibility info into vismap! |
81 |
root |
1.4 |
|
82 |
|
|
unsigned int generation; |
83 |
root |
1.22 |
typedef map<visible *, visibility_base *> visibility_map; |
84 |
|
|
visibility_map vismap; |
85 |
root |
1.17 |
|
86 |
root |
1.24 |
vector<octant *> vislist; // octants that want to be drawn |
87 |
root |
1.17 |
|
88 |
root |
1.22 |
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 |
root |
1.17 |
vector<oq_data> occ_queries; |
96 |
root |
1.22 |
void begin_occ_query (recv_occ_query &recv, void *id = 0); |
97 |
root |
1.17 |
void end_occ_query (); |
98 |
root |
1.13 |
|
99 |
|
|
void reset_projection (); |
100 |
|
|
|
101 |
|
|
// public |
102 |
|
|
|
103 |
|
|
void begin (); |
104 |
root |
1.31 |
void render (enum pass_type p, pass &data); |
105 |
root |
1.13 |
void end (); |
106 |
root |
1.1 |
|
107 |
root |
1.15 |
bool may_draw (const entity *e); |
108 |
root |
1.1 |
|
109 |
root |
1.12 |
view (); |
110 |
|
|
~view (); |
111 |
root |
1.31 |
}; |
112 |
|
|
|
113 |
|
|
struct light : view |
114 |
|
|
{ |
115 |
|
|
colour c; |
116 |
|
|
GLfloat intensity; |
117 |
|
|
GLfloat radius; |
118 |
root |
1.1 |
}; |
119 |
root |
1.7 |
|
120 |
root |
1.1 |
#endif |
121 |
|
|
|