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