X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?a=blobdiff_plain;f=liberebus%2Fsrc%2Ferebus.h;h=e6e067b338375a16fb8e4728694ec38dcfe380a9;hb=11a8b7dc9f82d6ed298cb18c94b8053c41832fa1;hp=c439e439e30a5e5f62c2b43ed504e8524b358444;hpb=b5cff57ff6e83f7660e31636a986d2fcedf786e5;p=erebus2020 diff --git a/liberebus/src/erebus.h b/liberebus/src/erebus.h index c439e43..e6e067b 100644 --- a/liberebus/src/erebus.h +++ b/liberebus/src/erebus.h @@ -3,13 +3,28 @@ #include +struct erb_rend; struct erb_node; struct erb_surf; struct erb_ray; struct erb_hit; +struct erb_aabb; + +struct erb_rect { + int x, y, w, h; +}; typedef int (*erb_intersect_func)(struct erb_surf *surf, struct erb_ray *ray, struct erb_hit *hit); +typedef void (*erb_hitgeom_func)(struct erb_surf *surf, struct erb_hit *hit); typedef void (*erb_sample_func)(struct erb_surf *surf, cgm_vec3 *pos); +typedef void (*erb_bbox_func)(struct erb_surf *surf, struct erb_aabb *bb); + +/* job (block/frame) completion callback type */ +typedef void (*erb_done_func)(unsigned int job, struct erb_rect *rect, void *cls); + +struct erb_aabb { + cgm_vec3 pos, sz; +}; struct erb_node { struct erb_node *par; /* parent node */ @@ -22,8 +37,15 @@ struct erb_node { struct erb_surf { struct erb_node *node; /* transformation node for this surface */ + struct erb_aabb bbox; /* local space bounding box */ + int bbox_valid; + erb_intersect_func isect; /* intersection routine */ + erb_hitgeom_func hitgeom; /* calculate derived values of the erb_hit structure */ erb_sample_func sample; /* random sample generation */ + erb_bbox_func calc_bbox; /* bounds calculation */ + + long data[1]; /* type chosen to match worst case alignment req. */ }; struct erb_ray { @@ -35,10 +57,54 @@ struct erb_ray { struct erb_hit { float t, err; + cgm_vec3 pos, lpos; /* global and local space hit positions */ struct erb_surf *surf; + float total_dist; + + /* derived by calc_hit */ + cgm_vec3 norm, tang; + float u, v; }; -int erb_init(void); -void erb_cleanup(void); +struct erb_rend *erb_create(void); +void erb_destroy(struct erb_rend *erb); + +int erb_allocframe(struct erb_rend *erb, int width, int height); +float *erb_getframe(struct erb_rend *erb); + +/* clears the framebuffer and sample counters to begin rendering a new frame */ +void erb_begin(struct erb_rend *erb); +/* finalizes the frame, averaging samples (optional) */ +float *erb_end(struct erb_rend *erb); + +void erb_set_done_callback(struct erb_rend *erb, erb_done_func donecb, void *cls); + +void erb_queue_frame(struct erb_rend *erb, unsigned int job_id); +void erb_queue_block(struct erb_rend *erb, unsigned int job_id, int x, int y, + int width, int height); +void erb_wait(struct erb_rend *erb); + +void erb_primary_ray(struct erb_rend *erb, struct erb_ray *ray, int sample); +void erb_sample_ray(struct erb_rend *erb, struct erb_ray *ray, float *col); + +/* transformation nodes */ +struct erb_node *erb_node(void); +void erb_free_node(struct erb_node *n); +int erb_node_addchild(struct erb_node *n, struct erb_node *c); +int erb_node_rmchild(struct erb_node *n, struct erb_node *c); +int erb_node_addsurf(struct erb_node *n, struct erb_surf *s); +int erb_node_rmsurf(struct erb_node *n, struct erb_surf *s); + +/* sets the transformation matrix and also calculates the inverse */ +void erb_node_setxform(struct erb_node *n, float *mat); + +/* surfaces */ +struct erb_surf *erb_surface(int datasz); +void erb_free_surface(struct erb_surf *surf); +struct erb_surf *erb_surf_sphere(float rad); +struct erb_surf *erb_surf_box(float xsz, float ysz, float zsz); + +/* utility functions */ +void erb_xform_ray(struct erb_ray *inray, float *mat, cgm_vec3 *org, cgm_vec3 *dir); #endif /* RENDLIB_H_ */