include/raytracer.h
branchpyrit
changeset 50 14a727b70d07
parent 48 a4913301c626
child 52 a6413a3d741d
equal deleted inserted replaced
49:558fde7da82a 50:14a727b70d07
    26 
    26 
    27 #ifndef RAYTRACER_H
    27 #ifndef RAYTRACER_H
    28 #define RAYTRACER_H
    28 #define RAYTRACER_H
    29 
    29 
    30 #include <vector>
    30 #include <vector>
       
    31 #include <queue>
    31 
    32 
    32 #include "common.h"
    33 #include "common.h"
    33 #include "container.h"
    34 #include "container.h"
    34 #include "scene.h"
    35 #include "scene.h"
    35 
    36 
    58 	Float ao_distance, ao_angle;
    59 	Float ao_distance, ao_angle;
    59 	int num_threads;
    60 	int num_threads;
    60 	int max_depth;
    61 	int max_depth;
    61 
    62 
    62 	Vector3 SphereDistribute(int i, int n, Float extent, Vector3 &normal);
    63 	Vector3 SphereDistribute(int i, int n, Float extent, Vector3 &normal);
       
    64 	
       
    65 	queue<Sample*> sample_queue;
       
    66 	bool sample_queue_end;
       
    67 	pthread_mutex_t sample_queue_mutex, sampler_mutex;
       
    68 	pthread_cond_t sample_queue_cond, worker_ready_cond;
       
    69 
       
    70 	static void *raytrace_worker(void *d);
    63 public:
    71 public:
    64 	Raytracer(): top(NULL), camera(NULL), lights(), bg_colour(0.0, 0.0, 0.0),
    72 	Raytracer(): top(NULL), camera(NULL), lights(), bg_colour(0.0, 0.0, 0.0),
    65 		ao_samples(0), num_threads(2), max_depth(3) {};
    73 		ao_samples(0), num_threads(2), max_depth(3)
       
    74 	{
       
    75 		pthread_mutex_init(&sample_queue_mutex, NULL);
       
    76 		pthread_mutex_init(&sampler_mutex, NULL);
       
    77 		pthread_cond_init (&sample_queue_cond, NULL);
       
    78 		pthread_cond_init (&worker_ready_cond, NULL);
       
    79 	};
       
    80 	~Raytracer()
       
    81 	{
       
    82 		pthread_mutex_destroy(&sample_queue_mutex);
       
    83 		pthread_mutex_destroy(&sampler_mutex);
       
    84 		pthread_cond_destroy (&sample_queue_cond);
       
    85 		pthread_cond_destroy (&worker_ready_cond);
       
    86 	}
       
    87 
    66 	void render();
    88 	void render();
    67 	Colour raytrace(Ray &ray, int depth, Shape *origin_shape);
    89 	Colour raytrace(Ray &ray, int depth, Shape *origin_shape);
    68 	void addshape(Shape *shape) { top->addShape(shape); };
    90 	void addshape(Shape *shape) { top->addShape(shape); };
    69 	void addlight(Light *light);
    91 	void addlight(Light *light);
    70 	void setSampler(Sampler *sampl) { sampler = sampl; };
    92 	void setSampler(Sampler *sampl) { sampler = sampl; };