Blender V4.3
render_types.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2001-2002 NaN Holding BV. All rights reserved.
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#pragma once
10
11/* ------------------------------------------------------------------------- */
12/* exposed internal in render module only! */
13/* ------------------------------------------------------------------------- */
14
15#include <mutex>
16
17#include "DNA_scene_types.h"
18
19#include "BLI_threads.h"
20
21#include "RE_compositor.hh"
22#include "RE_pipeline.h"
23
24#include "tile_highlight.h"
25
27class RenderContext;
28class Profiler;
29} // namespace blender::realtime_compositor
30
31struct bNodeTree;
32struct Depsgraph;
33struct Main;
34struct Object;
35struct RenderEngine;
36struct ReportList;
37struct Scene;
38
39struct BaseRender {
40 BaseRender() = default;
41 virtual ~BaseRender();
42
43 /* Get class which manages highlight of tiles.
44 * Note that it might not exist: for example, viewport render does not support the tile
45 * highlight. */
47
48 /* GPU/realtime compositor. */
49 virtual void compositor_execute(const Scene &scene,
50 const RenderData &render_data,
51 const bNodeTree &node_tree,
52 const char *view_name,
55 virtual void compositor_free() = 0;
56
57 virtual void display_init(RenderResult *render_result) = 0;
58 virtual void display_clear(RenderResult *render_result) = 0;
59 virtual void display_update(RenderResult *render_result, rcti *rect) = 0;
60 virtual void current_scene_update(struct Scene *scene) = 0;
61
62 virtual void stats_draw(RenderStats *render_stats) = 0;
63 virtual void progress(float progress) = 0;
64
65 virtual void draw_lock() = 0;
66 virtual void draw_unlock() = 0;
67
68 /* Test whether render is to be stopped: if the function returns true rendering will be stopped
69 * as soon as the render pipeline allows it. */
70 virtual bool test_break() = 0;
71
78 virtual bool prepare_viewlayer(struct ViewLayer *view_layer, struct Depsgraph *depsgraph) = 0;
79
80 /* Result of rendering */
81 RenderResult *result = nullptr;
82
83 /* Read/write mutex, all internal code that writes to the `result` must use a
84 * write lock, all external code must use a read lock. Internal code is assumed
85 * to not conflict with writes, so no lock used for that. */
87
88 /* Render engine. */
89 struct RenderEngine *engine = nullptr;
90
91 /* Guard for drawing render result using engine's `draw()` callback. */
93};
94
95struct ViewRender : public BaseRender {
97 {
98 return nullptr;
99 }
100
101 void compositor_execute(const Scene & /*scene*/,
102 const RenderData & /*render_data*/,
103 const bNodeTree & /*node_tree*/,
104 const char * /*view_name*/,
106 blender::realtime_compositor::Profiler * /*profiler*/) override
107 {
108 }
109 void compositor_free() override {}
110
111 void display_init(RenderResult * /*render_result*/) override {}
112 void display_clear(RenderResult * /*render_result*/) override {}
113 void display_update(RenderResult * /*render_result*/, rcti * /*rect*/) override {}
114 void current_scene_update(struct Scene * /*scene*/) override {}
115
116 void stats_draw(RenderStats * /*render_stats*/) override {}
117 void progress(const float /*progress*/) override {}
118
119 void draw_lock() override {}
120 void draw_unlock() override {}
121
122 bool test_break() override
123 {
124 return false;
125 }
126
127 bool prepare_viewlayer(struct ViewLayer * /*view_layer*/,
128 struct Depsgraph * /*depsgraph*/) override
129 {
130 return true;
131 }
132};
133
135struct Render : public BaseRender {
136 /* NOTE: Currently unused, provision for the future.
137 * Add these now to allow the guarded memory allocator to catch C-specific function calls. */
138 Render() = default;
139 virtual ~Render();
140
145
146 void compositor_execute(const Scene &scene,
147 const RenderData &render_data,
148 const bNodeTree &node_tree,
149 const char *view_name,
151 blender::realtime_compositor::Profiler *profiler) override;
152 void compositor_free() override;
153
154 void display_init(RenderResult *render_result) override;
155 void display_clear(RenderResult *render_result) override;
156 void display_update(RenderResult *render_result, rcti *rect) override;
157 void current_scene_update(struct Scene *scene) override;
158
159 void stats_draw(RenderStats *render_stats) override;
160 void progress(float progress) override;
161
162 void draw_lock() override;
163 void draw_unlock() override;
164
165 bool test_break() override;
166
167 bool prepare_viewlayer(struct ViewLayer *view_layer, struct Depsgraph *depsgraph) override;
168
169 char name[RE_MAXNAME] = "";
170
171 /* state settings */
172 short flag = 0;
173 bool ok = false;
174
175 /* if render with single-layer option, other rendered layers are stored here */
178 ListBase fullresult = {nullptr, nullptr};
179 /* True if result has GPU textures, to quickly skip cache clear. */
181
185 int winx = 0, winy = 0;
186 rcti disprect = {0, 0, 0, 0}; /* part within winx winy */
187 rctf viewplane = {0, 0, 0, 0}; /* mapped on winx winy */
188
189 /* final picture width and height (within disprect) */
190 int rectx = 0, recty = 0;
191
192 /* Camera transform. Used by Freestyle, Eevee, and other draw manager engines.. */
193 float winmat[4][4] = {{0}};
194
195 /* Clipping. */
196 float clip_start = 0.0f;
197 float clip_end = 0.0f;
198
199 /* main, scene, and its full copy of renderdata and world */
200 struct Main *main = nullptr;
201 Scene *scene = nullptr;
204 struct Object *camera_override = nullptr;
205
207
208 /* NOTE: This is a minimal dependency graph and evaluated scene which is enough to access view
209 * layer visibility and use for postprocessing (compositor and sequencer). */
210 struct Depsgraph *pipeline_depsgraph = nullptr;
212
213 /* Realtime Compositor.
214 * NOTE: Use bare pointer instead of smart pointer because the RealtimeCompositor is a fully
215 * opaque type. */
218
219 /* Callbacks for the corresponding base class method implementation. */
220 void (*display_init_cb)(void *handle, RenderResult *rr) = nullptr;
221 void *dih = nullptr;
222 void (*display_clear_cb)(void *handle, RenderResult *rr) = nullptr;
223 void *dch = nullptr;
224 void (*display_update_cb)(void *handle, RenderResult *rr, rcti *rect) = nullptr;
225 void *duh = nullptr;
226 void (*current_scene_update_cb)(void *handle, struct Scene *scene) = nullptr;
227 void *suh = nullptr;
228
229 void (*stats_draw_cb)(void *handle, RenderStats *ri) = nullptr;
230 void *sdh = nullptr;
231 void (*progress_cb)(void *handle, float i) = nullptr;
232 void *prh = nullptr;
233
234 void (*draw_lock_cb)(void *handle, bool lock) = nullptr;
235 void *dlh = nullptr;
236 bool (*test_break_cb)(void *handle) = nullptr;
237 void *tbh = nullptr;
238
239 bool (*prepare_viewlayer_cb)(void *handle, struct ViewLayer *vl, struct Depsgraph *depsgraph);
241
243
248 struct ReportList *reports = nullptr;
249
250 void **movie_ctx_arr = nullptr;
251 char viewname[MAX_NAME] = "";
252
253 /* TODO: replace by a whole draw manager. */
254 void *system_gpu_context = nullptr;
255 void *blender_gpu_context = nullptr;
256};
257
258/* **************** defines ********************* */
259
261#define R_ANIMATION 1 << 0
262/* Indicates that the render pipeline should not write its render result. This happens for instance
263 * when the render pipeline uses the compositor, but the compositor node tree does not have an
264 * output composite node or a render layer input, and consequently no render result. In that case,
265 * the output will be written from the File Output nodes, since the render pipeline will early fail
266 * if neither a File Output nor a Composite node exist in the scene. */
267#define R_SKIP_WRITE 1 << 1
pthread_rwlock_t ThreadRWMutex
#define BLI_RWLOCK_INITIALIZER
#define BLI_MUTEX_INITIALIZER
Definition BLI_threads.h:84
pthread_mutex_t ThreadMutex
Definition BLI_threads.h:83
#define MAX_NAME
Definition DNA_defs.h:50
#define RE_MAXNAME
Definition RE_pipeline.h:40
volatile int lock
const Depsgraph * depsgraph
virtual void compositor_execute(const Scene &scene, const RenderData &render_data, const bNodeTree &node_tree, const char *view_name, blender::realtime_compositor::RenderContext *render_context, blender::realtime_compositor::Profiler *profiler)=0
virtual void compositor_free()=0
virtual void display_update(RenderResult *render_result, rcti *rect)=0
virtual void draw_lock()=0
virtual void stats_draw(RenderStats *render_stats)=0
ThreadMutex engine_draw_mutex
virtual void current_scene_update(struct Scene *scene)=0
virtual void draw_unlock()=0
virtual ~BaseRender()
virtual bool test_break()=0
virtual void progress(float progress)=0
virtual void display_clear(RenderResult *render_result)=0
struct RenderEngine * engine
virtual bool prepare_viewlayer(struct ViewLayer *view_layer, struct Depsgraph *depsgraph)=0
ThreadRWMutex resultmutex
virtual void display_init(RenderResult *render_result)=0
BaseRender()=default
virtual blender::render::TilesHighlight * get_tile_highlight()=0
void compositor_free() override
void * blender_gpu_context
void * dch
float winmat[4][4]
void * sdh
Scene * pipeline_scene_eval
void * duh
void * prh
void draw_unlock() override
void draw_lock() override
bool(* prepare_viewlayer_cb)(void *handle, struct ViewLayer *vl, struct Depsgraph *depsgraph)
void display_update(RenderResult *render_result, rcti *rect) override
bool test_break() override
bool result_has_gpu_texture_caches
RenderResult * pushedresult
float clip_start
RenderData r
Render()=default
struct Main * main
void * dih
void * system_gpu_context
float clip_end
bool prepare_viewlayer(struct ViewLayer *view_layer, struct Depsgraph *depsgraph) override
void(* current_scene_update_cb)(void *handle, struct Scene *scene)
void compositor_execute(const Scene &scene, const RenderData &render_data, const bNodeTree &node_tree, const char *view_name, blender::realtime_compositor::RenderContext *render_context, blender::realtime_compositor::Profiler *profiler) override
void * dlh
void(* progress_cb)(void *handle, float i)
Scene * scene
ListBase fullresult
void display_init(RenderResult *render_result) override
void(* display_init_cb)(void *handle, RenderResult *rr)
struct Depsgraph * pipeline_depsgraph
blender::render::TilesHighlight * get_tile_highlight() override
void progress(float progress) override
void * prepare_vl_handle
void(* display_clear_cb)(void *handle, RenderResult *rr)
short flag
virtual ~Render()
blender::render::TilesHighlight tile_highlight
bool(* test_break_cb)(void *handle)
char single_view_layer[MAX_NAME]
char viewname[MAX_NAME]
void display_clear(RenderResult *render_result) override
RenderStats i
void current_scene_update(struct Scene *scene) override
void * tbh
void ** movie_ctx_arr
rctf viewplane
void * suh
struct ReportList * reports
rcti disprect
struct Object * camera_override
void(* draw_lock_cb)(void *handle, bool lock)
void(* display_update_cb)(void *handle, RenderResult *rr, rcti *rect)
std::mutex compositor_mutex
void(* stats_draw_cb)(void *handle, RenderStats *ri)
void stats_draw(RenderStats *render_stats) override
void stats_draw(RenderStats *) override
bool test_break() override
void progress(const float) override
blender::render::TilesHighlight * get_tile_highlight() override
void display_update(RenderResult *, rcti *) override
void current_scene_update(struct Scene *) override
void compositor_free() override
void compositor_execute(const Scene &, const RenderData &, const bNodeTree &, const char *, blender::realtime_compositor::RenderContext *, blender::realtime_compositor::Profiler *) override
void display_clear(RenderResult *) override
void draw_unlock() override
void draw_lock() override
void display_init(RenderResult *) override
bool prepare_viewlayer(struct ViewLayer *, struct Depsgraph *) override