blob: bdefd4a920de446148afcbecaa57e8c77f17bd6c [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
11#include "GrGeometryProcessor.h"
12
13class 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.
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;
29 GrColor fCoverage;
30 };
31
32 struct PositionColorAttr {
33 SkPoint fPosition;
34 SkColor fColor;
35 };
36
37 struct PositionColorCoverageAttr {
38 SkPoint fPosition;
39 SkColor fColor;
40 GrColor fCoverage;
41 };
42
43 struct PositionLocalCoordAttr {
44 SkPoint fPosition;
45 SkPoint fLocalCoord;
46 };
47
48 struct PositionLocalCoordCoverageAttr {
49 SkPoint fPosition;
50 SkPoint fLocalCoord;
51 GrColor fCoverage;
52 };
53
54 struct PositionColorLocalCoordAttr {
55 SkPoint fPosition;
56 GrColor fColor;
57 SkPoint fLocalCoord;
58 };
59
60 struct PositionColorLocalCoordCoverage {
61 SkPoint fPosition;
62 GrColor fColor;
63 SkPoint fLocalCoord;
64 GrColor fCoverage;
65 };
66
67 enum GPType {
68 kPosition_GPType = 0x0, // we ALWAYS have position
69 kColor_GPType = 0x01,
70 kLocalCoord_GPType = 0x02,
71 kCoverage_GPType= 0x04,
72 kLastGPType = kCoverage_GPType
73 };
74
joshualitte9d60952015-07-27 12:13:14 -070075 struct Color {
76 enum Type {
77 kNone_Type,
78 kUniform_Type,
79 kAttribute_Type,
80 };
81 Color(GrColor color) : fType(kUniform_Type), fColor(color) {}
82 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
83 SkASSERT(type != kUniform_Type);
84
85 // TODO This is temporary
86 if (kAttribute_Type == type) {
87 fColor = GrColor_WHITE;
88 }
89 }
90
91 Type fType;
92 GrColor fColor;
93 };
94
95 struct Coverage {
96 enum Type {
97 kNone_Type,
98 kSolid_Type,
99 kUniform_Type,
100 kAttribute_Type,
101 };
102 Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
103 Coverage(Type type) : fType(type), fCoverage(0xff) {
104 SkASSERT(type != kUniform_Type);
105 }
106
107 Type fType;
108 uint8_t fCoverage;
109 };
110
111 struct LocalCoords {
112 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700113 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700114 kUsePosition_Type,
115 kHasExplicit_Type,
116 };
joshualitt0d986d82015-07-28 10:01:18 -0700117 LocalCoords(Type type) : fType(type), fMatrix(NULL) {}
118 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
119 SkASSERT(kUnused_Type != type);
120 }
121 bool hasLocalMatrix() const { return NULL != fMatrix; }
122
123 Type fType;
124 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700125 };
126
joshualitt7a0d6972015-07-28 10:20:08 -0700127 const GrGeometryProcessor* Create(const Color&,
128 const Coverage&,
129 const LocalCoords&,
130 const SkMatrix& viewMatrix = SkMatrix::I());
joshualitte9d60952015-07-27 12:13:14 -0700131
joshualitt5478d422014-11-14 16:00:38 -0800132 /*
joshualitt0d986d82015-07-28 10:01:18 -0700133 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
134 * attribute. The view matrix must still be provided to compute correctly transformed
135 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800136 */
joshualitt7a0d6972015-07-28 10:20:08 -0700137 const GrGeometryProcessor* CreateForDeviceSpace(const Color&,
138 const Coverage&,
139 const LocalCoords&,
140 const SkMatrix& viewMatrix);
joshualitt0d986d82015-07-28 10:01:18 -0700141
142 // TODO deprecate this
joshualitt7a0d6972015-07-28 10:20:08 -0700143 const GrGeometryProcessor* Create(uint32_t gpTypeFlags,
144 GrColor,
145 bool localCoordsWillBeRead,
146 bool coverageWillBeIgnored,
147 const SkMatrix& viewMatrix = SkMatrix::I(),
148 const SkMatrix& localMatrix = SkMatrix::I(),
149 uint8_t coverage = 0xff);
joshualitt8fc6c2d2014-12-22 15:27:05 -0800150
joshualitt7a0d6972015-07-28 10:20:08 -0700151 inline size_t DefaultVertexStride() { return sizeof(PositionAttr); }
joshualitt4973d9d2014-11-08 09:24:25 -0800152};
153
154#endif