OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrDefaultGeoProcFactory.h" | 8 #include "GrDefaultGeoProcFactory.h" |
9 | 9 |
10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
11 #include "gl/GrGLGeometryProcessor.h" | 11 #include "gl/GrGLGeometryProcessor.h" |
12 #include "gl/GrGLUtil.h" | 12 #include "gl/GrGLUtil.h" |
13 #include "gl/builders/GrGLProgramBuilder.h" | 13 #include "glsl/GrGLSLFragmentShaderBuilder.h" |
| 14 #include "glsl/GrGLSLProgramBuilder.h" |
| 15 #include "glsl/GrGLSLVertexShaderBuilder.h" |
14 | 16 |
15 /* | 17 /* |
16 * The default Geometry Processor simply takes position and multiplies it by the
uniform view | 18 * The default Geometry Processor simply takes position and multiplies it by the
uniform view |
17 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or | 19 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per
vertex color or |
18 * local coords. | 20 * local coords. |
19 */ | 21 */ |
20 | 22 |
21 enum GPFlag { | 23 enum GPFlag { |
22 kColor_GPFlag = 0x1, | 24 kColor_GPFlag = 0x1, |
23 kLocalCoord_GPFlag = 0x2, | 25 kLocalCoord_GPFlag = 0x2, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } | 57 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } |
56 | 58 |
57 class GLProcessor : public GrGLGeometryProcessor { | 59 class GLProcessor : public GrGLGeometryProcessor { |
58 public: | 60 public: |
59 GLProcessor() | 61 GLProcessor() |
60 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} | 62 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} |
61 | 63 |
62 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 64 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
63 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); | 65 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
64 GrGLSLGPBuilder* pb = args.fPB; | 66 GrGLSLGPBuilder* pb = args.fPB; |
65 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 67 GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
66 GrGLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); | 68 GrGLSLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); |
67 | 69 |
68 // emit attributes | 70 // emit attributes |
69 vsBuilder->emitAttributes(gp); | 71 vsBuilder->emitAttributes(gp); |
70 | 72 |
71 // Setup pass through color | 73 // Setup pass through color |
72 if (!gp.colorIgnored()) { | 74 if (!gp.colorIgnored()) { |
73 if (gp.hasVertexColor()) { | 75 if (gp.hasVertexColor()) { |
74 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor)
; | 76 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor)
; |
75 } else { | 77 } else { |
76 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor
m); | 78 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor
m); |
(...skipping 21 matching lines...) Expand all Loading... |
98 // Setup coverage as pass through | 100 // Setup coverage as pass through |
99 if (!gp.coverageWillBeIgnored()) { | 101 if (!gp.coverageWillBeIgnored()) { |
100 if (gp.hasVertexCoverage()) { | 102 if (gp.hasVertexCoverage()) { |
101 fs->codeAppendf("float alpha = 1.0;"); | 103 fs->codeAppendf("float alpha = 1.0;"); |
102 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); | 104 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); |
103 fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 105 fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); |
104 } else if (gp.coverage() == 0xff) { | 106 } else if (gp.coverage() == 0xff) { |
105 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 107 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
106 } else { | 108 } else { |
107 const char* fragCoverage; | 109 const char* fragCoverage; |
108 fCoverageUniform = pb->addUniform(GrGLProgramBuilder::kFragm
ent_Visibility, | 110 fCoverageUniform = pb->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, |
109 kFloat_GrSLType, | 111 kFloat_GrSLType, |
110 kDefault_GrSLPrecision, | 112 kDefault_GrSLPrecision, |
111 "Coverage", | 113 "Coverage", |
112 &fragCoverage); | 114 &fragCoverage); |
113 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag
Coverage); | 115 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag
Coverage); |
114 } | 116 } |
115 } | 117 } |
116 } | 118 } |
117 | 119 |
118 static inline void GenKey(const GrGeometryProcessor& gp, | 120 static inline void GenKey(const GrGeometryProcessor& gp, |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 } | 312 } |
311 | 313 |
312 if (localCoords.hasLocalMatrix()) { | 314 if (localCoords.hasLocalMatrix()) { |
313 invert.preConcat(*localCoords.fMatrix); | 315 invert.preConcat(*localCoords.fMatrix); |
314 } | 316 } |
315 } | 317 } |
316 | 318 |
317 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 319 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
318 return Create(color, coverage, inverted, SkMatrix::I()); | 320 return Create(color, coverage, inverted, SkMatrix::I()); |
319 } | 321 } |
OLD | NEW |