| 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" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } | 57 bool hasVertexCoverage() const { return SkToBool(fInCoverage); } |
| 58 | 58 |
| 59 class GLSLProcessor : public GrGLSLGeometryProcessor { | 59 class GLSLProcessor : public GrGLSLGeometryProcessor { |
| 60 public: | 60 public: |
| 61 GLSLProcessor() | 61 GLSLProcessor() |
| 62 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} | 62 : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL), f
Coverage(0xff) {} |
| 63 | 63 |
| 64 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { | 64 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override { |
| 65 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); | 65 const DefaultGeoProc& gp = args.fGP.cast<DefaultGeoProc>(); |
| 66 GrGLSLGPBuilder* pb = args.fPB; | 66 GrGLSLGPBuilder* pb = args.fPB; |
| 67 GrGLSLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 67 GrGLSLVertexBuilder* vertBuilder = args.fVertBuilder; |
| 68 GrGLSLFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); | 68 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 69 | 69 |
| 70 // emit attributes | 70 // emit attributes |
| 71 vsBuilder->emitAttributes(gp); | 71 vertBuilder->emitAttributes(gp); |
| 72 | 72 |
| 73 // Setup pass through color | 73 // Setup pass through color |
| 74 if (!gp.colorIgnored()) { | 74 if (!gp.colorIgnored()) { |
| 75 if (gp.hasVertexColor()) { | 75 if (gp.hasVertexColor()) { |
| 76 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor)
; | 76 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor)
; |
| 77 } else { | 77 } else { |
| 78 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor
m); | 78 this->setupUniformColor(pb, fragBuilder, args.fOutputColor,
&fColorUniform); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 // Setup position | 82 // Setup position |
| 83 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatri
x(), | 83 this->setupPosition(pb, |
| 84 vertBuilder, |
| 85 gpArgs, |
| 86 gp.inPosition()->fName, |
| 87 gp.viewMatrix(), |
| 84 &fViewMatrixUniform); | 88 &fViewMatrixUniform); |
| 85 | 89 |
| 86 if (gp.hasExplicitLocalCoords()) { | 90 if (gp.hasExplicitLocalCoords()) { |
| 87 // emit transforms with explicit local coords | 91 // emit transforms with explicit local coords |
| 88 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords(
)->fName, | 92 this->emitTransforms(pb, |
| 89 gp.localMatrix(), args.fTransformsIn, args.
fTransformsOut); | 93 vertBuilder, |
| 94 gpArgs->fPositionVar, |
| 95 gp.inLocalCoords()->fName, |
| 96 gp.localMatrix(), |
| 97 args.fTransformsIn, |
| 98 args.fTransformsOut); |
| 90 } else if(gp.hasTransformedLocalCoords()) { | 99 } else if(gp.hasTransformedLocalCoords()) { |
| 91 // transforms have already been applied to vertex attributes on
the cpu | 100 // transforms have already been applied to vertex attributes on
the cpu |
| 92 this->emitTransforms(pb, gp.inLocalCoords()->fName, | 101 this->emitTransforms(pb, |
| 93 args.fTransformsIn, args.fTransformsOut); | 102 vertBuilder, |
| 103 gp.inLocalCoords()->fName, |
| 104 args.fTransformsIn, |
| 105 args.fTransformsOut); |
| 94 } else { | 106 } else { |
| 95 // emit transforms with position | 107 // emit transforms with position |
| 96 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()->
fName, | 108 this->emitTransforms(pb, |
| 97 gp.localMatrix(), args.fTransformsIn, args.
fTransformsOut); | 109 vertBuilder, |
| 110 gpArgs->fPositionVar, |
| 111 gp.inPosition()->fName, |
| 112 gp.localMatrix(), |
| 113 args.fTransformsIn, |
| 114 args.fTransformsOut); |
| 98 } | 115 } |
| 99 | 116 |
| 100 // Setup coverage as pass through | 117 // Setup coverage as pass through |
| 101 if (!gp.coverageWillBeIgnored()) { | 118 if (!gp.coverageWillBeIgnored()) { |
| 102 if (gp.hasVertexCoverage()) { | 119 if (gp.hasVertexCoverage()) { |
| 103 fs->codeAppendf("float alpha = 1.0;"); | 120 fragBuilder->codeAppendf("float alpha = 1.0;"); |
| 104 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); | 121 args.fPB->addPassThroughAttribute(gp.inCoverage(), "alpha"); |
| 105 fs->codeAppendf("%s = vec4(alpha);", args.fOutputCoverage); | 122 fragBuilder->codeAppendf("%s = vec4(alpha);", args.fOutputCo
verage); |
| 106 } else if (gp.coverage() == 0xff) { | 123 } else if (gp.coverage() == 0xff) { |
| 107 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); | 124 fragBuilder->codeAppendf("%s = vec4(1);", args.fOutputCovera
ge); |
| 108 } else { | 125 } else { |
| 109 const char* fragCoverage; | 126 const char* fragCoverage; |
| 110 fCoverageUniform = pb->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, | 127 fCoverageUniform = pb->addUniform(GrGLSLProgramBuilder::kFra
gment_Visibility, |
| 111 kFloat_GrSLType, | 128 kFloat_GrSLType, |
| 112 kDefault_GrSLPrecision, | 129 kDefault_GrSLPrecision, |
| 113 "Coverage", | 130 "Coverage", |
| 114 &fragCoverage); | 131 &fragCoverage); |
| 115 fs->codeAppendf("%s = vec4(%s);", args.fOutputCoverage, frag
Coverage); | 132 fragBuilder->codeAppendf("%s = vec4(%s);", args.fOutputCover
age, fragCoverage); |
| 116 } | 133 } |
| 117 } | 134 } |
| 118 } | 135 } |
| 119 | 136 |
| 120 static inline void GenKey(const GrGeometryProcessor& gp, | 137 static inline void GenKey(const GrGeometryProcessor& gp, |
| 121 const GrGLSLCaps&, | 138 const GrGLSLCaps&, |
| 122 GrProcessorKeyBuilder* b) { | 139 GrProcessorKeyBuilder* b) { |
| 123 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); | 140 const DefaultGeoProc& def = gp.cast<DefaultGeoProc>(); |
| 124 uint32_t key = def.fFlags; | 141 uint32_t key = def.fFlags; |
| 125 key |= def.colorIgnored() << 8; | 142 key |= def.colorIgnored() << 8; |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 } | 329 } |
| 313 | 330 |
| 314 if (localCoords.hasLocalMatrix()) { | 331 if (localCoords.hasLocalMatrix()) { |
| 315 invert.preConcat(*localCoords.fMatrix); | 332 invert.preConcat(*localCoords.fMatrix); |
| 316 } | 333 } |
| 317 } | 334 } |
| 318 | 335 |
| 319 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 336 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
| 320 return Create(color, coverage, inverted, SkMatrix::I()); | 337 return Create(color, coverage, inverted, SkMatrix::I()); |
| 321 } | 338 } |
| OLD | NEW |