| 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 "gl/builders/GrGLProgramBuilder.h" |
| 8 #include "GrCustomCoordsTextureEffect.h" | 9 #include "GrCustomCoordsTextureEffect.h" |
| 9 #include "gl/GrGLEffect.h" | 10 #include "gl/GrGLEffect.h" |
| 10 #include "gl/GrGLShaderBuilder.h" | |
| 11 #include "gl/GrGLSL.h" | 11 #include "gl/GrGLSL.h" |
| 12 #include "gl/GrGLTexture.h" | 12 #include "gl/GrGLTexture.h" |
| 13 #include "gl/GrGLVertexEffect.h" | 13 #include "gl/GrGLVertexEffect.h" |
| 14 #include "GrTBackendEffectFactory.h" | 14 #include "GrTBackendEffectFactory.h" |
| 15 #include "GrTexture.h" | 15 #include "GrTexture.h" |
| 16 | 16 |
| 17 class GrGLCustomCoordsTextureEffect : public GrGLVertexEffect { | 17 class GrGLCustomCoordsTextureEffect : public GrGLVertexEffect { |
| 18 public: | 18 public: |
| 19 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G
rDrawEffect& drawEffect) | 19 GrGLCustomCoordsTextureEffect(const GrBackendEffectFactory& factory, const G
rDrawEffect& drawEffect) |
| 20 : INHERITED (factory) {} | 20 : INHERITED (factory) {} |
| 21 | 21 |
| 22 virtual void emitCode(GrGLFullShaderBuilder* builder, | 22 virtual void emitCode(GrGLFullProgramBuilder* builder, |
| 23 const GrDrawEffect& drawEffect, | 23 const GrDrawEffect& drawEffect, |
| 24 const GrEffectKey& key, | 24 const GrEffectKey& key, |
| 25 const char* outputColor, | 25 const char* outputColor, |
| 26 const char* inputColor, | 26 const char* inputColor, |
| 27 const TransformedCoordsArray&, | 27 const TransformedCoordsArray&, |
| 28 const TextureSamplerArray& samplers) SK_OVERRIDE { | 28 const TextureSamplerArray& samplers) SK_OVERRIDE { |
| 29 SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVe
rtexAttribs()); | 29 SkASSERT(1 == drawEffect.castEffect<GrCustomCoordsTextureEffect>().numVe
rtexAttribs()); |
| 30 | 30 |
| 31 SkString fsCoordName; | 31 SkString fsCoordName; |
| 32 const char* vsVaryingName; | 32 const char* vsVaryingName; |
| 33 const char* fsVaryingNamePtr; | 33 const char* fsVaryingNamePtr; |
| 34 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &f
sVaryingNamePtr); | 34 builder->addVarying(kVec2f_GrSLType, "textureCoords", &vsVaryingName, &f
sVaryingNamePtr); |
| 35 fsCoordName = fsVaryingNamePtr; | 35 fsCoordName = fsVaryingNamePtr; |
| 36 | 36 |
| 37 const char* attrName = | 37 GrGLVertexShaderBuilder* vsBuilder = builder->getVertexShaderBuilder(); |
| 38 builder->getEffectAttributeName(drawEffect.getVertexAttribIndices()[
0])->c_str(); | 38 const SkString* attr0Name = |
| 39 builder->vsCodeAppendf("\t%s = %s;\n", vsVaryingName, attrName); | 39 vsBuilder->getEffectAttributeName(drawEffect.getVertexAttribIndices(
)[0]); |
| 40 vsBuilder->codeAppendf("\t%s = %s;\n", vsVaryingName, attr0Name->c_str()
); |
| 40 | 41 |
| 41 builder->fsCodeAppendf("\t%s = ", outputColor); | 42 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder
(); |
| 42 builder->fsAppendTextureLookupAndModulate(inputColor, | 43 fsBuilder->codeAppendf("\t%s = ", outputColor); |
| 44 fsBuilder->appendTextureLookupAndModulate(inputColor, |
| 43 samplers[0], | 45 samplers[0], |
| 44 fsCoordName.c_str(), | 46 fsCoordName.c_str(), |
| 45 kVec2f_GrSLType); | 47 kVec2f_GrSLType); |
| 46 builder->fsCodeAppend(";\n"); | 48 fsBuilder->codeAppend(";\n"); |
| 47 } | 49 } |
| 48 | 50 |
| 49 virtual void setData(const GrGLProgramDataManager& pdman, | 51 virtual void setData(const GrGLProgramDataManager& pdman, |
| 50 const GrDrawEffect& drawEffect) SK_OVERRIDE {} | 52 const GrDrawEffect& drawEffect) SK_OVERRIDE {} |
| 51 | 53 |
| 52 private: | 54 private: |
| 53 typedef GrGLVertexEffect INHERITED; | 55 typedef GrGLVertexEffect INHERITED; |
| 54 }; | 56 }; |
| 55 | 57 |
| 56 /////////////////////////////////////////////////////////////////////////////// | 58 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 }; | 100 }; |
| 99 SkShader::TileMode tileModes[] = { | 101 SkShader::TileMode tileModes[] = { |
| 100 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 102 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 101 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 103 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
| 102 }; | 104 }; |
| 103 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 105 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
| 104 GrTextureParams::kNon
e_FilterMode); | 106 GrTextureParams::kNon
e_FilterMode); |
| 105 | 107 |
| 106 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); | 108 return GrCustomCoordsTextureEffect::Create(textures[texIdx], params); |
| 107 } | 109 } |
| OLD | NEW |