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 | |
Brian Salomon | 0c26a9d | 2017-07-06 10:09:38 -0400 | [diff] [blame] | 11 | #include "GrColorSpaceXform.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 12 | #include "GrGeometryProcessor.h" |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 13 | #include "GrShaderCaps.h" |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 14 | |
Ruiqi Mao | c97a339 | 2018-08-15 10:44:19 -0400 | [diff] [blame] | 15 | constexpr int kMaxBones = 80; // Supports up to 80 bones per mesh. |
| 16 | |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 17 | /* |
| 18 | * A factory for creating default Geometry Processors which simply multiply position by the uniform |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 19 | * view matrix and wire through color, coverage, UV coords if requested. |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 20 | */ |
joshualitt | 7a0d697 | 2015-07-28 10:20:08 -0700 | [diff] [blame] | 21 | namespace GrDefaultGeoProcFactory { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 22 | struct Color { |
| 23 | enum Type { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 24 | kPremulGrColorUniform_Type, |
| 25 | kPremulGrColorAttribute_Type, |
Brian Osman | 2a4c4df | 2018-12-20 14:06:54 -0500 | [diff] [blame] | 26 | kPremulWideColorAttribute_Type, |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 27 | kUnpremulSkColorAttribute_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 28 | }; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 29 | explicit Color(const SkPMColor4f& color) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 30 | : fType(kPremulGrColorUniform_Type) |
| 31 | , fColor(color) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 32 | , fColorSpaceXform(nullptr) {} |
| 33 | Color(Type type) |
| 34 | : fType(type) |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 35 | , fColor(SK_PMColor4fILLEGAL) |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 36 | , fColorSpaceXform(nullptr) { |
Brian Salomon | 3de0aee | 2017-01-29 09:34:17 -0500 | [diff] [blame] | 37 | SkASSERT(type != kPremulGrColorUniform_Type); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | Type fType; |
Brian Osman | cf86085 | 2018-10-31 14:04:39 -0400 | [diff] [blame] | 41 | SkPMColor4f fColor; |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 42 | |
Brian Osman | 08a50e0 | 2018-06-15 15:06:48 -0400 | [diff] [blame] | 43 | // This only applies to SkColor. Any GrColors are assumed to have been color converted |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 44 | // during paint conversion. |
Brian Osman | fa6d865 | 2017-05-31 09:37:27 -0400 | [diff] [blame] | 45 | sk_sp<GrColorSpaceXform> fColorSpaceXform; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | struct Coverage { |
| 49 | enum Type { |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 50 | kSolid_Type, |
| 51 | kUniform_Type, |
| 52 | kAttribute_Type, |
Brian Osman | 80879d4 | 2019-01-07 16:15:27 -0500 | [diff] [blame] | 53 | kAttributeTweakAlpha_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 54 | }; |
Brian Salomon | 8c852be | 2017-01-04 10:44:42 -0500 | [diff] [blame] | 55 | explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {} |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 56 | Coverage(Type type) : fType(type), fCoverage(0xff) { |
| 57 | SkASSERT(type != kUniform_Type); |
| 58 | } |
| 59 | |
| 60 | Type fType; |
| 61 | uint8_t fCoverage; |
| 62 | }; |
| 63 | |
| 64 | struct LocalCoords { |
| 65 | enum Type { |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 66 | kUnused_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 67 | kUsePosition_Type, |
| 68 | kHasExplicit_Type, |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 69 | kHasTransformed_Type, |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 70 | }; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 71 | LocalCoords(Type type) : fType(type), fMatrix(nullptr) {} |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 72 | LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) { |
| 73 | SkASSERT(kUnused_Type != type); |
| 74 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 75 | bool hasLocalMatrix() const { return nullptr != fMatrix; } |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 76 | |
| 77 | Type fType; |
| 78 | const SkMatrix* fMatrix; |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 79 | }; |
| 80 | |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 81 | struct Bones { |
| 82 | Bones(const float bones[], int boneCount) |
| 83 | : fBones(bones) |
| 84 | , fBoneCount(boneCount) {} |
| 85 | |
| 86 | const float* fBones; |
| 87 | int fBoneCount; |
| 88 | }; |
| 89 | |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 90 | sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*, |
| 91 | const Color&, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 92 | const Coverage&, |
| 93 | const LocalCoords&, |
| 94 | const SkMatrix& viewMatrix); |
joshualitt | e9d6095 | 2015-07-27 12:13:14 -0700 | [diff] [blame] | 95 | |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 96 | /* |
joshualitt | 0d986d8 | 2015-07-28 10:01:18 -0700 | [diff] [blame] | 97 | * Use this factory to create a GrGeometryProcessor that expects a device space vertex position |
| 98 | * attribute. The view matrix must still be provided to compute correctly transformed |
| 99 | * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible. |
joshualitt | 5478d42 | 2014-11-14 16:00:38 -0800 | [diff] [blame] | 100 | */ |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 101 | sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*, |
| 102 | const Color&, |
bungeman | 06ca8ec | 2016-06-09 08:01:03 -0700 | [diff] [blame] | 103 | const Coverage&, |
| 104 | const LocalCoords&, |
| 105 | const SkMatrix& viewMatrix); |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 106 | |
| 107 | /* |
| 108 | * Use this factory to create a GrGeometryProcessor that supports skeletal animation through |
| 109 | * deformation of vertices using matrices that are passed in. This should only be called from |
| 110 | * GrDrawVerticesOp. |
| 111 | */ |
Ruiqi Mao | b609e6d | 2018-07-17 10:19:38 -0400 | [diff] [blame] | 112 | sk_sp<GrGeometryProcessor> MakeWithBones(const GrShaderCaps*, |
| 113 | const Color&, |
Ruiqi Mao | 4ec72f7 | 2018-07-10 17:21:07 -0400 | [diff] [blame] | 114 | const Coverage&, |
| 115 | const LocalCoords&, |
| 116 | const Bones&, |
| 117 | const SkMatrix& viewMatrix); |
joshualitt | 4973d9d | 2014-11-08 09:24:25 -0800 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | #endif |