--- libgender/view.h 2004/10/17 09:43:07 1.26 +++ libgender/view.h 2005/08/11 19:28:45 1.41 @@ -9,6 +9,9 @@ #include "util.h" #include "event.h" +#include "shader.h" + +extern struct skybox *world_skybox; struct visibility_base { @@ -30,7 +33,26 @@ occ_query (view &ctx, void *id, GLuint count) : ctx(ctx), id(id), count(count) { }; }; -typedef event_receiver recv_occ_query; +enum pass_type { + DEPTH, // mandatory, render depth only + POSTDEPTH, // mandatory, occ tests or ignored + LIGHTED, // optional, render faces in full glory +}; + +struct pass_data +{ + pass_type type; + + struct light *l; + + typedef map matmap_t; + matmap_t matmap; + + pass_data (light *l, pass_type type = LIGHTED) : l(l), type(type) { } +}; + +extern pass_data pass_depth; // the standard depth pass +extern pass_data pass_postdepth; // the standard post-depth pass struct view { @@ -41,29 +63,25 @@ 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* + sector eorig; // orig of currently-rendered entity in relation to the camera GLfloat gamma; // only to be used by friends: TODO - GLfloat nz_far, nc_far; + GLfloat nz_far, nz_near, nc_far; GLfloat diagfact; // bounding box border to depth factor GLfloat perspfact; // perspfact * (1/depth)=> pixels - gl::matrix projection; - struct { plane l, r, t, b, n, f; + cone c; + sphere s; } frustum; - // the passes - enum pass { - DEPTH, // mandatory, render depth only - POSTDEPTH, // mandatory, occ tests or ignored - LIGHTED, // optional, render faces in full glory - } pass; + pass_data *pass; + bool first_lighted; // first lighted pass - struct light *l; set drawn; // TODO: put drawn info and octant+entity visibility info into vismap! unsigned int generation; @@ -71,16 +89,16 @@ visibility_map vismap; vector vislist; // octants that want to be drawn + vector postdepthlist; // octants that want to checked struct oq_data { - recv_occ_query *recv; GLint id; - void *data; + int *res; // not GLuint because -1 is so nice a flag - oq_data (recv_occ_query *recv, GLint id, void *data) : recv(recv), id(id), data(data) { }; + oq_data (GLint id, int &res) : id(id), res(&res) { }; }; vector occ_queries; - void begin_occ_query (recv_occ_query &recv, void *id = 0); + void begin_occ_query (int &res); void end_occ_query (); void reset_projection (); @@ -88,13 +106,48 @@ // public void begin (); - void render (enum pass p); + void render (pass_data &pass); void end (); bool may_draw (const entity *e); view (); ~view (); + + int stat1; //D + int stat2; //D +}; + +struct light : view +{ + // the following variables are valid in the fragment shader as well as in the vertex shader + bool has_lightvec; // is a light vector available? + shader::temp_3f sh_lightvec; // not defined unless has_lightvec is true + shader::temp_3f sh_colour; // always available for any light + + virtual void enable (view &ctx); + virtual void disable (view &ctx); + + virtual void vsh () = 0; // vertex shader + virtual void fsh () = 0; // fragment shader + +protected: + shader::varying_3f lightvec; + shader::varying_1f camdist; + shader::uniform_3f lightpos; // or direction +}; + +struct linear_light : light +{ + colour c; + GLfloat intensity; + GLfloat radius; + + void enable (view &ctx); + void disable (view &ctx); + + void vsh (); + void fsh (); }; #endif