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 "GrFontAtlasSizes.h" | 9 #include "GrFontAtlasSizes.h" |
10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ | 22 void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{ |
23 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); | 23 const GrBitmapTextGeoProc& cte = args.fGP.cast<GrBitmapTextGeoProc>(); |
24 | 24 |
25 GrGLGPBuilder* pb = args.fPB; | 25 GrGLGPBuilder* pb = args.fPB; |
26 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); | 26 GrGLVertexBuilder* vsBuilder = pb->getVertexShaderBuilder(); |
27 | 27 |
28 // emit attributes | 28 // emit attributes |
29 vsBuilder->emitAttributes(cte); | 29 vsBuilder->emitAttributes(cte); |
30 | 30 |
| 31 // compute numbers to be hardcoded to convert texture coordinates from i
nt to float |
| 32 SkASSERT(cte.numTextures() == 1); |
| 33 GrTexture* atlas = cte.textureAccess(0).getTexture(); |
| 34 SkASSERT(atlas); |
| 35 SkScalar recipWidth = 1.0f / atlas->width(); |
| 36 SkScalar recipHeight = 1.0f / atlas->height(); |
| 37 |
31 GrGLVertToFrag v(kVec2f_GrSLType); | 38 GrGLVertToFrag v(kVec2f_GrSLType); |
32 pb->addVarying("TextureCoords", &v); | 39 pb->addVarying("TextureCoords", &v); |
33 // this is only used with text, so our texture bounds always match the g
lyph atlas | 40 vsBuilder->codeAppendf("%s = vec2(%.*f, %.*f) * %s;", v.vsOut(), |
34 if (cte.maskFormat() == kA8_GrMaskFormat) { | 41 SK_FLT_DECIMAL_DIG, recipWidth, |
35 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_A8_RECIP_WIDTH ",
" | 42 SK_FLT_DECIMAL_DIG, recipHeight, |
36 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", v.vsOut()
, | 43 cte.inTextureCoords()->fName); |
37 cte.inTextureCoords()->fName); | |
38 } else { | |
39 vsBuilder->codeAppendf("%s = vec2(" GR_FONT_ATLAS_RECIP_WIDTH ", " | |
40 GR_FONT_ATLAS_RECIP_HEIGHT ")*%s;", v.vsOut()
, | |
41 cte.inTextureCoords()->fName); | |
42 } | |
43 | 44 |
44 // Setup pass through color | 45 // Setup pass through color |
45 if (!cte.colorIgnored()) { | 46 if (!cte.colorIgnored()) { |
46 if (cte.hasVertexColor()) { | 47 if (cte.hasVertexColor()) { |
47 pb->addPassThroughAttribute(cte.inColor(), args.fOutputColor); | 48 pb->addPassThroughAttribute(cte.inColor(), args.fOutputColor); |
48 } else { | 49 } else { |
49 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); | 50 this->setupUniformColor(pb, args.fOutputColor, &fColorUniform); |
50 } | 51 } |
51 } | 52 } |
52 | 53 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 static inline void GenKey(const GrGeometryProcessor& proc, | 96 static inline void GenKey(const GrGeometryProcessor& proc, |
96 const GrBatchTracker& bt, | 97 const GrBatchTracker& bt, |
97 const GrGLSLCaps&, | 98 const GrGLSLCaps&, |
98 GrProcessorKeyBuilder* b) { | 99 GrProcessorKeyBuilder* b) { |
99 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); | 100 const GrBitmapTextGeoProc& gp = proc.cast<GrBitmapTextGeoProc>(); |
100 uint32_t key = 0; | 101 uint32_t key = 0; |
101 key |= gp.usesLocalCoords() && gp.localMatrix().hasPerspective() ? 0x1 :
0x0; | 102 key |= gp.usesLocalCoords() && gp.localMatrix().hasPerspective() ? 0x1 :
0x0; |
102 key |= gp.colorIgnored() ? 0x2 : 0x0; | 103 key |= gp.colorIgnored() ? 0x2 : 0x0; |
103 key |= gp.maskFormat() << 3; | 104 key |= gp.maskFormat() << 3; |
104 b->add32(key); | 105 b->add32(key); |
| 106 |
| 107 // Currently we hardcode numbers to convert atlas coordinates to normali
zed floating point |
| 108 SkASSERT(gp.numTextures() == 1); |
| 109 GrTexture* atlas = gp.textureAccess(0).getTexture(); |
| 110 SkASSERT(atlas); |
| 111 b->add32(atlas->width()); |
| 112 b->add32(atlas->height()); |
105 } | 113 } |
106 | 114 |
107 private: | 115 private: |
108 GrColor fColor; | 116 GrColor fColor; |
109 UniformHandle fColorUniform; | 117 UniformHandle fColorUniform; |
110 | 118 |
111 typedef GrGLGeometryProcessor INHERITED; | 119 typedef GrGLGeometryProcessor INHERITED; |
112 }; | 120 }; |
113 | 121 |
114 /////////////////////////////////////////////////////////////////////////////// | 122 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 break; | 185 break; |
178 case 2: | 186 case 2: |
179 format = kARGB_GrMaskFormat; | 187 format = kARGB_GrMaskFormat; |
180 break; | 188 break; |
181 } | 189 } |
182 | 190 |
183 return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
exIdx], params, | 191 return GrBitmapTextGeoProc::Create(GrRandomColor(d->fRandom), d->fTextures[t
exIdx], params, |
184 format, GrTest::TestMatrix(d->fRandom), | 192 format, GrTest::TestMatrix(d->fRandom), |
185 d->fRandom->nextBool()); | 193 d->fRandom->nextBool()); |
186 } | 194 } |
OLD | NEW |