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 , fHasExplicitLocalCoords(false) |
26 , fHasTransformedLocalCoords(false) {} | |
26 | 27 |
27 bool willUseGeoShader() const override { return fWillUseGeoShader; } | 28 bool willUseGeoShader() const override { return fWillUseGeoShader; } |
28 | 29 |
29 // TODO delete when paths are in batch | 30 // TODO delete when paths are in batch |
30 void initBatchTracker(GrBatchTracker*, const GrPipelineInfo&) const override {} | 31 void initBatchTracker(GrBatchTracker*, const GrPipelineInfo&) const override {} |
31 | 32 |
32 // TODO delete this when paths are in batch | 33 // TODO delete this when paths are in batch |
33 bool canMakeEqual(const GrBatchTracker& mine, | 34 bool canMakeEqual(const GrBatchTracker& mine, |
34 const GrPrimitiveProcessor& that, | 35 const GrPrimitiveProcessor& that, |
35 const GrBatchTracker& theirs) const override { | 36 const GrBatchTracker& theirs) const override { |
36 SkFAIL("Unsupported\n"); | 37 SkFAIL("Unsupported\n"); |
37 return false; | 38 return false; |
38 } | 39 } |
39 | 40 |
40 // TODO Delete when paths are in batch | 41 // TODO Delete when paths are in batch |
41 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { | 42 void getInvariantOutputColor(GrInitInvariantOutput* out) const override { |
42 SkFAIL("Unsupported\n"); | 43 SkFAIL("Unsupported\n"); |
43 } | 44 } |
44 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { | 45 void getInvariantOutputCoverage(GrInitInvariantOutput* out) const override { |
45 SkFAIL("Unsupported\n"); | 46 SkFAIL("Unsupported\n"); |
46 } | 47 } |
47 | 48 |
49 bool hasTransformedLocalCoords() const override { return fHasTransformedLoca lCoords; } | |
bsalomon
2015/08/05 15:17:02
should we be using enums rather than a set of bool
| |
50 | |
51 bool hasExplicitLocalCoords() const override { return fHasExplicitLocalCoord s; } | |
52 | |
48 protected: | 53 protected: |
49 /** | 54 /** |
50 * Subclasses call this from their constructor to register vertex attributes . Attributes | 55 * Subclasses call this from their constructor to register vertex attributes . Attributes |
51 * will be padded to the nearest 4 bytes for performance reasons. | 56 * 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 | 57 * 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 | 58 * 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. | 59 * 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 | 60 * The processor key should reflect the vertex attributes, or there lack the reof in the |
56 * GrGeometryProcessor. | 61 * GrGeometryProcessor. |
57 */ | 62 */ |
58 const Attribute& addVertexAttrib(const Attribute& attribute) { | 63 const Attribute& addVertexAttrib(const Attribute& attribute) { |
59 SkASSERT(fNumAttribs < kMaxVertexAttribs); | 64 SkASSERT(fNumAttribs < kMaxVertexAttribs); |
60 fVertexStride += attribute.fOffset; | 65 fVertexStride += attribute.fOffset; |
61 fAttribs[fNumAttribs] = attribute; | 66 fAttribs[fNumAttribs] = attribute; |
62 return fAttribs[fNumAttribs++]; | 67 return fAttribs[fNumAttribs++]; |
63 } | 68 } |
64 | 69 |
65 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 70 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
66 | 71 |
67 // TODO hack see above | 72 /** |
68 void setHasLocalCoords() { fHasLocalCoords = true; } | 73 * If a GrFragmentProcessor in the GrPipeline needs localCoods, we will prov ide them in one of |
74 * three ways | |
75 * 1) LocalCoordTransform * Position - in Shader | |
76 * 2) LocalCoordTransform * ExplicitLocalCoords- in Shader | |
77 * 3) A transformation on the CPU uploaded via vertex attribute | |
78 */ | |
79 void setHasExplicitLocalCoords() { | |
80 SkASSERT(!fHasTransformedLocalCoords); | |
81 fHasExplicitLocalCoords = true; | |
82 } | |
83 void setHasTransformedLocalCoords() { | |
84 SkASSERT(!fHasExplicitLocalCoords); | |
85 fHasTransformedLocalCoords = true; | |
86 } | |
69 | 87 |
70 private: | 88 private: |
71 bool hasExplicitLocalCoords() const override { return fHasLocalCoords; } | |
72 | |
73 bool fWillUseGeoShader; | 89 bool fWillUseGeoShader; |
74 bool fHasLocalCoords; | 90 bool fHasExplicitLocalCoords; |
91 bool fHasTransformedLocalCoords; | |
75 | 92 |
76 typedef GrPrimitiveProcessor INHERITED; | 93 typedef GrPrimitiveProcessor INHERITED; |
77 }; | 94 }; |
78 | 95 |
79 #endif | 96 #endif |
OLD | NEW |