blob: 243685439d6eebc7843689be3587d67c5cdc5a94 [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 */
21class GrDefaultGeoProcFactory {
22public:
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
joshualitte9d60952015-07-27 12:13:14 -070076 struct Color {
77 enum Type {
78 kNone_Type,
79 kUniform_Type,
80 kAttribute_Type,
81 };
82 Color(GrColor color) : fType(kUniform_Type), fColor(color) {}
83 Color(Type type) : fType(type), fColor(GrColor_ILLEGAL) {
84 SkASSERT(type != kUniform_Type);
85
86 // TODO This is temporary
87 if (kAttribute_Type == type) {
88 fColor = GrColor_WHITE;
89 }
90 }
91
92 Type fType;
93 GrColor fColor;
94 };
95
96 struct Coverage {
97 enum Type {
98 kNone_Type,
99 kSolid_Type,
100 kUniform_Type,
101 kAttribute_Type,
102 };
103 Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
104 Coverage(Type type) : fType(type), fCoverage(0xff) {
105 SkASSERT(type != kUniform_Type);
106 }
107
108 Type fType;
109 uint8_t fCoverage;
110 };
111
112 struct LocalCoords {
113 enum Type {
joshualitt0d986d82015-07-28 10:01:18 -0700114 kUnused_Type,
joshualitte9d60952015-07-27 12:13:14 -0700115 kUsePosition_Type,
116 kHasExplicit_Type,
117 };
joshualitt0d986d82015-07-28 10:01:18 -0700118 LocalCoords(Type type) : fType(type), fMatrix(NULL) {}
119 LocalCoords(Type type, const SkMatrix* matrix) : fType(type), fMatrix(matrix) {
120 SkASSERT(kUnused_Type != type);
121 }
122 bool hasLocalMatrix() const { return NULL != fMatrix; }
123
124 Type fType;
125 const SkMatrix* fMatrix;
joshualitte9d60952015-07-27 12:13:14 -0700126 };
127
128 static const GrGeometryProcessor* Create(const Color&,
129 const Coverage&,
joshualitt0d986d82015-07-28 10:01:18 -0700130 const LocalCoords&,
131 const SkMatrix& viewMatrix = SkMatrix::I());
joshualitte9d60952015-07-27 12:13:14 -0700132
joshualitt5478d422014-11-14 16:00:38 -0800133 /*
joshualitt0d986d82015-07-28 10:01:18 -0700134 * Use this factory to create a GrGeometryProcessor that expects a device space vertex position
135 * attribute. The view matrix must still be provided to compute correctly transformed
136 * coordinates for GrFragmentProcessors. It may fail if the view matrix is not invertible.
joshualitt5478d422014-11-14 16:00:38 -0800137 */
joshualitt0d986d82015-07-28 10:01:18 -0700138 static const GrGeometryProcessor* CreateForDeviceSpace(const Color&,
139 const Coverage&,
140 const LocalCoords&,
141 const SkMatrix& viewMatrix);
142
143 // TODO deprecate this
joshualitt8059eb92014-12-29 15:10:07 -0800144 static const GrGeometryProcessor* Create(uint32_t gpTypeFlags,
145 GrColor,
bsalomon7765a472015-07-08 11:26:37 -0700146 bool localCoordsWillBeRead,
147 bool coverageWillBeIgnored,
joshualitt8059eb92014-12-29 15:10:07 -0800148 const SkMatrix& viewMatrix = SkMatrix::I(),
149 const SkMatrix& localMatrix = SkMatrix::I(),
joshualitt8059eb92014-12-29 15:10:07 -0800150 uint8_t coverage = 0xff);
joshualitt8fc6c2d2014-12-22 15:27:05 -0800151
joshualitt2e3b3e32014-12-09 13:31:14 -0800152 static size_t DefaultVertexStride() { return sizeof(PositionAttr); }
joshualitt4973d9d2014-11-08 09:24:25 -0800153};
154
155#endif