--- libgender/view.h 2004/10/06 00:27:01 1.11 +++ libgender/view.h 2004/10/17 09:43:07 1.26 @@ -3,51 +3,98 @@ #include #include +#include using namespace std; #include "util.h" +#include "event.h" -struct view { - sector orig; - point p; - vec3 d, u; - float fov; - int w, h; +struct visibility_base +{ + unsigned int generation; // freshness check +}; - void draw (draw_context &ctx); +struct visible { + visibility_base *get_visibility (view &ctx); + virtual visibility_base *new_visibility () = 0; + virtual void clear_visibility (visibility_base *vs) = 0; }; -struct visibility_state { - unsigned int generation; - enum { UNKNOWN, OCCLUDED, PARTIAL, FULL } visibility; +struct occ_query +{ + struct view &ctx; + void *id; + GLuint count; - visibility_state () : generation(0), visibility(UNKNOWN) { }; + occ_query (view &ctx, void *id, GLuint count) : ctx(ctx), id(id), count(count) { }; }; -struct draw_context { - view &v; +typedef event_receiver recv_occ_query; - matrix projection; +struct view +{ + sector orig; + point p; + vec3 d, u; + GLfloat fov; + GLfloat z_near, z_far, c_far; + int w, h; + GLfloat pixfact; // how many pixels on screen are drawn by a unit length line, *roughly* + + GLfloat gamma; + + // only to be used by friends: TODO + + GLfloat nz_far, nc_far; + GLfloat diagfact; // bounding box border to depth factor + GLfloat perspfact; // perspfact * (1/depth)=> pixels - void transform (const matrix &m); + gl::matrix projection; struct { plane l, r, t, b, n, f; } frustum; - enum { DEPTH, LIGHTED } mode; - light *l; - set drawn; + + // the passes + enum pass { + DEPTH, // mandatory, render depth only + POSTDEPTH, // mandatory, occ tests or ignored + LIGHTED, // optional, render faces in full glory + } pass; + + struct light *l; + set drawn; // TODO: put drawn info and octant+entity visibility info into vismap! unsigned int generation; - map vismap; - vector vislist; // octants partially or fully visible - vector checklist; // octants possibly visible + typedef map visibility_map; + visibility_map vismap; + + vector vislist; // octants that want to be drawn + + struct oq_data { + recv_occ_query *recv; + GLint id; + void *data; + + oq_data (recv_occ_query *recv, GLint id, void *data) : recv(recv), id(id), data(data) { }; + }; + vector occ_queries; + void begin_occ_query (recv_occ_query &recv, void *id = 0); + void end_occ_query (); + + void reset_projection (); + + // public + + void begin (); + void render (enum pass p); + void end (); - bool may_draw (entity_base *e); + bool may_draw (const entity *e); - draw_context (view &v); - ~draw_context (); + view (); + ~view (); }; #endif