forked from turanszkij/WickedEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwiImage.h
223 lines (200 loc) · 8.36 KB
/
wiImage.h
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#pragma once
#include "CommonInclude.h"
#include "wiGraphicsDevice.h"
#include "wiEnums.h"
#include "wiColor.h"
#include "wiCanvas.h"
#include "wiPrimitive.h"
namespace wi::image
{
// Do not alter order or value because it is bound to lua manually!
enum STENCILMODE
{
STENCILMODE_DISABLED,
STENCILMODE_EQUAL,
STENCILMODE_LESS,
STENCILMODE_LESSEQUAL,
STENCILMODE_GREATER,
STENCILMODE_GREATEREQUAL,
STENCILMODE_NOT,
STENCILMODE_ALWAYS,
STENCILMODE_COUNT
};
enum STENCILREFMODE
{
STENCILREFMODE_ENGINE,
STENCILREFMODE_USER,
STENCILREFMODE_ALL,
STENCILREFMODE_COUNT
};
enum SAMPLEMODE
{
SAMPLEMODE_CLAMP,
SAMPLEMODE_WRAP,
SAMPLEMODE_MIRROR,
SAMPLEMODE_COUNT
};
enum QUALITY
{
QUALITY_NEAREST,
QUALITY_LINEAR,
QUALITY_ANISOTROPIC,
QUALITY_COUNT
};
struct Params
{
enum FLAGS
{
EMPTY = 0,
DRAWRECT = 1 << 0,
DRAWRECT2 = 1 << 1,
MIRROR = 1 << 2,
EXTRACT_NORMALMAP = 1 << 3,
FULLSCREEN = 1 << 4,
BACKGROUND = 1 << 5,
OUTPUT_COLOR_SPACE_HDR10_ST2084 = 1 << 6,
OUTPUT_COLOR_SPACE_LINEAR = 1 << 7,
CORNER_ROUNDING = 1 << 8,
DEPTH_TEST = 1 << 9,
ANGULAR_DOUBLESIDED = 1 << 10,
ANGULAR_INVERSE = 1 << 11,
};
uint32_t _flags = EMPTY;
XMFLOAT3 pos = XMFLOAT3(0, 0, 0);
XMFLOAT2 siz = XMFLOAT2(1, 1);
XMFLOAT2 scale = XMFLOAT2(1, 1);
XMFLOAT4 color = XMFLOAT4(1, 1, 1, 1);
XMFLOAT4 drawRect = XMFLOAT4(0, 0, 0, 0);
XMFLOAT4 drawRect2 = XMFLOAT4(0, 0, 0, 0);
XMFLOAT2 texOffset = XMFLOAT2(0, 0);
XMFLOAT2 texOffset2 = XMFLOAT2(0, 0);
XMFLOAT2 pivot = XMFLOAT2(0, 0); // (0,0) : upperleft, (0.5,0.5) : center, (1,1) : bottomright
float rotation = 0;
float fade = 0;
float opacity = 1;
float intensity = 1;
float hdr_scaling = 1.0f; // a scaling value for use by linear output mapping
float mask_alpha_range_start = 0; // constrain mask alpha to not go below this level
float mask_alpha_range_end = 1; // constrain mask alpha to not go above this level
XMFLOAT2 angular_softness_direction = XMFLOAT2(0, 1);
float angular_softness_inner_angle = 0;
float angular_softness_outer_angle = 0;
// you can deform the image by its corners (0: top left, 1: top right, 2: bottom left, 3: bottom right)
XMFLOAT2 corners[4] = {
XMFLOAT2(0, 0), XMFLOAT2(1, 0),
XMFLOAT2(0, 1), XMFLOAT2(1, 1)
};
const XMMATRIX* customRotation = nullptr;
const XMMATRIX* customProjection = nullptr;
struct Rounding
{
float radius = 0; // the radius of corner (in logical pixel units)
int segments = 18; // how many segments to add to smoothing curve
} corners_rounding[4]; // specify rounding corners (0: top left, 1: top right, 2: bottom left, 3: bottom right)
float border_soften = 0; // how much alpha softening to apply to image border in range [0, 1] (0: disable)
uint8_t stencilRef = 0;
STENCILMODE stencilComp = STENCILMODE_DISABLED;
STENCILREFMODE stencilRefMode = STENCILREFMODE_ALL;
wi::enums::BLENDMODE blendFlag = wi::enums::BLENDMODE_ALPHA;
SAMPLEMODE sampleFlag = SAMPLEMODE_MIRROR;
QUALITY quality = QUALITY_LINEAR;
const wi::graphics::Texture* maskMap = nullptr;
int image_subresource = -1;
int mask_subresource = -1;
// Set a mask map that will be used to multiply the base image
constexpr void setMaskMap(const wi::graphics::Texture* tex) { maskMap = tex; }
constexpr bool isDrawRectEnabled() const { return _flags & DRAWRECT; }
constexpr bool isDrawRect2Enabled() const { return _flags & DRAWRECT2; }
constexpr bool isMirrorEnabled() const { return _flags & MIRROR; }
constexpr bool isExtractNormalMapEnabled() const { return _flags & EXTRACT_NORMALMAP; }
constexpr bool isFullScreenEnabled() const { return _flags & FULLSCREEN; }
constexpr bool isBackgroundEnabled() const { return _flags & BACKGROUND; }
constexpr bool isHDR10OutputMappingEnabled() const { return _flags & OUTPUT_COLOR_SPACE_HDR10_ST2084; }
constexpr bool isLinearOutputMappingEnabled() const { return _flags & OUTPUT_COLOR_SPACE_LINEAR; }
constexpr bool isCornerRoundingEnabled() const { return _flags & CORNER_ROUNDING; }
constexpr bool isDepthTestEnabled() const { return _flags & DEPTH_TEST; }
constexpr bool isAngularSoftnessDoubleSided() const { return _flags & ANGULAR_DOUBLESIDED; }
constexpr bool isAngularSoftnessInverse() const { return _flags & ANGULAR_INVERSE; }
// enables draw rectangle for base texture (cutout texture outside draw rectangle)
constexpr void enableDrawRect(const XMFLOAT4& rect) { _flags |= DRAWRECT; drawRect = rect; }
// enables draw rectangle for mask texture (cutout texture outside draw rectangle)
constexpr void enableDrawRect2(const XMFLOAT4& rect) { _flags |= DRAWRECT2; drawRect2 = rect; }
// mirror the image horizontally
constexpr void enableMirror() { _flags |= MIRROR; }
// enable normal map extraction shader that will perform texcolor * 2 - 1 (preferably onto a signed render target)
constexpr void enableExtractNormalMap() { _flags |= EXTRACT_NORMALMAP; }
// enable full screen override. It just draws texture onto the full screen, disabling any other setup except sampler and stencil)
constexpr void enableFullScreen() { _flags |= FULLSCREEN; }
// enable background, which samples a background screen texture on transparent areas instead of alpha blending
// the background tex should be bound with wi::image::SetBackground() beforehand
constexpr void enableBackground() { _flags |= BACKGROUND; }
// enable HDR10 output mapping, if this image can be interpreted in linear space and converted to HDR10 display format
constexpr void enableHDR10OutputMapping() { _flags |= OUTPUT_COLOR_SPACE_HDR10_ST2084; }
// enable linear output mapping, which means removing gamma curve and outputting in linear space (useful for blending in HDR space)
constexpr void enableLinearOutputMapping(float scaling = 1.0f) { _flags |= OUTPUT_COLOR_SPACE_LINEAR; hdr_scaling = scaling; }
constexpr void enableCornerRounding() { _flags |= CORNER_ROUNDING; }
constexpr void enableDepthTest() { _flags |= DEPTH_TEST; }
constexpr void enableAngularSoftnessDoubleSided() { _flags |= ANGULAR_DOUBLESIDED; }
constexpr void enableAngularSoftnessInverse() { _flags |= ANGULAR_INVERSE; }
// disable draw rectangle for base texture (whole texture will be drawn, no cutout)
constexpr void disableDrawRect() { _flags &= ~DRAWRECT; }
// disable draw rectangle for mask texture (whole texture will be drawn, no cutout)
constexpr void disableDrawRect2() { _flags &= ~DRAWRECT2; }
constexpr void disableMirror() { _flags &= ~MIRROR; }
constexpr void disableExtractNormalMap() { _flags &= ~EXTRACT_NORMALMAP; }
constexpr void disableFullScreen() { _flags &= ~FULLSCREEN; }
constexpr void disableBackground() { _flags &= ~BACKGROUND; }
constexpr void disableHDR10OutputMapping() { _flags &= ~OUTPUT_COLOR_SPACE_HDR10_ST2084; }
constexpr void disableLinearOutputMapping() { _flags &= ~OUTPUT_COLOR_SPACE_LINEAR; }
constexpr void disableCornerRounding() { _flags &= ~CORNER_ROUNDING; }
constexpr void disableDepthTest() { _flags &= ~DEPTH_TEST; }
constexpr void disableAngularSoftnessDoubleSided() { _flags &= ~ANGULAR_DOUBLESIDED; }
constexpr void disableAngularSoftnessInverse() { _flags &= ~ANGULAR_INVERSE; }
Params() = default;
Params(
float width,
float height
) :
siz(width, height)
{}
Params(
float posX,
float posY,
float width,
float height,
const XMFLOAT4& color = XMFLOAT4(1, 1, 1, 1)
) :
pos(posX, posY, 0),
siz(width, height),
color(color)
{}
Params(
const XMFLOAT4& color,
wi::enums::BLENDMODE blendFlag = wi::enums::BLENDMODE_ALPHA,
bool background = false
) :
color(color),
blendFlag(blendFlag)
{
if (background)
{
enableBackground();
}
}
Params(
const wi::primitive::Hitbox2D& hitbox, const XMFLOAT4& color = XMFLOAT4(1, 1, 1, 1)
) :
pos(XMFLOAT3(hitbox.pos.x, hitbox.pos.y, 0)),
siz(hitbox.siz),
color(color)
{}
};
// Set canvas to handle DPI-aware image rendering (applied to all image rendering commands on the current thread)
void SetCanvas(const wi::Canvas& current_canvas);
// Set a background texture (applied to all image rendering commands on the current thread that used enableBackground())
void SetBackground(const wi::graphics::Texture& texture);
// Draw the specified texture with the specified parameters
void Draw(const wi::graphics::Texture* texture, const Params& params, wi::graphics::CommandList cmd);
// Initializes the image renderer
void Initialize();
}