OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2013 Google Inc. | |
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 GrBezierEffect_DEFINED | |
9 #define GrBezierEffect_DEFINED | |
10 | |
11 #include "GrEffect.h" | |
12 #include "GrDrawTargetCaps.h" | |
13 | |
14 enum GrBezierEdgeType { | |
15 kFillAA_GrBezierEdgeType, | |
16 kHairAA_GrBezierEdgeType, | |
17 kFillNoAA_GrBezierEdgeType, | |
18 }; | |
19 | |
20 static inline bool GrBezierEdgeTypeIsFill(const GrBezierEdgeType edgeType) { | |
bsalomon
2013/08/22 13:01:43
Probably doesn't matter, but each of these could b
| |
21 return (kFillAA_GrBezierEdgeType == edgeType || kFillNoAA_GrBezierEdgeType = = edgeType); | |
22 } | |
23 | |
24 static inline bool GrBezierEdgeTypeIsAA(const GrBezierEdgeType edgeType) { | |
25 return (kFillAA_GrBezierEdgeType == edgeType || kHairAA_GrBezierEdgeType == edgeType); | |
26 } | |
27 | |
28 /** | |
29 * Shader is based off of Loop-Blinn Quadratic GPU Rendering | |
30 * The output of this effect is a hairline edge for conics. | |
31 * Conics specified by implicit equation K^2 - LM. | |
32 * K, L, and M, are the first three values of the vertex attribute, | |
33 * the fourth value is not used. Distance is calculated using a | |
34 * first order approximation from the taylor series. | |
35 * Coverage is max(0, 1-distance). | |
36 * | |
37 * Test were also run using a second order distance approximation. | |
38 * There were two versions of the second order approx. The first version | |
39 * is of roughly the form: | |
40 * f(q) = |f(p)| - ||f'(p)||*||q-p|| - ||f''(p)||*||q-p||^2. | |
41 * The second is similar: | |
42 * f(q) = |f(p)| + ||f'(p)||*||q-p|| + ||f''(p)||*||q-p||^2. | |
43 * The exact version of the equations can be found in the paper | |
44 * "Distance Approximations for Rasterizing Implicit Curves" by Gabriel Taubin | |
45 * | |
46 * In both versions we solve the quadratic for ||q-p||. | |
47 * Version 1: | |
48 * gFM is magnitude of first partials and gFM2 is magnitude of 2nd partials (as derived from paper) | |
49 * builder->fsCodeAppend("\t\tedgeAlpha = (sqrt(gFM*gFM+4.0*func*gF2M) - gFM)/(2 .0*gF2M);\n"); | |
50 * Version 2: | |
51 * builder->fsCodeAppend("\t\tedgeAlpha = (gFM - sqrt(gFM*gFM-4.0*func*gF2M))/(2 .0*gF2M);\n"); | |
52 * | |
53 * Also note that 2nd partials of k,l,m are zero | |
54 * | |
55 * When comparing the two second order approximations to the first order approxi mations, | |
56 * the following results were found. Version 1 tends to underestimate the distan ces, thus it | |
57 * basically increases all the error that we were already seeing in the first or der | |
58 * approx. So this version is not the one to use. Version 2 has the opposite eff ect | |
59 * and tends to overestimate the distances. This is much closer to what we are | |
60 * looking for. It is able to render ellipses (even thin ones) without the need to chop. | |
61 * However, it can not handle thin hyperbolas well and thus would still rely on | |
62 * chopping to tighten the clipping. Another side effect of the overestimating i s | |
63 * that the curves become much thinner and "ropey". If all that was ever rendere d | |
64 * were "not too thin" curves and ellipses then 2nd order may have an advantage since | |
65 * only one geometry would need to be rendered. However no benches were run comp aring | |
66 * chopped first order and non chopped 2nd order. | |
67 */ | |
68 class GrGLConicEffect; | |
69 | |
70 class GrConicEffect : public GrEffect { | |
71 public: | |
72 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) { | |
73 GR_CREATE_STATIC_EFFECT(gConicFillAA, GrConicEffect, (edgeType)); | |
74 GR_CREATE_STATIC_EFFECT(gConicHairAA, GrConicEffect, (edgeType)); | |
75 GR_CREATE_STATIC_EFFECT(gConicFillNoAA, GrConicEffect, (edgeType)); | |
76 if (kFillAA_GrBezierEdgeType == edgeType) { | |
77 if (!caps.shaderDerivativeSupport()) { | |
78 return NULL; | |
79 } | |
80 gConicFillAA->ref(); | |
81 return gConicFillAA; | |
82 } else if (kHairAA_GrBezierEdgeType == edgeType) { | |
83 if (!caps.shaderDerivativeSupport()) { | |
84 return NULL; | |
85 } | |
86 gConicHairAA->ref(); | |
87 return gConicHairAA; | |
88 } else { | |
89 gConicFillNoAA->ref(); | |
90 return gConicFillNoAA; | |
91 } | |
92 } | |
93 | |
94 virtual ~GrConicEffect(); | |
95 | |
96 static const char* Name() { return "Conic"; } | |
97 | |
98 inline bool isAntiAliased() const { return fAntiAlias; } | |
99 inline bool isFilled() const { return fFill; } | |
100 | |
101 typedef GrGLConicEffect GLEffect; | |
102 | |
103 virtual void getConstantColorComponents(GrColor* color, | |
104 uint32_t* validFlags) const SK_OVERR IDE { | |
105 *validFlags = 0; | |
106 } | |
107 | |
108 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | |
109 | |
110 private: | |
111 GrConicEffect(GrBezierEdgeType edgeType); | |
112 | |
113 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | |
114 | |
115 bool fAntiAlias; | |
116 bool fFill; | |
117 | |
118 GR_DECLARE_EFFECT_TEST; | |
119 | |
120 typedef GrEffect INHERITED; | |
121 }; | |
122 | |
123 /////////////////////////////////////////////////////////////////////////////// | |
124 /** | |
125 * The output of this effect is a hairline edge for quadratics. | |
126 * Quadratic specified by 0=u^2-v canonical coords. u and v are the first | |
127 * two components of the vertex attribute. At the three control points that defi ne | |
128 * the Quadratic, u, v have the values {0,0}, {1/2, 0}, and {1, 1} respectively. | |
129 * Uses unsigned distance. | |
bsalomon
2013/08/22 13:01:43
Probably need to strike out this uses unsigned dis
| |
130 * Coverage is min(0, 1-distance). 3rd & 4th component unused. | |
131 * Requires shader derivative instruction support. | |
132 */ | |
133 class GrGLQuadEffect; | |
134 | |
135 class GrQuadEffect : public GrEffect { | |
136 public: | |
137 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) { | |
138 GR_CREATE_STATIC_EFFECT(gQuadFillAA, GrQuadEffect, (kFillAA_GrBezierEdge Type)); | |
139 GR_CREATE_STATIC_EFFECT(gQuadHairAA, GrQuadEffect, (kHairAA_GrBezierEdge Type)); | |
140 GR_CREATE_STATIC_EFFECT(gQuadFillNoAA, GrQuadEffect, (kFillNoAA_GrBezier EdgeType)); | |
141 if (kFillAA_GrBezierEdgeType == edgeType) { | |
142 if (!caps.shaderDerivativeSupport()) { | |
143 return NULL; | |
144 } | |
145 gQuadFillAA->ref(); | |
146 return gQuadFillAA; | |
147 } else if (kHairAA_GrBezierEdgeType == edgeType) { | |
148 if (!caps.shaderDerivativeSupport()) { | |
149 return NULL; | |
150 } | |
151 gQuadHairAA->ref(); | |
152 return gQuadHairAA; | |
153 } else { | |
154 gQuadFillNoAA->ref(); | |
155 return gQuadFillNoAA; | |
156 } | |
157 } | |
158 | |
159 virtual ~GrQuadEffect(); | |
160 | |
161 static const char* Name() { return "Quad"; } | |
162 | |
163 inline bool isAntiAliased() const { return fAntiAlias; } | |
164 inline bool isFilled() const { return fFill; } | |
165 | |
166 typedef GrGLQuadEffect GLEffect; | |
167 | |
168 virtual void getConstantColorComponents(GrColor* color, | |
169 uint32_t* validFlags) const SK_OVERR IDE { | |
170 *validFlags = 0; | |
171 } | |
172 | |
173 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | |
174 | |
175 private: | |
176 GrQuadEffect(const GrBezierEdgeType); | |
bsalomon
2013/08/22 13:01:43
const?
| |
177 | |
178 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | |
179 | |
180 bool fAntiAlias; | |
181 bool fFill; | |
182 | |
183 GR_DECLARE_EFFECT_TEST; | |
184 | |
185 typedef GrEffect INHERITED; | |
186 }; | |
187 | |
188 ////////////////////////////////////////////////////////////////////////////// | |
189 /** | |
190 * Shader is based off of "Resolution Independent Curve Rendering using | |
191 * Programmable Graphics Hardware" by Loop and Blinn. | |
192 * The output of this effect is a hairline edge for non rational cubics. | |
193 * Cubics are specified by implicit equation K^3 - LM. | |
194 * K, L, and M, are the first three values of the vertex attribute, | |
195 * the fourth value is not used. Distance is calculated using a | |
196 * first order approximation from the taylor series. | |
197 * Coverage is max(0, 1-distance). | |
198 */ | |
199 class GrGLCubicEffect; | |
200 | |
201 class GrCubicEffect : public GrEffect { | |
202 public: | |
203 static GrEffectRef* Create(const GrBezierEdgeType edgeType, const GrDrawTarg etCaps& caps) { | |
204 GR_CREATE_STATIC_EFFECT(gCubicFillAA, GrCubicEffect, (kFillAA_GrBezierEd geType)); | |
205 GR_CREATE_STATIC_EFFECT(gCubicHairAA, GrCubicEffect, (kHairAA_GrBezierEd geType)); | |
206 GR_CREATE_STATIC_EFFECT(gCubicFillNoAA, GrCubicEffect, (kFillNoAA_GrBezi erEdgeType)); | |
207 if (kFillAA_GrBezierEdgeType == edgeType) { | |
208 if (!caps.shaderDerivativeSupport()) { | |
209 return NULL; | |
210 } | |
211 gCubicFillAA->ref(); | |
212 return gCubicFillAA; | |
213 } else if (kHairAA_GrBezierEdgeType == edgeType) { | |
214 if (!caps.shaderDerivativeSupport()) { | |
215 return NULL; | |
216 } | |
217 gCubicHairAA->ref(); | |
218 return gCubicHairAA; | |
219 } else { | |
220 gCubicFillNoAA->ref(); | |
221 return gCubicFillNoAA; | |
222 } | |
223 } | |
224 | |
225 virtual ~GrCubicEffect(); | |
226 | |
227 static const char* Name() { return "Cubic"; } | |
228 | |
229 inline bool isAntiAliased() const { return fAntiAlias; } | |
230 inline bool isFilled() const { return fFill; } | |
231 | |
232 typedef GrGLCubicEffect GLEffect; | |
233 | |
234 virtual void getConstantColorComponents(GrColor* color, | |
235 uint32_t* validFlags) const SK_OVERR IDE { | |
236 *validFlags = 0; | |
237 } | |
238 | |
239 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | |
240 | |
241 private: | |
242 GrCubicEffect(const GrBezierEdgeType); | |
bsalomon
2013/08/22 13:01:43
const?
| |
243 | |
244 virtual bool onIsEqual(const GrEffect& other) const SK_OVERRIDE; | |
245 | |
246 bool fAntiAlias; | |
247 bool fFill; | |
248 | |
249 GR_DECLARE_EFFECT_TEST; | |
250 | |
251 typedef GrEffect INHERITED; | |
252 }; | |
253 | |
254 #endif | |
OLD | NEW |