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