OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "GrDefaultGeoProcFactory.h" | 8 #include "GrDefaultGeoProcFactory.h" |
9 | 9 |
10 #include "GrInvariantOutput.h" | 10 #include "GrInvariantOutput.h" |
11 #include "gl/GrGLGeometryProcessor.h" | 11 #include "gl/GrGLGeometryProcessor.h" |
12 #include "gl/builders/GrGLProgramBuilder.h" | 12 #include "gl/builders/GrGLProgramBuilder.h" |
13 | 13 |
14 /* | 14 /* |
15 * The default Geometry Processor simply takes position and multiplies it by the uniform view | 15 * The default Geometry Processor simply takes position and multiplies it by the uniform view |
16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or | 16 * matrix. It also leaves coverage untouched. Behind the scenes, we may add per vertex color or |
17 * local coords. | 17 * local coords. |
18 */ | 18 */ |
19 | |
20 enum GPFlag { | |
21 kPosition_GPFlag = 0x0, // we ALWAYS have position | |
bsalomon
2015/08/05 17:13:56
kill it?
| |
22 kColor_GPFlag = 0x1, | |
23 kLocalCoord_GPFlag = 0x2, | |
24 kCoverage_GPFlag= 0x4, | |
25 kTransformedLocalCoord_GPFlag = 0x8, | |
26 }; | |
27 | |
19 class DefaultGeoProc : public GrGeometryProcessor { | 28 class DefaultGeoProc : public GrGeometryProcessor { |
20 public: | 29 public: |
21 static GrGeometryProcessor* Create(uint32_t gpTypeFlags, | 30 static GrGeometryProcessor* Create(uint32_t gpTypeFlags, |
22 GrColor color, | 31 GrColor color, |
23 const SkMatrix& viewMatrix, | 32 const SkMatrix& viewMatrix, |
24 const SkMatrix& localMatrix, | 33 const SkMatrix& localMatrix, |
25 bool localCoordsWillBeRead, | 34 bool localCoordsWillBeRead, |
26 bool coverageWillBeIgnored, | 35 bool coverageWillBeIgnored, |
27 uint8_t coverage) { | 36 uint8_t coverage) { |
28 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, | 37 return SkNEW_ARGS(DefaultGeoProc, (gpTypeFlags, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
70 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor) ; | 79 pb->addPassThroughAttribute(gp.inColor(), args.fOutputColor) ; |
71 } else { | 80 } else { |
72 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor m); | 81 this->setupUniformColor(pb, args.fOutputColor, &fColorUnifor m); |
73 } | 82 } |
74 } | 83 } |
75 | 84 |
76 // Setup position | 85 // Setup position |
77 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatri x(), | 86 this->setupPosition(pb, gpArgs, gp.inPosition()->fName, gp.viewMatri x(), |
78 &fViewMatrixUniform); | 87 &fViewMatrixUniform); |
79 | 88 |
80 if (gp.inLocalCoords()) { | 89 if (gp.hasExplicitLocalCoords()) { |
81 // emit transforms with explicit local coords | 90 // emit transforms with explicit local coords |
82 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName, | 91 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inLocalCoords( )->fName, |
83 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); | 92 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); |
93 } else if(gp.hasTransformedLocalCoords()) { | |
94 // transforms have already been applied to vertex attributes on the cpu | |
95 this->emitTransforms(pb, gp.inLocalCoords()->fName, | |
96 args.fTransformsIn, args.fTransformsOut); | |
84 } else { | 97 } else { |
85 // emit transforms with position | 98 // emit transforms with position |
86 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName, | 99 this->emitTransforms(pb, gpArgs->fPositionVar, gp.inPosition()-> fName, |
87 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); | 100 gp.localMatrix(), args.fTransformsIn, args. fTransformsOut); |
88 } | 101 } |
89 | 102 |
90 // Setup coverage as pass through | 103 // Setup coverage as pass through |
91 if (!gp.coverageWillBeIgnored()) { | 104 if (!gp.coverageWillBeIgnored()) { |
92 if (gp.hasVertexCoverage()) { | 105 if (gp.hasVertexCoverage()) { |
93 fs->codeAppendf("float alpha = 1.0;"); | 106 fs->codeAppendf("float alpha = 1.0;"); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 , fInLocalCoords(NULL) | 205 , fInLocalCoords(NULL) |
193 , fInCoverage(NULL) | 206 , fInCoverage(NULL) |
194 , fColor(color) | 207 , fColor(color) |
195 , fViewMatrix(viewMatrix) | 208 , fViewMatrix(viewMatrix) |
196 , fLocalMatrix(localMatrix) | 209 , fLocalMatrix(localMatrix) |
197 , fCoverage(coverage) | 210 , fCoverage(coverage) |
198 , fFlags(gpTypeFlags) | 211 , fFlags(gpTypeFlags) |
199 , fLocalCoordsWillBeRead(localCoordsWillBeRead) | 212 , fLocalCoordsWillBeRead(localCoordsWillBeRead) |
200 , fCoverageWillBeIgnored(coverageWillBeIgnored) { | 213 , fCoverageWillBeIgnored(coverageWillBeIgnored) { |
201 this->initClassID<DefaultGeoProc>(); | 214 this->initClassID<DefaultGeoProc>(); |
202 bool hasColor = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kColor_G PType); | 215 bool hasColor = SkToBool(gpTypeFlags & kColor_GPFlag); |
203 bool hasLocalCoord = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kLo calCoord_GPType); | 216 bool hasExplicitLocalCoords = SkToBool(gpTypeFlags & kLocalCoord_GPFlag) ; |
204 bool hasCoverage = SkToBool(gpTypeFlags & GrDefaultGeoProcFactory::kCove rage_GPType); | 217 bool hasTransformedLocalCoords = SkToBool(gpTypeFlags & kTransformedLoca lCoord_GPFlag); |
218 bool hasLocalCoord = hasExplicitLocalCoords || hasTransformedLocalCoords ; | |
219 bool hasCoverage = SkToBool(gpTypeFlags & kCoverage_GPFlag); | |
205 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType, | 220 fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVe rtexAttribType, |
206 kHigh_GrSLPrecision)); | 221 kHigh_GrSLPrecision)); |
207 if (hasColor) { | 222 if (hasColor) { |
208 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); | 223 fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVer texAttribType)); |
209 } | 224 } |
210 if (hasLocalCoord) { | 225 if (hasLocalCoord) { |
211 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", | 226 fInLocalCoords = &this->addVertexAttrib(Attribute("inLocalCoord", |
212 kVec2f_GrVertexAtt ribType)); | 227 kVec2f_GrVertexAtt ribType)); |
213 this->setHasLocalCoords(); | 228 if (hasExplicitLocalCoords) { |
229 this->setHasExplicitLocalCoords(); | |
230 } else { | |
231 SkASSERT(hasTransformedLocalCoords); | |
232 this->setHasTransformedLocalCoords(); | |
233 } | |
214 } | 234 } |
215 if (hasCoverage) { | 235 if (hasCoverage) { |
216 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", | 236 fInCoverage = &this->addVertexAttrib(Attribute("inCoverage", |
217 kFloat_GrVertexAttrib Type)); | 237 kFloat_GrVertexAttrib Type)); |
218 } | 238 } |
219 } | 239 } |
220 | 240 |
221 const Attribute* fInPosition; | 241 const Attribute* fInPosition; |
222 const Attribute* fInColor; | 242 const Attribute* fInColor; |
223 const Attribute* fInLocalCoords; | 243 const Attribute* fInLocalCoords; |
224 const Attribute* fInCoverage; | 244 const Attribute* fInCoverage; |
225 GrColor fColor; | 245 GrColor fColor; |
226 SkMatrix fViewMatrix; | 246 SkMatrix fViewMatrix; |
227 SkMatrix fLocalMatrix; | 247 SkMatrix fLocalMatrix; |
228 uint8_t fCoverage; | 248 uint8_t fCoverage; |
229 uint32_t fFlags; | 249 uint32_t fFlags; |
230 bool fLocalCoordsWillBeRead; | 250 bool fLocalCoordsWillBeRead; |
231 bool fCoverageWillBeIgnored; | 251 bool fCoverageWillBeIgnored; |
232 | 252 |
233 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; | 253 GR_DECLARE_GEOMETRY_PROCESSOR_TEST; |
234 | 254 |
235 typedef GrGeometryProcessor INHERITED; | 255 typedef GrGeometryProcessor INHERITED; |
236 }; | 256 }; |
237 | 257 |
238 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); | 258 GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DefaultGeoProc); |
239 | 259 |
240 GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { | 260 GrGeometryProcessor* DefaultGeoProc::TestCreate(GrProcessorTestData* d) { |
241 uint32_t flags = 0; | 261 uint32_t flags = 0; |
242 if (d->fRandom->nextBool()) { | 262 if (d->fRandom->nextBool()) { |
243 flags |= GrDefaultGeoProcFactory::kColor_GPType; | 263 flags |= kColor_GPFlag; |
244 } | 264 } |
245 if (d->fRandom->nextBool()) { | 265 if (d->fRandom->nextBool()) { |
246 flags |= GrDefaultGeoProcFactory::kCoverage_GPType; | 266 flags |= kCoverage_GPFlag; |
247 } | 267 } |
248 if (d->fRandom->nextBool()) { | 268 if (d->fRandom->nextBool()) { |
249 flags |= GrDefaultGeoProcFactory::kLocalCoord_GPType; | 269 flags |= kLocalCoord_GPFlag; |
270 } | |
271 if (d->fRandom->nextBool()) { | |
272 flags |= kTransformedLocalCoord_GPFlag; | |
250 } | 273 } |
251 | 274 |
252 return DefaultGeoProc::Create(flags, | 275 return DefaultGeoProc::Create(flags, |
253 GrRandomColor(d->fRandom), | 276 GrRandomColor(d->fRandom), |
254 GrTest::TestMatrix(d->fRandom), | 277 GrTest::TestMatrix(d->fRandom), |
255 GrTest::TestMatrix(d->fRandom), | 278 GrTest::TestMatrix(d->fRandom), |
256 d->fRandom->nextBool(), | 279 d->fRandom->nextBool(), |
257 d->fRandom->nextBool(), | 280 d->fRandom->nextBool(), |
258 GrRandomCoverage(d->fRandom)); | 281 GrRandomCoverage(d->fRandom)); |
259 } | 282 } |
260 | 283 |
261 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color, | 284 const GrGeometryProcessor* GrDefaultGeoProcFactory::Create(const Color& color, |
262 const Coverage& cover age, | 285 const Coverage& cover age, |
263 const LocalCoords& lo calCoords, | 286 const LocalCoords& lo calCoords, |
264 const SkMatrix& viewM atrix) { | 287 const SkMatrix& viewM atrix) { |
265 uint32_t flags = 0; | 288 uint32_t flags = 0; |
266 flags |= color.fType == Color::kAttribute_Type ? kColor_GPType : 0; | 289 flags |= color.fType == Color::kAttribute_Type ? kColor_GPFlag : 0; |
267 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPType : 0; | 290 flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverage_GPFlag : 0; |
268 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G PType : 0; | 291 flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoord_G PFlag : 0; |
292 flags |= localCoords.fType == LocalCoords::kHasTransformed_Type ? | |
293 kTransformedLocalCoord_GPFlag : 0; | |
269 | 294 |
270 uint8_t inCoverage = coverage.fCoverage; | 295 uint8_t inCoverage = coverage.fCoverage; |
271 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; | 296 bool coverageWillBeIgnored = coverage.fType == Coverage::kNone_Type; |
272 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; | 297 bool localCoordsWillBeRead = localCoords.fType != LocalCoords::kUnused_Type; |
273 | 298 |
274 GrColor inColor = color.fColor; | 299 GrColor inColor = color.fColor; |
275 return DefaultGeoProc::Create(flags, | 300 return DefaultGeoProc::Create(flags, |
276 inColor, | 301 inColor, |
277 viewMatrix, | 302 viewMatrix, |
278 localCoords.fMatrix ? *localCoords.fMatrix : S kMatrix::I(), | 303 localCoords.fMatrix ? *localCoords.fMatrix : S kMatrix::I(), |
(...skipping 16 matching lines...) Expand all Loading... | |
295 } | 320 } |
296 | 321 |
297 if (localCoords.hasLocalMatrix()) { | 322 if (localCoords.hasLocalMatrix()) { |
298 invert.preConcat(*localCoords.fMatrix); | 323 invert.preConcat(*localCoords.fMatrix); |
299 } | 324 } |
300 } | 325 } |
301 | 326 |
302 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); | 327 LocalCoords inverted(LocalCoords::kUsePosition_Type, &invert); |
303 return Create(color, coverage, inverted, SkMatrix::I()); | 328 return Create(color, coverage, inverted, SkMatrix::I()); |
304 } | 329 } |
OLD | NEW |