Blender V4.3
COM_context.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8#include "BLI_string_ref.hh"
9
10#include "DNA_ID.h"
11#include "DNA_scene_types.h"
12#include "DNA_vec_types.h"
13
14#include "GPU_shader.hh"
15#include "GPU_texture.hh"
16
17#include "COM_domain.hh"
18#include "COM_meta_data.hh"
19#include "COM_profiler.hh"
20#include "COM_render_context.hh"
21#include "COM_result.hh"
23#include "COM_texture_pool.hh"
24
26
27/* ------------------------------------------------------------------------------------------------
28 * Context
29 *
30 * A Context is an abstract class that is implemented by the caller of the evaluator to provide the
31 * necessary data and functionalities for the correct operation of the evaluator. This includes
32 * providing input data like render passes and the active scene, as well as references to the data
33 * where the output of the evaluator will be written. The class also provides a reference to the
34 * texture pool which should be implemented by the caller and provided during construction.
35 * Finally, the class have an instance of a static resource manager for acquiring cached resources
36 * efficiently. */
37class Context {
38 private:
39 /* A texture pool that can be used to allocate textures for the compositor efficiently. */
40 TexturePool &texture_pool_;
41 /* A static cache manager that can be used to acquire cached resources for the compositor
42 * efficiently. */
43 StaticCacheManager cache_manager_;
44
45 public:
47
48 /* Get the compositing scene. */
49 virtual const Scene &get_scene() const = 0;
50
51 /* Get the node tree used for compositing. */
52 virtual const bNodeTree &get_node_tree() const = 0;
53
54 /* True if the compositor should use GPU acceleration. */
55 virtual bool use_gpu() const = 0;
56
57 /* True if the compositor should write file outputs, false otherwise. */
58 virtual bool use_file_output() const = 0;
59
60 /* True if the compositor should compute node previews, false otherwise. */
61 virtual bool should_compute_node_previews() const = 0;
62
63 /* True if the compositor should write the composite output, otherwise, the compositor is assumed
64 * to not support the composite output and just displays its viewer output. In that case, the
65 * composite output will be used as a fallback viewer if no other viewer exists */
66 virtual bool use_composite_output() const = 0;
67
68 /* Get the render settings for compositing. */
69 virtual const RenderData &get_render_data() const = 0;
70
71 /* Get the width and height of the render passes and of the output texture returned by the
72 * get_input_texture and get_output_texture methods respectively. */
73 virtual int2 get_render_size() const = 0;
74
75 /* Get the rectangular region representing the area of the input that the compositor will operate
76 * on. Conversely, the compositor will only update the region of the output that corresponds to
77 * the compositing region. In the base case, the compositing region covers the entirety of the
78 * render region with a lower bound of zero and an upper bound of the render size returned by the
79 * get_render_size method. In other cases, the compositing region might be a subset of the render
80 * region. Callers should check the validity of the region through is_valid_compositing_region(),
81 * since the region can be zero sized. */
82 virtual rcti get_compositing_region() const = 0;
83
84 /* Get the result where the result of the compositor should be written. */
86
87 /* Get the result where the result of the compositor viewer should be written, given the domain
88 * of the result to be viewed, its precision, and whether the output is a non-color data image
89 * that should be displayed without view transform. */
91 bool is_data,
92 ResultPrecision precision) = 0;
93
94 /* Get the texture where the given render pass is stored. This should be called by the Render
95 * Layer node to populate its outputs. */
96 virtual GPUTexture *get_input_texture(const Scene *scene,
97 int view_layer,
98 const char *pass_name) = 0;
99
100 /* Get the name of the view currently being rendered. */
101 virtual StringRef get_view_name() const = 0;
102
103 /* Get the precision of the intermediate results of the compositor. */
104 virtual ResultPrecision get_precision() const = 0;
105
106 /* Set an info message. This is called by the compositor evaluator to inform or warn the user
107 * about something, typically an error. The implementation should display the message in an
108 * appropriate place, which can be directly in the UI or just logged to the output stream. */
109 virtual void set_info_message(StringRef message) const = 0;
110
111 /* Returns the ID recalculate flag of the given ID and reset it to zero. The given ID is assumed
112 * to be one that has a DrawDataList and conforms to the IdDdtTemplate.
113 *
114 * The ID recalculate flag is a mechanism through which one can identify if an ID has changed
115 * since the last time the flag was reset, hence why the method reset the flag after querying it,
116 * that is, to ready it to track the next change. */
117 virtual IDRecalcFlag query_id_recalc_flag(ID *id) const = 0;
118
119 /* Populates the given meta data from the render stamp information of the given render pass. */
120 virtual void populate_meta_data_for_pass(const Scene *scene,
121 int view_layer_id,
122 const char *pass_name,
123 MetaData &meta_data) const;
124
125 /* Get a pointer to the render context of this context. A render context stores information about
126 * the current render. It might be null if the compositor is not being evaluated as part of a
127 * render pipeline. */
128 virtual RenderContext *render_context() const;
129
130 /* Get a pointer to the profiler of this context. It might be null if the compositor context does
131 * not support profiling. */
132 virtual Profiler *profiler() const;
133
134 /* Gets called after the evaluation of each compositor operation. See overrides for possible
135 * uses. */
136 virtual void evaluate_operation_post() const;
137
138 /* Returns true if the compositor evaluation is canceled and that the evaluator should stop
139 * executing as soon as possible. */
140 virtual bool is_canceled() const;
141
142 /* Resets the context's internal structures like texture pool and cache manager. This should be
143 * called before every evaluation. */
144 void reset();
145
146 /* Get the size of the compositing region. See get_compositing_region(). The output size is
147 * sanitized such that it is at least 1 in both dimensions. However, the developer is expected to
148 * gracefully handled zero sizes regions by checking the is_valid_compositing_region method. */
150
151 /* Returns true if the compositing region has a valid size, that is, has at least one pixel in
152 * both dimensions, returns false otherwise. */
153 bool is_valid_compositing_region() const;
154
155 /* Get the normalized render percentage of the active scene. */
156 float get_render_percentage() const;
157
158 /* Get the current frame number of the active scene. */
159 int get_frame_number() const;
160
161 /* Get the current time in seconds of the active scene. */
162 float get_time() const;
163
164 /* Get a GPU shader with the given info name and precision. */
165 GPUShader *get_shader(const char *info_name, ResultPrecision precision);
166
167 /* Get a GPU shader with the given info name and context's precision. */
168 GPUShader *get_shader(const char *info_name);
169
170 /* Create a result of the given type and precision. */
172
173 /* Create a result of the given type using the context's precision. */
175
176 /* Get a reference to the texture pool of this context. */
178
179 /* Get a reference to the static cache manager of this context. */
181};
182
183} // namespace blender::realtime_compositor
ID and Library types, which are fundamental for SDNA.
IDRecalcFlag
Definition DNA_ID.h:1016
struct GPUShader GPUShader
virtual IDRecalcFlag query_id_recalc_flag(ID *id) const =0
virtual rcti get_compositing_region() const =0
virtual const Scene & get_scene() const =0
virtual Result get_viewer_output_result(Domain domain, bool is_data, ResultPrecision precision)=0
GPUShader * get_shader(const char *info_name, ResultPrecision precision)
Result create_result(ResultType type, ResultPrecision precision)
virtual bool use_composite_output() const =0
virtual bool use_gpu() const =0
virtual const RenderData & get_render_data() const =0
virtual ResultPrecision get_precision() const =0
virtual bool should_compute_node_previews() const =0
virtual const bNodeTree & get_node_tree() const =0
virtual bool use_file_output() const =0
virtual void set_info_message(StringRef message) const =0
virtual int2 get_render_size() const =0
virtual StringRef get_view_name() const =0
virtual GPUTexture * get_input_texture(const Scene *scene, int view_layer, const char *pass_name)=0
virtual void populate_meta_data_for_pass(const Scene *scene, int view_layer_id, const char *pass_name, MetaData &meta_data) const
Definition DNA_ID.h:413