| 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 #include "gl/GrGLProgram.h" | 9 #include "gl/GrGLProgram.h" |
| 10 #include "gl/GrGLSLPrettyPrint.h" | 10 #include "gl/GrGLSLPrettyPrint.h" |
| (...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 this->emitAndInstallProc(proc, outputColor->c_str(), outputCoverage->c_str()
); | 270 this->emitAndInstallProc(proc, outputColor->c_str(), outputCoverage->c_str()
); |
| 271 | 271 |
| 272 fFS.codeAppend("}"); | 272 fFS.codeAppend("}"); |
| 273 } | 273 } |
| 274 | 274 |
| 275 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, | 275 void GrGLProgramBuilder::emitAndInstallProc(const GrPendingFragmentStage& fs, |
| 276 const char* outColor, | 276 const char* outColor, |
| 277 const char* inColor) { | 277 const char* inColor) { |
| 278 GrGLInstalledFragProc* ifp = SkNEW(GrGLInstalledFragProc); | 278 GrGLInstalledFragProc* ifp = SkNEW(GrGLInstalledFragProc); |
| 279 | 279 |
| 280 const GrFragmentProcessor& fp = *fs.getProcessor(); | 280 const GrFragmentProcessor& fp = *fs.processor(); |
| 281 ifp->fGLProc.reset(fp.createGLInstance()); | 281 ifp->fGLProc.reset(fp.createGLInstance()); |
| 282 | 282 |
| 283 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); | 283 SkSTArray<4, GrGLProcessor::TextureSampler> samplers(fp.numTextures()); |
| 284 this->emitSamplers(fp, &samplers, ifp); | 284 this->emitSamplers(fp, &samplers, ifp); |
| 285 | 285 |
| 286 // Fragment processors can have coord transforms | 286 // Fragment processors can have coord transforms |
| 287 SkSTArray<2, GrGLProcessor::TransformedCoords> coords(fp.numTransforms()); | 287 SkSTArray<2, GrGLProcessor::TransformedCoords> coords(fp.numTransforms()); |
| 288 this->emitTransforms(fs, &coords, ifp); | 288 this->emitTransforms(fs, &coords, ifp); |
| 289 | 289 |
| 290 ifp->fGLProc->emitCode(this, fp, outColor, inColor, coords, samplers); | 290 ifp->fGLProc->emitCode(this, fp, outColor, inColor, coords, samplers); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 } | 365 } |
| 366 | 366 |
| 367 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { | 367 void GrGLProgramBuilder::verify(const GrFragmentProcessor& fp) { |
| 368 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); | 368 SkASSERT(fFS.hasReadFragmentPosition() == fp.willReadFragmentPosition()); |
| 369 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); | 369 SkASSERT(fFS.hasReadDstColor() == fp.willReadDstColor()); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage, | 372 void GrGLProgramBuilder::emitTransforms(const GrPendingFragmentStage& stage, |
| 373 GrGLProcessor::TransformedCoordsArray* o
utCoords, | 373 GrGLProcessor::TransformedCoordsArray* o
utCoords, |
| 374 GrGLInstalledFragProc* ifp) { | 374 GrGLInstalledFragProc* ifp) { |
| 375 const GrFragmentProcessor* processor = stage.getProcessor(); | 375 const GrFragmentProcessor* processor = stage.processor(); |
| 376 int numTransforms = processor->numTransforms(); | 376 int numTransforms = processor->numTransforms(); |
| 377 ifp->fTransforms.push_back_n(numTransforms); | 377 ifp->fTransforms.push_back_n(numTransforms); |
| 378 | 378 |
| 379 for (int t = 0; t < numTransforms; t++) { | 379 for (int t = 0; t < numTransforms; t++) { |
| 380 const char* uniName = "StageMatrix"; | 380 const char* uniName = "StageMatrix"; |
| 381 GrSLType varyingType; | 381 GrSLType varyingType; |
| 382 | 382 |
| 383 // TODO when we have deleted the coord change matrices we can get rid of
the below check | |
| 384 GrCoordSet coordType = processor->coordTransform(t).sourceCoords(); | 383 GrCoordSet coordType = processor->coordTransform(t).sourceCoords(); |
| 385 const SkMatrix& localMatrix = fOptState.getPrimitiveProcessor()->localMa
trix(); | 384 const SkMatrix& localMatrix = fOptState.getPrimitiveProcessor()->localMa
trix(); |
| 386 if (localMatrix.isIdentity()) { | 385 uint32_t type = processor->coordTransform(t).getMatrix().getType(); |
| 387 varyingType = stage.isPerspectiveCoordTransform(t) ? kVec3f_GrSLType
: | 386 if (kLocal_GrCoordSet == coordType) { |
| 388 kVec2f_GrSLType
; | 387 type |= localMatrix.getType(); |
| 389 } else { | |
| 390 uint32_t type = processor->coordTransform(t).getMatrix().getType(); | |
| 391 if (kLocal_GrCoordSet == coordType) { | |
| 392 type |= localMatrix.getType(); | |
| 393 } | |
| 394 varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_
GrSLType : | |
| 395 kVec2f_
GrSLType; | |
| 396 } | 388 } |
| 389 varyingType = SkToBool(SkMatrix::kPerspective_Mask & type) ? kVec3f_GrSL
Type : |
| 390 kVec2f_GrSL
Type; |
| 397 GrSLPrecision precision = processor->coordTransform(t).precision(); | 391 GrSLPrecision precision = processor->coordTransform(t).precision(); |
| 398 | 392 |
| 399 SkString suffixedUniName; | 393 SkString suffixedUniName; |
| 400 if (0 != t) { | 394 if (0 != t) { |
| 401 suffixedUniName.append(uniName); | 395 suffixedUniName.append(uniName); |
| 402 suffixedUniName.appendf("_%i", t); | 396 suffixedUniName.appendf("_%i", t); |
| 403 uniName = suffixedUniName.c_str(); | 397 uniName = suffixedUniName.c_str(); |
| 404 } | 398 } |
| 405 ifp->fTransforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVert
ex_Visibility, | 399 ifp->fTransforms[t].fHandle = this->addUniform(GrGLProgramBuilder::kVert
ex_Visibility, |
| 406 kMat33f_GrSLType, precisi
on, | 400 kMat33f_GrSLType, precisi
on, |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 } | 545 } |
| 552 | 546 |
| 553 ////////////////////////////////////////////////////////////////////////////////
/////////////////// | 547 ////////////////////////////////////////////////////////////////////////////////
/////////////////// |
| 554 | 548 |
| 555 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { | 549 GrGLInstalledFragProcs::~GrGLInstalledFragProcs() { |
| 556 int numProcs = fProcs.count(); | 550 int numProcs = fProcs.count(); |
| 557 for (int e = 0; e < numProcs; ++e) { | 551 for (int e = 0; e < numProcs; ++e) { |
| 558 SkDELETE(fProcs[e]); | 552 SkDELETE(fProcs[e]); |
| 559 } | 553 } |
| 560 } | 554 } |
| OLD | NEW |