Blender V4.3
COM_conversion_operation.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 "GPU_shader.hh"
8
9#include "COM_context.hh"
11#include "COM_result.hh"
13
15
16/* --------------------------------------------------------------------
17 * Conversion Operation
18 *
19 * A simple operation that converts a result from a certain type to another. See the derived
20 * classes for more details. */
22 public:
23 using SimpleOperation::SimpleOperation;
24
25 /* If the input result is a single value, execute_single is called. Otherwise, the shader
26 * provided by get_conversion_shader is dispatched for GPU contexts or execute_cpu is called for
27 * CPU contexts. */
28 void execute() override;
29
30 /* Determine if a conversion operation is needed for the input with the given result and
31 * descriptor. If it is not needed, return a null pointer. If it is needed, return an instance of
32 * the appropriate conversion operation. */
34 const Result &input_result,
35 const InputDescriptor &input_descriptor);
36
37 protected:
38 /* Convert the input single value result to the output single value result. */
39 virtual void execute_single(const Result &input, Result &output) = 0;
40
41 /* Convert the input to the appropriate type and write the result to the output on the CPU. */
42 virtual void execute_cpu(const Result &input, Result &output) = 0;
43
44 /* Get the shader the will be used for conversion. */
45 virtual GPUShader *get_conversion_shader() const = 0;
46};
47
48/* --------------------------------------------------------------------
49 * Convert Float to Vector Operation
50 *
51 * Takes a float result and outputs a vector result. The first three components of the output are
52 * filled with the input float, while the fourth component is set to 1. */
54 public:
56
57 void execute_single(const Result &input, Result &output) override;
58
59 void execute_cpu(const Result &input, Result &output) override;
60
61 GPUShader *get_conversion_shader() const override;
62};
63
64/* --------------------------------------------------------------------
65 * Convert Float to Color Operation
66 *
67 * Takes a float result and outputs a color result. All three color channels of the output are
68 * filled with the input float and the alpha channel is set to 1. */
70 public:
72
73 void execute_single(const Result &input, Result &output) override;
74
75 void execute_cpu(const Result &input, Result &output) override;
76
77 GPUShader *get_conversion_shader() const override;
78};
79
80/* --------------------------------------------------------------------
81 * Convert Color to Float Operation
82 *
83 * Takes a color result and outputs a float result. The output is the average of the three color
84 * channels, the alpha channel is ignored. */
86 public:
88
89 void execute_single(const Result &input, Result &output) override;
90
91 void execute_cpu(const Result &input, Result &output) override;
92
93 GPUShader *get_conversion_shader() const override;
94};
95
96/* --------------------------------------------------------------------
97 * Convert Color to Vector Operation
98 *
99 * Takes a color result and outputs a vector result. The output is an exact copy of the input since
100 * vectors are 4D. */
102 public:
104
105 void execute_single(const Result &input, Result &output) override;
106
107 void execute_cpu(const Result &input, Result &output) override;
108
109 GPUShader *get_conversion_shader() const override;
110};
111
112/* --------------------------------------------------------------------
113 * Convert Vector to Float Operation
114 *
115 * Takes a vector result and outputs a float result. The output is the average of the three
116 *components. */
118 public:
120
121 void execute_single(const Result &input, Result &output) override;
122
123 void execute_cpu(const Result &input, Result &output) override;
124
125 GPUShader *get_conversion_shader() const override;
126};
127
128/* --------------------------------------------------------------------
129 * Convert Vector to Color Operation
130 *
131 * Takes a vector result and outputs a color result. The output is a copy of the three vector
132 * components to the three color channels with the alpha channel set to 1. */
134 public:
136
137 void execute_single(const Result &input, Result &output) override;
138
139 void execute_cpu(const Result &input, Result &output) override;
140
141 GPUShader *get_conversion_shader() const override;
142};
143
144} // namespace blender::realtime_compositor
struct GPUShader GPUShader
virtual void execute_cpu(const Result &input, Result &output)=0
virtual GPUShader * get_conversion_shader() const =0
virtual void execute_single(const Result &input, Result &output)=0
static SimpleOperation * construct_if_needed(Context &context, const Result &input_result, const InputDescriptor &input_descriptor)
void execute_cpu(const Result &input, Result &output) override
void execute_single(const Result &input, Result &output) override
void execute_cpu(const Result &input, Result &output) override
void execute_single(const Result &input, Result &output) override
void execute_single(const Result &input, Result &output) override
void execute_cpu(const Result &input, Result &output) override
void execute_cpu(const Result &input, Result &output) override
void execute_single(const Result &input, Result &output) override
void execute_single(const Result &input, Result &output) override
void execute_cpu(const Result &input, Result &output) override
void execute_cpu(const Result &input, Result &output) override
void execute_single(const Result &input, Result &output) override