1 | |
2 | // |
3 | // This source file is part of appleseed. |
4 | // Visit http://appleseedhq.net/ for additional information and resources. |
5 | // |
6 | // This software is released under the MIT license. |
7 | // |
8 | // Copyright (c) 2012-2013 Esteban Tovagliari, Jupiter Jazz Limited |
9 | // Copyright (c) 2014-2017 Esteban Tovagliari, The appleseedhq Organization |
10 | // |
11 | // Permission is hereby granted, free of charge, to any person obtaining a copy |
12 | // of this software and associated documentation files (the "Software"), to deal |
13 | // in the Software without restriction, including without limitation the rights |
14 | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
15 | // copies of the Software, and to permit persons to whom the Software is |
16 | // furnished to do so, subject to the following conditions: |
17 | // |
18 | // The above copyright notice and this permission notice shall be included in |
19 | // all copies or substantial portions of the Software. |
20 | // |
21 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
22 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
23 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
24 | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
25 | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
26 | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
27 | // THE SOFTWARE. |
28 | // |
29 | |
30 | // appleseed.python headers. |
31 | #include "pyseed.h" // has to be first, to avoid redefinition warnings |
32 | #include "gillocks.h" |
33 | |
34 | // appleseed.renderer headers. |
35 | #include "renderer/kernel/rendering/defaultrenderercontroller.h" |
36 | #include "renderer/kernel/rendering/irenderercontroller.h" |
37 | |
38 | // appleseed.foundation headers. |
39 | #include "foundation/platform/compiler.h" |
40 | |
41 | namespace bpy = boost::python; |
42 | using namespace foundation; |
43 | using namespace renderer; |
44 | |
45 | namespace |
46 | { |
47 | class IRendererControllerWrapper |
48 | : public IRendererController |
49 | , public bpy::wrapper<IRendererController> |
50 | { |
51 | public: |
52 | virtual void on_rendering_begin() APPLESEED_OVERRIDE |
53 | { |
54 | // Lock Python's global interpreter lock (GIL), |
55 | // it was released in MasterRenderer.render. |
56 | ScopedGILLock lock; |
57 | |
58 | try |
59 | { |
60 | get_override("on_rendering_begin" )(); |
61 | } |
62 | catch (bpy::error_already_set) |
63 | { |
64 | PyErr_Print(); |
65 | } |
66 | } |
67 | |
68 | virtual void on_rendering_success() APPLESEED_OVERRIDE |
69 | { |
70 | // Lock Python's global interpreter lock (GIL), |
71 | // it was released in MasterRenderer.render. |
72 | ScopedGILLock lock; |
73 | |
74 | try |
75 | { |
76 | get_override("on_rendering_success" )(); |
77 | } |
78 | catch (bpy::error_already_set) |
79 | { |
80 | PyErr_Print(); |
81 | } |
82 | } |
83 | |
84 | virtual void on_rendering_abort() APPLESEED_OVERRIDE |
85 | { |
86 | // Lock Python's global interpreter lock (GIL), |
87 | // it was released in MasterRenderer.render. |
88 | ScopedGILLock lock; |
89 | |
90 | try |
91 | { |
92 | get_override("on_rendering_abort" )(); |
93 | } |
94 | catch (bpy::error_already_set) |
95 | { |
96 | PyErr_Print(); |
97 | } |
98 | } |
99 | |
100 | virtual void on_frame_begin() APPLESEED_OVERRIDE |
101 | { |
102 | // Lock Python's global interpreter lock (GIL), |
103 | // it was released in MasterRenderer.render. |
104 | ScopedGILLock lock; |
105 | |
106 | try |
107 | { |
108 | get_override("on_frame_begin" )(); |
109 | } |
110 | catch (bpy::error_already_set) |
111 | { |
112 | PyErr_Print(); |
113 | } |
114 | } |
115 | |
116 | virtual void on_frame_end() APPLESEED_OVERRIDE |
117 | { |
118 | // Lock Python's global interpreter lock (GIL), |
119 | // it was released in MasterRenderer.render. |
120 | ScopedGILLock lock; |
121 | |
122 | try |
123 | { |
124 | get_override("on_frame_end" )(); |
125 | } |
126 | catch (bpy::error_already_set) |
127 | { |
128 | PyErr_Print(); |
129 | } |
130 | } |
131 | |
132 | virtual void on_progress() APPLESEED_OVERRIDE |
133 | { |
134 | // Lock Python's global interpreter lock (GIL), |
135 | // it was released in MasterRenderer.render. |
136 | ScopedGILLock lock; |
137 | |
138 | try |
139 | { |
140 | get_override("on_progress" )(); |
141 | } |
142 | catch (bpy::error_already_set) |
143 | { |
144 | PyErr_Print(); |
145 | } |
146 | } |
147 | |
148 | virtual Status get_status() const APPLESEED_OVERRIDE |
149 | { |
150 | // Lock Python's global interpreter lock (GIL), |
151 | // it was released in MasterRenderer.render. |
152 | ScopedGILLock lock; |
153 | |
154 | try |
155 | { |
156 | return get_override("get_status" )(); |
157 | } |
158 | catch (bpy::error_already_set) |
159 | { |
160 | PyErr_Print(); |
161 | return AbortRendering; |
162 | } |
163 | } |
164 | }; |
165 | } |
166 | |
167 | void bind_renderer_controller() |
168 | { |
169 | bpy::enum_<IRendererController::Status>("IRenderControllerStatus" ) |
170 | .value("ContinueRendering" , IRendererController::ContinueRendering) |
171 | .value("PauseRendering" , IRendererController::PauseRendering) |
172 | .value("TerminateRendering" , IRendererController::TerminateRendering) |
173 | .value("AbortRendering" , IRendererController::AbortRendering) |
174 | .value("RestartRendering" , IRendererController::RestartRendering) |
175 | .value("ReinitializeRendering" , IRendererController::ReinitializeRendering) |
176 | ; |
177 | |
178 | bpy::class_<IRendererControllerWrapper, boost::noncopyable>("IRendererController" ) |
179 | .def("on_rendering_begin" , bpy::pure_virtual(&IRendererController::on_rendering_begin)) |
180 | .def("on_rendering_success" , bpy::pure_virtual(&IRendererController::on_rendering_success)) |
181 | .def("on_rendering_abort" , bpy::pure_virtual(&IRendererController::on_rendering_abort)) |
182 | .def("on_frame_begin" , bpy::pure_virtual(&IRendererController::on_frame_begin)) |
183 | .def("on_frame_end" , bpy::pure_virtual(&IRendererController::on_frame_end)) |
184 | .def("on_progress" , bpy::pure_virtual(&IRendererController::on_progress)) |
185 | .def("get_status" , bpy::pure_virtual(&IRendererController::get_status)) |
186 | ; |
187 | |
188 | bpy::class_<DefaultRendererController, boost::noncopyable>("DefaultRendererController" ); |
189 | } |
190 | |