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 "GrBitmapTextGeoProc.h" | 8 #include "GrBitmapTextGeoProc.h" |
9 #include "GrInvariantOutput.h" | 9 #include "GrInvariantOutput.h" |
10 #include "GrTexture.h" | 10 #include "GrTexture.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 "gl/builders/GrGLProgramBuilder.h" | 15 #include "gl/builders/GrGLProgramBuilder.h" |
16 | 16 |
17 struct BitmapTextBatchTracker { | 17 struct BitmapTextBatchTracker { |
18 GrGPInput fInputColorType; | 18 GrGPInput fInputColorType; |
19 GrColor fColor; | 19 GrColor fColor; |
20 bool fUsesLocalCoords; | 20 bool fUsesLocalCoords; |
21 }; | 21 }; |
22 | 22 |
23 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { | 23 class GrGLBitmapTextGeoProc : public GrGLGeometryProcessor { |
24 public: | 24 public: |
25 GrGLBitmapTextGeoProc(const GrGeometryProcessor&, const GrBatchTracker&) | 25 GrGLBitmapTextGeoProc(const GrGeometryProcessor&, const GrBatchTracker&) |
26 : fColor(GrColor_ILLEGAL) {} | 26 : fColor(GrColor_ILLEGAL) {} |
27 | 27 |
28 void onEmitCode(EmitArgs& args) SK_OVERRIDE { | 28 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) SK_OVERRIDE{ |
29 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); | 29 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); |
30 const BitmapTextBatchTracker& local = args.fBT.cast<BitmapTextBatchTrack
er>(); | 30 const BitmapTextBatchTracker& local = args.fBT.cast<BitmapTextBatchTrack
er>(); |
31 | 31 |
32 GrGLGPBuilder* pb = args.fPB; | 32 GrGLGPBuilder* pb = args.fPB; |
33 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 33 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
34 | 34 |
35 // emit attributes | 35 // emit attributes |
36 vsBuilder->emitAttributes(cte); | 36 vsBuilder->emitAttributes(cte); |
37 | 37 |
38 GrGLVertToFrag v(kVec2f_GrSLType); | 38 GrGLVertToFrag v(kVec2f_GrSLType); |
39 pb->addVarying("TextureCoords", &v); | 39 pb->addVarying("TextureCoords", &v); |
40 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); | 40 vsBuilder->codeAppendf("%s = %s;", v.vsOut(), cte.inTextureCoords()->fNa
me); |
41 | 41 |
42 // Setup pass through color | 42 // Setup pass through color |
43 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, cte.inColor(), | 43 this->setupColorPassThrough(pb, local.fInputColorType, args.fOutputColor
, cte.inColor(), |
44 &fColorUniform); | 44 &fColorUniform); |
45 | 45 |
46 // setup uniform viewMatrix | 46 // setup uniform viewMatrix |
47 this->addUniformViewMatrix(pb); | 47 this->addUniformViewMatrix(pb); |
48 | 48 |
49 // Setup position | 49 // Setup position |
50 vsBuilder->codeAppendf("%s = %s * vec3(%s, 1);", this->position(), this
->uViewM(), | 50 SetupPosition(vsBuilder, gpArgs, cte.inPosition()->fName, |
51 cte.inPosition()->fName); | 51 cte.viewMatrix(), this->uViewM()); |
52 | 52 |
53 // emit transforms | 53 // emit transforms |
54 this->emitTransforms(args.fPB, this->position(), cte.inPosition()->fNam
e, | 54 this->emitTransforms(args.fPB, gpArgs->fPositionVar, cte.inPosition()->f
Name, |
55 cte.localMatrix(), args.fTransformsIn, args.fTransf
ormsOut); | 55 cte.localMatrix(), args.fTransformsIn, args.fTransf
ormsOut); |
56 | 56 |
57 GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); | 57 GrGLGPFragmentBuilder* fsBuilder = pb->getFragmentShaderBuilder(); |
58 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); | 58 fsBuilder->codeAppendf("%s = ", args.fOutputCoverage); |
59 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLT
ype); | 59 fsBuilder->appendTextureLookup(args.fSamplers[0], v.fsIn(), kVec2f_GrSLT
ype); |
60 fsBuilder->codeAppend(";"); | 60 fsBuilder->codeAppend(";"); |
61 } | 61 } |
62 | 62 |
63 virtual void setData(const GrGLProgramDataManager& pdman, | 63 virtual void setData(const GrGLProgramDataManager& pdman, |
64 const GrPrimitiveProcessor& gp, | 64 const GrPrimitiveProcessor& gp, |
(...skipping 14 matching lines...) Expand all Loading... |
79 const GrGLCaps&, | 79 const GrGLCaps&, |
80 GrProcessorKeyBuilder* b) { | 80 GrProcessorKeyBuilder* b) { |
81 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); | 81 const BitmapTextBatchTracker& local = bt.cast<BitmapTextBatchTracker>(); |
82 // We have to put the optional vertex attribute as part of the key. See
the comment | 82 // We have to put the optional vertex attribute as part of the key. See
the comment |
83 // on addVertexAttrib. | 83 // on addVertexAttrib. |
84 // TODO When we have deferred geometry we can fix this | 84 // TODO When we have deferred geometry we can fix this |
85 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); | 85 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); |
86 uint32_t key = 0; | 86 uint32_t key = 0; |
87 key |= SkToBool(gp.inColor()) ? 0x1 : 0x0; | 87 key |= SkToBool(gp.inColor()) ? 0x1 : 0x0; |
88 key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0
x2 : 0x0; | 88 key |= local.fUsesLocalCoords && proc.localMatrix().hasPerspective() ? 0
x2 : 0x0; |
| 89 key |= ComputePosKey(gp.viewMatrix()) << 2; |
89 b->add32(local.fInputColorType << 16 | key); | 90 b->add32(local.fInputColorType << 16 | key); |
90 } | 91 } |
91 | 92 |
92 private: | 93 private: |
93 GrColor fColor; | 94 GrColor fColor; |
94 UniformHandle fColorUniform; | 95 UniformHandle fColorUniform; |
95 | 96 |
96 typedef GrGLGeometryProcessor INHERITED; | 97 typedef GrGLGeometryProcessor INHERITED; |
97 }; | 98 }; |
98 | 99 |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 182 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
182 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], | 183 kTileModes[random->nextULessThan(SK_ARRAY_COUNT(kTileModes))], |
183 }; | 184 }; |
184 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : | 185 GrTextureParams params(tileModes, random->nextBool() ? GrTextureParams::kBil
erp_FilterMode : |
185 GrTextureParams::kNon
e_FilterMode); | 186 GrTextureParams::kNon
e_FilterMode); |
186 | 187 |
187 return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx],
params, | 188 return GrBitmapTextGeoProc::Create(GrRandomColor(random), textures[texIdx],
params, |
188 random->nextBool(), random->nextBool(), | 189 random->nextBool(), random->nextBool(), |
189 GrProcessorUnitTest::TestMatrix(random)); | 190 GrProcessorUnitTest::TestMatrix(random)); |
190 } | 191 } |
OLD | NEW |