Merging r42800 through r42895 from trunk into soc-2011-tomato
[blender-staging.git] / intern / cycles / blender / addon / engine.py
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 # <pep8 compliant>
20
21 import bpy
22
23
24 def init():
25     import _cycles
26     import os.path
27
28     path = os.path.dirname(__file__)
29     user_path = os.path.dirname(os.path.abspath(bpy.utils.user_resource('CONFIG', '')))
30
31     _cycles.init(path, user_path)
32
33
34 def create(engine, data, scene, region=0, v3d=0, rv3d=0):
35     import _cycles
36
37     data = data.as_pointer()
38     scene = scene.as_pointer()
39     if region:
40         region = region.as_pointer()
41     if v3d:
42         v3d = v3d.as_pointer()
43     if rv3d:
44         rv3d = rv3d.as_pointer()
45
46     engine.session = _cycles.create(engine.as_pointer(), data, scene, region, v3d, rv3d)
47
48
49 def free(engine):
50     if hasattr(engine, "session"):
51         if engine.session:
52             import _cycles
53             _cycles.free(engine.session)
54         del engine.session
55
56
57 def render(engine):
58     import _cycles
59     if hasattr(engine, "session"):
60         _cycles.render(engine.session)
61
62
63 def update(engine, data, scene):
64     import _cycles
65     _cycles.sync(engine.session)
66
67
68 def draw(engine, region, v3d, rv3d):
69     import _cycles
70     v3d = v3d.as_pointer()
71     rv3d = rv3d.as_pointer()
72
73     # draw render image
74     _cycles.draw(engine.session, v3d, rv3d)
75
76
77 def available_devices():
78     import _cycles
79     return _cycles.available_devices()
80
81
82 def with_osl():
83     import _cycles
84     return _cycles.with_osl