+float *erb_getframe(struct erb_rend *erb)
+{
+ return erb->fb_pixels;
+}
+
+void erb_begin(struct erb_rend *erb)
+{
+ memset(erb->fb_pixels, 0, erb->fb_size);
+}
+
+float *erb_end(struct erb_rend *erb)
+{
+ int i, npix = erb->fb_width * erb->fb_height;
+ float s;
+ float *pptr = erb->fb_pixels;
+
+ for(i=0; i<npix; i++) {
+ if(pptr[3] > 1) {
+ s = 1.0f / pptr[3];
+ *pptr++ *= s;
+ *pptr++ *= s;
+ *pptr++ *= s;
+ *pptr++ = 1.0f;
+ } else {
+ pptr += 4;
+ }
+ }
+
+ return erb->fb_pixels;
+}
+
+void erb_set_done_callback(struct erb_rend *erb, erb_done_func donecb, void *cls)
+{
+ erb->donecb = donecb;
+ erb->donecls = cls;
+}
+
+void erb_queue_frame(struct erb_rend *erb, unsigned int job_id)
+{
+ erb_queue_block(erb, job_id, 0, 0, erb->fb_width, erb->fb_height);
+}
+
+void erb_queue_block(struct erb_rend *erb, unsigned int job_id, int x, int y,
+ int width, int height)
+{
+ struct render_job *job;
+
+ if(!(job = alloc_job())) {
+ fprintf(stderr, "erb_queue_block: failed to allocate rendering job\n");
+ return;
+ }
+
+ job->erb = erb;
+ job->id = job_id;
+ job->rect.x = x;
+ job->rect.y = y;
+ job->rect.w = width;
+ job->rect.h = height;
+
+ tpool_enqueue(tpool, job, proc_render_job, done_render_job);
+}
+
+void erb_wait(struct erb_rend *erb)
+{
+ /* XXX should we have a per-renderer instance thread pool, to wait only for our own jobs? */
+ tpool_wait(tpool);
+}
+
+void erb_primary_ray(struct erb_rend *erb, struct erb_ray *ray, int sample)
+{
+ /* TODO */
+}
+
+void erb_sample_ray(struct erb_rend *erb, struct erb_ray *ray, float *col)
+{
+ /* TODO */
+ col[0] = fmod(col[0] + 1.0f, 1.0f);
+ col[1] = col[2] = fmod(col[1] + 0.33f, 1.0f);
+}
+
+static void proc_render_job(void *cls)
+{
+ int i, j, fboffs;
+ struct erb_rend *erb;
+ struct render_job *job = cls;
+ float *fbptr;
+ struct erb_ray ray;
+
+ erb = job->erb;
+ fboffs = job->rect.y * erb->fb_width + job->rect.x;
+ fbptr = erb->fb_pixels + fboffs * 4;
+
+ for(i=0; i<job->rect.h; i++) {
+ for(j=0; j<job->rect.w; j++) {
+ erb_primary_ray(erb, &ray, (int)fbptr[3]);
+ erb_sample_ray(erb, &ray, fbptr);
+ fbptr += 4;
+ }
+ fbptr += (erb->fb_width - job->rect.w) * 4;
+ }
+}
+
+static void done_render_job(void *cls)