ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.h
Revision: 1.34
Committed: Sun Nov 7 03:28:20 2004 UTC (19 years, 7 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.33: +14 -12 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
86 set<const entity *> drawn; // TODO: put drawn info and octant+entity visibility info into vismap!
87
88 unsigned int generation;
89 typedef map<visible *, visibility_base *> visibility_map;
90 visibility_map vismap;
91
92 vector<octant *> vislist; // octants that want to be drawn
93
94 struct oq_data {
95 recv_occ_query *recv;
96 GLint id;
97 void *data;
98
99 oq_data (recv_occ_query *recv, GLint id, void *data) : recv(recv), id(id), data(data) { };
100 };
101 vector<oq_data> occ_queries;
102 void begin_occ_query (recv_occ_query &recv, void *id = 0);
103 void end_occ_query ();
104
105 void reset_projection ();
106
107 // public
108
109 void begin ();
110 void render (pass_data &pass);
111 void end ();
112
113 bool may_draw (const entity *e);
114
115 view ();
116 ~view ();
117 };
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
148 #endif
149