OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2014 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 "gl/GrGLXferProcessor.h" |
| 9 |
| 10 #include "GrXferProcessor.h" |
| 11 #include "gl/builders/GrGLFragmentShaderBuilder.h" |
| 12 #include "gl/builders/GrGLProgramBuilder.h" |
| 13 |
| 14 void GrGLXferProcessor::emitCode(const EmitArgs& args) { |
| 15 if (args.fXP.getDstCopyTexture()) { |
| 16 GrGLFPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 17 const char* dstColor = fsBuilder->dstColor(); |
| 18 |
| 19 const char* dstCopyTopLeftName; |
| 20 const char* dstCopyCoordScaleName; |
| 21 |
| 22 fDstCopyTopLeftUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_
Visibility, |
| 23 kVec2f_GrSLType, |
| 24 kDefault_GrSLPrecision, |
| 25 "DstCopyUpperLeft", |
| 26 &dstCopyTopLeftName); |
| 27 fDstCopyScaleUni = args.fPB->addUniform(GrGLProgramBuilder::kFragment_Vi
sibility, |
| 28 kVec2f_GrSLType, |
| 29 kDefault_GrSLPrecision, |
| 30 "DstCopyCoordScale", |
| 31 &dstCopyCoordScaleName); |
| 32 const char* fragPos = fsBuilder->fragmentPosition(); |
| 33 |
| 34 fsBuilder->codeAppend("// Read color from copy of the destination.\n"); |
| 35 fsBuilder->codeAppendf("vec2 _dstTexCoord = (%s.xy - %s) * %s;", |
| 36 fragPos, dstCopyTopLeftName, dstCopyCoordScaleNam
e); |
| 37 fsBuilder->codeAppendf("vec4 %s = ", dstColor); |
| 38 fsBuilder->appendTextureLookup(args.fSamplers[0], "_dstTexCoord", kVec2f
_GrSLType); |
| 39 fsBuilder->codeAppend(";"); |
| 40 } |
| 41 |
| 42 this->onEmitCode(args); |
| 43 } |
| 44 |
| 45 void GrGLXferProcessor::setData(const GrGLProgramDataManager& pdm, const GrXferP
rocessor& xp) { |
| 46 if (xp.getDstCopyTexture()) { |
| 47 if (fDstCopyTopLeftUni.isValid()) { |
| 48 pdm.set2f(fDstCopyTopLeftUni, static_cast<GrGLfloat>(xp.dstCopyTextu
reOffset().fX), |
| 49 static_cast<GrGLfloat>(xp.dstCopyTextureOffset().fY)); |
| 50 pdm.set2f(fDstCopyScaleUni, 1.f / xp.getDstCopyTexture()->width(), |
| 51 1.f / xp.getDstCopyTexture()->height()); |
| 52 } else { |
| 53 SkASSERT(!fDstCopyScaleUni.isValid()); |
| 54 } |
| 55 } else { |
| 56 SkASSERT(!fDstCopyTopLeftUni.isValid()); |
| 57 SkASSERT(!fDstCopyScaleUni.isValid()); |
| 58 } |
| 59 this->onSetData(pdm, xp); |
| 60 } |
| 61 |
OLD | NEW |