src/raytracer.cc
branchpyrit
changeset 20 f22952603f29
parent 19 4e0955fca797
child 21 79b516a3803d
--- a/src/raytracer.cc	Mon Nov 26 23:12:40 2007 +0100
+++ b/src/raytracer.cc	Thu Nov 29 18:30:16 2007 +0100
@@ -11,7 +11,6 @@
 
 #include <stdio.h>
 #include <malloc.h>
-#include "common.h"
 #include "raytracer.h"
 
 // Hammersley spherical point distribution
@@ -195,22 +194,13 @@
 	return (void *)d;
 }
 
-float *Raytracer::render(int w, int h)
+void Raytracer::render(int w, int h, float *buffer)
 {
-	if (!camera || !top)
-		return NULL;
-
-	float *data;
-
-	data = (float *) malloc(w*h*3*sizeof(float));
-	if (!data)
-		return NULL;
+	if (!camera || !top || !buffer)
+		return;
 
 	RenderrowData *d;
 
-	printf("* building kd-tree\n");
-	top->optimize();
-
 	float S = 0.5/w;
 	Vector3 dfix = camera->u*(-w/2.0*S/camera->f)
 		+ camera->v*(h/2.0*S/camera->f) + camera->p;
@@ -218,7 +208,7 @@
 	Vector3 dy = camera->v * (-S/camera->f);
 
 #ifdef PTHREADS
-	printf("* pthreads enabled, using %d threads\n", num_threads);
+	infomsg("* pthreads enabled, using %d threads\n", num_threads);
 	pthread_t threads[num_threads];
 	for (int t = 0; t < num_threads; t++)
 		threads[t] = pthread_self();
@@ -226,8 +216,9 @@
 #endif
 
 	/* for each pixel... */
-	printf("* rendering row   0 (  0%% done)");
-	for (int y = 0; y < h; y++) {
+	infomsg("* rendering row   0 (  0%% done)");
+	for (int y = 0; y < h; y++)
+	{
 		d = (RenderrowData*) malloc(sizeof(RenderrowData));
 		d->rt = this;
 		d->w = w;
@@ -237,12 +228,12 @@
 #if OVERSAMPLING
 		d->dy = dy;
 #endif
-		d->iter = data + y*3*w;
+		d->iter = buffer + y*3*w;
 #ifdef PTHREADS
 		/* create new thread and increase 't' */
 		int rc = pthread_create(&threads[t++], NULL, renderrow, (void *)d);
 		if (rc) {
-			printf("\nERROR: return code from pthread_create() is %d\n", rc);
+			infomsg("\nERROR: return code from pthread_create() is %d\n", rc);
 			exit(1);
 		}
 		/* when 't' owerflows, reset it */
@@ -258,18 +249,16 @@
 		free(d);
 #endif
 		dfix += dy;
-		printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%4d (%2d%% done)", y, y*100/(h-1));
+		infomsg("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b%4d (%2d%% done)", y, y*100/(h-1));
 	}
-	printf("\n");
+	infomsg("\n");
 
 #ifdef PTHREADS
-	printf("* waiting for threads to finish\n");
+	infomsg("* waiting for threads to finish\n");
 	for (t = 0; t < num_threads; t++)
 		if (pthread_join(threads[t], (void**)&d) == 0)
 			free(d);
 #endif
-
-	return data;
 }
 
 void Raytracer::addlight(Light *light)