joshualitt | 249af15 | 2014-09-15 11:41:13 -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 "GrEffect.h" |
| 12 | |
| 13 | /** |
| 14 | * If an effect needs specialized vertex shader code, then it must inherit from this class. |
| 15 | * Otherwise it won't be able to add vertex attribs, and it will be given a vertexless shader |
| 16 | * program in emitCode. |
| 17 | */ |
| 18 | class GrGeometryProcessor : public GrEffect { |
| 19 | public: |
| 20 | GrGeometryProcessor() { fRequiresVertexShader = true; } |
| 21 | |
| 22 | protected: |
| 23 | /** |
| 24 | * Subclasses call this from their constructor to register vertex attributes (at most |
| 25 | * kMaxVertexAttribs). This must only be called from the constructor because GrEffects are |
| 26 | * immutable. |
| 27 | * |
| 28 | * We return a reference to the added var so that derived classes can name it nicely and use it |
| 29 | * in shader code. |
| 30 | */ |
| 31 | const GrShaderVar& addVertexAttrib(const GrShaderVar& var) { |
| 32 | SkASSERT(GrShaderVar::kAttribute_TypeModifier == var.getTypeModifier()); |
| 33 | SkASSERT(fVertexAttribs.count() < kMaxVertexAttribs); |
| 34 | return fVertexAttribs.push_back(var); |
| 35 | } |
| 36 | |
| 37 | private: |
| 38 | typedef GrEffect INHERITED; |
| 39 | }; |
| 40 | |
| 41 | #endif |