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 "GrGeometryData.h" | 11 #include "GrGeometryData.h" |
12 #include "GrProcessor.h" | 12 #include "GrProcessor.h" |
13 #include "GrShaderVar.h" | 13 #include "GrShaderVar.h" |
14 | 14 |
15 /** | 15 /** |
16 * A GrGeomteryProcessor is used to perform computation in the vertex shader and | 16 * A GrGeomteryProcessor is used to perform computation in the vertex shader and |
17 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | 17 * add support for custom vertex attributes. A GrGemeotryProcessor is typically |
18 * tied to the code that does a specific type of high-level primitive rendering | 18 * tied to the code that does a specific type of high-level primitive rendering |
19 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is | 19 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw is |
20 * specified using GrDrawState. There can only be one geometry processor active for | 20 * specified using GrDrawState. There can only be one geometry processor active for |
21 * a draw. The custom vertex attributes required by the geometry processor must be | 21 * a draw. The custom vertex attributes required by the geometry processor must be |
22 * added to the vertex attribute array specified on the GrDrawState. | 22 * added to the vertex attribute array specified on the GrDrawState. |
23 * GrGeometryProcessor subclasses should be immutable after construction. | 23 * GrGeometryProcessor subclasses should be immutable after construction. |
24 */ | 24 */ |
25 class GrGeometryProcessor : public GrProcessor { | 25 class GrGeometryProcessor : public GrProcessor { |
26 public: | 26 public: |
27 GrGeometryProcessor() | 27 GrGeometryProcessor() |
28 : fWillUseGeoShader(false) {} | 28 : fVertexStride(0) |
29 , fWillUseGeoShader(false) | |
30 , fHasVertexColor(false) | |
31 , fHasVertexCoverage(false) | |
32 , fHasLocalCoords(false) {} | |
29 | 33 |
30 virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; | 34 virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; |
31 | 35 |
32 /* | 36 /* |
33 * This only has a max because GLProgramsTest needs to generate test arrays, and these have to | 37 * This is a safeguard to prevent GPs from going beyond platform specific at tribute limits. |
34 * be static | 38 * This number can almost certainly be raised if required. |
35 * TODO make this truly dynamic | |
36 */ | 39 */ |
37 static const int kMaxVertexAttribs = 2; | 40 static const int kMaxVertexAttribs = 6; |
38 typedef SkTArray<GrShaderVar, true> VertexAttribArray; | |
39 | 41 |
40 const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; } | 42 struct GrAttribute { |
43 GrAttribute(const char* name, GrVertexAttribType type) : fName(name), fT ype(type) {} | |
44 const char* fName; | |
45 GrVertexAttribType fType; | |
46 }; | |
47 | |
48 typedef SkTArray<GrAttribute, true> VertexAttribArray; | |
49 | |
50 const VertexAttribArray& getAttribs() const { return fAttribs; } | |
51 | |
52 size_t getVertexStride() const { return fVertexStride; } | |
41 | 53 |
42 bool willUseGeoShader() const { return fWillUseGeoShader; } | 54 bool willUseGeoShader() const { return fWillUseGeoShader; } |
43 | 55 |
44 /** Returns true if this and other processor conservatively draw identically . It can only return | 56 /** Returns true if this and other processor conservatively draw identically . It can only return |
45 true when the two prcoessors are of the same subclass (i.e. they return the same object from | 57 true when the two prcoessors are of the same subclass (i.e. they return the same object from |
46 from getFactory()). | 58 from getFactory()). |
47 A return value of true from isEqual() should not be used to test whether the processors | 59 A return value of true from isEqual() should not be used to test whether the processors |
48 would generate the same shader code. To test for identical code generati on use the | 60 would generate the same shader code. To test for identical code generati on use the |
49 processors' keys computed by the GrBackendEffectFactory. */ | 61 processors' keys computed by the GrBackendEffectFactory. */ |
50 bool isEqual(const GrGeometryProcessor& that) const { | 62 bool isEqual(const GrGeometryProcessor& that) const { |
51 if (&this->getFactory() != &that.getFactory() || !this->hasSameTextureAc cesses(that)) { | 63 if (&this->getFactory() != &that.getFactory() || !this->hasSameTextureAc cesses(that)) { |
52 return false; | 64 return false; |
53 } | 65 } |
54 return this->onIsEqual(that); | 66 return this->onIsEqual(that); |
55 } | 67 } |
56 | 68 |
69 // TODO this is a total hack until the gp can own whether or not it uses uni form | |
70 // color / coverage | |
71 bool hasVertexColor() const { return fHasVertexColor; } | |
72 bool hasVertexCoverage() const { return fHasVertexCoverage; } | |
73 bool hasLocalCoords() const { return fHasLocalCoords; } | |
74 | |
57 protected: | 75 protected: |
58 /** | 76 /** |
59 * Subclasses call this from their constructor to register vertex attributes (at most | 77 * Subclasses call this from their constructor to register vertex attributes |
60 * kMaxVertexAttribs). This must only be called from the constructor because GrProcessors are | |
61 * immutable. | |
62 */ | 78 */ |
63 const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { | 79 const GrAttribute& addVertexAttrib(const GrAttribute& attribute) { |
64 SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); | 80 fVertexStride += GrVertexAttribTypeSize(attribute.fType); |
65 return fVertexAttribs.push_back(var); | 81 return fAttribs.push_back(attribute); |
bsalomon
2014/12/02 18:06:05
Is this right? Will we wind up with unaligned attr
| |
66 } | 82 } |
67 | 83 |
68 void setWillUseGeoShader() { fWillUseGeoShader = true; } | 84 void setWillUseGeoShader() { fWillUseGeoShader = true; } |
69 | 85 |
86 // TODO hack see above | |
87 void setHasVertexColor() { fHasVertexColor = true; } | |
88 void setHasVertexCoverage() { fHasVertexCoverage = true; } | |
89 void setHasLocalCoords() { fHasLocalCoords = true; } | |
90 | |
70 private: | 91 private: |
71 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 92 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
72 | 93 |
73 SkSTArray<kMaxVertexAttribs, GrShaderVar, true> fVertexAttribs; | 94 SkSTArray<kMaxVertexAttribs, GrAttribute, true> fAttribs; |
95 size_t fVertexStride; | |
74 bool fWillUseGeoShader; | 96 bool fWillUseGeoShader; |
97 bool fHasVertexColor; | |
98 bool fHasVertexCoverage; | |
99 bool fHasLocalCoords; | |
75 | 100 |
76 typedef GrProcessor INHERITED; | 101 typedef GrProcessor INHERITED; |
77 }; | 102 }; |
78 | 103 |
79 #endif | 104 #endif |
OLD | NEW |