Merge remote-tracking branch 'origin/master' into blender2.8
[blender.git] / intern / cycles / blender / blender_sync.cpp
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include "background.h"
18 #include "camera.h"
19 #include "film.h"
20 #include "graph.h"
21 #include "integrator.h"
22 #include "light.h"
23 #include "mesh.h"
24 #include "nodes.h"
25 #include "object.h"
26 #include "scene.h"
27 #include "shader.h"
28 #include "curves.h"
29
30 #include "device.h"
31
32 #include "blender_sync.h"
33 #include "blender_session.h"
34 #include "blender_util.h"
35
36 #include "util_debug.h"
37 #include "util_foreach.h"
38 #include "util_opengl.h"
39 #include "util_hash.h"
40
41 CCL_NAMESPACE_BEGIN
42
43 /* Constructor */
44
45 BlenderSync::BlenderSync(BL::RenderEngine& b_engine,
46                          BL::BlendData& b_data,
47                          BL::Scene& b_scene,
48                          Scene *scene,
49                          bool preview,
50                          Progress &progress,
51                          bool is_cpu)
52 : b_engine(b_engine),
53   b_data(b_data),
54   b_scene(b_scene),
55   shader_map(&scene->shaders),
56   object_map(&scene->objects),
57   mesh_map(&scene->meshes),
58   light_map(&scene->lights),
59   world_map(NULL),
60   world_recalc(false),
61   scene(scene),
62   preview(preview),
63   experimental(false),
64   is_cpu(is_cpu),
65   dicing_rate(1.0f),
66   max_subdivisions(12),
67   progress(progress)
68 {
69         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
70         dicing_rate = preview ? RNA_float_get(&cscene, "preview_dicing_rate") : RNA_float_get(&cscene, "dicing_rate");
71         max_subdivisions = RNA_int_get(&cscene, "max_subdivisions");
72 }
73
74 BlenderSync::~BlenderSync()
75 {
76 }
77
78 /* Sync */
79
80 bool BlenderSync::sync_recalc()
81 {
82         /* sync recalc flags from blender to cycles. actual update is done separate,
83          * so we can do it later on if doing it immediate is not suitable */
84
85         BL::BlendData::materials_iterator b_mat;
86         bool has_updated_objects = b_data.objects.is_updated();
87         for(b_data.materials.begin(b_mat); b_mat != b_data.materials.end(); ++b_mat) {
88                 if(b_mat->is_updated() || (b_mat->node_tree() && b_mat->node_tree().is_updated())) {
89                         shader_map.set_recalc(*b_mat);
90                 }
91                 else {
92                         Shader *shader = shader_map.find(*b_mat);
93                         if(has_updated_objects && shader != NULL && shader->has_object_dependency) {
94                                 shader_map.set_recalc(*b_mat);
95                         }
96                 }
97         }
98
99         BL::BlendData::lamps_iterator b_lamp;
100
101         for(b_data.lamps.begin(b_lamp); b_lamp != b_data.lamps.end(); ++b_lamp)
102                 if(b_lamp->is_updated() || (b_lamp->node_tree() && b_lamp->node_tree().is_updated()))
103                         shader_map.set_recalc(*b_lamp);
104
105         bool dicing_prop_changed = false;
106
107         if(experimental) {
108                 PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
109
110                 float updated_dicing_rate = preview ? RNA_float_get(&cscene, "preview_dicing_rate")
111                                                     : RNA_float_get(&cscene, "dicing_rate");
112
113                 if(dicing_rate != updated_dicing_rate) {
114                         dicing_rate = updated_dicing_rate;
115                         dicing_prop_changed = true;
116                 }
117
118                 int updated_max_subdivisions = RNA_int_get(&cscene, "max_subdivisions");
119
120                 if(max_subdivisions != updated_max_subdivisions) {
121                         max_subdivisions = updated_max_subdivisions;
122                         dicing_prop_changed = true;
123                 }
124         }
125
126         BL::BlendData::objects_iterator b_ob;
127
128         for(b_data.objects.begin(b_ob); b_ob != b_data.objects.end(); ++b_ob) {
129                 if(b_ob->is_updated()) {
130                         object_map.set_recalc(*b_ob);
131                         light_map.set_recalc(*b_ob);
132                 }
133
134                 if(object_is_mesh(*b_ob)) {
135                         if(b_ob->is_updated_data() || b_ob->data().is_updated() ||
136                            (dicing_prop_changed && object_subdivision_type(*b_ob, preview, experimental) != Mesh::SUBDIVISION_NONE))
137                         {
138                                 BL::ID key = BKE_object_is_modified(*b_ob)? *b_ob: b_ob->data();
139                                 mesh_map.set_recalc(key);
140                         }
141                 }
142                 else if(object_is_light(*b_ob)) {
143                         if(b_ob->is_updated_data() || b_ob->data().is_updated())
144                                 light_map.set_recalc(*b_ob);
145                 }
146         }
147
148         BL::BlendData::meshes_iterator b_mesh;
149
150         for(b_data.meshes.begin(b_mesh); b_mesh != b_data.meshes.end(); ++b_mesh) {
151                 if(b_mesh->is_updated()) {
152                         mesh_map.set_recalc(*b_mesh);
153                 }
154         }
155
156         BL::BlendData::worlds_iterator b_world;
157
158         for(b_data.worlds.begin(b_world); b_world != b_data.worlds.end(); ++b_world) {
159                 if(world_map == b_world->ptr.data) {
160                         if(b_world->is_updated() ||
161                            (b_world->node_tree() && b_world->node_tree().is_updated()))
162                         {
163                                 world_recalc = true;
164                         }
165                         else if(b_world->node_tree() && b_world->use_nodes()) {
166                                 Shader *shader = scene->default_background;
167                                 if(has_updated_objects && shader->has_object_dependency) {
168                                         world_recalc = true;
169                                 }
170                         }
171                 }
172         }
173
174         bool recalc =
175                 shader_map.has_recalc() ||
176                 object_map.has_recalc() ||
177                 light_map.has_recalc() ||
178                 mesh_map.has_recalc() ||
179                 BlendDataObjects_is_updated_get(&b_data.ptr) ||
180                 world_recalc;
181
182         return recalc;
183 }
184
185 void BlenderSync::sync_data(BL::RenderSettings& b_render,
186                             BL::SpaceView3D& b_v3d,
187                             BL::Object& b_override,
188                             int width, int height,
189                             void **python_thread_state,
190                             const char *layer)
191 {
192         sync_render_layers(b_v3d, layer);
193         sync_integrator();
194         sync_film();
195         sync_shaders();
196         sync_images();
197         sync_curve_settings();
198
199         mesh_synced.clear(); /* use for objects and motion sync */
200
201         if(scene->need_motion() == Scene::MOTION_PASS ||
202            scene->need_motion() == Scene::MOTION_NONE ||
203            scene->camera->motion_position == Camera::MOTION_POSITION_CENTER)
204         {
205                 sync_objects(b_v3d);
206         }
207         sync_motion(b_render,
208                     b_v3d,
209                     b_override,
210                     width, height,
211                     python_thread_state);
212
213         mesh_synced.clear();
214 }
215
216 /* Integrator */
217
218 void BlenderSync::sync_integrator()
219 {
220 #ifdef __CAMERA_MOTION__
221         BL::RenderSettings r = b_scene.render();
222 #endif
223         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
224
225         experimental = (get_enum(cscene, "feature_set") != 0);
226
227         Integrator *integrator = scene->integrator;
228         Integrator previntegrator = *integrator;
229
230         integrator->min_bounce = get_int(cscene, "min_bounces");
231         integrator->max_bounce = get_int(cscene, "max_bounces");
232
233         integrator->max_diffuse_bounce = get_int(cscene, "diffuse_bounces");
234         integrator->max_glossy_bounce = get_int(cscene, "glossy_bounces");
235         integrator->max_transmission_bounce = get_int(cscene, "transmission_bounces");
236         integrator->max_volume_bounce = get_int(cscene, "volume_bounces");
237
238         integrator->transparent_max_bounce = get_int(cscene, "transparent_max_bounces");
239         integrator->transparent_min_bounce = get_int(cscene, "transparent_min_bounces");
240         integrator->transparent_shadows = get_boolean(cscene, "use_transparent_shadows");
241
242         integrator->volume_max_steps = get_int(cscene, "volume_max_steps");
243         integrator->volume_step_size = get_float(cscene, "volume_step_size");
244
245         integrator->caustics_reflective = get_boolean(cscene, "caustics_reflective");
246         integrator->caustics_refractive = get_boolean(cscene, "caustics_refractive");
247         integrator->filter_glossy = get_float(cscene, "blur_glossy");
248
249         integrator->seed = get_int(cscene, "seed");
250         if(get_boolean(cscene, "use_animated_seed")) {
251                 integrator->seed = hash_int_2d(b_scene.frame_current(),
252                                                get_int(cscene, "seed")) +
253                                    hash_int_2d((int)(b_scene.frame_subframe() * (float)INT_MAX),
254                                                get_int(cscene, "seed"));
255         }
256
257         integrator->sampling_pattern = (SamplingPattern)get_enum(
258                 cscene,
259                 "sampling_pattern",
260                 SAMPLING_NUM_PATTERNS,
261                 SAMPLING_PATTERN_SOBOL);
262
263         integrator->sample_clamp_direct = get_float(cscene, "sample_clamp_direct");
264         integrator->sample_clamp_indirect = get_float(cscene, "sample_clamp_indirect");
265 #ifdef __CAMERA_MOTION__
266         if(!preview) {
267                 if(integrator->motion_blur != r.use_motion_blur()) {
268                         scene->object_manager->tag_update(scene);
269                         scene->camera->tag_update();
270                 }
271
272                 integrator->motion_blur = r.use_motion_blur();
273         }
274 #endif
275
276         integrator->method = (Integrator::Method)get_enum(cscene,
277                                                           "progressive",
278                                                           Integrator::NUM_METHODS,
279                                                           Integrator::PATH);
280
281         integrator->sample_all_lights_direct = get_boolean(cscene, "sample_all_lights_direct");
282         integrator->sample_all_lights_indirect = get_boolean(cscene, "sample_all_lights_indirect");
283         integrator->light_sampling_threshold = get_float(cscene, "light_sampling_threshold");
284
285         int diffuse_samples = get_int(cscene, "diffuse_samples");
286         int glossy_samples = get_int(cscene, "glossy_samples");
287         int transmission_samples = get_int(cscene, "transmission_samples");
288         int ao_samples = get_int(cscene, "ao_samples");
289         int mesh_light_samples = get_int(cscene, "mesh_light_samples");
290         int subsurface_samples = get_int(cscene, "subsurface_samples");
291         int volume_samples = get_int(cscene, "volume_samples");
292
293         if(get_boolean(cscene, "use_square_samples")) {
294                 integrator->diffuse_samples = diffuse_samples * diffuse_samples;
295                 integrator->glossy_samples = glossy_samples * glossy_samples;
296                 integrator->transmission_samples = transmission_samples * transmission_samples;
297                 integrator->ao_samples = ao_samples * ao_samples;
298                 integrator->mesh_light_samples = mesh_light_samples * mesh_light_samples;
299                 integrator->subsurface_samples = subsurface_samples * subsurface_samples;
300                 integrator->volume_samples = volume_samples * volume_samples;
301         } 
302         else {
303                 integrator->diffuse_samples = diffuse_samples;
304                 integrator->glossy_samples = glossy_samples;
305                 integrator->transmission_samples = transmission_samples;
306                 integrator->ao_samples = ao_samples;
307                 integrator->mesh_light_samples = mesh_light_samples;
308                 integrator->subsurface_samples = subsurface_samples;
309                 integrator->volume_samples = volume_samples;
310         }
311
312         if(integrator->modified(previntegrator))
313                 integrator->tag_update(scene);
314 }
315
316 /* Film */
317
318 void BlenderSync::sync_film()
319 {
320         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
321
322         Film *film = scene->film;
323         Film prevfilm = *film;
324         
325         film->exposure = get_float(cscene, "film_exposure");
326         film->filter_type = (FilterType)get_enum(cscene,
327                                                  "pixel_filter_type",
328                                                  FILTER_NUM_TYPES,
329                                                  FILTER_BLACKMAN_HARRIS);
330         film->filter_width = (film->filter_type == FILTER_BOX)? 1.0f: get_float(cscene, "filter_width");
331
332         if(b_scene.world()) {
333                 BL::WorldMistSettings b_mist = b_scene.world().mist_settings();
334
335                 film->mist_start = b_mist.start();
336                 film->mist_depth = b_mist.depth();
337
338                 switch(b_mist.falloff()) {
339                         case BL::WorldMistSettings::falloff_QUADRATIC:
340                                 film->mist_falloff = 2.0f;
341                                 break;
342                         case BL::WorldMistSettings::falloff_LINEAR:
343                                 film->mist_falloff = 1.0f;
344                                 break;
345                         case BL::WorldMistSettings::falloff_INVERSE_QUADRATIC:
346                                 film->mist_falloff = 0.5f;
347                                 break;
348                 }
349         }
350
351         if(film->modified(prevfilm))
352                 film->tag_update(scene);
353 }
354
355 /* Render Layer */
356
357 void BlenderSync::sync_render_layers(BL::SpaceView3D& b_v3d, const char *layer)
358 {
359         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
360         string layername;
361
362         /* 3d view */
363         if(b_v3d) {
364                 if(RNA_boolean_get(&cscene, "preview_active_layer")) {
365                         BL::RenderLayers layers(b_scene.render().ptr);
366                         layername = layers.active().name();
367                         layer = layername.c_str();
368                 }
369                 else {
370                         render_layer.scene_layer = get_layer(b_v3d.layers(), b_v3d.layers_local_view());
371                         render_layer.layer = render_layer.scene_layer;
372                         render_layer.exclude_layer = 0;
373                         render_layer.holdout_layer = 0;
374                         render_layer.material_override = PointerRNA_NULL;
375                         render_layer.use_background_shader = true;
376                         render_layer.use_background_ao = true;
377                         render_layer.use_hair = true;
378                         render_layer.use_surfaces = true;
379                         render_layer.use_viewport_visibility = true;
380                         render_layer.samples = 0;
381                         render_layer.bound_samples = false;
382                         return;
383                 }
384         }
385
386         /* render layer */
387         BL::RenderSettings r = b_scene.render();
388         BL::RenderSettings::layers_iterator b_rlay;
389         int use_layer_samples = get_enum(cscene, "use_layer_samples");
390         bool first_layer = true;
391         uint layer_override = get_layer(b_engine.layer_override());
392         uint scene_layers = layer_override ? layer_override : get_layer(b_scene.layers());
393
394         for(r.layers.begin(b_rlay); b_rlay != r.layers.end(); ++b_rlay) {
395                 if((!layer && first_layer) || (layer && b_rlay->name() == layer)) {
396                         render_layer.name = b_rlay->name();
397
398                         render_layer.holdout_layer = get_layer(b_rlay->layers_zmask());
399                         render_layer.exclude_layer = get_layer(b_rlay->layers_exclude());
400
401                         render_layer.scene_layer = scene_layers & ~render_layer.exclude_layer;
402                         render_layer.scene_layer |= render_layer.exclude_layer & render_layer.holdout_layer;
403
404                         render_layer.layer = get_layer(b_rlay->layers());
405                         render_layer.layer |= render_layer.holdout_layer;
406
407                         render_layer.material_override = b_rlay->material_override();
408                         render_layer.use_background_shader = b_rlay->use_sky();
409                         render_layer.use_background_ao = b_rlay->use_ao();
410                         render_layer.use_surfaces = b_rlay->use_solid();
411                         render_layer.use_hair = b_rlay->use_strand();
412                         render_layer.use_viewport_visibility = false;
413
414                         render_layer.bound_samples = (use_layer_samples == 1);
415                         if(use_layer_samples != 2) {
416                                 int samples = b_rlay->samples();
417                                 if(get_boolean(cscene, "use_square_samples"))
418                                         render_layer.samples = samples * samples;
419                                 else
420                                         render_layer.samples = samples;
421                         }
422                 }
423
424                 first_layer = false;
425         }
426 }
427
428 /* Images */
429 void BlenderSync::sync_images()
430 {
431         /* Sync is a convention for this API, but currently it frees unused buffers. */
432
433         const bool is_interface_locked = b_engine.render() &&
434                                          b_engine.render().use_lock_interface();
435         if(is_interface_locked == false && BlenderSession::headless == false) {
436                 /* If interface is not locked, it's possible image is needed for
437                  * the display.
438                  */
439                 return;
440         }
441         /* Free buffers used by images which are not needed for render. */
442         BL::BlendData::images_iterator b_image;
443         for(b_data.images.begin(b_image);
444             b_image != b_data.images.end();
445             ++b_image)
446         {
447                 /* TODO(sergey): Consider making it an utility function to check
448                  * whether image is considered builtin.
449                  */
450                 const bool is_builtin = b_image->packed_file() ||
451                                         b_image->source() == BL::Image::source_GENERATED ||
452                                         b_image->source() == BL::Image::source_MOVIE ||
453                                         b_engine.is_preview();
454                 if(is_builtin == false) {
455                         b_image->buffers_free();
456                 }
457                 /* TODO(sergey): Free builtin images not used by any shader. */
458         }
459 }
460
461 /* Scene Parameters */
462
463 SceneParams BlenderSync::get_scene_params(BL::Scene& b_scene,
464                                           bool background,
465                                           bool is_cpu)
466 {
467         BL::RenderSettings r = b_scene.render();
468         SceneParams params;
469         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
470         const bool shadingsystem = RNA_boolean_get(&cscene, "shading_system");
471
472         if(shadingsystem == 0)
473                 params.shadingsystem = SHADINGSYSTEM_SVM;
474         else if(shadingsystem == 1)
475                 params.shadingsystem = SHADINGSYSTEM_OSL;
476         
477         if(background)
478                 params.bvh_type = SceneParams::BVH_STATIC;
479         else
480                 params.bvh_type = (SceneParams::BVHType)get_enum(
481                         cscene,
482                         "debug_bvh_type",
483                         SceneParams::BVH_NUM_TYPES,
484                         SceneParams::BVH_STATIC);
485
486         params.use_bvh_spatial_split = RNA_boolean_get(&cscene, "debug_use_spatial_splits");
487         params.use_bvh_unaligned_nodes = RNA_boolean_get(&cscene, "debug_use_hair_bvh");
488
489         if(background && params.shadingsystem != SHADINGSYSTEM_OSL)
490                 params.persistent_data = r.use_persistent_data();
491         else
492                 params.persistent_data = false;
493
494 #if !(defined(__GNUC__) && (defined(i386) || defined(_M_IX86)))
495         if(is_cpu) {
496                 params.use_qbvh = DebugFlags().cpu.qbvh && system_cpu_support_sse2();
497         }
498         else
499 #endif
500         {
501                 params.use_qbvh = false;
502         }
503
504         return params;
505 }
506
507 /* Session Parameters */
508
509 bool BlenderSync::get_session_pause(BL::Scene& b_scene, bool background)
510 {
511         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
512         return (background)? false: get_boolean(cscene, "preview_pause");
513 }
514
515 SessionParams BlenderSync::get_session_params(BL::RenderEngine& b_engine,
516                                               BL::UserPreferences& b_userpref,
517                                               BL::Scene& b_scene,
518                                               bool background)
519 {
520         SessionParams params;
521         PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
522
523         /* feature set */
524         params.experimental = (get_enum(cscene, "feature_set") != 0);
525
526         /* device type */
527         vector<DeviceInfo>& devices = Device::available_devices();
528         
529         /* device default CPU */
530         foreach(DeviceInfo& device, devices) {
531                 if(device.type == DEVICE_CPU) {
532                         params.device = device;
533                         break;
534                 }
535         }
536
537         if(get_enum(cscene, "device") == 2) {
538                 /* find network device */
539                 foreach(DeviceInfo& info, devices)
540                         if(info.type == DEVICE_NETWORK)
541                                 params.device = info;
542         }
543         else if(get_enum(cscene, "device") == 1) {
544                 PointerRNA b_preferences;
545
546                 BL::UserPreferences::addons_iterator b_addon_iter;
547                 for(b_userpref.addons.begin(b_addon_iter); b_addon_iter != b_userpref.addons.end(); ++b_addon_iter) {
548                         if(b_addon_iter->module() == "cycles") {
549                                 b_preferences = b_addon_iter->preferences().ptr;
550                                 break;
551                         }
552                 }
553
554                 int compute_device = get_enum(b_preferences, "compute_device_type");
555
556                 if(compute_device != 0) {
557                         vector<DeviceInfo> used_devices;
558                         RNA_BEGIN(&b_preferences, device, "devices") {
559                                 if(get_enum(device, "type") == compute_device && get_boolean(device, "use")) {
560                                         string id = get_string(device, "id");
561                                         foreach(DeviceInfo& info, devices) {
562                                                 if(info.id == id) {
563                                                         used_devices.push_back(info);
564                                                         break;
565                                                 }
566                                         }
567                                 }
568                         } RNA_END
569
570                         if(used_devices.size() == 1) {
571                                 params.device = used_devices[0];
572                         }
573                         else if(used_devices.size() > 1) {
574                                 params.device = Device::get_multi_device(used_devices);
575                         }
576                         /* Else keep using the CPU device that was set before. */
577                 }
578         }
579
580         /* Background */
581         params.background = background;
582
583         /* samples */
584         int samples = get_int(cscene, "samples");
585         int aa_samples = get_int(cscene, "aa_samples");
586         int preview_samples = get_int(cscene, "preview_samples");
587         int preview_aa_samples = get_int(cscene, "preview_aa_samples");
588         
589         if(get_boolean(cscene, "use_square_samples")) {
590                 aa_samples = aa_samples * aa_samples;
591                 preview_aa_samples = preview_aa_samples * preview_aa_samples;
592
593                 samples = samples * samples;
594                 preview_samples = preview_samples * preview_samples;
595         }
596
597         if(get_enum(cscene, "progressive") == 0) {
598                 if(background) {
599                         params.samples = aa_samples;
600                 }
601                 else {
602                         params.samples = preview_aa_samples;
603                         if(params.samples == 0)
604                                 params.samples = INT_MAX;
605                 }
606         }
607         else {
608                 if(background) {
609                         params.samples = samples;
610                 }
611                 else {
612                         params.samples = preview_samples;
613                         if(params.samples == 0)
614                                 params.samples = INT_MAX;
615                 }
616         }
617
618         /* tiles */
619         if(params.device.type != DEVICE_CPU && !background) {
620                 /* currently GPU could be much slower than CPU when using tiles,
621                  * still need to be investigated, but meanwhile make it possible
622                  * to work in viewport smoothly
623                  */
624                 int debug_tile_size = get_int(cscene, "debug_tile_size");
625
626                 params.tile_size = make_int2(debug_tile_size, debug_tile_size);
627         }
628         else {
629                 int tile_x = b_engine.tile_x();
630                 int tile_y = b_engine.tile_y();
631
632                 params.tile_size = make_int2(tile_x, tile_y);
633         }
634
635         if((BlenderSession::headless == false) && background) {
636                 params.tile_order = (TileOrder)get_enum(cscene, "tile_order");
637         }
638         else {
639                 params.tile_order = TILE_BOTTOM_TO_TOP;
640         }
641
642         params.start_resolution = get_int(cscene, "preview_start_resolution");
643
644         /* other parameters */
645         if(b_scene.render().threads_mode() == BL::RenderSettings::threads_mode_FIXED)
646                 params.threads = b_scene.render().threads();
647         else
648                 params.threads = 0;
649
650         params.cancel_timeout = (double)get_float(cscene, "debug_cancel_timeout");
651         params.reset_timeout = (double)get_float(cscene, "debug_reset_timeout");
652         params.text_timeout = (double)get_float(cscene, "debug_text_timeout");
653
654         params.progressive_refine = get_boolean(cscene, "use_progressive_refine");
655
656         if(background) {
657                 if(params.progressive_refine)
658                         params.progressive = true;
659                 else
660                         params.progressive = false;
661
662                 params.start_resolution = INT_MAX;
663         }
664         else
665                 params.progressive = true;
666
667         /* shading system - scene level needs full refresh */
668         const bool shadingsystem = RNA_boolean_get(&cscene, "shading_system");
669
670         if(shadingsystem == 0)
671                 params.shadingsystem = SHADINGSYSTEM_SVM;
672         else if(shadingsystem == 1)
673                 params.shadingsystem = SHADINGSYSTEM_OSL;
674         
675         /* color managagement */
676 #ifdef GLEW_MX
677         /* When using GLEW MX we need to check whether we've got an OpenGL
678          * context for current window. This is because command line rendering
679          * doesn't have OpenGL context actually.
680          */
681         if(glewGetContext() != NULL)
682 #endif
683         {
684                 params.display_buffer_linear = GLEW_ARB_half_float_pixel &&
685                                                b_engine.support_display_space_shader(b_scene);
686         }
687
688         if(b_engine.is_preview()) {
689                 /* For preview rendering we're using same timeout as
690                  * blender's job update.
691                  */
692                 params.progressive_update_timeout = 0.1;
693         }
694
695         return params;
696 }
697
698 CCL_NAMESPACE_END
699