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