Index: src/gpu/effects/GrEllipseEdgeEffect.cpp |
=================================================================== |
--- src/gpu/effects/GrEllipseEdgeEffect.cpp (revision 0) |
+++ src/gpu/effects/GrEllipseEdgeEffect.cpp (working copy) |
@@ -0,0 +1,83 @@ |
+/* |
robertphillips
2013/03/05 20:30:13
2013
jvanverth1
2013/03/07 15:21:54
Done.
|
+ * Copyright 2012 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "GrEllipseEdgeEffect.h" |
+#include "gl/GrGLEffect.h" |
+#include "gl/GrGLEffectMatrix.h" |
+#include "gl/GrGLSL.h" |
+#include "gl/GrGLTexture.h" |
+#include "GrTBackendEffectFactory.h" |
+#include "GrTexture.h" |
+ |
+#define ELLIPSE_EDGE_ATTR0 "aEllipseEdge" |
+ |
+class GrGLEllipseEdgeEffect : public GrGLEffect { |
+public: |
+ GrGLEllipseEdgeEffect(const GrBackendEffectFactory& factory, const GrEffectRef&) |
+ : INHERITED (factory) {} |
+ |
+ virtual void emitCode(GrGLShaderBuilder* builder, |
+ const GrEffectStage&, |
+ EffectKey key, |
+ const char* vertexCoords, |
+ const char* outputColor, |
+ const char* inputColor, |
+ const TextureSamplerArray& samplers) SK_OVERRIDE { |
+ const char *vsName, *fsName; |
+ builder->addVarying(kVec4f_GrSLType, "EllipseEdge", &vsName, &fsName); |
+ builder->fVSAttrs.push_back().set(kVec4f_GrSLType, |
+ GrGLShaderVar::kAttribute_TypeModifier, |
+ ELLIPSE_EDGE_ATTR0); |
+ builder->fVSCode.appendf("\t%s = " ELLIPSE_EDGE_ATTR0 ";\n", vsName); |
+ |
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.
|
+ builder->fFSCode.append("\tfloat edgeAlpha;\n"); |
+ builder->fFSCode.appendf("\tvec2 offset = (%s.xy - %s.xy);\n", builder->fragmentPosition(), fsName); |
+ builder->fFSCode.appendf("\toffset.y *= %s.w;\n", fsName); |
+ builder->fFSCode.append("\tfloat d = length(offset);\n"); |
+ builder->fFSCode.appendf("\tedgeAlpha = smoothstep(d - 0.5, d + 0.5, %s.z);\n", fsName); |
+ builder->fFSCode.appendf("\t%s = ", outputColor); |
+ GrGLSLModulate4f(&builder->fFSCode, inputColor, "edgeAlpha"); |
+ builder->fFSCode.append(";\n"); |
+ |
+ } |
+ |
+ 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.
|
+ return 0x1; |
+ } |
+ |
+ virtual void setData(const GrGLUniformManager& uman, const GrEffectStage& stage) SK_OVERRIDE { |
+ } |
+ |
+private: |
robertphillips
2013/03/05 20:30:13
unused?
jvanverth1
2013/03/07 15:21:54
Done.
|
+ bool fDiscardIfOutsideEdge; |
+ typedef GrGLEffect INHERITED; |
+}; |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+GrEllipseEdgeEffect::GrEllipseEdgeEffect() : GrEffect() { |
+ this->addVertexAttribName(ELLIPSE_EDGE_ATTR0); |
+} |
+ |
+void GrEllipseEdgeEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
robertphillips
2013/03/05 20:30:13
Remove dead code?
jvanverth1
2013/03/07 15:21:54
Done.
|
+// this->updateConstantColorComponentsForModulation(color, validFlags); |
+ *validFlags = 0; |
+} |
+ |
+const GrBackendEffectFactory& GrEllipseEdgeEffect::getFactory() const { |
+ return GrTBackendEffectFactory<GrEllipseEdgeEffect>::getInstance(); |
+} |
+ |
+/////////////////////////////////////////////////////////////////////////////// |
+ |
+GR_DEFINE_EFFECT_TEST(GrEllipseEdgeEffect); |
+ |
+GrEffectRef* GrEllipseEdgeEffect::TestCreate(SkMWCRandom* random, |
+ GrContext* context, |
+ GrTexture* textures[]) { |
+ return GrEllipseEdgeEffect::Create(); |
+} |