OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "gm.h" | 9 #include "gm.h" |
10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 DCFP(GrProcessorDataManager*, const SkMatrix& m) : fDeviceTransform(kDevice_
GrCoordSet, m) { | 58 DCFP(GrProcessorDataManager*, const SkMatrix& m) : fDeviceTransform(kDevice_
GrCoordSet, m) { |
59 this->addCoordTransform(&fDeviceTransform); | 59 this->addCoordTransform(&fDeviceTransform); |
60 this->initClassID<DCFP>(); | 60 this->initClassID<DCFP>(); |
61 } | 61 } |
62 | 62 |
63 void getGLProcessorKey(const GrGLSLCaps& caps, | 63 void getGLProcessorKey(const GrGLSLCaps& caps, |
64 GrProcessorKeyBuilder* b) const override {} | 64 GrProcessorKeyBuilder* b) const override {} |
65 | 65 |
66 GrGLFragmentProcessor* createGLInstance() const override { | 66 GrGLFragmentProcessor* createGLInstance() const override { |
67 class DCGLFP : public GrGLFragmentProcessor { | 67 class DCGLFP : public GrGLFragmentProcessor { |
68 void emitCode(GrGLFPBuilder* builder, | 68 void emitCode(EmitArgs& args) override { |
69 const GrFragmentProcessor& fp, | 69 GrGLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBuild
er(); |
70 const char* outputColor, | 70 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoo
rds, 0).c_str()); |
71 const char* inputColor, | |
72 const TransformedCoordsArray& coords, | |
73 const TextureSamplerArray& samplers) override { | |
74 GrGLFragmentBuilder* fpb = builder->getFragmentShaderBuilder(); | |
75 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(coords, 0
).c_str()); | |
76 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); | 71 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); |
77 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," | 72 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," |
78 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," | 73 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," |
79 "(r.x + r.y) / 20.0," | 74 "(r.x + r.y) / 20.0," |
80 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); | 75 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); |
81 fpb->codeAppendf("color.rgb *= color.a;" | 76 fpb->codeAppendf("color.rgb *= color.a;" |
82 "%s = color * %s;", | 77 "%s = color * %s;", |
83 outputColor, GrGLSLExpr4(inputColor).c_str()
); | 78 args.fOutputColor, GrGLSLExpr4(args.fInputCo
lor).c_str()); |
84 } | 79 } |
85 void setData(const GrGLProgramDataManager&, const GrProcessor&) over
ride {} | 80 void setData(const GrGLProgramDataManager&, const GrProcessor&) over
ride {} |
86 }; | 81 }; |
87 return SkNEW(DCGLFP); | 82 return SkNEW(DCGLFP); |
88 } | 83 } |
89 | 84 |
90 const char* name() const override { return "DCFP"; } | 85 const char* name() const override { return "DCFP"; } |
91 | 86 |
92 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { | 87 void onComputeInvariantOutput(GrInvariantOutput* inout) const override { |
93 inout->mulByUnknownFourComponents(); | 88 inout->mulByUnknownFourComponents(); |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 }; | 287 }; |
293 | 288 |
294 SkTArray<Prim*> fPrims; | 289 SkTArray<Prim*> fPrims; |
295 | 290 |
296 typedef GM INHERITED; | 291 typedef GM INHERITED; |
297 }; | 292 }; |
298 | 293 |
299 DEF_GM( return SkNEW(DCShaderGM); ) | 294 DEF_GM( return SkNEW(DCShaderGM); ) |
300 } | 295 } |
301 #endif | 296 #endif |
OLD | NEW |