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