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 | |
32 // TODO delete this when paths are in batch | 29 // TODO delete this when paths are in batch |
33 bool canMakeEqual(const GrBatchTracker& mine, | 30 bool canMakeEqual(const GrBatchTracker& mine, |
34 const GrPrimitiveProcessor& that, | 31 const GrPrimitiveProcessor& that, |
35 const GrBatchTracker& theirs) const override { | 32 const GrBatchTracker& theirs) const override { |
36 SkFAIL("Unsupported\n"); | 33 SkFAIL("Unsupported\n"); |
37 return false; | 34 return false; |
38 } | 35 } |
39 | 36 |
40 // TODO Delete when paths are in batch | 37 // TODO Delete when paths are in batch |
41 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 38 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
42 SkFAIL("Unsupported\n"); | 39 SkFAIL("Unsupported\n"); |
43 } | 40 } |
44 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 41 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
45 SkFAIL("Unsupported\n"); | 42 SkFAIL("Unsupported\n"); |
46 } | 43 } |
47 | 44 |
48 protected: | 45 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 |
49 /** | 75 /** |
50 * Subclasses call this from their constructor to register vertex attributes
. Attributes | 76 * Subclasses call this from their constructor to register vertex attributes
. Attributes |
51 * will be padded to the nearest 4 bytes for performance reasons. | 77 * will be padded to the nearest 4 bytes for performance reasons. |
52 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside | 78 * TODO After deferred geometry, we should do all of this inline in Generate
Geometry alongside |
53 * the struct used to actually populate the attributes. This is all extreme
ly fragile, vertex | 79 * the struct used to actually populate the attributes. This is all extreme
ly fragile, vertex |
54 * attributes have to be added in the order they will appear in the struct w
hich maps memory. | 80 * attributes have to be added in the order they will appear in the struct w
hich maps memory. |
55 * The processor key should reflect the vertex attributes, or there lack the
reof in the | 81 * The processor key should reflect the vertex attributes, or there lack the
reof in the |
56 * GrGeometryProcessor. | 82 * GrGeometryProcessor. |
57 */ | 83 */ |
58 const Attribute& addVertexAttrib(const Attribute& attribute) { | 84 const Attribute& addVertexAttrib(const Attribute& attribute) { |
(...skipping 11 matching lines...) Expand all Loading... |
70 private: | 96 private: |
71 bool hasExplicitLocalCoords() const override { return fHasLocalCoords; } | 97 bool hasExplicitLocalCoords() const override { return fHasLocalCoords; } |
72 | 98 |
73 bool fWillUseGeoShader; | 99 bool fWillUseGeoShader; |
74 bool fHasLocalCoords; | 100 bool fHasLocalCoords; |
75 | 101 |
76 typedef GrPrimitiveProcessor INHERITED; | 102 typedef GrPrimitiveProcessor INHERITED; |
77 }; | 103 }; |
78 | 104 |
79 #endif | 105 #endif |
OLD | NEW |