distray

view src/rend.cc @ 0:cf494adee646

distance field raytracer
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 25 Dec 2015 05:41:10 +0200
parents
children
line source
1 #include "rend.h"
2 #include "threadpool.h"
4 static float *pixels;
5 static int width, height;
7 static Matrix4x4 cam_matrix, inv_cam_matrix;
8 static float (*distfunc)(float, float, float);
10 static ThreadPool tpool;
13 void set_framebuffer(int x, int y, float *pix)
14 {
15 pixels = pix;
16 width = x;
17 height = y;
18 }
20 void set_distance_function(float (*dfunc)(float, float, float))
21 {
22 distfunc = dfunc;
23 }
25 void set_camera_matrix(const Matrix4x4 &xform)
26 {
27 cam_matrix = xform;
28 inv_cam_matrix = xform.inverse();
29 }
31 static void render_scanline(int y)
32 {
33 float *pptr = pixels + y * width * 4;
34 for(int i=0; i<width; i++) {
35 }
36 }
38 void start_render()
39 {
40 for(int i=0; i<height; i++) {
41 tpool.add_work(std::bind(render_scanline, i));
42 }
43 }
45 void wait_render()
46 {
47 tpool.wait();
48 }
50 void render()
51 {
52 start_render();
53 wait_render();
54 }