Cycles render engine, initial commit. This is the engine itself, blender modification...
[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 import bpy
20
21 def init():
22         from cycles import libcycles_blender as lib
23         import os.path
24         lib.init(os.path.dirname(__file__))
25
26 def create(engine, scene, offline):
27         from cycles import libcycles_blender as lib
28         data = bpy.data.as_pointer()
29         scene = scene.as_pointer()
30
31         if not offline and bpy.context.area.type == 'VIEW_3D':
32                 region = bpy.context.region.as_pointer()
33                 v3d = bpy.context.space_data.as_pointer()
34                 rv3d = bpy.context.region_data.as_pointer()
35         else:
36                 region = 0
37                 v3d = 0
38                 rv3d = 0
39
40         engine.session = lib.create(engine.as_pointer(), data, scene, region, v3d, rv3d)
41
42 def free(engine):
43         if "session" in dir(engine):
44                 if engine.session:
45                         from cycles import libcycles_blender as lib
46                         lib.free(engine.session)
47                 del engine.session
48
49 def render(engine, scene):
50         from cycles import libcycles_blender as lib
51         lib.render(engine.session)
52
53 def update(engine, scene):
54         from cycles import libcycles_blender as lib
55         lib.sync(engine.session)
56
57 def draw(engine, scene):
58         from cycles import libcycles_blender as lib
59         v3d = bpy.context.space_data.as_pointer()
60         rv3d = bpy.context.region_data.as_pointer()
61         region = bpy.context.region
62
63         # draw render image
64         status, substatus = lib.draw(engine.session, v3d, rv3d)
65
66         # draw text over image
67         if status != "":
68                 import blf
69                 import bgl
70
71                 fontid = 0 # todo, find out how to set this
72                 dim = blf.dimensions(fontid, status)
73                 dim_sub = blf.dimensions(fontid, substatus)
74
75                 padding = 5
76
77                 x = (region.width - max(dim[0], dim_sub[0]))*0.5 - padding
78                 y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 - padding
79
80                 bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
81                 bgl.glEnable(bgl.GL_BLEND)
82                 bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
83                 bgl.glRectf(x, y, x+max(dim[0], dim_sub[0])+padding+padding, y+dim[1]+dim_sub[1]+padding+padding+2)
84                 bgl.glDisable(bgl.GL_BLEND)
85
86                 x = (region.width - dim[0])*0.5
87                 y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 + dim_sub[1] + padding
88
89                 bgl.glColor3f(0.8, 0.8, 0.8)
90                 blf.position(fontid, x, y, 0)
91                 blf.draw(fontid, status)
92
93                 x = (region.width - dim_sub[0])*0.5
94                 y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5
95
96                 bgl.glColor3f(0.6, 0.6, 0.6)
97                 blf.position(fontid, x, y, 0)
98                 blf.draw(fontid, substatus)
99
100 def available_devices():
101         from cycles import libcycles_blender as lib
102         return lib.available_devices()
103
104 def with_osl():
105         from cycles import libcycles_blender as lib
106         return lib.with_osl()
107