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::SceneLayer b_scene_layer;
112         BL::SpaceView3D b_v3d;
113         BL::RegionView3D b_rv3d;
114         string b_rlay_name;
115         string b_rview_name;
116
117         string last_status;
118         string last_error;
119         float last_progress;
120         double last_status_time;
121
122         int width, height;
123         double start_resize_time;
124
125         void *python_thread_state;
126
127         /* Global state which is common for all render sessions created from Blender.
128          * Usually denotes command line arguments.
129          */
130
131         /* Blender is running from the command line, no windows are shown and some
132          * extra render optimization is possible (possible to free draw-only data and
133          * so on.
134          */
135         static bool headless;
136
137         /* ** Resumable render ** */
138
139         /* Overall number of chunks in which the sample range is to be devided. */
140         static int num_resumable_chunks;
141
142         /* Current resumable chunk index to render. */
143         static int current_resumable_chunk;
144
145         /* Alternative to single-chunk rendering to render a range of chunks. */
146         static int start_resumable_chunk;
147         static int end_resumable_chunk;
148
149 protected:
150         void do_write_update_render_result(BL::RenderResult& b_rr,
151                                            BL::RenderLayer& b_rlay,
152                                            RenderTile& rtile,
153                                            bool do_update_only);
154         void do_write_update_render_tile(RenderTile& rtile, bool do_update_only, bool highlight);
155
156         int builtin_image_frame(const string &builtin_name);
157         void builtin_image_info(const string &builtin_name,
158                                 void *builtin_data,
159                                 bool &is_float,
160                                 int &width,
161                                 int &height,
162                                 int &depth,
163                                 int &channels,
164                                 bool &free_cache);
165         bool builtin_image_pixels(const string &builtin_name,
166                                   void *builtin_data,
167                                   unsigned char *pixels,
168                                   const size_t pixels_size,
169                                   const bool free_cache);
170         bool builtin_image_float_pixels(const string &builtin_name,
171                                         void *builtin_data,
172                                         float *pixels,
173                                         const size_t pixels_size,
174                                         const bool free_cache);
175
176         /* Update tile manager to reflect resumable render settings. */
177         void update_resumable_tile_manager(int num_samples);
178 };
179
180 CCL_NAMESPACE_END
181
182 #endif /* __BLENDER_SESSION_H__ */