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.32 |
#include "shader.h" |
13 |
root |
1.1 |
|
14 |
root |
1.40 |
extern struct skybox *world_skybox; |
15 |
|
|
|
16 |
root |
1.22 |
struct visibility_base |
17 |
root |
1.20 |
{ |
18 |
root |
1.22 |
unsigned int generation; // freshness check |
19 |
|
|
}; |
20 |
root |
1.12 |
|
21 |
root |
1.22 |
struct visible { |
22 |
|
|
visibility_base *get_visibility (view &ctx); |
23 |
|
|
virtual visibility_base *new_visibility () = 0; |
24 |
|
|
virtual void clear_visibility (visibility_base *vs) = 0; |
25 |
root |
1.12 |
}; |
26 |
|
|
|
27 |
root |
1.20 |
struct occ_query |
28 |
|
|
{ |
29 |
root |
1.26 |
struct view &ctx; |
30 |
root |
1.22 |
void *id; |
31 |
root |
1.26 |
GLuint count; |
32 |
root |
1.17 |
|
33 |
root |
1.26 |
occ_query (view &ctx, void *id, GLuint count) : ctx(ctx), id(id), count(count) { }; |
34 |
root |
1.17 |
}; |
35 |
|
|
|
36 |
root |
1.34 |
enum pass_type { |
37 |
|
|
DEPTH, // mandatory, render depth only |
38 |
|
|
POSTDEPTH, // mandatory, occ tests or ignored |
39 |
root |
1.35 |
LIGHTED, // optional, render faces in full glory |
40 |
root |
1.34 |
}; |
41 |
|
|
|
42 |
|
|
struct pass_data |
43 |
root |
1.31 |
{ |
44 |
root |
1.34 |
pass_type type; |
45 |
|
|
|
46 |
root |
1.31 |
struct light *l; |
47 |
|
|
|
48 |
root |
1.32 |
typedef map<struct material *, shader::program_object> matmap_t; |
49 |
|
|
matmap_t matmap; |
50 |
|
|
|
51 |
root |
1.34 |
pass_data (light *l, pass_type type = LIGHTED) : l(l), type(type) { } |
52 |
root |
1.31 |
}; |
53 |
|
|
|
54 |
root |
1.34 |
extern pass_data pass_depth; // the standard depth pass |
55 |
|
|
extern pass_data pass_postdepth; // the standard post-depth pass |
56 |
root |
1.31 |
|
57 |
root |
1.20 |
struct view |
58 |
|
|
{ |
59 |
root |
1.2 |
sector orig; |
60 |
|
|
point p; |
61 |
|
|
vec3 d, u; |
62 |
root |
1.13 |
GLfloat fov; |
63 |
root |
1.19 |
GLfloat z_near, z_far, c_far; |
64 |
root |
1.2 |
int w, h; |
65 |
root |
1.21 |
GLfloat pixfact; // how many pixels on screen are drawn by a unit length line, *roughly* |
66 |
root |
1.30 |
sector eorig; // orig of currently-rendered entity in relation to the camera |
67 |
root |
1.2 |
|
68 |
root |
1.13 |
GLfloat gamma; |
69 |
root |
1.4 |
|
70 |
root |
1.17 |
// only to be used by friends: TODO |
71 |
root |
1.5 |
|
72 |
root |
1.28 |
GLfloat nz_far, nz_near, nc_far; |
73 |
root |
1.17 |
GLfloat diagfact; // bounding box border to depth factor |
74 |
root |
1.21 |
GLfloat perspfact; // perspfact * (1/depth)=> pixels |
75 |
root |
1.13 |
|
76 |
root |
1.5 |
struct { |
77 |
|
|
plane l, r, t, b, n, f; |
78 |
root |
1.27 |
cone c; |
79 |
|
|
sphere s; |
80 |
root |
1.5 |
} frustum; |
81 |
root |
1.14 |
|
82 |
root |
1.34 |
pass_data *pass; |
83 |
root |
1.35 |
bool first_lighted; // first lighted pass |
84 |
root |
1.26 |
|
85 |
|
|
set<const entity *> drawn; // TODO: put drawn info and octant+entity visibility info into vismap! |
86 |
root |
1.4 |
|
87 |
|
|
unsigned int generation; |
88 |
root |
1.22 |
typedef map<visible *, visibility_base *> visibility_map; |
89 |
|
|
visibility_map vismap; |
90 |
root |
1.17 |
|
91 |
root |
1.24 |
vector<octant *> vislist; // octants that want to be drawn |
92 |
root |
1.37 |
vector<octant *> postdepthlist; // octants that want to checked |
93 |
root |
1.17 |
|
94 |
root |
1.22 |
struct oq_data { |
95 |
|
|
GLint id; |
96 |
root |
1.41 |
int *res; // not GLuint because -1 is so nice a flag |
97 |
root |
1.22 |
|
98 |
root |
1.41 |
oq_data (GLint id, int &res) : id(id), res(&res) { }; |
99 |
root |
1.22 |
}; |
100 |
root |
1.17 |
vector<oq_data> occ_queries; |
101 |
root |
1.41 |
void begin_occ_query (int &res); |
102 |
root |
1.17 |
void end_occ_query (); |
103 |
root |
1.13 |
|
104 |
|
|
void reset_projection (); |
105 |
|
|
|
106 |
|
|
// public |
107 |
|
|
|
108 |
|
|
void begin (); |
109 |
root |
1.34 |
void render (pass_data &pass); |
110 |
root |
1.13 |
void end (); |
111 |
root |
1.1 |
|
112 |
root |
1.15 |
bool may_draw (const entity *e); |
113 |
root |
1.1 |
|
114 |
root |
1.12 |
view (); |
115 |
|
|
~view (); |
116 |
root |
1.36 |
|
117 |
|
|
int stat1; //D |
118 |
|
|
int stat2; //D |
119 |
root |
1.31 |
}; |
120 |
|
|
|
121 |
|
|
struct light : view |
122 |
|
|
{ |
123 |
root |
1.33 |
// the following variables are valid in the fragment shader as well as in the vertex shader |
124 |
|
|
bool has_lightvec; // is a light vector available? |
125 |
root |
1.38 |
shader::temp_3f sh_lightvec; // not defined unless has_lightvec is true |
126 |
|
|
shader::temp_3f sh_colour; // always available for any light |
127 |
root |
1.32 |
|
128 |
root |
1.38 |
virtual void enable (view &ctx); |
129 |
|
|
virtual void disable (view &ctx); |
130 |
root |
1.33 |
|
131 |
root |
1.39 |
virtual void vsh () = 0; // vertex shader |
132 |
|
|
virtual void fsh () = 0; // fragment shader |
133 |
|
|
|
134 |
root |
1.33 |
protected: |
135 |
root |
1.38 |
shader::varying_3f lightvec; |
136 |
|
|
shader::varying_1f camdist; |
137 |
root |
1.33 |
shader::uniform_3f lightpos; // or direction |
138 |
root |
1.32 |
}; |
139 |
|
|
|
140 |
|
|
struct linear_light : light |
141 |
|
|
{ |
142 |
root |
1.31 |
colour c; |
143 |
|
|
GLfloat intensity; |
144 |
|
|
GLfloat radius; |
145 |
root |
1.32 |
|
146 |
root |
1.39 |
void enable (view &ctx); |
147 |
|
|
void disable (view &ctx); |
148 |
|
|
|
149 |
root |
1.32 |
void vsh (); |
150 |
root |
1.33 |
void fsh (); |
151 |
root |
1.1 |
}; |
152 |
root |
1.7 |
|
153 |
root |
1.1 |
#endif |
154 |
|
|
|