blob: b5aef98aa31966dfc07a49964450ed6b720e1145 [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 {
joshualitt4973d9d2014-11-08 09:24:25 -080022 // Structs for adding vertex attributes
23 struct PositionAttr {
24 SkPoint fPosition;
25 };
26
27 struct PositionCoverageAttr {
28 SkPoint fPosition;
senorblancof57372d2016-08-31 10:36:19 -070029 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080030 };
31
32 struct PositionColorAttr {
33 SkPoint fPosition;
34 SkColor fColor;
35 };
36
37 struct PositionColorCoverageAttr {
38 SkPoint fPosition;
39 SkColor fColor;
senorblancof57372d2016-08-31 10:36:19 -070040 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080041 };
42
43 struct PositionLocalCoordAttr {
44 SkPoint fPosition;
45 SkPoint fLocalCoord;
46 };
47
48 struct PositionLocalCoordCoverageAttr {
49 SkPoint fPosition;
50 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070051 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080052 };
53
54 struct PositionColorLocalCoordAttr {
55 SkPoint fPosition;
56 GrColor fColor;
57 SkPoint fLocalCoord;
58 };
59
Ruiqi Mao4ec72f72018-07-10 17:21:07 -040060 struct PositionColorLocalCoordCoverageAttr {
joshualitt4973d9d2014-11-08 09:24:25 -080061 SkPoint fPosition;
62 GrColor fColor;
63 SkPoint fLocalCoord;
senorblancof57372d2016-08-31 10:36:19 -070064 float fCoverage;
joshualitt4973d9d2014-11-08 09:24:25 -080065 };
66
joshualitte9d60952015-07-27 12:13:14 -070067 struct Color {
68 enum Type {
Brian Salomon3de0aee2017-01-29 09:34:17 -050069 kPremulGrColorUniform_Type,
70 kPremulGrColorAttribute_Type,
71 kUnpremulSkColorAttribute_Type,
joshualitte9d60952015-07-27 12:13:14 -070072 };
Brian Osmanfa6d8652017-05-31 09:37:27 -040073 explicit Color(GrColor color)
74 : fType(kPremulGrColorUniform_Type)
75 , fColor(color)
Brian Osmanfa6d8652017-05-31 09:37:27 -040076 , fColorSpaceXform(nullptr) {}
77 Color(Type type)
78 : fType(type)
79 , fColor(GrColor_ILLEGAL)
Brian Osmanfa6d8652017-05-31 09:37:27 -040080 , fColorSpaceXform(nullptr) {
Brian Salomon3de0aee2017-01-29 09:34:17 -050081 SkASSERT(type != kPremulGrColorUniform_Type);
joshualitte9d60952015-07-27 12:13:14 -070082 }
83
84 Type fType;
85 GrColor fColor;
Brian Osmanfa6d8652017-05-31 09:37:27 -040086
Brian Osman08a50e02018-06-15 15:06:48 -040087 // This only applies to SkColor. Any GrColors are assumed to have been color converted
Brian Osmanfa6d8652017-05-31 09:37:27 -040088 // during paint conversion.
Brian Osmanfa6d8652017-05-31 09:37:27 -040089 sk_sp<GrColorSpaceXform> fColorSpaceXform;
joshualitte9d60952015-07-27 12:13:14 -070090 };
91
92 struct Coverage {
93 enum Type {
joshualitte9d60952015-07-27 12:13:14 -070094 kSolid_Type,
95 kUniform_Type,
96 kAttribute_Type,
97 };
Brian Salomon8c852be2017-01-04 10:44:42 -050098 explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
joshualitte9d60952015-07-27 12:13:14 -070099 Coverage(Type type) : fType(type), fCoverage(0xff) {
100 SkASSERT(type != kUniform_Type);
101 }
102
103 Type fType;
104 uint8_t fCoverage;
105 };
106
107 struct LocalCoords {
108 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700109 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700110 kUsePosition_Type,
111 kHasExplicit_Type,
joshualittb2aa7cb2015-08-05 11:05:22 -0700112 kHasTransformed_Type,
joshualitte9d60952015-07-27 12:13:14 -0700113 };
halcanary96fcdcc2015-08-27 07:41:13 -0700114 LocalCoords(Type type) : fType(type), fMatrix(nullptr) {}
joshualitt0d986d82015-07-28 10:01:18 -0700115 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
116 SkASSERT(kUnused_Type != type);
117 }
halcanary96fcdcc2015-08-27 07:41:13 -0700118 bool hasLocalMatrix() const { return nullptr != fMatrix; }
joshualitt0d986d82015-07-28 10:01:18 -0700119
120 Type fType;
121 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700122 };
123
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400124 struct Bones {
125 Bones(const float bones[], int boneCount)
126 : fBones(bones)
127 , fBoneCount(boneCount) {}
128
129 const float* fBones;
130 int fBoneCount;
131 };
132
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400133 sk_sp<GrGeometryProcessor> Make(const GrShaderCaps*,
134 const Color&,
bungeman06ca8ec2016-06-09 08:01:03 -0700135 const Coverage&,
136 const LocalCoords&,
137 const SkMatrix& viewMatrix);
joshualitte9d60952015-07-27 12:13:14 -0700138
joshualitt5478d422014-11-14 16:00:38 -0800139 /*
joshualitt0d986d82015-07-28 10:01:18 -0700140 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
141 * attribute. The view matrix must still be provided to compute correctly transformed
142 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800143 */
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400144 sk_sp<GrGeometryProcessor> MakeForDeviceSpace(const GrShaderCaps*,
145 const Color&,
bungeman06ca8ec2016-06-09 08:01:03 -0700146 const Coverage&,
147 const LocalCoords&,
148 const SkMatrix& viewMatrix);
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400149
150 /*
151 * Use this factory to create a GrGeometryProcessor that supports skeletal animation through
152 * deformation of vertices using matrices that are passed in. This should only be called from
153 * GrDrawVerticesOp.
154 */
Ruiqi Maob609e6d2018-07-17 10:19:38 -0400155 sk_sp<GrGeometryProcessor> MakeWithBones(const GrShaderCaps*,
156 const Color&,
Ruiqi Mao4ec72f72018-07-10 17:21:07 -0400157 const Coverage&,
158 const LocalCoords&,
159 const Bones&,
160 const SkMatrix& viewMatrix);
joshualitt4973d9d2014-11-08 09:24:25 -0800161};
162
163#endif