src/raytracer.cc
branchpyrit
changeset 46 6493fb65f0b1
parent 44 3763b26244f0
child 47 320d5d466864
equal deleted inserted replaced
45:76b254ce92cf 46:6493fb65f0b1
   440 	pthread_exit((void *)d);
   440 	pthread_exit((void *)d);
   441 #endif
   441 #endif
   442 	return (void *)d;
   442 	return (void *)d;
   443 }
   443 }
   444 
   444 
   445 void Raytracer::render(int w, int h, Float *buffer)
   445 void Raytracer::render()
   446 {
   446 {
   447 	if (!camera || !top || !buffer)
   447 	if (!sampler || !camera || !top)
   448 		return;
   448 		return;
       
   449 
       
   450 	// create workers
       
   451 	// ...
       
   452 
       
   453 	sampler->init();
       
   454 	int sampnum = 0;
       
   455 	while ( (sampnum = sampler->initSampleSet()) > 0 )
       
   456 	{
       
   457 		Sample *sample, *prev = NULL;
       
   458 		while ( (sample = sampler->nextSample(prev)) != NULL )
       
   459 		{
       
   460 			Ray ray = camera->makeRay(sample);
       
   461 			//raystack->push(ray);
       
   462 
       
   463 			// in worker:
       
   464 			Colour col = raytrace(ray, 0, NULL);
       
   465 			sampler->saveSample(sample, col);
       
   466 
       
   467 			delete prev;
       
   468 			prev = sample;
       
   469 		}
       
   470 	}
       
   471 
       
   472 	// wait for workers
       
   473 	// ...
       
   474 
       
   475 #if 0
   449 
   476 
   450 	RenderrowData *d;
   477 	RenderrowData *d;
   451 
   478 
   452 	Float S = 0.5/w;
   479 	Float S = 0.5/w;
   453 	Vector3 dfix = camera->u*(-w/2.0*S/camera->f)
   480 	Vector3 dfix = camera->u*(-w/2.0*S/camera->f)
   481 		int rc = pthread_create(&threads[t++], NULL, renderrow, (void *)d);
   508 		int rc = pthread_create(&threads[t++], NULL, renderrow, (void *)d);
   482 		if (rc) {
   509 		if (rc) {
   483 			dbgmsg(0, "\nE pthread_create unsuccessful, return code was %d\n", rc);
   510 			dbgmsg(0, "\nE pthread_create unsuccessful, return code was %d\n", rc);
   484 			exit(1);
   511 			exit(1);
   485 		}
   512 		}
   486 		/* when 't' owerflows, reset it */
   513 		/* when 't' overflows, reset it */
   487 		if (t >= num_threads)
   514 		if (t >= num_threads)
   488 			t = 0;
   515 			t = 0;
   489 		/* wait for next thread in fifo queue, so the descriptor can be reused;
   516 		/* wait for next thread in fifo queue, so the descriptor can be reused;
   490 		   this also limits number of running threads */
   517 		   this also limits number of running threads */
   491 		if (!pthread_equal(threads[t], pthread_self()))
   518 		if (!pthread_equal(threads[t], pthread_self()))
   504 	dbgmsg(2, "- waiting for threads to finish\n");
   531 	dbgmsg(2, "- waiting for threads to finish\n");
   505 	for (t = 0; t < num_threads; t++)
   532 	for (t = 0; t < num_threads; t++)
   506 		if (pthread_join(threads[t], (void**)&d) == 0)
   533 		if (pthread_join(threads[t], (void**)&d) == 0)
   507 			free(d);
   534 			free(d);
   508 #endif
   535 #endif
       
   536 
       
   537 #endif
   509 }
   538 }
   510 
   539 
   511 void Raytracer::addlight(Light *light)
   540 void Raytracer::addlight(Light *light)
   512 {
   541 {
   513 	lights.push_back(light);
   542 	lights.push_back(light);