diff options
Diffstat (limited to 'src/sksl/SkSLCPPCodeGenerator.cpp')
-rw-r--r-- | src/sksl/SkSLCPPCodeGenerator.cpp | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp index be402088cc..86565016d6 100644 --- a/src/sksl/SkSLCPPCodeGenerator.cpp +++ b/src/sksl/SkSLCPPCodeGenerator.cpp @@ -637,6 +637,29 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) { this->write(" }\n"); } +void CPPCodeGenerator::writeOnTextureSampler() { + bool foundSampler = false; + for (const auto& param : fSectionAndParameterHelper.getParameters()) { + if (param->fType.kind() == Type::kSampler_Kind) { + if (!foundSampler) { + this->writef( + "const GrFragmentProcessor::TextureSampler& %s::onTextureSampler(int " + "index) const {\n", + fFullName.c_str()); + this->writef(" return IthTextureSampler(index, %s", + HCodeGenerator::FieldName(String(param->fName).c_str()).c_str()); + foundSampler = true; + } else { + this->writef(", %s", + HCodeGenerator::FieldName(String(param->fName).c_str()).c_str()); + } + } + } + if (foundSampler) { + this->write(");\n}\n"); + } +} + void CPPCodeGenerator::writeClone() { if (!this->writeSection(CLONE_SECTION)) { if (fSectionAndParameterHelper.getSection(FIELDS_SECTION)) { @@ -662,15 +685,18 @@ void CPPCodeGenerator::writeClone() { } this->writef(" {\n"); int childCount = 0; + int samplerCount = 0; for (const auto& param : fSectionAndParameterHelper.getParameters()) { if (param->fType.kind() == Type::kSampler_Kind) { - this->writef(" this->addTextureSampler(&%s);\n", - HCodeGenerator::FieldName(String(param->fName).c_str()).c_str()); + ++samplerCount; } else if (param->fType == *fContext.fFragmentProcessor_Type) { this->writef(" this->registerChildProcessor(src.childProcessor(%d).clone());" "\n", childCount++); } } + if (samplerCount) { + this->writef(" this->setTextureSamplerCnt(%d);", samplerCount); + } for (const Section* s : fSectionAndParameterHelper.getSections(COORD_TRANSFORM_SECTION)) { String field = HCodeGenerator::FieldName(s->fArgument.c_str()); this->writef(" this->addCoordTransform(&%sCoordTransform);\n", field.c_str()); @@ -819,6 +845,7 @@ bool CPPCodeGenerator::generateCode() { this->write(" return true;\n" "}\n"); this->writeClone(); + this->writeOnTextureSampler(); this->writeTest(); this->writeSection(CPP_END_SECTION); |