1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "GPU_shader.h"
#include "COM_context.hh"
#include "COM_input_descriptor.hh"
#include "COM_result.hh"
#include "COM_simple_operation.hh"
namespace blender::realtime_compositor {
/* -------------------------------------------------------------------------------------------------
* Conversion Operation
*
* A simple operation that converts a result from a certain type to another. See the derived
* classes for more details. */
class ConversionOperation : public SimpleOperation {
public:
using SimpleOperation::SimpleOperation;
/* If the input result is a single value, execute_single is called. Otherwise, the shader
* provided by get_conversion_shader is dispatched. */
void execute() override;
/* Determine if a conversion operation is needed for the input with the given result and
* descriptor. If it is not needed, return a null pointer. If it is needed, return an instance of
* the appropriate conversion operation. */
static SimpleOperation *construct_if_needed(Context &context,
const Result &input_result,
const InputDescriptor &input_descriptor);
protected:
/* Convert the input single value result to the output single value result. */
virtual void execute_single(const Result &input, Result &output) = 0;
/* Get the shader the will be used for conversion. */
virtual GPUShader *get_conversion_shader() const = 0;
};
/* -------------------------------------------------------------------------------------------------
* Convert Float To Vector Operation
*
* Takes a float result and outputs a vector result. All three components of the output are filled
* with the input float. */
class ConvertFloatToVectorOperation : public ConversionOperation {
public:
ConvertFloatToVectorOperation(Context &context);
void execute_single(const Result &input, Result &output) override;
GPUShader *get_conversion_shader() const override;
};
/* -------------------------------------------------------------------------------------------------
* Convert Float To Color Operation
*
* Takes a float result and outputs a color result. All three color channels of the output are
* filled with the input float and the alpha channel is set to 1. */
class ConvertFloatToColorOperation : public ConversionOperation {
public:
ConvertFloatToColorOperation(Context &context);
void execute_single(const Result &input, Result &output) override;
GPUShader *get_conversion_shader() const override;
};
/* -------------------------------------------------------------------------------------------------
* Convert Color To Float Operation
*
* Takes a color result and outputs a float result. The output is the average of the three color
* channels, the alpha channel is ignored. */
class ConvertColorToFloatOperation : public ConversionOperation {
public:
ConvertColorToFloatOperation(Context &context);
void execute_single(const Result &input, Result &output) override;
GPUShader *get_conversion_shader() const override;
};
/* -------------------------------------------------------------------------------------------------
* Convert Color To Vector Operation
*
* Takes a color result and outputs a vector result. The output is a copy of the three color
* channels to the three vector components. */
class ConvertColorToVectorOperation : public ConversionOperation {
public:
ConvertColorToVectorOperation(Context &context);
void execute_single(const Result &input, Result &output) override;
GPUShader *get_conversion_shader() const override;
};
/* -------------------------------------------------------------------------------------------------
* Convert Vector To Float Operation
*
* Takes a vector result and outputs a float result. The output is the average of the three
* components. */
class ConvertVectorToFloatOperation : public ConversionOperation {
public:
ConvertVectorToFloatOperation(Context &context);
void execute_single(const Result &input, Result &output) override;
GPUShader *get_conversion_shader() const override;
};
/* -------------------------------------------------------------------------------------------------
* Convert Vector To Color Operation
*
* Takes a vector result and outputs a color result. The output is a copy of the three vector
* components to the three color channels with the alpha channel set to 1. */
class ConvertVectorToColorOperation : public ConversionOperation {
public:
ConvertVectorToColorOperation(Context &context);
void execute_single(const Result &input, Result &output) override;
GPUShader *get_conversion_shader() const override;
};
} // namespace blender::realtime_compositor
|