Flutter Engine
The Flutter Engine
CommonDepthStencilSettings.h
Go to the documentation of this file.
1/*
2 * Copyright 2022 Google LLC
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef skgpu_graphite_render_CommonDepthStencilSettings_DEFINED
9#define skgpu_graphite_render_CommonDepthStencilSettings_DEFINED
10
12
13namespace skgpu::graphite {
14
15/**
16 * DepthStencilSettings reusable by RenderSteps that can shade directly in a single pass, using
17 * GREATER or GEQUAL depth tests depending on if they allow self-intersections.
18 */
19
21 /*front=*/ {},
22 /*back=*/ {},
23 /*stencilRef=*/ 0,
24 /*stencilTest=*/ false,
25 /*depthCompare=*/CompareOp::kGreater,
26 /*depthTest=*/ true,
27 /*depthWrite=*/ true
28};
29
31 /*front=*/ {},
32 /*back=*/ {},
33 /*stencilRef=*/ 0,
34 /*stencilTest=*/ false,
35 /*depthCompare=*/CompareOp::kGEqual,
36 /*depthTest=*/ true,
37 /*depthWrite=*/ true
38};
39
40/**
41 * "stencil" pass DepthStencilSettings reusable for RenderSteps following some form of
42 * stencil-then-cover multi-pass algorithm.
43 */
44
45// Increments stencil value on clockwise triangles. Used for "winding" fill.
47 /*stencilFail=*/ StencilOp::kKeep,
48 /*depthFail=*/ StencilOp::kKeep,
49 /*dsPass=*/ StencilOp::kIncWrap,
50 /*compare=*/ CompareOp::kAlways,
51 /*readMask=*/ 0xffffffff,
52 /*writeMask=*/ 0xffffffff
53};
54
55// Decrements stencil value on counterclockwise triangles. Used for "winding" fill.
57 /*stencilFail=*/ StencilOp::kKeep,
58 /*depthFail=*/ StencilOp::kKeep,
59 /*dsPass=*/ StencilOp::kDecWrap,
60 /*compare=*/ CompareOp::kAlways,
61 /*readMask=*/ 0xffffffff,
62 /*writeMask=*/ 0xffffffff
63};
64
65// Toggles the bottom stencil bit. Used for "even-odd" fill.
67 /*stencilFail=*/ StencilOp::kKeep,
68 /*depthFail=*/ StencilOp::kKeep,
69 /*dsPass=*/ StencilOp::kInvert,
70 /*compare=*/ CompareOp::kAlways,
71 /*readMask=*/ 0xffffffff,
72 /*writeMask=*/ 0x00000001
73};
74
75// Stencil settings to use for a standard Redbook "stencil" pass corresponding to a "winding"
76// fill rule (regular or inverse is selected by a follow-up pass).
78 /*front=*/ kIncrementCW,
79 /*back=*/ kDecrementCCW,
80 /*stencilRef=*/ 0,
81 /*stencilTest=*/ true,
82 /*depthCompare=*/CompareOp::kGreater,
83 /*depthTest=*/ true,
84 /*depthWrite=*/ false // The depth write will be handled by the covering pass
85};
86
87// Stencil settings to use for a standard Redbook "stencil" pass corresponding to an "even-odd"
88// fill rule (regular or inverse is selected by a follow-up pass).
90 /*front=*/ kToggle,
91 /*back=*/ kToggle,
92 /*stencilRef=*/ 0,
93 /*stencilTest=*/ true,
94 /*depthCompare=*/CompareOp::kGreater,
95 /*depthTest=*/ true,
96 /*depthWrite=*/ false // The depth write will be handled by the covering pass
97};
98
99/**
100 * "cover" pass DepthStencilSettings reusable for RenderSteps following some form of
101 * stencil-then-cover multi-pass algorithm.
102 */
103
104// Resets non-zero bits to 0, passes when not zero. We set depthFail to kZero because if we
105// encounter that case, the kNotEqual=0 stencil test passed, so it does need to be set back to 0
106// and the dsPass op won't be run. In practice, since the stencil steps will fail the same depth
107// test, the stencil value will likely not be non-zero, but best to be explicit.
109 /*stencilFail=*/ StencilOp::kKeep,
110 /*depthFail=*/ StencilOp::kZero,
111 /*dsPass=*/ StencilOp::kZero,
112 /*compare=*/ CompareOp::kNotEqual,
113 /*readMask=*/ 0xffffffff,
114 /*writeMask=*/ 0xffffffff
115};
116
117 // Resets non-zero bits to 0, passes when zero.
119 /*stencilFail=*/ StencilOp::kZero,
120 /*depthFail=*/ StencilOp::kKeep,
121 /*dsPass=*/ StencilOp::kKeep,
122 /*compare=*/ CompareOp::kEqual,
123 /*readMask=*/ 0xffffffff,
124 /*writeMask=*/ 0xffffffff
125};
126
127// Stencil settings to use for a standard Redbook "cover" pass for a regular fill, assuming that the
128// stencil buffer has been modified by either kWindingStencilPass or kEvenOddStencilPass.
130 /*front=*/ kPassNonZero,
131 /*back=*/ kPassNonZero,
132 /*stencilRef=*/ 0,
133 /*stencilTest=*/ true,
134 /*depthCompare=*/CompareOp::kGreater,
135 /*depthTest=*/ true,
136 /*depthWrite=*/ true
137};
138
139// Stencil settings to use for a standard Redbook "cover" pass for inverse fills, assuming that the
140// stencil buffer has been modified by either kWindingStencilPass or kEvenOddStencilPass.
142 /*front=*/ kPassZero,
143 /*back=*/ kPassZero,
144 /*stencilRef=*/ 0,
145 /*stencilTest=*/ true,
146 /*depthCompare=*/CompareOp::kGreater,
147 /*depthTest=*/ true,
148 /*depthWrite=*/ true
149};
150
151} // namespace skgpu::graphite
152
153#endif // skgpu_graphite_render_CommonDepthStencilSettings_DEFINED
constexpr DepthStencilSettings::Face kPassNonZero
constexpr DepthStencilSettings::Face kPassZero
constexpr DepthStencilSettings kWindingStencilPass
static constexpr DepthStencilSettings kDirectDepthGEqualPass
constexpr DepthStencilSettings::Face kDecrementCCW
constexpr DepthStencilSettings kRegularCoverPass
static constexpr DepthStencilSettings kDirectDepthGreaterPass
constexpr DepthStencilSettings kEvenOddStencilPass
constexpr DepthStencilSettings::Face kToggle
constexpr DepthStencilSettings kInverseCoverPass
constexpr DepthStencilSettings::Face kIncrementCW