OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "GrConvolutionEffect.h" | 8 #include "GrConvolutionEffect.h" |
9 #include "gl/GrGLFragmentProcessor.h" | 9 #include "gl/GrGLFragmentProcessor.h" |
10 #include "gl/GrGLTexture.h" | 10 #include "gl/GrGLTexture.h" |
11 #include "gl/builders/GrGLProgramBuilder.h" | 11 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 12 #include "glsl/GrGLSLProgramBuilder.h" |
12 #include "glsl/GrGLSLProgramDataManager.h" | 13 #include "glsl/GrGLSLProgramDataManager.h" |
13 | 14 |
14 // For brevity | 15 // For brevity |
15 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; | 16 typedef GrGLSLProgramDataManager::UniformHandle UniformHandle; |
16 | 17 |
17 class GrGLConvolutionEffect : public GrGLFragmentProcessor { | 18 class GrGLConvolutionEffect : public GrGLFragmentProcessor { |
18 public: | 19 public: |
19 GrGLConvolutionEffect(const GrProcessor&); | 20 GrGLConvolutionEffect(const GrProcessor&); |
20 | 21 |
21 virtual void emitCode(EmitArgs&) override; | 22 virtual void emitCode(EmitArgs&) override; |
(...skipping 19 matching lines...) Expand all Loading... |
41 }; | 42 }; |
42 | 43 |
43 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProcessor& processor) { | 44 GrGLConvolutionEffect::GrGLConvolutionEffect(const GrProcessor& processor) { |
44 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); | 45 const GrConvolutionEffect& c = processor.cast<GrConvolutionEffect>(); |
45 fRadius = c.radius(); | 46 fRadius = c.radius(); |
46 fUseBounds = c.useBounds(); | 47 fUseBounds = c.useBounds(); |
47 fDirection = c.direction(); | 48 fDirection = c.direction(); |
48 } | 49 } |
49 | 50 |
50 void GrGLConvolutionEffect::emitCode(EmitArgs& args) { | 51 void GrGLConvolutionEffect::emitCode(EmitArgs& args) { |
51 fImageIncrementUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment
_Visibility, | 52 fImageIncrementUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragme
nt_Visibility, |
52 kVec2f_GrSLType, kDefault_GrSLPreci
sion, | 53 kVec2f_GrSLType, kDefault_GrSLPreci
sion, |
53 "ImageIncrement"); | 54 "ImageIncrement"); |
54 if (this->useBounds()) { | 55 if (this->useBounds()) { |
55 fBoundsUni = args.fBuilder->addUniform(GrGLProgramBuilder::kFragment_Vis
ibility, | 56 fBoundsUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_V
isibility, |
56 kVec2f_GrSLType, kDefault_GrSLPrecision
, | 57 kVec2f_GrSLType, kDefault_GrSLPrecision
, |
57 "Bounds"); | 58 "Bounds"); |
58 } | 59 } |
59 fKernelUni = args.fBuilder->addUniformArray(GrGLProgramBuilder::kFragment_Vi
sibility, | 60 fKernelUni = args.fBuilder->addUniformArray(GrGLSLProgramBuilder::kFragment_
Visibility, |
60 kFloat_GrSLType, kDefault_GrSLPrecisio
n, | 61 kFloat_GrSLType, kDefault_GrSLPrecisio
n, |
61 "Kernel", this->width()); | 62 "Kernel", this->width()); |
62 | 63 |
63 GrGLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder(); | 64 GrGLSLFragmentBuilder* fsBuilder = args.fBuilder->getFragmentShaderBuilder()
; |
64 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); | 65 SkString coords2D = fsBuilder->ensureFSCoords2D(args.fCoords, 0); |
65 | 66 |
66 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor); | 67 fsBuilder->codeAppendf("\t\t%s = vec4(0, 0, 0, 0);\n", args.fOutputColor); |
67 | 68 |
68 int width = this->width(); | 69 int width = this->width(); |
69 const GrGLSLShaderVar& kernel = args.fBuilder->getUniformVariable(fKernelUni
); | 70 const GrGLSLShaderVar& kernel = args.fBuilder->getUniformVariable(fKernelUni
); |
70 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); | 71 const char* imgInc = args.fBuilder->getUniformCStr(fImageIncrementUni); |
71 | 72 |
72 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); | 73 fsBuilder->codeAppendf("\t\tvec2 coord = %s - %d.0 * %s;\n", coords2D.c_str(
), fRadius, imgInc); |
73 | 74 |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 232 } |
232 | 233 |
233 bool useBounds = d->fRandom->nextBool(); | 234 bool useBounds = d->fRandom->nextBool(); |
234 return GrConvolutionEffect::Create(d->fTextures[texIdx], | 235 return GrConvolutionEffect::Create(d->fTextures[texIdx], |
235 dir, | 236 dir, |
236 radius, | 237 radius, |
237 kernel, | 238 kernel, |
238 useBounds, | 239 useBounds, |
239 bounds); | 240 bounds); |
240 } | 241 } |
OLD | NEW |