4 #include <cgmath/cgmath.h>
17 typedef int (*erb_intersect_func)(struct erb_surf *surf, struct erb_ray *ray, struct erb_hit *hit);
18 typedef void (*erb_hitgeom_func)(struct erb_surf *surf, struct erb_hit *hit);
19 typedef void (*erb_sample_func)(struct erb_surf *surf, cgm_vec3 *pos);
20 typedef void (*erb_bbox_func)(struct erb_surf *surf, struct erb_aabb *bb);
22 /* job (block/frame) completion callback type */
23 typedef void (*erb_done_func)(unsigned int job, struct erb_rect *rect, void *cls);
30 struct erb_node *par; /* parent node */
31 struct erb_node *clist; /* child nodes */
32 struct erb_surf *surflist; /* surfaces in this node */
33 float xform[16], inv_xform[16]; /* global transformation */
34 float node_xform[16], inv_node_xform[16]; /* local transformation */
38 struct erb_node *node; /* transformation node for this surface */
40 struct erb_aabb bbox; /* local space bounding box */
43 erb_intersect_func isect; /* intersection routine */
44 erb_hitgeom_func hitgeom; /* calculate derived values of the erb_hit structure */
45 erb_sample_func sample; /* random sample generation */
46 erb_bbox_func calc_bbox; /* bounds calculation */
48 long data[1]; /* type chosen to match worst case alignment req. */
52 cgm_vec3 o, d; /* origin and direction */
53 float tmin, tmax; /* segment bounds */
54 float ior; /* IOR of the medium through which this ray travels */
55 float total_dist; /* travel distance accumulator */
60 cgm_vec3 pos, lpos; /* global and local space hit positions */
61 struct erb_surf *surf;
64 /* derived by calc_hit */
69 struct erb_rend *erb_create(void);
70 void erb_destroy(struct erb_rend *erb);
72 int erb_allocframe(struct erb_rend *erb, int width, int height);
73 float *erb_getframe(struct erb_rend *erb);
75 /* clears the framebuffer and sample counters to begin rendering a new frame */
76 void erb_begin(struct erb_rend *erb);
77 /* finalizes the frame, averaging samples (optional) */
78 float *erb_end(struct erb_rend *erb);
80 void erb_set_done_callback(struct erb_rend *erb, erb_done_func donecb, void *cls);
82 void erb_queue_frame(struct erb_rend *erb, unsigned int job_id);
83 void erb_queue_block(struct erb_rend *erb, unsigned int job_id, int x, int y,
84 int width, int height);
85 void erb_wait(struct erb_rend *erb);
87 void erb_primary_ray(struct erb_rend *erb, struct erb_ray *ray, int sample);
88 void erb_sample_ray(struct erb_rend *erb, struct erb_ray *ray, float *col);
90 /* transformation nodes */
91 struct erb_node *erb_node(void);
92 void erb_free_node(struct erb_node *n);
93 int erb_node_addchild(struct erb_node *n, struct erb_node *c);
94 int erb_node_rmchild(struct erb_node *n, struct erb_node *c);
95 int erb_node_addsurf(struct erb_node *n, struct erb_surf *s);
96 int erb_node_rmsurf(struct erb_node *n, struct erb_surf *s);
98 /* sets the transformation matrix and also calculates the inverse */
99 void erb_node_setxform(struct erb_node *n, float *mat);
102 struct erb_surf *erb_surface(int datasz);
103 void erb_free_surface(struct erb_surf *surf);
104 struct erb_surf *erb_surf_sphere(float rad);
105 struct erb_surf *erb_surf_box(float xsz, float ysz, float zsz);
107 /* utility functions */
108 void erb_xform_ray(struct erb_ray *inray, float *mat, cgm_vec3 *org, cgm_vec3 *dir);
110 #endif /* RENDLIB_H_ */