OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrGeometryProcessor_DEFINED | 8 #ifndef GrGeometryProcessor_DEFINED |
9 #define GrGeometryProcessor_DEFINED | 9 #define GrGeometryProcessor_DEFINED |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... |
32 static const size_t kMaxSize = 32; | 32 static const size_t kMaxSize = 32; |
33 | 33 |
34 private: | 34 private: |
35 uint8_t fData[kMaxSize]; | 35 uint8_t fData[kMaxSize]; |
36 }; | 36 }; |
37 | 37 |
38 class GrGLCaps; | 38 class GrGLCaps; |
39 class GrGLGeometryProcessor; | 39 class GrGLGeometryProcessor; |
40 class GrOptDrawState; | 40 class GrOptDrawState; |
41 | 41 |
| 42 struct GrInitInvariantOutput; |
| 43 |
| 44 /* |
| 45 * GrGeometryProcessors and GrPathProcessors may effect invariantColor |
| 46 */ |
| 47 class GrPrimitiveProcessor : public GrProcessor { |
| 48 public: |
| 49 virtual void computeOutputColor(GrInitInvariantOutput* out) const = 0; |
| 50 virtual void computeOutputCoverage(GrInitInvariantOutput* out) const = 0; |
| 51 |
| 52 private: |
| 53 typedef GrProcessor INHERITED; |
| 54 }; |
| 55 |
42 /** | 56 /** |
43 * A GrGeometryProcessor is used to perform computation in the vertex shader and | 57 * A GrGeometryProcessor is used to perform computation in the vertex shader and |
44 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | 58 * add support for custom vertex attributes. A GrGemeotryProcessor is typically |
45 * tied to the code that does a specific type of high-level primitive rendering | 59 * tied to the code that does a specific type of high-level primitive rendering |
46 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is | 60 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is |
47 * specified using GrDrawState. There can only be one geometry processor active
for | 61 * specified using GrDrawState. There can only be one geometry processor active
for |
48 * a draw. The custom vertex attributes required by the geometry processor must
be | 62 * a draw. The custom vertex attributes required by the geometry processor must
be |
49 * added to the vertex attribute array specified on the GrDrawState. | 63 * added to the vertex attribute array specified on the GrDrawState. |
50 * GrGeometryProcessor subclasses should be immutable after construction. | 64 * GrGeometryProcessor subclasses should be immutable after construction. |
51 */ | 65 */ |
52 class GrGeometryProcessor : public GrProcessor { | 66 class GrGeometryProcessor : public GrPrimitiveProcessor { |
53 public: | 67 public: |
54 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) | 68 GrGeometryProcessor(GrColor color, uint8_t coverage = 0xff) |
55 : fVertexStride(0) | 69 : fVertexStride(0) |
56 , fColor(color) | 70 , fColor(color) |
57 , fCoverage(coverage) | 71 , fCoverage(coverage) |
58 , fWillUseGeoShader(false) | 72 , fWillUseGeoShader(false) |
59 , fHasVertexColor(false) | 73 , fHasVertexColor(false) |
60 , fHasVertexCoverage(false) | 74 , fHasVertexCoverage(false) |
61 , fHasLocalCoords(false) {} | 75 , fHasLocalCoords(false) {} |
62 | 76 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 146 |
133 GrColor getColor() const { return fColor; } | 147 GrColor getColor() const { return fColor; } |
134 uint8_t getCoverage() const { return fCoverage; } | 148 uint8_t getCoverage() const { return fCoverage; } |
135 | 149 |
136 // TODO this is a total hack until the gp can own whether or not it uses uni
form | 150 // TODO this is a total hack until the gp can own whether or not it uses uni
form |
137 // color / coverage | 151 // color / coverage |
138 bool hasVertexColor() const { return fHasVertexColor; } | 152 bool hasVertexColor() const { return fHasVertexColor; } |
139 bool hasVertexCoverage() const { return fHasVertexCoverage; } | 153 bool hasVertexCoverage() const { return fHasVertexCoverage; } |
140 bool hasLocalCoords() const { return fHasLocalCoords; } | 154 bool hasLocalCoords() const { return fHasLocalCoords; } |
141 | 155 |
142 void computeInvariantColor(GrInvariantOutput* inout) const; | 156 virtual void computeOutputColor(GrInitInvariantOutput* out) const SK_OVERRID
E; |
| 157 virtual void computeOutputCoverage(GrInitInvariantOutput* out) const SK_OVER
RIDE; |
143 | 158 |
144 protected: | 159 protected: |
145 /** | 160 /** |
146 * Subclasses call this from their constructor to register vertex attributes
. Attributes | 161 * Subclasses call this from their constructor to register vertex attributes
. Attributes |
147 * will be padded to the nearest 4 bytes for performance reasons. | 162 * will be padded to the nearest 4 bytes for performance reasons. |
148 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside | 163 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside |
149 * the struct used to actually populate the attributes | 164 * the struct used to actually populate the attributes |
150 */ | 165 */ |
151 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { | 166 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
152 fVertexStride += attribute.fOffset; | 167 fVertexStride += attribute.fOffset; |
153 return fAttribs.push_back(attribute); | 168 return fAttribs.push_back(attribute); |
154 } | 169 } |
155 | 170 |
156 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 171 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
157 | 172 |
158 // TODO hack see above | 173 // TODO hack see above |
159 void setHasVertexColor() { fHasVertexColor = true; } | 174 void setHasVertexColor() { fHasVertexColor = true; } |
160 void setHasVertexCoverage() { fHasVertexCoverage = true; } | 175 void setHasVertexCoverage() { fHasVertexCoverage = true; } |
161 void setHasLocalCoords() { fHasLocalCoords = true; } | 176 void setHasLocalCoords() { fHasLocalCoords = true; } |
162 | 177 |
| 178 virtual void onComputeOutputColor(GrInitInvariantOutput*) const {} |
| 179 virtual void onComputeOutputCoverage(GrInitInvariantOutput*) const = 0; |
| 180 |
163 private: | 181 private: |
164 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 182 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
165 | 183 |
166 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; | 184 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
167 size_t fVertexStride; | 185 size_t fVertexStride; |
168 GrColor fColor; | 186 GrColor fColor; |
169 uint8_t fCoverage; | 187 uint8_t fCoverage; |
170 bool fWillUseGeoShader; | 188 bool fWillUseGeoShader; |
171 bool fHasVertexColor; | 189 bool fHasVertexColor; |
172 bool fHasVertexCoverage; | 190 bool fHasVertexCoverage; |
173 bool fHasLocalCoords; | 191 bool fHasLocalCoords; |
174 | 192 |
175 typedef GrProcessor INHERITED; | 193 typedef GrProcessor INHERITED; |
176 }; | 194 }; |
| 195 |
| 196 /* |
| 197 * The path equivalent of the GP. Can only upload uniform color. |
| 198 */ |
| 199 class GrPathProcessor : public GrProcessor { |
| 200 public: |
| 201 GrPathProcessor(GrColor color) : fColor(color) {} |
| 202 virtual void computeOutputColor(GrInitInvariantOutput* out) const SK_OVERRID
E; |
| 203 virtual void computeOutputCoverage(GrInitInvariantOutput* out) const SK_OVER
RIDE; |
| 204 |
| 205 private: |
| 206 GrColor fColor; |
| 207 |
| 208 typedef GrProcessor INHERITED; |
| 209 }; |
177 #endif | 210 #endif |
OLD | NEW |