joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrGeometryProcessor_DEFINED |
| 9 | #define GrGeometryProcessor_DEFINED |
| 10 | |
| 11 | #include "GrProcessor.h" |
bsalomon | 6251d17 | 2014-10-15 10:50:36 -0700 | [diff] [blame] | 12 | #include "GrShaderVar.h" |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 13 | |
| 14 | /** |
| 15 | * A GrGeomteryProcessor is used to perform computation in the vertex shader and |
| 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 |
| 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 |
| 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. |
| 22 | * GrGeometryProcessor subclasses should be immutable after construction. |
| 23 | */ |
| 24 | class GrGeometryProcessor : public GrProcessor { |
| 25 | public: |
| 26 | GrGeometryProcessor() {} |
| 27 | |
| 28 | virtual const GrBackendGeometryProcessorFactory& getFactory() const = 0; |
| 29 | |
| 30 | /* |
| 31 | * This only has a max because GLProgramsTest needs to generate test arrays, and these have to |
| 32 | * be static |
| 33 | * TODO make this truly dynamic |
| 34 | */ |
| 35 | static const int kMaxVertexAttribs = 2; |
| 36 | typedef SkTArray<GrShaderVar, true> VertexAttribArray; |
| 37 | |
| 38 | const VertexAttribArray& getVertexAttribs() const { return fVertexAttribs; } |
| 39 | |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 40 | /** Returns true if this and other processor conservatively draw identically. It can only return |
| 41 | true when the two prcoessors are of the same subclass (i.e. they return the same object from |
bsalomon | 6251d17 | 2014-10-15 10:50:36 -0700 | [diff] [blame] | 42 | from getFactory()). |
bsalomon | 98b33eb | 2014-10-15 11:05:26 -0700 | [diff] [blame] | 43 | A return value of true from isEqual() should not be used to test whether the prcoessors |
| 44 | would generate the same shader code. To test for identical code generation use the |
| 45 | processors' keys computed by the GrBackendEffectFactory. */ |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 46 | bool isEqual(const GrGeometryProcessor& that) const { |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame^] | 47 | if (&this->getFactory() != &that.getFactory() || !this->hasSameTextureAccesses(that)) { |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 48 | return false; |
| 49 | } |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame^] | 50 | return this->onIsEqual(that); |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 51 | } |
| 52 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 53 | protected: |
| 54 | /** |
| 55 | * Subclasses call this from their constructor to register vertex attributes (at most |
| 56 | * kMaxVertexAttribs). This must only be called from the constructor because GrProcessors are |
| 57 | * immutable. |
| 58 | */ |
| 59 | const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { |
| 60 | SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); |
| 61 | return fVertexAttribs.push_back(var); |
| 62 | } |
| 63 | |
| 64 | private: |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 65 | virtual bool onIsEqual(const GrGeometryProcessor&) const = 0; |
| 66 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 67 | SkSTArray<kMaxVertexAttribs, GrShaderVar, true> fVertexAttribs; |
| 68 | |
| 69 | typedef GrProcessor INHERITED; |
| 70 | }; |
| 71 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 72 | #endif |