joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrDefaultGeoProcFactory_DEFINED |
| 9 | #define GrDefaultGeoProcFactory_DEFINED |
| 10 | |
| 11 | #include "GrGeometryProcessor.h" |
| 12 | |
| 13 | class GrDrawState; |
| 14 | |
| 15 | /* |
| 16 | * A factory for creating default Geometry Processors which simply multiply position by the uniform |
| 17 | * view matrix and wire through color, coverage, UV coords if requested. Right now this is only |
| 18 | * used in the creation of optimized draw states because adding default GPs to the drawstate can |
| 19 | * interfere with batching due to updating the drawstate. |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 20 | */ |
| 21 | class GrDefaultGeoProcFactory { |
| 22 | public: |
| 23 | // Structs for adding vertex attributes |
| 24 | struct PositionAttr { |
| 25 | SkPoint fPosition; |
| 26 | }; |
| 27 | |
| 28 | struct PositionCoverageAttr { |
| 29 | SkPoint fPosition; |
| 30 | GrColor fCoverage; |
| 31 | }; |
| 32 | |
| 33 | struct PositionColorAttr { |
| 34 | SkPoint fPosition; |
| 35 | SkColor fColor; |
| 36 | }; |
| 37 | |
| 38 | struct PositionColorCoverageAttr { |
| 39 | SkPoint fPosition; |
| 40 | SkColor fColor; |
| 41 | GrColor fCoverage; |
| 42 | }; |
| 43 | |
| 44 | struct PositionLocalCoordAttr { |
| 45 | SkPoint fPosition; |
| 46 | SkPoint fLocalCoord; |
| 47 | }; |
| 48 | |
| 49 | struct PositionLocalCoordCoverageAttr { |
| 50 | SkPoint fPosition; |
| 51 | SkPoint fLocalCoord; |
| 52 | GrColor fCoverage; |
| 53 | }; |
| 54 | |
| 55 | struct PositionColorLocalCoordAttr { |
| 56 | SkPoint fPosition; |
| 57 | GrColor fColor; |
| 58 | SkPoint fLocalCoord; |
| 59 | }; |
| 60 | |
| 61 | struct PositionColorLocalCoordCoverage { |
| 62 | SkPoint fPosition; |
| 63 | GrColor fColor; |
| 64 | SkPoint fLocalCoord; |
| 65 | GrColor fCoverage; |
| 66 | }; |
| 67 | |
| 68 | enum GPType { |
| 69 | kPosition_GPType = 0x0, // we ALWAYS have position |
| 70 | kColor_GPType = 0x01, |
| 71 | kLocalCoord_GPType = 0x02, |
| 72 | kCoverage_GPType= 0x04, |
| 73 | kLastGPType = kCoverage_GPType |
| 74 | }; |
| 75 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 76 | /* |
| 77 | * The following functions are used to create default GPs. If you just need to create |
| 78 | * attributes seperately from creating the default GP, use the SetAttribs function followed |
| 79 | * by the Create function. Otherwise use CreateAndSetAttribs to do both at once. |
| 80 | * |
| 81 | * You must unref the return from Create. |
| 82 | */ |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 83 | // TODO clean this up |
| 84 | static const GrGeometryProcessor* Create(uint32_t gpTypeFlags, |
| 85 | GrColor, |
| 86 | const SkMatrix& viewMatrix = SkMatrix::I(), |
| 87 | const SkMatrix& localMatrix = SkMatrix::I(), |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 88 | bool opaqueVertexColors = false, |
joshualitt | 8059eb9 | 2014-12-29 15:10:07 -0800 | [diff] [blame] | 89 | uint8_t coverage = 0xff); |
joshualitt | 8fc6c2d | 2014-12-22 15:27:05 -0800 | [diff] [blame] | 90 | |
joshualitt | 2e3b3e3 | 2014-12-09 13:31:14 -0800 | [diff] [blame] | 91 | static size_t DefaultVertexStride() { return sizeof(PositionAttr); } |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | #endif |