| 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 "GrProcessor.h" | 11 #include "GrProcessor.h" |
| 12 #include "GrShaderVar.h" | 12 #include "GrShaderVar.h" |
| 13 | 13 |
| 14 /** | 14 /** |
| 15 * A GrGeomteryProcessor is used to perform computation in the vertex shader and | 15 * A GrGeomteryProcessor is used to perform computation in the vertex shader and |
| 16 * add support for custom vertex attributes. A GrGemeotryProcessor is typically | 16 * add support for custom vertex attributes. A GrGemeotryProcessor is typically |
| 17 * tied to the code that does a specific type of high-level primitive rendering | 17 * tied to the code that does a specific type of high-level primitive rendering |
| 18 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is | 18 * (e.g. anti-aliased circle rendering). The GrGeometryProcessor used for a draw
is |
| 19 * specified using GrDrawState. There can only be one geometry processor active
for | 19 * specified using GrDrawState. There can only be one geometry processor active
for |
| 20 * a draw. The custom vertex attributes required by the geometry processor must
be | 20 * a draw. The custom vertex attributes required by the geometry processor must
be |
| 21 * added to the vertex attribute array specified on the GrDrawState. | 21 * added to the vertex attribute array specified on the GrDrawState. |
| 22 * GrGeometryProcessor subclasses should be immutable after construction. | 22 * GrGeometryProcessor subclasses should be immutable after construction. |
| 23 */ | 23 */ |
| 24 class GrGeometryProcessor : public GrProcessor { | 24 class GrGeometryProcessor : public GrProcessor { |
| 25 public: | 25 public: |
| 26 GrGeometryProcessor() | 26 GrGeometryProcessor() {} |
| 27 : fWillUseGeoShader(false) {} | |
| 28 | 27 |
| 29 virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; | 28 virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; |
| 30 | 29 |
| 31 /* | 30 /* |
| 32 * This only has a max because GLProgramsTest needs to generate test arrays,
and these have to | 31 * This only has a max because GLProgramsTest needs to generate test arrays,
and these have to |
| 33 * be static | 32 * be static |
| 34 * TODO make this truly dynamic | 33 * TODO make this truly dynamic |
| 35 */ | 34 */ |
| 36 static const int kMaxVertexAttribs = 2; | 35 static const int kMaxVertexAttribs = 2; |
| 37 typedef SkTArray<GrShaderVar, true> VertexAttribArray; | 36 typedef SkTArray<GrShaderVar, true> VertexAttribArray; |
| 38 | 37 |
| 39 const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; } | 38 const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; } |
| 40 | 39 |
| 41 bool willUseGeoShader() const { return fWillUseGeoShader; } | |
| 42 | |
| 43 /** Returns true if this and other processor conservatively draw identically
. It can only return | 40 /** Returns true if this and other processor conservatively draw identically
. It can only return |
| 44 true when the two prcoessors are of the same subclass (i.e. they return
the same object from | 41 true when the two prcoessors are of the same subclass (i.e. they return
the same object from |
| 45 from getFactory()). | 42 from getFactory()). |
| 46 A return value of true from isEqual() should not be used to test whether
the prcoessors | 43 A return value of true from isEqual() should not be used to test whether
the prcoessors |
| 47 would generate the same shader code. To test for identical code generati
on use the | 44 would generate the same shader code. To test for identical code generati
on use the |
| 48 processors' keys computed by the GrBackendEffectFactory. */ | 45 processors' keys computed by the GrBackendEffectFactory. */ |
| 49 bool isEqual(const GrGeometryProcessor& that) const { | 46 bool isEqual(const GrGeometryProcessor& that) const { |
| 50 if (&this->getFactory() != &that.getFactory() || !this->hasSameTextureAc
cesses(that)) { | 47 if (&this->getFactory() != &that.getFactory() || !this->hasSameTextureAc
cesses(that)) { |
| 51 return false; | 48 return false; |
| 52 } | 49 } |
| 53 return this->onIsEqual(that); | 50 return this->onIsEqual(that); |
| 54 } | 51 } |
| 55 | 52 |
| 56 protected: | 53 protected: |
| 57 /** | 54 /** |
| 58 * Subclasses call this from their constructor to register vertex attributes
(at most | 55 * Subclasses call this from their constructor to register vertex attributes
(at most |
| 59 * kMaxVertexAttribs). This must only be called from the constructor because
GrProcessors are | 56 * kMaxVertexAttribs). This must only be called from the constructor because
GrProcessors are |
| 60 * immutable. | 57 * immutable. |
| 61 */ | 58 */ |
| 62 const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { | 59 const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { |
| 63 SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); | 60 SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); |
| 64 return fVertexAttribs.push_back(var); | 61 return fVertexAttribs.push_back(var); |
| 65 } | 62 } |
| 66 | 63 |
| 67 void setWillUseGeoShader() { fWillUseGeoShader = true; } | |
| 68 | |
| 69 private: | 64 private: |
| 70 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; | 65 virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
| 71 | 66 |
| 72 SkSTArray<kMaxVertexAttribs, GrShaderVar, true> fVertexAttribs; | 67 SkSTArray<kMaxVertexAttribs, GrShaderVar, true> fVertexAttribs; |
| 73 bool fWillUseGeoShader; | |
| 74 | 68 |
| 75 typedef GrProcessor INHERITED; | 69 typedef GrProcessor INHERITED; |
| 76 }; | 70 }; |
| 77 | 71 |
| 78 #endif | 72 #endif |
| OLD | NEW |