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 |
11 #include "GrFragmentProcessor.h" | 11 #include "GrFragmentProcessor.h" |
12 #include "GrCoordTransform.h" | 12 #include "GrCoordTransform.h" |
13 #include "effects/GrXfermodeFragmentProcessor.h" | 13 #include "effects/GrXfermodeFragmentProcessor.h" |
14 #include "gl/GrGLFragmentProcessor.h" | 14 #include "glsl/GrGLSLFragmentProcessor.h" |
15 #include "glsl/GrGLSLFragmentShaderBuilder.h" | 15 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
16 #include "glsl/GrGLSLProgramBuilder.h" | 16 #include "glsl/GrGLSLProgramBuilder.h" |
17 #include "glsl/GrGLSLProgramDataManager.h" | 17 #include "glsl/GrGLSLProgramDataManager.h" |
18 #include "Resources.h" | 18 #include "Resources.h" |
19 #include "SkReadBuffer.h" | 19 #include "SkReadBuffer.h" |
20 #include "SkShader.h" | 20 #include "SkShader.h" |
21 #include "SkStream.h" | 21 #include "SkStream.h" |
22 #include "SkTypeface.h" | 22 #include "SkTypeface.h" |
23 #include "SkWriteBuffer.h" | 23 #include "SkWriteBuffer.h" |
24 | 24 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 return new DCShader(matrix); | 57 return new DCShader(matrix); |
58 } | 58 } |
59 | 59 |
60 class DCFP : public GrFragmentProcessor { | 60 class DCFP : public GrFragmentProcessor { |
61 public: | 61 public: |
62 DCFP(const SkMatrix& m) : fDeviceTransform(kDevice_GrCoordSet, m) { | 62 DCFP(const SkMatrix& m) : fDeviceTransform(kDevice_GrCoordSet, m) { |
63 this->addCoordTransform(&fDeviceTransform); | 63 this->addCoordTransform(&fDeviceTransform); |
64 this->initClassID<DCFP>(); | 64 this->initClassID<DCFP>(); |
65 } | 65 } |
66 | 66 |
67 GrGLFragmentProcessor* onCreateGLInstance() const override { | 67 GrGLSLFragmentProcessor* onCreateGLInstance() const override { |
68 class DCGLFP : public GrGLFragmentProcessor { | 68 class DCGLFP : public GrGLSLFragmentProcessor { |
69 void emitCode(EmitArgs& args) override { | 69 void emitCode(EmitArgs& args) override { |
70 GrGLSLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBui
lder(); | 70 GrGLSLFragmentBuilder* fpb = args.fBuilder->getFragmentShaderBui
lder(); |
71 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoo
rds, 0).c_str()); | 71 fpb->codeAppendf("vec2 c = %s;", fpb->ensureFSCoords2D(args.fCoo
rds, 0).c_str()); |
72 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); | 72 fpb->codeAppend("vec2 r = mod(c, vec2(20.0));"); |
73 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," | 73 fpb->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5," |
74 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," | 74 "0.5*cos((c.x + c.y) / 15.0)
+ 0.5," |
75 "(r.x + r.y) / 20.0," | 75 "(r.x + r.y) / 20.0," |
76 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); | 76 "distance(r, vec2(15.0)) / 2
0.0 + 0.2);"); |
77 fpb->codeAppendf("color.rgb *= color.a;" | 77 fpb->codeAppendf("color.rgb *= color.a;" |
78 "%s = color * %s;", | 78 "%s = color * %s;", |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 }; | 290 }; |
291 | 291 |
292 SkTArray<Prim*> fPrims; | 292 SkTArray<Prim*> fPrims; |
293 | 293 |
294 typedef GM INHERITED; | 294 typedef GM INHERITED; |
295 }; | 295 }; |
296 | 296 |
297 DEF_GM(return new DCShaderGM;) | 297 DEF_GM(return new DCShaderGM;) |
298 } | 298 } |
299 #endif | 299 #endif |
OLD | NEW |