Cycles: Initialize "headless" flags on engine initialization
authorSergey Sharybin <sergey.vfx@gmail.com>
Wed, 18 Feb 2015 16:16:52 +0000 (21:16 +0500)
committerSergey Sharybin <sergey.vfx@gmail.com>
Wed, 18 Feb 2015 16:52:51 +0000 (21:52 +0500)
This flag is global for all the sessions and never changes. so it doesn't
really make sense to pass it around to all sessions and synchronization
routines.

Switched to a static member of BlenderSession now, but it's probably more
logical to introduce some sort of BlenderGlobals. Doesn't currently worth
a hassle for a single boolean flag tho.

intern/cycles/blender/addon/__init__.py
intern/cycles/blender/addon/engine.py
intern/cycles/blender/blender_python.cpp
intern/cycles/blender/blender_session.cpp
intern/cycles/blender/blender_session.h
intern/cycles/blender/blender_sync.cpp
intern/cycles/blender/blender_sync.h

index 8714dfae84e9f2da7f05f8544699cff7fd52ed8a..64e4a8391d1e464ef871d4e27b18e5aeb698ebe8 100644 (file)
@@ -59,7 +59,7 @@ class CyclesRender(bpy.types.RenderEngine):
                               None, None, None, use_osl)
         else:
             if not self.session:
-                engine.create(self, data, scene, headless=bpy.app.background)
+                engine.create(self, data, scene)
             else:
                 engine.reset(self, data, scene)
 
index 400cf70da8d429d8600be1ad2268e25cad01a152..e50a8e45b52e1029f3df6150db80b72b85c13b1b 100644 (file)
@@ -25,10 +25,10 @@ def init():
     path = os.path.dirname(__file__)
     user_path = os.path.dirname(os.path.abspath(bpy.utils.user_resource('CONFIG', '')))
 
-    _cycles.init(path, user_path)
+    _cycles.init(path, user_path, bpy.app.background)
 
 
-def create(engine, data, scene, region=None, v3d=None, rv3d=None, preview_osl=False, headless=False):
+def create(engine, data, scene, region=None, v3d=None, rv3d=None, preview_osl=False):
     import bpy
     import _cycles
 
@@ -42,7 +42,7 @@ def create(engine, data, scene, region=None, v3d=None, rv3d=None, preview_osl=Fa
     if rv3d:
         rv3d = rv3d.as_pointer()
 
-    engine.session = _cycles.create(engine.as_pointer(), userpref, data, scene, region, v3d, rv3d, preview_osl, headless)
+    engine.session = _cycles.create(engine.as_pointer(), userpref, data, scene, region, v3d, rv3d, preview_osl)
 
 
 def free(engine):
index 78419f76283091cb64a832abec7ab558977df8cc..292af14c63a71f6ad6705ae5d8c7ebd8144800cb 100644 (file)
@@ -73,8 +73,9 @@ static const char *PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce)
 static PyObject *init_func(PyObject *self, PyObject *args)
 {
        PyObject *path, *user_path;
+       int headless;
 
-       if(!PyArg_ParseTuple(args, "OO", &path, &user_path)) {
+       if(!PyArg_ParseTuple(args, "OOi", &path, &user_path, &headless)) {
                return NULL;
        }
 
@@ -84,16 +85,18 @@ static PyObject *init_func(PyObject *self, PyObject *args)
        Py_XDECREF(path_coerce);
        Py_XDECREF(user_path_coerce);
 
+       BlenderSession::headless = headless;
+
        Py_RETURN_NONE;
 }
 
 static PyObject *create_func(PyObject *self, PyObject *args)
 {
        PyObject *pyengine, *pyuserpref, *pydata, *pyscene, *pyregion, *pyv3d, *pyrv3d;
-       int preview_osl, headless;
+       int preview_osl;
 
-       if(!PyArg_ParseTuple(args, "OOOOOOOii", &pyengine, &pyuserpref, &pydata, &pyscene,
-                            &pyregion, &pyv3d, &pyrv3d, &preview_osl, &headless))
+       if(!PyArg_ParseTuple(args, "OOOOOOOi", &pyengine, &pyuserpref, &pydata, &pyscene,
+                            &pyregion, &pyv3d, &pyrv3d, &preview_osl))
        {
                return NULL;
        }
@@ -147,7 +150,7 @@ static PyObject *create_func(PyObject *self, PyObject *args)
                }
 
                /* offline session or preview render */
-               session = new BlenderSession(engine, userpref, data, scene, headless);
+               session = new BlenderSession(engine, userpref, data, scene);
        }
 
        python_thread_state_save(&session->python_thread_state);
index 466a39e009b691ee08c258d2dd5da05aecf21b0a..e61203d807a62f5ee4f24e4890ff01c8bfa65843 100644 (file)
 
 CCL_NAMESPACE_BEGIN
 
+bool BlenderSession::headless = false;
+
 BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b_userpref_,
-       BL::BlendData b_data_, BL::Scene b_scene_, bool headless_)
+       BL::BlendData b_data_, BL::Scene b_scene_)
 : b_engine(b_engine_), b_userpref(b_userpref_), b_data(b_data_), b_render(b_engine_.render()), b_scene(b_scene_),
   b_v3d(PointerRNA_NULL), b_rv3d(PointerRNA_NULL), python_thread_state(NULL)
 {
@@ -52,7 +54,6 @@ BlenderSession::BlenderSession(BL::RenderEngine b_engine_, BL::UserPreferences b
        height = render_resolution_y(b_render);
 
        background = true;
-       headless = headless_;
        last_redraw_time = 0.0;
        start_resize_time = 0.0;
 }
@@ -87,7 +88,7 @@ void BlenderSession::create()
 
 void BlenderSession::create_session()
 {
-       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background, headless);
+       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
        bool is_cpu = session_params.device.type == DEVICE_CPU;
        SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background, is_cpu);
        bool session_pause = BlenderSync::get_session_pause(b_scene, background);
@@ -144,7 +145,7 @@ void BlenderSession::reset_session(BL::BlendData b_data_, BL::Scene b_scene_)
        b_render = b_engine.render();
        b_scene = b_scene_;
 
-       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background, headless);
+       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
        const bool is_cpu = session_params.device.type == DEVICE_CPU;
        SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background, is_cpu);
 
@@ -409,7 +410,7 @@ void BlenderSession::render()
        session->update_render_tile_cb = function_bind(&BlenderSession::update_render_tile, this, _1);
 
        /* get buffer parameters */
-       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background, headless);
+       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
        BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_scene, b_v3d, b_rv3d, scene->camera, width, height);
 
        /* render each layer */
@@ -541,7 +542,7 @@ void BlenderSession::bake(BL::Object b_object, const string& pass_type, BL::Bake
        sync->sync_data(b_v3d, b_engine.camera_override(), &python_thread_state);
 
        /* get buffer parameters */
-       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background, headless);
+       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
        BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_scene, b_v3d, b_rv3d, scene->camera, width, height);
 
        scene->bake_manager->set_shader_limit((size_t)b_engine.tile_x(), (size_t)b_engine.tile_y());
@@ -644,7 +645,7 @@ void BlenderSession::synchronize()
                return;
 
        /* on session/scene parameter changes, we recreate session entirely */
-       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background, headless);
+       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
        const bool is_cpu = session_params.device.type == DEVICE_CPU;
        SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background, is_cpu);
        bool session_pause = BlenderSync::get_session_pause(b_scene, background);
@@ -745,7 +746,7 @@ bool BlenderSession::draw(int w, int h)
 
                /* reset if requested */
                if(reset) {
-                       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background, headless);
+                       SessionParams session_params = BlenderSync::get_session_params(b_engine, b_userpref, b_scene, background);
                        BufferParams buffer_params = BlenderSync::get_buffer_params(b_render, b_scene, b_v3d, b_rv3d, scene->camera, width, height);
                        bool session_pause = BlenderSync::get_session_pause(b_scene, background);
 
index dc9f9c18f7940f641019a903c4e2ea3651bf7375..c8070286006c804838de02e1baa47f0efeb2a665 100644 (file)
@@ -34,7 +34,7 @@ class RenderTile;
 class BlenderSession {
 public:
        BlenderSession(BL::RenderEngine b_engine, BL::UserPreferences b_userpref,
-               BL::BlendData b_data, BL::Scene b_scene, bool is_headless);
+               BL::BlendData b_data, BL::Scene b_scene);
        BlenderSession(BL::RenderEngine b_engine, BL::UserPreferences b_userpref,
                BL::BlendData b_data, BL::Scene b_scene,
                BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, int width, int height);
@@ -76,7 +76,7 @@ public:
        void update_bake_progress();
 
        bool background;
-       bool headless;
+       static bool headless;
        Session *session;
        Scene *scene;
        BlenderSync *sync;
index fb32f67d71aebcba6b5b9f3119c5eaa3912bceff..fe33ccbc6c19666e3d99472acb66a181d9a5abde 100644 (file)
@@ -30,6 +30,7 @@
 #include "device.h"
 
 #include "blender_sync.h"
+#include "blender_session.h"
 #include "blender_util.h"
 
 #include "util_debug.h"
@@ -410,8 +411,7 @@ bool BlenderSync::get_session_pause(BL::Scene b_scene, bool background)
 SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine,
                                               BL::UserPreferences b_userpref,
                                               BL::Scene b_scene,
-                                              bool background,
-                                              bool headless)
+                                              bool background)
 {
        SessionParams params;
        PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
@@ -501,7 +501,7 @@ SessionParams BlenderSync::get_session_params(BL::RenderEngine b_engine,
                params.tile_size = make_int2(tile_x, tile_y);
        }
 
-       if(headless == false) {
+       if(BlenderSession::headless == false) {
                params.tile_order = (TileOrder)RNA_enum_get(&cscene, "tile_order");
        }
        else {
index a16824f68734e35d39211d747518cd32809e8171..6a320ac8085d0cbbb6e59366297bb8266bc5f93e 100644 (file)
@@ -66,8 +66,7 @@ public:
        static SessionParams get_session_params(BL::RenderEngine b_engine,
                                                BL::UserPreferences b_userpref,
                                                BL::Scene b_scene,
-                                               bool background,
-                                               bool headless);
+                                               bool background);
        static bool get_session_pause(BL::Scene b_scene, bool background);
        static BufferParams get_buffer_params(BL::RenderSettings b_render, BL::Scene b_scene, BL::SpaceView3D b_v3d, BL::RegionView3D b_rv3d, Camera *cam, int width, int height);