blob: 96363f05fe5119ad29e60ef0d9b9466d6e59d3e4 [file] [log] [blame]
joshualitt4973d9d2014-11-08 09:24:25 -08001/*
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 Salomon0c26a9d2017-07-06 10:09:38 -040011#include "GrColorSpaceXform.h"
joshualitt4973d9d2014-11-08 09:24:25 -080012#include "GrGeometryProcessor.h"
Ruiqi Maob609e6d2018-07-17 10:19:38 -040013#include "GrShaderCaps.h"
joshualitt4973d9d2014-11-08 09:24:25 -080014
Ruiqi Maoc97a3392018-08-15 10:44:19 -040015constexpr int kMaxBones = 80; // Supports up to 80 bones per mesh.
16
joshualitt4973d9d2014-11-08 09:24:25 -080017/*
18 * A factory for creating default Geometry Processors which simply multiply position by the uniform
Brian Salomon09d994e2016-12-21 11:14:46 -050019 * view matrix and wire through color, coverage, UV coords if requested.
joshualitt4973d9d2014-11-08 09:24:25 -080020 */
joshualitt7a0d6972015-07-28 10:20:08 -070021namespace GrDefaultGeoProcFactory {
joshualitte9d60952015-07-27 12:13:14 -070022 struct Color {
23 enum Type {
Brian Salomon3de0aee2017-01-29 09:34:17 -050024 kPremulGrColorUniform_Type,
25 kPremulGrColorAttribute_Type,
Brian Osman2a4c4df2018-12-20 14:06:54 -050026 kPremulWideColorAttribute_Type,
Brian Salomon3de0aee2017-01-29 09:34:17 -050027 kUnpremulSkColorAttribute_Type,
joshualitte9d60952015-07-27 12:13:14 -070028 };
Brian Osmancf860852018-10-31 14:04:39 -040029 explicit Color(const SkPMColor4f& color)
Brian Osmanfa6d8652017-05-31 09:37:27 -040030 : fType(kPremulGrColorUniform_Type)
31 , fColor(color)
Brian Osmanfa6d8652017-05-31 09:37:27 -040032 , fColorSpaceXform(nullptr) {}
33 Color(Type type)
34 : fType(type)
Brian Osmancf860852018-10-31 14:04:39 -040035 , fColor(SK_PMColor4fILLEGAL)
Brian Osmanfa6d8652017-05-31 09:37:27 -040036 , fColorSpaceXform(nullptr) {
Brian Salomon3de0aee2017-01-29 09:34:17 -050037 SkASSERT(type != kPremulGrColorUniform_Type);
joshualitte9d60952015-07-27 12:13:14 -070038 }
39
40 Type fType;
Brian Osmancf860852018-10-31 14:04:39 -040041 SkPMColor4f fColor;
Brian Osmanfa6d8652017-05-31 09:37:27 -040042
Brian Osman08a50e02018-06-15 15:06:48 -040043 // This only applies to SkColor. Any GrColors are assumed to have been color converted
Brian Osmanfa6d8652017-05-31 09:37:27 -040044 // during paint conversion.
Brian Osmanfa6d8652017-05-31 09:37:27 -040045 sk_sp<GrColorSpaceXform> fColorSpaceXform;
joshualitte9d60952015-07-27 12:13:14 -070046 };
47
48 struct Coverage {
49 enum Type {
joshualitte9d60952015-07-27 12:13:14 -070050 kSolid_Type,
51 kUniform_Type,
52 kAttribute_Type,
Brian Osman80879d42019-01-07 16:15:27 -050053 kAttributeTweakAlpha_Type,
joshualitte9d60952015-07-27 12:13:14 -070054 };
Brian Salomon8c852be2017-01-04 10:44:42 -050055 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
joshualitte9d60952015-07-27 12:13:14 -070056 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 {
joshualitt0d986d82015-07-28 10:01:18 -070066 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -070067 kUsePosition_Type,
68 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -070069 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -070070 };
halcanary96fcdcc2015-08-27 07:41:13 -070071 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -070072 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
73 SkASSERT(kUnused_Type != type);
74 }
halcanary96fcdcc2015-08-27 07:41:13 -070075 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -070076
77 Type fType;
78 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -070079 };
80
Ruiqi Mao4ec72f72018-07-10 17:21:07 -040081 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 Maob609e6d2018-07-17 10:19:38 -040090 sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*,
91 const Color&,
bungeman06ca8ec2016-06-09 08:01:03 -070092 const Coverage&,
93 const LocalCoords&,
94 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -070095
joshualitt5478d422014-11-14 16:00:38 -080096 /*
joshualitt0d986d82015-07-28 10:01:18 -070097 * 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.
joshualitt5478d422014-11-14 16:00:38 -0800100 */
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400101 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*,
102 const Color&,
bungeman06ca8ec2016-06-09 08:01:03 -0700103 const Coverage&,
104 const LocalCoords&,
105 const SkMatrix& viewMatrix);
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400106
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 Maob609e6d2018-07-17 10:19:38 -0400112 sk_sp<GrGeometryProcessor> MakeWithBones(const GrShaderCaps*,
113 const Color&,
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400114 const Coverage&,
115 const LocalCoords&,
116 const Bones&,
117 const SkMatrix& viewMatrix);
joshualitt4973d9d2014-11-08 09:24:25 -0800118};
119
120#endif