OLD | NEW |
---|---|
(Empty) | |
1 /* | |
robertphillips
2013/03/05 20:30:13
2013
jvanverth1
2013/03/07 15:21:54
Done.
| |
2 * Copyright 2012 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 #include "GrEllipseEdgeEffect.h" | |
9 #include "gl/GrGLEffect.h" | |
10 #include "gl/GrGLEffectMatrix.h" | |
11 #include "gl/GrGLSL.h" | |
12 #include "gl/GrGLTexture.h" | |
13 #include "GrTBackendEffectFactory.h" | |
14 #include "GrTexture.h" | |
15 | |
16 #define ELLIPSE_EDGE_ATTR0 "aEllipseEdge" | |
17 | |
18 class GrGLEllipseEdgeEffect : public GrGLEffect { | |
19 public: | |
20 GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrEffectR ef&) | |
21 : INHERITED (factory) {} | |
22 | |
23 virtual void emitCode(GrGLShaderBuilder* builder, | |
24 const GrEffectStage&, | |
25 EffectKey key, | |
26 const char* vertexCoords, | |
27 const char* outputColor, | |
28 const char* inputColor, | |
29 const TextureSamplerArray& samplers) SK_OVERRIDE { | |
30 const char *vsName, *fsName; | |
31 builder->addVarying(kVec4f_GrSLType, "EllipseEdge", &vsName, &fsName); | |
32 builder->fVSAttrs.push_back().set(kVec4f_GrSLType, | |
33 GrGLShaderVar::kAttribute_TypeModifier , | |
34 ELLIPSE_EDGE_ATTR0); | |
35 builder->fVSCode.appendf("\t%s = " ELLIPSE_EDGE_ATTR0 ";\n", vsName); | |
36 | |
robertphillips
2013/03/05 20:30:13
Reprise the layout of the vec4? e.g., w == xRad/yR
jvanverth1
2013/03/07 15:21:54
Done.
| |
37 builder->fFSCode.append("\tfloat edgeAlpha;\n"); | |
38 builder->fFSCode.appendf("\tvec2 offset = (%s.xy - %s.xy);\n", builder-> fragmentPosition(), fsName); | |
39 builder->fFSCode.appendf("\toffset.y *= %s.w;\n", fsName); | |
40 builder->fFSCode.append("\tfloat d = length(offset);\n"); | |
41 builder->fFSCode.appendf("\tedgeAlpha = smoothstep(d - 0.5, d + 0.5, %s. z);\n", fsName); | |
42 builder->fFSCode.appendf("\t%s = ", outputColor); | |
43 GrGLSLModulate4f(&builder->fFSCode, inputColor, "edgeAlpha"); | |
44 builder->fFSCode.append(";\n"); | |
45 | |
46 } | |
47 | |
48 static inline EffectKey GenKey(const GrEffectStage& stage, const GrGLCaps&) { | |
robertphillips
2013/03/05 20:30:13
// Why 0x1?
jvanverth1
2013/03/07 15:21:54
Done.
| |
49 return 0x1; | |
50 } | |
51 | |
52 virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& st age) SK_OVERRIDE { | |
53 } | |
54 | |
55 private: | |
robertphillips
2013/03/05 20:30:13
unused?
jvanverth1
2013/03/07 15:21:54
Done.
| |
56 bool fDiscardIfOutsideEdge; | |
57 typedef GrGLEffect INHERITED; | |
58 }; | |
59 | |
60 /////////////////////////////////////////////////////////////////////////////// | |
61 | |
62 GrEllipseEdgeEffect::GrEllipseEdgeEffect() : GrEffect() { | |
63 this->addVertexAttribName(ELLIPSE_EDGE_ATTR0); | |
64 } | |
65 | |
66 void GrEllipseEdgeEffect::getConstantColorComponents(GrColor* color, uint32_t* v alidFlags) const { | |
robertphillips
2013/03/05 20:30:13
Remove dead code?
jvanverth1
2013/03/07 15:21:54
Done.
| |
67 // this->updateConstantColorComponentsForModulation(color, validFlags); | |
68 *validFlags = 0; | |
69 } | |
70 | |
71 const GrBackendEffectFactory& GrEllipseEdgeEffect::getFactory() const { | |
72 return GrTBackendEffectFactory<GrEllipseEdgeEffect>::getInstance(); | |
73 } | |
74 | |
75 /////////////////////////////////////////////////////////////////////////////// | |
76 | |
77 GR_DEFINE_EFFECT_TEST(GrEllipseEdgeEffect); | |
78 | |
79 GrEffectRef* GrEllipseEdgeEffect::TestCreate(SkMWCRandom* random, | |
80 GrContext* context, | |
81 GrTexture* textures[]) { | |
82 return GrEllipseEdgeEffect::Create(); | |
83 } | |
OLD | NEW |