Merge branch 'master' into blender2.8
[blender.git] / intern / cycles / blender / blender_session.h
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 #ifndef __BLENDER_SESSION_H__
18 #define __BLENDER_SESSION_H__
19
20 #include "device/device.h"
21 #include "render/scene.h"
22 #include "render/session.h"
23 #include "render/bake.h"
24
25 #include "util/util_vector.h"
26
27 CCL_NAMESPACE_BEGIN
28
29 class Scene;
30 class Session;
31 class RenderBuffers;
32 class RenderTile;
33
34 class BlenderSession {
35 public:
36         BlenderSession(BL::RenderEngine& b_engine,
37                        BL::UserPreferences& b_userpref,
38                        BL::BlendData& b_data,
39                        BL::Depsgraph& b_depsgraph,
40                        BL::Scene& b_scene);
41
42         BlenderSession(BL::RenderEngine& b_engine,
43                        BL::UserPreferences& b_userpref,
44                        BL::BlendData& b_data,
45                        BL::Depsgraph& b_depsgraph,
46                        BL::Scene& b_scene,
47                        BL::SpaceView3D& b_v3d,
48                        BL::RegionView3D& b_rv3d,
49                        int width, int height);
50
51         ~BlenderSession();
52
53         void create();
54
55         /* session */
56         void create_session();
57         void free_session();
58
59         void reset_session(BL::BlendData& b_data,
60                            BL::Scene& b_scene);
61
62         /* offline render */
63         void render();
64
65         void bake(BL::Object& b_object,
66                   const string& pass_type,
67                   const int custom_flag,
68                   const int object_id,
69                   BL::BakePixel& pixel_array,
70                   const size_t num_pixels,
71                   const int depth,
72                   float pixels[]);
73
74         void write_render_result(BL::RenderResult& b_rr,
75                                  BL::RenderLayer& b_rlay,
76                                  RenderTile& rtile);
77         void write_render_tile(RenderTile& rtile);
78
79         /* update functions are used to update display buffer only after sample was rendered
80          * only needed for better visual feedback */
81         void update_render_result(BL::RenderResult& b_rr,
82                                   BL::RenderLayer& b_rlay,
83                                   RenderTile& rtile);
84         void update_render_tile(RenderTile& rtile, bool highlight);
85
86         /* interactive updates */
87         void synchronize();
88
89         /* drawing */
90         bool draw(int w, int h);
91         void tag_redraw();
92         void tag_update();
93         void get_status(string& status, string& substatus);
94         void get_progress(float& progress, double& total_time, double& render_time);
95         void test_cancel();
96         void update_status_progress();
97         void update_bake_progress();
98
99         bool background;
100         Session *session;
101         Scene *scene;
102         BlenderSync *sync;
103         double last_redraw_time;
104
105         BL::RenderEngine b_engine;
106         BL::UserPreferences b_userpref;
107         BL::BlendData b_data;
108         BL::RenderSettings b_render;
109         BL::Depsgraph b_depsgraph;
110         BL::Scene b_scene;
111         BL::SpaceView3D b_v3d;
112         BL::RegionView3D b_rv3d;
113         string b_rlay_name;
114         string b_rview_name;
115
116         string last_status;
117         string last_error;
118         float last_progress;
119         double last_status_time;
120
121         int width, height;
122         double start_resize_time;
123
124         void *python_thread_state;
125
126         /* Global state which is common for all render sessions created from Blender.
127          * Usually denotes command line arguments.
128          */
129
130         /* Blender is running from the command line, no windows are shown and some
131          * extra render optimization is possible (possible to free draw-only data and
132          * so on.
133          */
134         static bool headless;
135
136         /* ** Resumable render ** */
137
138         /* Overall number of chunks in which the sample range is to be devided. */
139         static int num_resumable_chunks;
140
141         /* Current resumable chunk index to render. */
142         static int current_resumable_chunk;
143
144         /* Alternative to single-chunk rendering to render a range of chunks. */
145         static int start_resumable_chunk;
146         static int end_resumable_chunk;
147
148 protected:
149         void do_write_update_render_result(BL::RenderResult& b_rr,
150                                            BL::RenderLayer& b_rlay,
151                                            RenderTile& rtile,
152                                            bool do_update_only);
153         void do_write_update_render_tile(RenderTile& rtile, bool do_update_only, bool highlight);
154
155         int builtin_image_frame(const string &builtin_name);
156         void builtin_image_info(const string &builtin_name,
157                                 void *builtin_data,
158                                 bool &is_float,
159                                 int &width,
160                                 int &height,
161                                 int &depth,
162                                 int &channels,
163                                 bool &free_cache);
164         bool builtin_image_pixels(const string &builtin_name,
165                                   void *builtin_data,
166                                   unsigned char *pixels,
167                                   const size_t pixels_size,
168                                   const bool free_cache);
169         bool builtin_image_float_pixels(const string &builtin_name,
170                                         void *builtin_data,
171                                         float *pixels,
172                                         const size_t pixels_size,
173                                         const bool free_cache);
174
175         /* Update tile manager to reflect resumable render settings. */
176         void update_resumable_tile_manager(int num_samples);
177 };
178
179 CCL_NAMESPACE_END
180
181 #endif /* __BLENDER_SESSION_H__ */