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);
35 ERB_TRK_X, ERB_TRK_Y, ERB_TRK_Z, /* position (x,y,z) */
36 ERB_TRK_QX, ERB_TRK_QY, ERB_TRK_QZ, ERB_TRK_QW, /* rotation quat (xi+yj+zk+w) */
37 ERB_TRK_SX, ERB_TRK_SY, ERB_TRK_SZ, /* scaling (x,y,z) */
40 enum erb_interp { ERB_LINEAR, ERB_STEP, ERB_CUBIC };
41 enum erb_extrap { ERB_CLAMP, ERB_EXTEND, ERB_REPEAT };
44 enum erb_interp interp; /* interpolation mode */
45 enum erb_extrap extrap; /* extrapolation mode */
46 struct erb_key *keys; /* dynamic array of keyframes */
47 int num_keys, max_keys; /* max_keys: allocated size, num_keys: used */
51 struct erb_node *par; /* parent node */
52 struct erb_node *clist; /* child nodes */
53 struct erb_surf *surflist; /* surfaces in this node */
54 struct erb_track track[ERB_NUM_TRACKS]; /* PRS keyframe tracks */
55 float xform[16], inv_xform[16]; /* global transformation */
56 float node_xform[16], inv_node_xform[16]; /* local transformation */
60 struct erb_node *node; /* transformation node for this surface */
62 struct erb_aabb bbox; /* local space bounding box */
65 erb_intersect_func isect; /* intersection routine */
66 erb_hitgeom_func hitgeom; /* calculate derived values of the erb_hit structure */
67 erb_sample_func sample; /* random sample generation */
68 erb_bbox_func calc_bbox; /* bounds calculation */
70 long data[1]; /* type chosen to match worst case alignment req. */
74 cgm_vec3 o, d; /* origin and direction */
75 float tmin, tmax; /* segment bounds */
76 float ior; /* IOR of the medium through which this ray travels */
77 float total_dist; /* travel distance accumulator */
82 cgm_vec3 pos, lpos; /* global and local space hit positions */
83 struct erb_surf *surf;
86 /* derived by calc_hit */
91 struct erb_rend *erb_create(void);
92 void erb_destroy(struct erb_rend *erb);
94 int erb_allocframe(struct erb_rend *erb, int width, int height);
95 float *erb_getframe(struct erb_rend *erb);
97 void erb_setfov(struct erb_rend *erb, float vfov_deg);
99 /* clears the framebuffer and sample counters to begin rendering a new frame */
100 void erb_begin(struct erb_rend *erb);
101 /* finalizes the frame, averaging samples (optional) */
102 float *erb_end(struct erb_rend *erb);
104 void erb_set_done_callback(struct erb_rend *erb, erb_done_func donecb, void *cls);
106 void erb_queue_frame(struct erb_rend *erb, unsigned int job_id);
107 void erb_queue_block(struct erb_rend *erb, unsigned int job_id, int x, int y,
108 int width, int height);
109 void erb_wait(struct erb_rend *erb);
111 void erb_primary_ray(struct erb_rend *erb, struct erb_ray *ray, int sample);
112 void erb_sample_ray(struct erb_rend *erb, struct erb_ray *ray, float *col);
114 /* transformation nodes */
115 struct erb_node *erb_node(void);
116 void erb_free_node(struct erb_node *n);
117 int erb_node_addchild(struct erb_node *n, struct erb_node *c);
118 int erb_node_rmchild(struct erb_node *n, struct erb_node *c);
119 int erb_node_addsurf(struct erb_node *n, struct erb_surf *s);
120 int erb_node_rmsurf(struct erb_node *n, struct erb_surf *s);
122 /* sets the transformation matrix and also calculates the inverse */
123 void erb_node_pos(struct erb_node *n, long tm, float x, float y, float z);
124 void erb_node_rot(struct erb_node *n, long tm, float qx, float qy, float qz, float qw);
125 void erb_node_rot_axis(struct erb_node *n, long tm, float angle_deg, float x, float y, float z);
126 void erb_node_scale(struct erb_node *n, long tm, float sx, float sy, float sz);
127 /* calculates transformation matrices for time tm by keyframe interpolation */
128 void erb_node_update(struct erb_node *n, long tm);
129 /* sets transformation, ignoring animation keyframes */
130 void erb_node_setxform(struct erb_node *n, float *mat);
132 void erb_node_eval_pos(struct erb_node *n, long tm, cgm_vec3 *pos);
133 void erb_node_eval_rot(struct erb_node *n, long tm, cgm_quat *rot);
134 void erb_node_eval_scale(struct erb_node *n, long tm, cgm_vec3 *scale);
136 void erb_node_eval_matrix(struct erb_node *n, long tm, float *mat); /* mat[16] */
137 void erb_node_eval_node_matrix(struct erb_node *n, long tm, float *mat); /* mat[16] */
140 struct erb_surf *erb_surface(int datasz);
141 void erb_free_surface(struct erb_surf *surf);
142 struct erb_surf *erb_surf_sphere(float rad);
143 struct erb_surf *erb_surf_box(float xsz, float ysz, float zsz);
145 /* utility functions */
146 void erb_xform_ray(struct erb_ray *inray, float *mat, cgm_vec3 *org, cgm_vec3 *dir);
148 #endif /* RENDLIB_H_ */