ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.h
(Generate patch)

Comparing libgender/view.h (file contents):
Revision 1.23 by root, Sat Oct 16 14:48:48 2004 UTC vs.
Revision 1.35 by root, Tue Nov 9 22:24:14 2004 UTC

7 7
8using namespace std; 8using 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
13struct visibility_base 14struct visibility_base
14{ 15{
15 unsigned int generation; // freshness check 16 unsigned int generation; // freshness check
16}; 17};
21 virtual void clear_visibility (visibility_base *vs) = 0; 22 virtual void clear_visibility (visibility_base *vs) = 0;
22}; 23};
23 24
24struct occ_query 25struct occ_query
25{ 26{
26 struct view &v; 27 struct view &ctx;
27 void *id; 28 void *id;
28 GLuint r; 29 GLuint count;
29 30
30 occ_query (view &v, void *id, GLuint r) : v(v), id(id), r(r) { }; 31 occ_query (view &ctx, void *id, GLuint count) : ctx(ctx), id(id), count(count) { };
31}; 32};
32 33
33typedef event_receiver<void, occ_query> recv_occ_query; 34typedef event_receiver<void, occ_query> recv_occ_query;
35
36enum 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
42struct 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
54extern pass_data pass_depth; // the standard depth pass
55extern pass_data pass_postdepth; // the standard post-depth pass
34 56
35struct view 57struct 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 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 enum mode { DEPTH, POSTDEPTH, LIGHTED } mode; 84 pass_data *pass;
60 struct light *l; 85 bool first_lighted; // first lighted pass
61 set<const entity *> drawn; 86
87 set<const entity *> drawn; // TODO: put drawn info and octant+entity visibility info into vismap!
62 88
63 unsigned int generation; 89 unsigned int generation;
64 typedef map<visible *, visibility_base *> visibility_map; 90 typedef map<visible *, visibility_base *> visibility_map;
65 visibility_map vismap; 91 visibility_map vismap;
66 92
67 vector<octant *> vislist; // octants partially or fully visible in frustum 93 vector<octant *> vislist; // octants that want to be drawn
68 vector<octant *> farlist; // octants possibly visible
69 94
70 struct oq_data { 95 struct oq_data {
71 recv_occ_query *recv; 96 recv_occ_query *recv;
72 GLint id; 97 GLint id;
73 void *data; 98 void *data;
81 void reset_projection (); 106 void reset_projection ();
82 107
83 // public 108 // public
84 109
85 void begin (); 110 void begin ();
86 void pass (enum mode m); 111 void render (pass_data &pass);
87 void end (); 112 void end ();
88 113
89 bool may_draw (const entity *e); 114 bool may_draw (const entity *e);
90 115
91 view (); 116 view ();
92 ~view (); 117 ~view ();
93}; 118};
94 119
120struct light : view
121{
122 // the following variables are valid in the fragment shader as well as in the vertex shader
123 bool has_lightvec; // is a light vector available?
124 shader::temp_3f sh_lightvec; // not defined unless has_lightvec is true
125 shader::temp_3f sh_colour; // always available for any light
126
127 // vertex shader
128 virtual void vsh () = 0;
129 // fragment shader
130 virtual void fsh () = 0;
131
132 virtual void enable ();
133 virtual void disable ();
134
135protected:
136 shader::uniform_3f lightpos; // or direction
137};
138
139struct linear_light : light
140{
141 colour c;
142 GLfloat intensity;
143 GLfloat radius;
144
145 void vsh ();
146 void fsh ();
147};
148
95#endif 149#endif
96 150

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines