Render API: first step in updating RenderEngine to work according to:
[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, data, scene, region = 0, v3d = 0, rv3d = 0):
27         from cycles import libcycles_blender as lib
28
29         data = data.as_pointer()
30         scene = scene.as_pointer()
31         if region:
32                 region = region.as_pointer()
33         if v3d:
34                 v3d = v3d.as_pointer()
35         if rv3d:
36                 rv3d = rv3d.as_pointer()
37
38         engine.session = lib.create(engine.as_pointer(), data, scene, region, v3d, rv3d)
39
40 def free(engine):
41         if "session" in dir(engine):
42                 if engine.session:
43                         from cycles import libcycles_blender as lib
44                         lib.free(engine.session)
45                 del engine.session
46
47 def render(engine):
48         from cycles import libcycles_blender as lib
49         lib.render(engine.session)
50
51 def update(engine, data, scene):
52         from cycles import libcycles_blender as lib
53         lib.sync(engine.session)
54
55 def draw(engine, region, v3d, rv3d):
56         from cycles import libcycles_blender as lib
57         v3d = v3d.as_pointer()
58         rv3d = rv3d.as_pointer()
59
60         # draw render image
61         status, substatus = lib.draw(engine.session, v3d, rv3d)
62
63         # draw text over image
64         if status != "":
65                 import blf
66                 import bgl
67
68                 fontid = 0 # todo, find out how to set this
69                 dim = blf.dimensions(fontid, status)
70                 dim_sub = blf.dimensions(fontid, substatus)
71
72                 padding = 5
73
74                 x = (region.width - max(dim[0], dim_sub[0]))*0.5 - padding
75                 y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 - padding
76
77                 bgl.glColor4f(0.0, 0.0, 0.0, 0.5)
78                 bgl.glEnable(bgl.GL_BLEND)
79                 bgl.glBlendFunc(bgl.GL_SRC_ALPHA, bgl.GL_ONE_MINUS_SRC_ALPHA)
80                 bgl.glRectf(x, y, x+max(dim[0], dim_sub[0])+padding+padding, y+dim[1]+dim_sub[1]+padding+padding+2)
81                 bgl.glDisable(bgl.GL_BLEND)
82
83                 x = (region.width - dim[0])*0.5
84                 y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5 + dim_sub[1] + padding
85
86                 bgl.glColor3f(0.8, 0.8, 0.8)
87                 blf.position(fontid, x, y, 0)
88                 blf.draw(fontid, status)
89
90                 x = (region.width - dim_sub[0])*0.5
91                 y = (region.height - (dim[1] + dim_sub[1] + padding))*0.5
92
93                 bgl.glColor3f(0.6, 0.6, 0.6)
94                 blf.position(fontid, x, y, 0)
95                 blf.draw(fontid, substatus)
96
97 def available_devices():
98         from cycles import libcycles_blender as lib
99         return lib.available_devices()
100
101 def with_osl():
102         from cycles import libcycles_blender as lib
103         return lib.with_osl()
104