| 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 "GrGLProgramBuilder.h" | 8 #include "GrGLProgramBuilder.h" |
| 9 | 9 |
| 10 #include "gl/GrGLGeometryProcessor.h" | 10 #include "gl/GrGLGeometryProcessor.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); | 172 fUniforms[i].fVariable.appendDecl(this->ctxInfo(), out); |
| 173 out->append(";\n"); | 173 out->append(";\n"); |
| 174 } | 174 } |
| 175 } | 175 } |
| 176 } | 176 } |
| 177 | 177 |
| 178 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { | 178 const GrGLContextInfo& GrGLProgramBuilder::ctxInfo() const { |
| 179 return fGpu->ctxInfo(); | 179 return fGpu->ctxInfo(); |
| 180 } | 180 } |
| 181 | 181 |
| 182 static void append_gr_fp_coord_transforms(const GrFragmentProcessor* processor, | |
| 183 SkTArray<const GrCoordTransform*, true
>* procCoords) { | |
| 184 // add the coord transforms of this processor | |
| 185 for (int i = 0; i < processor->numTransforms(); ++i) { | |
| 186 procCoords->push_back(&processor->coordTransform(i)); | |
| 187 } | |
| 188 // recursively add the coord transforms of this processor's child processors | |
| 189 for (int i = 0; i < processor->numChildProcessors(); ++i) { | |
| 190 append_gr_fp_coord_transforms(processor->childProcessor(i), procCoords); | |
| 191 } | |
| 192 } | |
| 193 | |
| 194 bool GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr
4* inputCoverage) { | 182 bool GrGLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr
4* inputCoverage) { |
| 195 // First we loop over all of the installed processors and collect coord tran
sforms. These will | 183 // First we loop over all of the installed processors and collect coord tran
sforms. These will |
| 196 // be sent to the GrGLPrimitiveProcessor in its emitCode function | 184 // be sent to the GrGLPrimitiveProcessor in its emitCode function |
| 197 const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); | 185 const GrPrimitiveProcessor& primProc = this->primitiveProcessor(); |
| 198 int totalTextures = primProc.numTextures(); | 186 int totalTextures = primProc.numTextures(); |
| 199 const int maxTextureUnits = fGpu->glCaps().maxFragmentTextureUnits(); | 187 const int maxTextureUnits = fGpu->glCaps().maxFragmentTextureUnits(); |
| 200 | 188 |
| 201 for (int i = 0; i < this->pipeline().numFragmentStages(); i++) { | 189 for (int i = 0; i < this->pipeline().numFragmentStages(); i++) { |
| 202 const GrFragmentProcessor* processor = this->pipeline().getFragmentStage
(i).processor(); | 190 const GrFragmentProcessor* processor = this->pipeline().getFragmentStage
(i).processor(); |
| 203 | 191 |
| 204 if (!primProc.hasTransformedLocalCoords()) { | 192 if (!primProc.hasTransformedLocalCoords()) { |
| 205 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTran
sforms.push_back(); | 193 SkSTArray<2, const GrCoordTransform*, true>& procCoords = fCoordTran
sforms.push_back(); |
| 206 | 194 processor->gatherCoordTransforms(&procCoords); |
| 207 append_gr_fp_coord_transforms(processor, &procCoords); | |
| 208 } | 195 } |
| 209 | 196 |
| 210 totalTextures += processor->numTexturesIncludeChildProcs(); | 197 totalTextures += processor->numTextures(); |
| 211 if (totalTextures >= maxTextureUnits) { | 198 if (totalTextures >= maxTextureUnits) { |
| 212 GrCapsDebugf(fGpu->caps(), "Program would use too many texture units
\n"); | 199 GrCapsDebugf(fGpu->caps(), "Program would use too many texture units
\n"); |
| 213 return false; | 200 return false; |
| 214 } | 201 } |
| 215 } | 202 } |
| 216 | 203 |
| 217 this->emitAndInstallProc(primProc, inputColor, inputCoverage); | 204 this->emitAndInstallProc(primProc, inputColor, inputCoverage); |
| 218 | 205 |
| 219 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); | 206 fFragmentProcessors.reset(SkNEW(GrGLInstalledFragProcs)); |
| 220 int numProcs = this->pipeline().numFragmentStages(); | 207 int numProcs = this->pipeline().numFragmentStages(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 | 278 |
| 292 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, | 279 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, |
| 293 int index, | 280 int index, |
| 294 const char* outColor, | 281 const char* outColor, |
| 295 const char* inColor) { | 282 const char* inColor) { |
| 296 GrGLInstalledFragProc* ifp = SkNEW(GrGLInstalledFragProc); | 283 GrGLInstalledFragProc* ifp = SkNEW(GrGLInstalledFragProc); |
| 297 | 284 |
| 298 const GrFragmentProcessor& fp = *fs.processor(); | 285 const GrFragmentProcessor& fp = *fs.processor(); |
| 299 ifp->fGLProc.reset(fp.createGLInstance()); | 286 ifp->fGLProc.reset(fp.createGLInstance()); |
| 300 | 287 |
| 301 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTexturesIncludeCh
ildProcs()); | 288 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); |
| 302 this->emitSamplers(fp, &samplers, ifp); | 289 this->emitSamplers(fp, &samplers, ifp); |
| 303 | 290 |
| 304 GrGLFragmentProcessor::EmitArgs args(this, fp, outColor, inColor, fOutCoords
[index], samplers); | 291 GrGLFragmentProcessor::EmitArgs args(this, fp, outColor, inColor, fOutCoords
[index], samplers); |
| 305 ifp->fGLProc->emitCode(args); | 292 ifp->fGLProc->emitCode(args); |
| 306 | 293 |
| 307 // We have to check that effects and the code they emit are consistent, ie i
f an effect | 294 // We have to check that effects and the code they emit are consistent, ie i
f an effect |
| 308 // asks for dst color, then the emit code needs to follow suit | 295 // asks for dst color, then the emit code needs to follow suit |
| 309 verify(fp); | 296 verify(fp); |
| 310 fFragmentProcessors->fProcs.push_back(ifp); | 297 fFragmentProcessors->fProcs.push_back(ifp); |
| 311 } | 298 } |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 } | 498 } |
| 512 | 499 |
| 513 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 500 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 514 | 501 |
| 515 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 502 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
| 516 int numProcs = fProcs.count(); | 503 int numProcs = fProcs.count(); |
| 517 for (int e = 0; e < numProcs; ++e) { | 504 for (int e = 0; e < numProcs; ++e) { |
| 518 SkDELETE(fProcs[e]); | 505 SkDELETE(fProcs[e]); |
| 519 } | 506 } |
| 520 } | 507 } |
| OLD | NEW |