Blender V4.5
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
7#include <cstdint>
8
10#include "BLI_string_ref.hh"
11
12#include "DNA_scene_types.h"
13#include "DNA_vec_types.h"
14
15#include "GPU_shader.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
24namespace blender::compositor {
25
26/* Enumerates the possible outputs that the compositor can compute. */
27enum class OutputTypes : uint8_t {
28 None = 0,
29 Composite = 1 << 0,
30 Viewer = 1 << 1,
31 FileOutput = 1 << 2,
32 Previews = 1 << 3,
33};
35
36/* ------------------------------------------------------------------------------------------------
37 * Context
38 *
39 * A Context is an abstract class that is implemented by the caller of the evaluator to provide the
40 * necessary data and functionalities for the correct operation of the evaluator. This includes
41 * providing input data like render passes and the active scene, as well as references to the data
42 * where the output of the evaluator will be written. Finally, the class have an instance of a
43 * static resource manager for acquiring cached resources efficiently. */
45 private:
46 /* A static cache manager that can be used to acquire cached resources for the compositor
47 * efficiently. */
48 StaticCacheManager cache_manager_;
49
50 public:
51 /* Get the compositing scene. */
52 virtual const Scene &get_scene() const = 0;
53
54 /* Get the node tree used for compositing. */
55 virtual const bNodeTree &get_node_tree() const = 0;
56
57 /* True if the compositor should use GPU acceleration. */
58 virtual bool use_gpu() const = 0;
59
60 /* Get the OIDN denoiser quality which should be used if the user doesn't explicitly set
61 * denoising quality on a node. */
63
64 /* Returns all output types that should be computed. */
65 virtual OutputTypes needed_outputs() const = 0;
66
67 /* Get the render settings for compositing. */
68 virtual const RenderData &get_render_data() const = 0;
69
70 /* Get the width and height of the render passes and of the output texture returned by the
71 * get_pass and get_output_texture methods respectively. */
72 virtual int2 get_render_size() const = 0;
73
74 /* Get the rectangular region representing the area of the input that the compositor will operate
75 * on. Conversely, the compositor will only update the region of the output that corresponds to
76 * the compositing region. In the base case, the compositing region covers the entirety of the
77 * render region with a lower bound of zero and an upper bound of the render size returned by the
78 * get_render_size method. In other cases, the compositing region might be a subset of the render
79 * region. Callers should check the validity of the region through is_valid_compositing_region(),
80 * since the region can be zero sized. */
81 virtual rcti get_compositing_region() const = 0;
82
83 /* Get the result where the result of the compositor should be written. */
85
86 /* Get the result where the result of the compositor viewer should be written, given the domain
87 * of the result to be viewed, its precision, and whether the output is a non-color data image
88 * that should be displayed without view transform. */
90 bool is_data,
91 ResultPrecision precision) = 0;
92
93 /* Get the result where the given render pass is stored. */
94 virtual Result get_pass(const Scene *scene, int view_layer, const char *pass_name) = 0;
95
96 /* Get the name of the view currently being rendered. */
97 virtual StringRef get_view_name() const = 0;
98
99 /* Get the precision of the intermediate results of the compositor. */
100 virtual ResultPrecision get_precision() const = 0;
101
102 /* Set an info message. This is called by the compositor evaluator to inform or warn the user
103 * about something, typically an error. The implementation should display the message in an
104 * appropriate place, which can be directly in the UI or just logged to the output stream. */
105 virtual void set_info_message(StringRef message) const = 0;
106
107 /* True if the compositor should treat viewers as composite outputs because it has no concept of
108 * or support for viewers. */
109 virtual bool treat_viewer_as_composite_output() const;
110
111 /* Populates the given meta data from the render stamp information of the given render pass. */
112 virtual void populate_meta_data_for_pass(const Scene *scene,
113 int view_layer_id,
114 const char *pass_name,
115 MetaData &meta_data) const;
116
117 /* Get a pointer to the render context of this context. A render context stores information about
118 * the current render. It might be null if the compositor is not being evaluated as part of a
119 * render pipeline. */
120 virtual RenderContext *render_context() const;
121
122 /* Get a pointer to the profiler of this context. It might be null if the compositor context does
123 * not support profiling. */
124 virtual Profiler *profiler() const;
125
126 /* Gets called after the evaluation of each compositor operation. See overrides for possible
127 * uses. */
128 virtual void evaluate_operation_post() const;
129
130 /* Returns true if the compositor evaluation is canceled and that the evaluator should stop
131 * executing as soon as possible. */
132 virtual bool is_canceled() const;
133
134 /* Resets the context's internal structures like the cache manager. This should be called before
135 * every evaluation. */
136 void reset();
137
138 /* Get the size of the compositing region. See get_compositing_region(). The output size is
139 * sanitized such that it is at least 1 in both dimensions. However, the developer is expected to
140 * gracefully handled zero sizes regions by checking the is_valid_compositing_region method. */
142
143 /* Returns true if the compositing region has a valid size, that is, has at least one pixel in
144 * both dimensions, returns false otherwise. */
145 bool is_valid_compositing_region() const;
146
147 /* Get the normalized render percentage of the active scene. */
148 float get_render_percentage() const;
149
150 /* Get the current frame number of the active scene. */
151 int get_frame_number() const;
152
153 /* Get the current time in seconds of the active scene. */
154 float get_time() const;
155
156 /* Get a GPU shader with the given info name and precision. */
157 GPUShader *get_shader(const char *info_name, ResultPrecision precision);
158
159 /* Get a GPU shader with the given info name and context's precision. */
160 GPUShader *get_shader(const char *info_name);
161
162 /* Create a result of the given type and precision. */
164
165 /* Create a result of the given type using the context's precision. */
167
168 /* Get a reference to the static cache manager of this context. */
170};
171
172} // namespace blender::compositor
#define ENUM_OPERATORS(_type, _max)
eCompositorDenoiseQaulity
void reset()
clear internal cached data and reset random seed
virtual const Scene & get_scene() const =0
virtual int2 get_render_size() const =0
virtual Profiler * profiler() const
virtual const RenderData & get_render_data() const =0
Result create_result(ResultType type, ResultPrecision precision)
virtual ResultPrecision get_precision() const =0
virtual void populate_meta_data_for_pass(const Scene *scene, int view_layer_id, const char *pass_name, MetaData &meta_data) const
virtual OutputTypes needed_outputs() const =0
virtual Result get_viewer_output_result(Domain domain, bool is_data, ResultPrecision precision)=0
virtual bool treat_viewer_as_composite_output() const
virtual Result get_pass(const Scene *scene, int view_layer, const char *pass_name)=0
virtual RenderContext * render_context() const
virtual const bNodeTree & get_node_tree() const =0
virtual rcti get_compositing_region() const =0
virtual StringRef get_view_name() const =0
virtual eCompositorDenoiseQaulity get_denoise_quality() const =0
virtual Result get_output_result()=0
virtual void set_info_message(StringRef message) const =0
virtual bool use_gpu() const =0
#define class
static const char * get_shader(MorphologicalBlurOperation operation)
VecBase< int32_t, 2 > int2