ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.h
Revision: 1.37
Committed: Fri Nov 26 02:38:17 2004 UTC (19 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.36: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
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 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
57 struct view
58 {
59 sector orig;
60 point p;
61 vec3 d, u;
62 GLfloat fov;
63 GLfloat z_near, z_far, c_far;
64 int w, h;
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
67
68 GLfloat gamma;
69
70 // only to be used by friends: TODO
71
72 GLfloat nz_far, nz_near, nc_far;
73 GLfloat diagfact; // bounding box border to depth factor
74 GLfloat perspfact; // perspfact * (1/depth)=> pixels
75
76 gl::matrix projection;
77
78 struct {
79 plane l, r, t, b, n, f;
80 cone c;
81 sphere s;
82 } frustum;
83
84 pass_data *pass;
85 bool first_lighted; // first lighted pass
86
87 set<const entity *> drawn; // TODO: put drawn info and octant+entity visibility info into vismap!
88
89 unsigned int generation;
90 typedef map<visible *, visibility_base *> visibility_map;
91 visibility_map vismap;
92
93 vector<octant *> vislist; // octants that want to be drawn
94 vector<octant *> postdepthlist; // octants that want to checked
95
96 struct oq_data {
97 recv_occ_query *recv;
98 GLint id;
99 void *data;
100
101 oq_data (recv_occ_query *recv, GLint id, void *data) : recv(recv), id(id), data(data) { };
102 };
103 vector<oq_data> occ_queries;
104 void begin_occ_query (recv_occ_query &recv, void *id = 0);
105 void end_occ_query ();
106
107 void reset_projection ();
108
109 // public
110
111 void begin ();
112 void render (pass_data &pass);
113 void end ();
114
115 bool may_draw (const entity *e);
116
117 view ();
118 ~view ();
119
120 int stat1; //D
121 int stat2; //D
122 };
123
124 struct light : view
125 {
126 // the following variables are valid in the fragment shader as well as in the vertex shader
127 bool has_lightvec; // is a light vector available?
128 shader::temp_3f sh_lightvec; // not defined unless has_lightvec is true
129 shader::temp_3f sh_colour; // always available for any light
130
131 // vertex shader
132 virtual void vsh () = 0;
133 // fragment shader
134 virtual void fsh () = 0;
135
136 virtual void enable ();
137 virtual void disable ();
138
139 protected:
140 shader::uniform_3f lightpos; // or direction
141 };
142
143 struct linear_light : light
144 {
145 colour c;
146 GLfloat intensity;
147 GLfloat radius;
148
149 void vsh ();
150 void fsh ();
151 };
152
153 #endif
154