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 |
11 #include "GrPrimitiveProcessor.h" | 11 #include "GrPrimitiveProcessor.h" |
12 | 12 |
13 /** | 13 /** |
14 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor | 14 * A GrGeometryProcessor is a flexible method for rendering a primitive. The Gr
GeometryProcessor |
15 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it | 15 * has complete control over vertex attributes and uniforms(aside from the rende
r target) but it |
16 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and | 16 * must obey the same contract as any GrPrimitiveProcessor, specifically it must
emit a color and |
17 * coverage into the fragment shader. Where this color and coverage come from i
s completely the | 17 * coverage into the fragment shader. Where this color and coverage come from i
s completely the |
18 * responsibility of the GrGeometryProcessor. | 18 * responsibility of the GrGeometryProcessor. |
19 */ | 19 */ |
20 class GrGeometryProcessor : public GrPrimitiveProcessor { | 20 class GrGeometryProcessor : public GrPrimitiveProcessor { |
21 public: | 21 public: |
22 GrGeometryProcessor() | 22 GrGeometryProcessor() |
23 : INHERITED(false) | 23 : INHERITED(false) |
24 , fWillUseGeoShader(false) | 24 , fWillUseGeoShader(false) |
25 , fHasLocalCoords(false) {} | 25 , fHasLocalCoords(false) {} |
26 | 26 |
27 bool willUseGeoShader() const { return fWillUseGeoShader; } | 27 bool willUseGeoShader() const { return fWillUseGeoShader; } |
28 | 28 |
| 29 // TODO delete when paths are in batch |
| 30 void initBatchTracker(GrBatchTracker*, const GrPipelineInfo&) const override
{} |
| 31 |
29 // TODO delete this when paths are in batch | 32 // TODO delete this when paths are in batch |
30 bool canMakeEqual(const GrBatchTracker& mine, | 33 bool canMakeEqual(const GrBatchTracker& mine, |
31 const GrPrimitiveProcessor& that, | 34 const GrPrimitiveProcessor& that, |
32 const GrBatchTracker& theirs) const override { | 35 const GrBatchTracker& theirs) const override { |
33 SkFAIL("Unsupported\n"); | 36 SkFAIL("Unsupported\n"); |
34 return false; | 37 return false; |
35 } | 38 } |
36 | 39 |
37 // TODO Delete when paths are in batch | 40 // TODO Delete when paths are in batch |
38 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 41 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
39 SkFAIL("Unsupported\n"); | 42 SkFAIL("Unsupported\n"); |
40 } | 43 } |
41 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 44 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
42 SkFAIL("Unsupported\n"); | 45 SkFAIL("Unsupported\n"); |
43 } | 46 } |
44 | 47 |
45 protected: | 48 protected: |
46 /* | |
47 * An optional simple helper function to determine by what means the GrGeome
tryProcessor should | |
48 * use to provide color. If we are given an override color(ie the given ove
rridecolor is NOT | |
49 * GrColor_ILLEGAL) then we must always emit that color(currently overrides
are only supported | |
50 * via uniform, but with deferred Geometry we could use attributes). Otherw
ise, if our color is | |
51 * ignored then we should not emit a color. Lastly, if we don't have vertex
colors then we must | |
52 * emit a color via uniform | |
53 * TODO this function changes quite a bit with deferred geometry. There the
GrGeometryProcessor | |
54 * can upload a new color via attribute if needed. | |
55 */ | |
56 static GrGPInput GetColorInputType(GrColor* color, GrColor primitiveColor, | |
57 const GrPipelineInfo& init, | |
58 bool hasVertexColor) { | |
59 if (init.fColorIgnored) { | |
60 *color = GrColor_ILLEGAL; | |
61 return kIgnored_GrGPInput; | |
62 } else if (GrColor_ILLEGAL != init.fOverrideColor) { | |
63 *color = init.fOverrideColor; | |
64 return kUniform_GrGPInput; | |
65 } | |
66 | |
67 *color = primitiveColor; | |
68 if (hasVertexColor) { | |
69 return kAttribute_GrGPInput; | |
70 } else { | |
71 return kUniform_GrGPInput; | |
72 } | |
73 } | |
74 | |
75 /** | 49 /** |
76 * Subclasses call this from their constructor to register vertex attributes
. Attributes | 50 * Subclasses call this from their constructor to register vertex attributes
. Attributes |
77 * will be padded to the nearest 4 bytes for performance reasons. | 51 * will be padded to the nearest 4 bytes for performance reasons. |
78 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside | 52 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside |
79 * the struct used to actually populate the attributes. This is all extreme
ly fragile, vertex | 53 * the struct used to actually populate the attributes. This is all extreme
ly fragile, vertex |
80 * attributes have to be added in the order they will appear in the struct w
hich maps memory. | 54 * attributes have to be added in the order they will appear in the struct w
hich maps memory. |
81 * The processor key should reflect the vertex attributes, or there lack the
reof in the | 55 * The processor key should reflect the vertex attributes, or there lack the
reof in the |
82 * GrGeometryProcessor. | 56 * GrGeometryProcessor. |
83 */ | 57 */ |
84 const Attribute& addVertexAttrib(const Attribute& attribute) { | 58 const Attribute& addVertexAttrib(const Attribute& attribute) { |
(...skipping 11 matching lines...) Expand all Loading... |
96 private: | 70 private: |
97 bool hasExplicitLocalCoords() const override { return fHasLocalCoords; } | 71 bool hasExplicitLocalCoords() const override { return fHasLocalCoords; } |
98 | 72 |
99 bool fWillUseGeoShader; | 73 bool fWillUseGeoShader; |
100 bool fHasLocalCoords; | 74 bool fHasLocalCoords; |
101 | 75 |
102 typedef GrPrimitiveProcessor INHERITED; | 76 typedef GrPrimitiveProcessor INHERITED; |
103 }; | 77 }; |
104 | 78 |
105 #endif | 79 #endif |
OLD | NEW |