distray

diff 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 diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/rend.cc	Fri Dec 25 05:41:10 2015 +0200
     1.3 @@ -0,0 +1,54 @@
     1.4 +#include "rend.h"
     1.5 +#include "threadpool.h"
     1.6 +
     1.7 +static float *pixels;
     1.8 +static int width, height;
     1.9 +
    1.10 +static Matrix4x4 cam_matrix, inv_cam_matrix;
    1.11 +static float (*distfunc)(float, float, float);
    1.12 +
    1.13 +static ThreadPool tpool;
    1.14 +
    1.15 +
    1.16 +void set_framebuffer(int x, int y, float *pix)
    1.17 +{
    1.18 +	pixels = pix;
    1.19 +	width = x;
    1.20 +	height = y;
    1.21 +}
    1.22 +
    1.23 +void set_distance_function(float (*dfunc)(float, float, float))
    1.24 +{
    1.25 +	distfunc = dfunc;
    1.26 +}
    1.27 +
    1.28 +void set_camera_matrix(const Matrix4x4 &xform)
    1.29 +{
    1.30 +	cam_matrix = xform;
    1.31 +	inv_cam_matrix = xform.inverse();
    1.32 +}
    1.33 +
    1.34 +static void render_scanline(int y)
    1.35 +{
    1.36 +	float *pptr = pixels + y * width * 4;
    1.37 +	for(int i=0; i<width; i++) {
    1.38 +	}
    1.39 +}
    1.40 +
    1.41 +void start_render()
    1.42 +{
    1.43 +	for(int i=0; i<height; i++) {
    1.44 +		tpool.add_work(std::bind(render_scanline, i));
    1.45 +	}
    1.46 +}
    1.47 +
    1.48 +void wait_render()
    1.49 +{
    1.50 +	tpool.wait();
    1.51 +}
    1.52 +
    1.53 +void render()
    1.54 +{
    1.55 +	start_render();
    1.56 +	wait_render();
    1.57 +}