ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.h
Revision: 1.40
Committed: Tue Aug 9 23:58:43 2005 UTC (18 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.39: +2 -0 lines
Log Message:
*** empty log message ***

File Contents

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