OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #include "GrGLPathProcessor.h" |
| 9 |
| 10 #include "GrPathProcessor.h" |
| 11 #include "GrGLGpu.h" |
| 12 #include "GrGLPathRendering.h" |
| 13 |
| 14 GrGLPathProcessor::GrGLPathProcessor(const GrPathProcessor&, const GrBatchTracke
r&) |
| 15 : fColor(GrColor_ILLEGAL) {} |
| 16 |
| 17 void GrGLPathProcessor::emitCode(EmitArgs& args) { |
| 18 GrGLGPBuilder* pb = args.fPB; |
| 19 GrGLGPFragmentBuilder* fs = args.fPB->getFragmentShaderBuilder(); |
| 20 const PathBatchTracker& local = args.fBT.cast<PathBatchTracker>(); |
| 21 |
| 22 // emit transforms |
| 23 this->emitTransforms(args.fPB, args.fTransformsIn, args.fTransformsOut); |
| 24 |
| 25 // Setup uniform color |
| 26 if (kUniform_GrGPInput == local.fInputColorType) { |
| 27 const char* stagedLocalVarName; |
| 28 fColorUniform = pb->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 29 kVec4f_GrSLType, |
| 30 kDefault_GrSLPrecision, |
| 31 "Color", |
| 32 &stagedLocalVarName); |
| 33 fs->codeAppendf("%s = %s;", args.fOutputColor, stagedLocalVarName); |
| 34 } |
| 35 |
| 36 // setup constant solid coverage |
| 37 if (kAllOnes_GrGPInput == local.fInputCoverageType) { |
| 38 fs->codeAppendf("%s = vec4(1);", args.fOutputCoverage); |
| 39 } |
| 40 } |
| 41 |
| 42 void GrGLPathProcessor::GenKey(const GrPathProcessor&, |
| 43 const GrBatchTracker& bt, |
| 44 const GrGLCaps&, |
| 45 GrProcessorKeyBuilder* b) { |
| 46 const PathBatchTracker& local = bt.cast<PathBatchTracker>(); |
| 47 b->add32(local.fInputColorType | local.fInputCoverageType << 16); |
| 48 } |
| 49 |
| 50 void GrGLPathProcessor::setData(const GrGLProgramDataManager& pdman, |
| 51 const GrPrimitiveProcessor& primProc, |
| 52 const GrBatchTracker& bt) { |
| 53 const PathBatchTracker& local = bt.cast<PathBatchTracker>(); |
| 54 if (kUniform_GrGPInput == local.fInputColorType && local.fColor != fColor) { |
| 55 GrGLfloat c[4]; |
| 56 GrColorToRGBAFloat(local.fColor, c); |
| 57 pdman.set4fv(fColorUniform, 1, c); |
| 58 fColor = local.fColor; |
| 59 } |
| 60 } |
| 61 |
| 62 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 63 |
| 64 void GrGLLegacyPathProcessor::emitTransforms(GrGLGPBuilder*, const TransformsIn&
tin, |
| 65 TransformsOut* tout) { |
| 66 tout->push_back_n(tin.count()); |
| 67 fInstalledTransforms.push_back_n(tin.count()); |
| 68 for (int i = 0; i < tin.count(); i++) { |
| 69 const ProcCoords& coordTransforms = tin[i]; |
| 70 int texCoordIndex = this->addTexCoordSets(coordTransforms.count()); |
| 71 |
| 72 // Use the first uniform location as the texcoord index. |
| 73 fInstalledTransforms[i].push_back_n(1); |
| 74 fInstalledTransforms[i][0].fHandle = ShaderVarHandle(texCoordIndex); |
| 75 |
| 76 SkString name; |
| 77 for (int t = 0; t < coordTransforms.count(); ++t) { |
| 78 GrSLType type = coordTransforms[t]->getMatrix().hasPerspective() ? k
Vec3f_GrSLType : |
| 79 k
Vec2f_GrSLType; |
| 80 |
| 81 name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordI
ndex++); |
| 82 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords
, (name, type)); |
| 83 } |
| 84 } |
| 85 } |
| 86 |
| 87 void GrGLLegacyPathProcessor::setTransformData( |
| 88 const GrPrimitiveProcessor& primProc, |
| 89 int index, |
| 90 const SkTArray<const GrCoordTransform*, true>& transforms, |
| 91 GrGLPathRendering* glpr, |
| 92 GrGLuint) { |
| 93 // We've hidden the texcoord index in the first entry of the transforms arra
y for each |
| 94 // effect |
| 95 int texCoordIndex = fInstalledTransforms[index][0].fHandle.handle(); |
| 96 for (int t = 0; t < transforms.count(); ++t) { |
| 97 const SkMatrix& transform = GetTransformMatrix(primProc.localMatrix(), *
transforms[t]); |
| 98 GrGLPathRendering::PathTexGenComponents components = |
| 99 GrGLPathRendering::kST_PathTexGenComponents; |
| 100 if (transform.hasPerspective()) { |
| 101 components = GrGLPathRendering::kSTR_PathTexGenComponents; |
| 102 } |
| 103 glpr->enablePathTexGen(texCoordIndex++, components, transform); |
| 104 } |
| 105 } |
| 106 |
| 107 void GrGLLegacyPathProcessor::didSetData(GrGLPathRendering* glpr) { |
| 108 glpr->flushPathTexGenSettings(fTexCoordSetCnt); |
| 109 } |
| 110 |
| 111 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 112 |
| 113 void GrGLNormalPathProcessor::emitTransforms(GrGLGPBuilder* pb, const Transforms
In& tin, |
| 114 TransformsOut* tout) { |
| 115 tout->push_back_n(tin.count()); |
| 116 fInstalledTransforms.push_back_n(tin.count()); |
| 117 for (int i = 0; i < tin.count(); i++) { |
| 118 const ProcCoords& coordTransforms = tin[i]; |
| 119 fInstalledTransforms[i].push_back_n(coordTransforms.count()); |
| 120 for (int t = 0; t < coordTransforms.count(); t++) { |
| 121 GrSLType varyingType = |
| 122 coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_Gr
SLType : |
| 123 kVec2f_Gr
SLType; |
| 124 |
| 125 |
| 126 SkString strVaryingName("MatrixCoord"); |
| 127 strVaryingName.appendf("_%i_%i", i, t); |
| 128 GrGLVertToFrag v(varyingType); |
| 129 pb->addVarying(strVaryingName.c_str(), &v); |
| 130 SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back
(); |
| 131 varyingInfo.fVariable = pb->getFragmentShaderBuilder()->fInputs.back
(); |
| 132 varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; |
| 133 varyingInfo.fType = varyingType; |
| 134 fInstalledTransforms[i][t].fHandle = ShaderVarHandle(varyingInfo.fLo
cation); |
| 135 fInstalledTransforms[i][t].fType = varyingType; |
| 136 |
| 137 SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords
, |
| 138 (SkString(v.fsIn()), varyingType)); |
| 139 } |
| 140 } |
| 141 } |
| 142 |
| 143 void GrGLNormalPathProcessor::resolveSeparableVaryings(GrGLGpu* gpu, GrGLuint pr
ogramId) { |
| 144 int count = fSeparableVaryingInfos.count(); |
| 145 for (int i = 0; i < count; ++i) { |
| 146 GrGLint location; |
| 147 GR_GL_CALL_RET(gpu->glInterface(), |
| 148 location, |
| 149 GetProgramResourceLocation(programId, |
| 150 GR_GL_FRAGMENT_INPUT, |
| 151 fSeparableVaryingInfos[i].fVar
iable.c_str())); |
| 152 fSeparableVaryingInfos[i].fLocation = location; |
| 153 } |
| 154 } |
| 155 |
| 156 void GrGLNormalPathProcessor::setTransformData( |
| 157 const GrPrimitiveProcessor& primProc, |
| 158 int index, |
| 159 const SkTArray<const GrCoordTransform*, true>& coordTransforms, |
| 160 GrGLPathRendering* glpr, |
| 161 GrGLuint programID) { |
| 162 SkSTArray<2, Transform, true>& transforms = fInstalledTransforms[index]; |
| 163 int numTransforms = transforms.count(); |
| 164 for (int t = 0; t < numTransforms; ++t) { |
| 165 SkASSERT(transforms[t].fHandle.isValid()); |
| 166 const SkMatrix& transform = GetTransformMatrix(primProc.localMatrix(), |
| 167 *coordTransforms[t]); |
| 168 if (transforms[t].fCurrentValue.cheapEqualTo(transform)) { |
| 169 continue; |
| 170 } |
| 171 transforms[t].fCurrentValue = transform; |
| 172 const SeparableVaryingInfo& fragmentInput = |
| 173 fSeparableVaryingInfos[transforms[t].fHandle.handle()]; |
| 174 SkASSERT(transforms[t].fType == kVec2f_GrSLType || |
| 175 transforms[t].fType == kVec3f_GrSLType); |
| 176 unsigned components = transforms[t].fType == kVec2f_GrSLType ? 2 : 3; |
| 177 glpr->setProgramPathFragmentInputTransform(programID, |
| 178 fragmentInput.fLocation, |
| 179 GR_GL_OBJECT_LINEAR, |
| 180 components, |
| 181 transform); |
| 182 } |
| 183 } |
OLD | NEW |