void GrGLNormalPathProcessor::emitTransforms(GrGLGPBuilder* pb, const TransformsIn& tin, TransformsOut* tout) { tout->push_back_n(tin.count()); fInstalledTransforms.push_back_n(tin.count()); for (int i = 0; i < tin.count(); i++) { const ProcCoords& coordTransforms = tin[i]; fInstalledTransforms[i].push_back_n(coordTransforms.count()); for (int t = 0; t < coordTransforms.count(); t++) { GrSLType varyingType = coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_GrSLType : kVec2f_GrSLType; SkString strVaryingName("MatrixCoord"); strVaryingName.appendf("_%i_%i", i, t); GrGLVertToFrag v(varyingType); pb->addVarying(strVaryingName.c_str(), &v); SeparableVaryingInfo& varyingInfo = fSeparableVaryingInfos.push_back(); varyingInfo.fVariable = pb->getFragmentShaderBuilder()->fInputs.back(); varyingInfo.fLocation = fSeparableVaryingInfos.count() - 1; varyingInfo.fType = varyingType; fInstalledTransforms[i][t].fHandle = ShaderVarHandle(varyingInfo.fLocation); fInstalledTransforms[i][t].fType = varyingType; SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords, (SkString(v.fsIn()), varyingType)); } } }
void emitTransforms(GrGLSLVaryingHandler* varyingHandler, const TransformsIn& tin, TransformsOut* tout) { tout->push_back_n(tin.count()); fInstalledTransforms.push_back_n(tin.count()); for (int i = 0; i < tin.count(); i++) { const ProcCoords& coordTransforms = tin[i]; fInstalledTransforms[i].push_back_n(coordTransforms.count()); for (int t = 0; t < coordTransforms.count(); t++) { GrSLType varyingType = coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_GrSLType : kVec2f_GrSLType; SkString strVaryingName("MatrixCoord"); strVaryingName.appendf("_%i_%i", i, t); GrGLSLVertToFrag v(varyingType); GrGLVaryingHandler* glVaryingHandler = (GrGLVaryingHandler*) varyingHandler; fInstalledTransforms[i][t].fHandle = glVaryingHandler->addPathProcessingVarying(strVaryingName.c_str(), &v).toIndex(); fInstalledTransforms[i][t].fType = varyingType; SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLSLTransformedCoords, (SkString(v.fsIn()), varyingType)); } } }
void GrGLLegacyPathProcessor::emitTransforms(GrGLGPBuilder*, const TransformsIn& tin, TransformsOut* tout) { tout->push_back_n(tin.count()); fInstalledTransforms.push_back_n(tin.count()); for (int i = 0; i < tin.count(); i++) { const ProcCoords& coordTransforms = tin[i]; int texCoordIndex = this->addTexCoordSets(coordTransforms.count()); // Use the first uniform location as the texcoord index. fInstalledTransforms[i].push_back_n(1); fInstalledTransforms[i][0].fHandle = ShaderVarHandle(texCoordIndex); SkString name; for (int t = 0; t < coordTransforms.count(); ++t) { GrSLType type = coordTransforms[t]->getMatrix().hasPerspective() ? kVec3f_GrSLType : kVec2f_GrSLType; name.printf("%s(gl_TexCoord[%i])", GrGLSLTypeString(type), texCoordIndex++); SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords, (name, type)); } } }
void GrGLGeometryProcessor::emitTransforms(GrGLGPBuilder* pb, const GrShaderVar& posVar, const char* localCoords, const SkMatrix& localMatrix, const TransformsIn& tin, TransformsOut* tout) { GrGLVertexBuilder* vb = pb->getVertexShaderBuilder(); tout->push_back_n(tin.count()); fInstalledTransforms.push_back_n(tin.count()); for (int i = 0; i < tin.count(); i++) { const ProcCoords& coordTransforms = tin[i]; fInstalledTransforms[i].push_back_n(coordTransforms.count()); for (int t = 0; t < coordTransforms.count(); t++) { SkString strUniName("StageMatrix"); strUniName.appendf("_%i_%i", i, t); GrSLType varyingType; GrCoordSet coordType = coordTransforms[t]->sourceCoords(); uint32_t type = coordTransforms[t]->getMatrix().getType(); if (kLocal_GrCoordSet == coordType) { type |= localMatrix.getType(); } varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSLType : kVec2f_GrSLType; GrSLPrecision precision = coordTransforms[t]->precision(); const char* uniName; fInstalledTransforms[i][t].fHandle = pb->addUniform(GrGLProgramBuilder::kVertex_Visibility, kMat33f_GrSLType, precision, strUniName.c_str(), &uniName).toShaderBuilderIndex(); SkString strVaryingName("MatrixCoord"); strVaryingName.appendf("_%i_%i", i, t); GrGLVertToFrag v(varyingType); pb->addVarying(strVaryingName.c_str(), &v, precision); SkASSERT(kVec2f_GrSLType == varyingType || kVec3f_GrSLType == varyingType); SkNEW_APPEND_TO_TARRAY(&(*tout)[i], GrGLProcessor::TransformedCoords, (SkString(v.fsIn()), varyingType)); // varying = matrix * coords (logically) if (kDevice_GrCoordSet == coordType) { if (kVec2f_GrSLType == varyingType) { if (kVec2f_GrSLType == posVar.getType()) { vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniName, posVar.c_str()); } else { // The brackets here are just to scope the temp variable vb->codeAppendf("{ vec3 temp = %s * %s;", uniName, posVar.c_str()); vb->codeAppendf("%s = vec2(temp.x/temp.z, temp.y/temp.z); }", v.vsOut()); } } else { if (kVec2f_GrSLType == posVar.getType()) { vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, posVar.c_str()); } else { vb->codeAppendf("%s = %s * %s;", v.vsOut(), uniName, posVar.c_str()); } } } else { if (kVec2f_GrSLType == varyingType) { vb->codeAppendf("%s = (%s * vec3(%s, 1)).xy;", v.vsOut(), uniName, localCoords); } else { vb->codeAppendf("%s = %s * vec3(%s, 1);", v.vsOut(), uniName, localCoords); } } } } }