add BLI_strcpy_rlen, replace strcat, which was used in misleading way.
[blender.git] / intern / cycles / render / background.cpp
1 /*
2  * Copyright 2011, Blender Foundation.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18
19 #include "background.h"
20 #include "device.h"
21 #include "integrator.h"
22 #include "graph.h"
23 #include "nodes.h"
24 #include "scene.h"
25 #include "shader.h"
26
27 #include "util_foreach.h"
28 #include "util_math.h"
29 #include "util_types.h"
30
31 CCL_NAMESPACE_BEGIN
32
33 Background::Background()
34 {
35         ao_factor = 0.0f;
36         ao_distance = FLT_MAX;
37
38         use = true;
39
40         visibility = ~0;
41
42         transparent = false;
43         need_update = true;
44 }
45
46 Background::~Background()
47 {
48 }
49
50 void Background::device_update(Device *device, DeviceScene *dscene, Scene *scene)
51 {
52         if(!need_update)
53                 return;
54         
55         device_free(device, dscene);
56
57         /* set shader index and transparent option */
58         KernelBackground *kbackground = &dscene->data.background;
59
60         kbackground->ao_factor = ao_factor;
61         kbackground->ao_distance = ao_distance;
62
63         kbackground->transparent = transparent;
64         if(use)
65                 kbackground->shader = scene->shader_manager->get_shader_id(scene->default_background);
66         else
67                 kbackground->shader = scene->shader_manager->get_shader_id(scene->default_empty);
68
69         if(!(visibility & PATH_RAY_DIFFUSE))
70                 kbackground->shader |= SHADER_EXCLUDE_DIFFUSE;
71         if(!(visibility & PATH_RAY_GLOSSY))
72                 kbackground->shader |= SHADER_EXCLUDE_GLOSSY;
73         if(!(visibility & PATH_RAY_TRANSMIT))
74                 kbackground->shader |= SHADER_EXCLUDE_TRANSMIT;
75         if(!(visibility & PATH_RAY_CAMERA))
76                 kbackground->shader |= SHADER_EXCLUDE_CAMERA;
77
78         need_update = false;
79 }
80
81 void Background::device_free(Device *device, DeviceScene *dscene)
82 {
83 }
84
85 bool Background::modified(const Background& background)
86 {
87         return !(transparent == background.transparent &&
88                 use == background.use &&
89                 ao_factor == background.ao_factor &&
90                 ao_distance == background.ao_distance &&
91                 visibility == background.visibility);
92 }
93
94 void Background::tag_update(Scene *scene)
95 {
96         scene->integrator->tag_update(scene);
97         need_update = true;
98 }
99
100 CCL_NAMESPACE_END
101