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 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or | 22 // TODO the Hint can be handled in a much more clean way when we have deferr
ed geometry or |
23 // atleast bundles | 23 // atleast bundles |
24 GrGeometryProcessor(GrColor color, | 24 GrGeometryProcessor(GrColor color, |
25 const SkMatrix& viewMatrix = SkMatrix::I(), | 25 const SkMatrix& viewMatrix = SkMatrix::I(), |
26 const SkMatrix& localMatrix = SkMatrix::I(), | 26 const SkMatrix& localMatrix = SkMatrix::I()) |
27 bool opaqueVertexColors = false) | |
28 : INHERITED(viewMatrix, localMatrix, false) | 27 : INHERITED(viewMatrix, localMatrix, false) |
29 , fColor(color) | 28 , fColor(color) |
30 , fOpaqueVertexColors(opaqueVertexColors) | |
31 , fWillUseGeoShader(false) | 29 , fWillUseGeoShader(false) |
32 , fHasVertexColor(false) | |
33 , fHasLocalCoords(false) {} | 30 , fHasLocalCoords(false) {} |
34 | 31 |
35 bool willUseGeoShader() const { return fWillUseGeoShader; } | 32 bool willUseGeoShader() const { return fWillUseGeoShader; } |
36 | 33 |
37 /* | 34 // TODO delete this when paths are in batch |
38 * In an ideal world, two GrGeometryProcessors with the same class id and te
xture accesses | |
39 * would ALWAYS be able to batch together. If two GrGeometryProcesosrs are
the same then we | |
40 * will only keep one of them. The remaining GrGeometryProcessor then updat
es its | |
41 * GrBatchTracker to incorporate the draw information from the GrGeometryPro
cessor we discard. | |
42 * Any bundles associated with the discarded GrGeometryProcessor will be att
ached to the | |
43 * remaining GrGeometryProcessor. | |
44 */ | |
45 bool canMakeEqual(const GrBatchTracker& mine, | 35 bool canMakeEqual(const GrBatchTracker& mine, |
46 const GrPrimitiveProcessor& that, | 36 const GrPrimitiveProcessor& that, |
47 const GrBatchTracker& theirs) const override { | 37 const GrBatchTracker& theirs) const override { |
48 if (this->classID() != that.classID() || !this->hasSameTextureAccesses(t
hat)) { | 38 SkFAIL("Unsupported\n"); |
49 return false; | 39 return false; |
50 } | |
51 | |
52 // TODO let the GPs decide this | |
53 if (!this->viewMatrix().cheapEqualTo(that.viewMatrix())) { | |
54 return false; | |
55 } | |
56 | |
57 // TODO remove the hint | |
58 const GrGeometryProcessor& other = that.cast<GrGeometryProcessor>(); | |
59 if (fHasVertexColor && fOpaqueVertexColors != other.fOpaqueVertexColors)
{ | |
60 return false; | |
61 } | |
62 | |
63 // TODO this equality test should really be broken up, some of this can
live on the batch | |
64 // tracker test and some of this should be in bundles | |
65 if (!this->onIsEqual(other)) { | |
66 return false; | |
67 } | |
68 | |
69 return this->onCanMakeEqual(mine, other, theirs); | |
70 } | 40 } |
71 | 41 |
72 // TODO we can remove color from the GrGeometryProcessor base class once we
have bundles of | 42 // TODO we can remove color from the GrGeometryProcessor base class once we
have bundles of |
73 // primitive data | 43 // primitive data |
74 GrColor color() const { return fColor; } | 44 GrColor color() const { return fColor; } |
75 | 45 |
76 // TODO this is a total hack until the gp can do deferred geometry | 46 // TODO Delete when paths are in batch |
77 bool hasVertexColor() const { return fHasVertexColor; } | 47 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
78 | 48 SkFAIL("Unsupported\n"); |
79 void getInvariantOutputColor(GrInitInvariantOutput* out) const override; | 49 } |
80 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override; | 50 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
| 51 SkFAIL("Unsupported\n"); |
| 52 } |
81 | 53 |
82 protected: | 54 protected: |
83 /* | 55 /* |
84 * An optional simple helper function to determine by what means the GrGeome
tryProcessor should | 56 * An optional simple helper function to determine by what means the GrGeome
tryProcessor should |
85 * use to provide color. If we are given an override color(ie the given ove
rridecolor is NOT | 57 * use to provide color. If we are given an override color(ie the given ove
rridecolor is NOT |
86 * GrColor_ILLEGAL) then we must always emit that color(currently overrides
are only supported | 58 * GrColor_ILLEGAL) then we must always emit that color(currently overrides
are only supported |
87 * via uniform, but with deferred Geometry we could use attributes). Otherw
ise, if our color is | 59 * via uniform, but with deferred Geometry we could use attributes). Otherw
ise, if our color is |
88 * ignored then we should not emit a color. Lastly, if we don't have vertex
colors then we must | 60 * ignored then we should not emit a color. Lastly, if we don't have vertex
colors then we must |
89 * emit a color via uniform | 61 * emit a color via uniform |
90 * TODO this function changes quite a bit with deferred geometry. There the
GrGeometryProcessor | 62 * TODO this function changes quite a bit with deferred geometry. There the
GrGeometryProcessor |
(...skipping 30 matching lines...) Expand all Loading... |
121 const Attribute& addVertexAttrib(const Attribute& attribute) { | 93 const Attribute& addVertexAttrib(const Attribute& attribute) { |
122 SkASSERT(fNumAttribs < kMaxVertexAttribs); | 94 SkASSERT(fNumAttribs < kMaxVertexAttribs); |
123 fVertexStride += attribute.fOffset; | 95 fVertexStride += attribute.fOffset; |
124 fAttribs[fNumAttribs] = attribute; | 96 fAttribs[fNumAttribs] = attribute; |
125 return fAttribs[fNumAttribs++]; | 97 return fAttribs[fNumAttribs++]; |
126 } | 98 } |
127 | 99 |
128 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 100 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
129 | 101 |
130 // TODO hack see above | 102 // TODO hack see above |
131 void setHasVertexColor() { fHasVertexColor = true; } | |
132 void setHasLocalCoords() { fHasLocalCoords = true; } | 103 void setHasLocalCoords() { fHasLocalCoords = true; } |
133 | 104 |
134 virtual void onGetInvariantOutputColor(GrInitInvariantOutput*) const {} | |
135 virtual void onGetInvariantOutputCoverage(GrInitInvariantOutput*) const = 0; | |
136 | |
137 private: | 105 private: |
138 virtual bool onCanMakeEqual(const GrBatchTracker& mine, | |
139 const GrGeometryProcessor& that, | |
140 const GrBatchTracker& theirs) const = 0; | |
141 | |
142 // TODO delete this when we have more advanced equality testing via bundles
and the BT | |
143 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | |
144 | |
145 bool hasExplicitLocalCoords() const override { return fHasLocalCoords; } | 106 bool hasExplicitLocalCoords() const override { return fHasLocalCoords; } |
146 | 107 |
147 GrColor fColor; | 108 GrColor fColor; |
148 bool fOpaqueVertexColors; | |
149 bool fWillUseGeoShader; | 109 bool fWillUseGeoShader; |
150 bool fHasVertexColor; | |
151 bool fHasLocalCoords; | 110 bool fHasLocalCoords; |
152 | 111 |
153 typedef GrPrimitiveProcessor INHERITED; | 112 typedef GrPrimitiveProcessor INHERITED; |
154 }; | 113 }; |
155 | 114 |
156 #endif | 115 #endif |
OLD | NEW |