Blender
V4.3
source
blender
compositor
realtime_compositor
COM_render_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 <memory>
8
#include <string>
9
10
#include "
BLI_map.hh
"
11
#include "
BLI_math_vector_types.hh
"
12
13
#include "
DNA_scene_types.h
"
14
15
struct
RenderResult
;
16
17
namespace
blender::realtime_compositor
{
18
19
/* ------------------------------------------------------------------------------------------------
20
* File Output
21
*
22
* A FileOutput represents an image that will be saved to a file output. The image is internally
23
* stored as a RenderResult and saved at the path according to the image format. The image can
24
* either be saved as an EXR image or a non-EXR image, specified by the format. This is important
25
* because EXR images needs to constructed differently from other image types as will be explained
26
* in the following sections.
27
*
28
* For EXR images, the render result needs to be composed of passes for each layer, so the add_pass
29
* method should be called to add each of the passes. Additionally, an empty view should be added
30
* for each of the views referenced by the passes, using the single-argument overload of the
31
* add_view method. Those views are merely empty structure and does not hold any data aside from
32
* the view name. An exception to this rule is stereo EXR images, which needs to have the same
33
* structure as non-EXR images as explained in the following section.
34
*
35
* For non-EXR images, the render result needs to composed of views, so the multi-argument overload
36
* of the method add_view should be used to add each view.
37
*
38
* Color management will be applied on the images if save_as_render_ is true.
39
*
40
* Meta data can be added using the add_meta_data function. */
41
class
FileOutput
{
42
private
:
43
std::string path_;
44
ImageFormatData
format_;
45
RenderResult
*render_result_;
46
bool
save_as_render_;
47
Map<std::string, std::string>
meta_data_;
48
49
public
:
50
/* Allocate and initialize the internal render result of the file output using the give
51
* parameters. See the implementation for more information. */
52
FileOutput
(
const
std::string &path,
53
const
ImageFormatData
&
format
,
54
int2
size,
55
bool
save_as_render);
56
57
/* Free the internal render result. */
58
~FileOutput
();
59
60
/* Add an empty view with the given name. An empty view is just structure and does not hold any
61
* data aside from the view name. This should be called for each view referenced by passes. This
62
* should only be called for EXR images. */
63
void
add_view
(
const
char
*view_name);
64
65
/* Add a view of the given name that stores the given pixel buffer composed of the given number
66
* of channels. */
67
void
add_view
(
const
char
*view_name,
int
channels,
float
*buffer);
68
69
/* Add a pass of the given name in the given view that stores the given pixel buffer composed of
70
* each of the channels given by the channels string. The channels string should contain a
71
* character for each channel in the pixel buffer representing the channel ID. This should only
72
* be called for EXR images. The given view name should be the name of an added view using the
73
* add_view method. */
74
void
add_pass
(
const
char
*pass_name,
const
char
*view_name,
const
char
*channels,
float
*buffer);
75
76
/* Add meta data that will eventually be saved to the file if the format supports it. */
77
void
add_meta_data
(std::string key, std::string value);
78
79
/* Save the file to the path along with its meta data, reporting any reports to the standard
80
* output. */
81
void
save
(
Scene
*scene);
82
};
83
84
/* ------------------------------------------------------------------------------------------------
85
* Render Context
86
*
87
* A render context is created by the render pipeline and passed to the compositor to stores data
88
* that is specifically related to the rendering process. In particular, since the compositor is
89
* executed for each view separately and consecutively, it can be used to store and accumulate
90
* data from each of the evaluations of each view, for instance, to save all views in a single file
91
* for the File Output node, see the file_outputs_ member for more information. */
92
class
RenderContext
{
93
private
:
94
/* A mapping between file outputs and their image file paths. Those are constructed in the
95
* get_file_output method and saved in the save_file_outputs method. See those methods for more
96
* information. */
97
Map<std::string, std::unique_ptr<FileOutput>
> file_outputs_;
98
99
public
:
100
/* Check if there is an available file output with the given path in the context, if one exists,
101
* return it, otherwise, return a newly created one from the given parameters and add it to the
102
* context. The arguments are ignored if the file output already exist. This method is typically
103
* called in the File Output nodes in the compositor.
104
*
105
* Since the compositor gets executed multiple times for each view, for single view renders, the
106
* file output will be constructed and fully initialized in the same compositor evaluation. For
107
* multi-view renders, the file output will be constructed in the evaluation of the first view,
108
* and each view will subsequently add its data until the file output is fully initialized in the
109
* last view. The render pipeline code will then call the save_file_outputs method after all
110
* views were evaluated to write the file outputs. */
111
FileOutput
&
get_file_output
(std::string path,
112
ImageFormatData
format
,
113
int2
size,
114
bool
save_as_render);
115
116
/* Write the file outputs that were added to the context. The render pipeline code should call
117
* this method after all views were evaluated to write the file outputs. See the get_file_output
118
* method for more information. */
119
void
save_file_outputs
(
Scene
*scene);
120
};
121
122
}
// namespace blender::realtime_compositor
BLI_map.hh
BLI_math_vector_types.hh
DNA_scene_types.h
blender::Map
Definition
BLI_map.hh:129
blender::realtime_compositor::FileOutput
Definition
COM_render_context.hh:41
blender::realtime_compositor::FileOutput::FileOutput
FileOutput(const std::string &path, const ImageFormatData &format, int2 size, bool save_as_render)
Definition
render_context.cc:37
blender::realtime_compositor::FileOutput::add_view
void add_view(const char *view_name)
Definition
render_context.cc:66
blender::realtime_compositor::FileOutput::add_pass
void add_pass(const char *pass_name, const char *view_name, const char *channels, float *buffer)
Definition
render_context.cc:88
blender::realtime_compositor::FileOutput::save
void save(Scene *scene)
Definition
render_context.cc:119
blender::realtime_compositor::FileOutput::add_meta_data
void add_meta_data(std::string key, std::string value)
Definition
render_context.cc:114
blender::realtime_compositor::FileOutput::~FileOutput
~FileOutput()
Definition
render_context.cc:61
blender::realtime_compositor::RenderContext
Definition
COM_render_context.hh:92
blender::realtime_compositor::RenderContext::get_file_output
FileOutput & get_file_output(std::string path, ImageFormatData format, int2 size, bool save_as_render)
Definition
render_context.cc:140
blender::realtime_compositor::RenderContext::save_file_outputs
void save_file_outputs(Scene *scene)
Definition
render_context.cc:149
format
format
Definition
logImageCore.h:39
blender::realtime_compositor
Definition
BKE_node.hh:80
ImageFormatData
Definition
DNA_scene_types.h:394
RenderResult
Definition
RE_pipeline.h:101
Scene
Definition
DNA_scene_types.h:1988
blender::VecBase< int32_t, 2 >
Generated on Thu Feb 6 2025 07:36:39 for Blender by
doxygen
1.11.0