| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 "GrCustomCoordsTextureEffect.h" | 8 #include "GrCustomCoordsTextureEffect.h" |
| 9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
| 10 #include "gl/builders/GrGLProgramBuilder.h" | 10 #include "gl/builders/GrGLProgramBuilder.h" |
| 11 #include "gl/GrGLProcessor.h" | 11 #include "gl/GrGLProcessor.h" |
| 12 #include "gl/GrGLSL.h" | 12 #include "gl/GrGLSL.h" |
| 13 #include "gl/GrGLTexture.h" | 13 #include "gl/GrGLTexture.h" |
| 14 #include "gl/GrGLGeometryProcessor.h" | 14 #include "gl/GrGLGeometryProcessor.h" |
| 15 #include "GrTBackendProcessorFactory.h" | 15 #include "GrTBackendProcessorFactory.h" |
| 16 #include "GrTexture.h" | 16 #include "GrTexture.h" |
| 17 | 17 |
| 18 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { | 18 class GrGLCustomCoordsTextureEffect : public GrGLGeometryProcessor { |
| 19 public: | 19 public: |
| 20 GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, cons
t GrProcessor&) | 20 GrGLCustomCoordsTextureEffect(const GrBackendProcessorFactory& factory, cons
t GrProcessor&) |
| 21 : INHERITED (factory) {} | 21 : INHERITED (factory) {} |
| 22 | 22 |
| 23 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { | 23 virtual void emitCode(const EmitArgs& args) SK_OVERRIDE { |
| 24 const GrCustomCoordsTextureEffect& customCoordsTextureEffect = | 24 const GrCustomCoordsTextureEffect& cte = |
| 25 args.fGP.cast<GrCustomCoordsTextureEffect>(); | 25 args.fGP.cast<GrCustomCoordsTextureEffect>(); |
| 26 SkASSERT(1 == customCoordsTextureEffect.getVertexAttribs().count()); | 26 |
| 27 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); |
| 27 | 28 |
| 28 GrGLVertToFrag v(kVec2f_GrSLType); | 29 GrGLVertToFrag v(kVec2f_GrSLType); |
| 29 args.fPB->addVarying("TextureCoords", &v); | 30 args.fPB->addVarying("TextureCoords", &v); |
| 31 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); |
| 30 | 32 |
| 31 GrGLVertexBuilder* vsBuilder = args.fPB->getVertexShaderBuilder(); | 33 if (cte.inColor()) { |
| 32 const GrShaderVar& inTextureCoords = customCoordsTextureEffect.inTexture
Coords(); | 34 args.fPB->addPassThroughAttribute(cte.inColor(), args.fOutputColor); |
| 33 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), inTextureCoords.c_str()); | 35 } |
| 36 |
| 37 // setup output coords |
| 38 vsBuilder->codeAppendf("%s = %s;", vsBuilder->positionCoords(), cte.inPo
sition()->fName); |
| 39 vsBuilder->codeAppendf("%s = %s;", vsBuilder->localCoords(), cte.inPosit
ion()->fName); |
| 34 | 40 |
| 35 // setup position varying | 41 // setup position varying |
| 36 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition()
, | 42 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", vsBuilder->glPosition()
, |
| 37 vsBuilder->uViewM(), vsBuilder->inPosition()); | 43 vsBuilder->uViewM(), cte.inPosition()->fName); |
| 38 | 44 |
| 39 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); | 45 GrGLGPFragmentBuilder* fsBuilder = args.fPB->getFragmentShaderBuilder(); |
| 40 fsBuilder->codeAppendf("%s = ", args.fOutput); | 46 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); |
| 41 fsBuilder->appendTextureLookupAndModulate(args.fInput, | 47 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLT
ype); |
| 42 args.fSamplers[0], | |
| 43 v.fsIn(), | |
| 44 kVec2f_GrSLType); | |
| 45 fsBuilder->codeAppend(";"); | 48 fsBuilder->codeAppend(";"); |
| 46 } | 49 } |
| 47 | 50 |
| 48 virtual void setData(const GrGLProgramDataManager&, | 51 virtual void setData(const GrGLProgramDataManager&, |
| 49 const GrProcessor&) SK_OVERRIDE {} | 52 const GrProcessor&) SK_OVERRIDE {} |
| 50 | 53 |
| 54 static inline void GenKey(const GrProcessor& proc, const GrGLCaps&, |
| 55 GrProcessorKeyBuilder* b) { |
| 56 const GrCustomCoordsTextureEffect& gp = proc.cast<GrCustomCoordsTextureE
ffect>(); |
| 57 |
| 58 b->add32(SkToBool(gp.inColor())); |
| 59 } |
| 60 |
| 61 |
| 51 private: | 62 private: |
| 52 typedef GrGLGeometryProcessor INHERITED; | 63 typedef GrGLGeometryProcessor INHERITED; |
| 53 }; | 64 }; |
| 54 | 65 |
| 55 /////////////////////////////////////////////////////////////////////////////// | 66 /////////////////////////////////////////////////////////////////////////////// |
| 56 | 67 |
| 57 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, | 68 GrCustomCoordsTextureEffect::GrCustomCoordsTextureEffect(GrTexture* texture, |
| 58 const GrTextureParams&
params) | 69 const GrTextureParams&
params, |
| 59 : fTextureAccess(texture, params) | 70 bool hasColor) |
| 60 , fInTextureCoords(this->addVertexAttrib(GrShaderVar("inTextureCoords", | 71 : fTextureAccess(texture, params), fInColor(NULL) { |
| 61 kVec2f_GrSLType, | 72 fInPosition = &this->addVertexAttrib(GrAttribute("inPosition", kVec2f_GrVert
exAttribType)); |
| 62 GrShaderVar::kAttribute
_TypeModifier))) { | 73 if (hasColor) { |
| 74 fInColor = &this->addVertexAttrib(GrAttribute("inColor", kVec4ub_GrVerte
xAttribType)); |
| 75 this->setHasVertexColor(); |
| 76 } |
| 77 fInTextureCoords = &this->addVertexAttrib(GrAttribute("inTextureCoords", |
| 78 kVec2f_GrVertexAttribT
ype)); |
| 63 this->addTextureAccess(&fTextureAccess); | 79 this->addTextureAccess(&fTextureAccess); |
| 64 } | 80 } |
| 65 | 81 |
| 66 bool GrCustomCoordsTextureEffect::onIsEqual(const GrGeometryProcessor& other) co
nst { | 82 bool GrCustomCoordsTextureEffect::onIsEqual(const GrGeometryProcessor& other) co
nst { |
| 67 return true; | 83 const GrCustomCoordsTextureEffect& gp = other.cast<GrCustomCoordsTextureEffe
ct>(); |
| 84 return SkToBool(this->inColor()) == SkToBool(gp.inColor()); |
| 68 } | 85 } |
| 69 | 86 |
| 70 void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* in
out) const { | 87 void GrCustomCoordsTextureEffect::onComputeInvariantOutput(GrInvariantOutput* in
out) const { |
| 71 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { | 88 if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { |
| 72 inout->mulByUnknownAlpha(); | 89 inout->mulByUnknownAlpha(); |
| 73 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { | 90 } else if (GrPixelConfigIsOpaque(this->texture(0)->config())) { |
| 74 inout->mulByUnknownOpaqueColor(); | 91 inout->mulByUnknownOpaqueColor(); |
| 75 } else { | 92 } else { |
| 76 inout->mulByUnknownColor(); | 93 inout->mulByUnknownColor(); |
| 77 } | 94 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 96 SkShader::kRepeat_TileMode, | 113 SkShader::kRepeat_TileMode, |
| 97 SkShader::kMirror_TileMode, | 114 SkShader::kMirror_TileMode, |
| 98 }; | 115 }; |
| 99 SkShader::TileMode tileModes[] = { | 116 SkShader::TileMode tileModes[] = { |
| 100 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 117 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 101 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 118 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 102 }; | 119 }; |
| 103 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 120 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 104 GrTextureParams::kNon
e_FilterMode); | 121 GrTextureParams::kNon
e_FilterMode); |
| 105 | 122 |
| 106 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | 123 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params, random-
>nextBool()); |
| 107 } | 124 } |
| OLD | NEW |