tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 GrCustomStage_DEFINED |
| 9 | #define GrCustomStage_DEFINED |
| 10 | |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 11 | #include "GrRefCnt.h" |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame^] | 12 | #include "GrNoncopyable.h" |
| 13 | #include "GrProgramStageFactory.h" |
| 14 | #include "SkTemplates.h" |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 15 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 16 | class GrContext; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 17 | |
| 18 | /** Provides custom vertex shader, fragment shader, uniform data for a |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame^] | 19 | particular stage of the Ganesh shading pipeline. */ |
tomhudson@google.com | 07eecdc | 2012-04-20 18:35:38 +0000 | [diff] [blame] | 20 | class GrCustomStage : public GrRefCnt { |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 21 | |
| 22 | public: |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame^] | 23 | typedef GrProgramStageFactory::StageKey StageKey; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 24 | |
| 25 | GrCustomStage(); |
| 26 | virtual ~GrCustomStage(); |
| 27 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 28 | /** Human-meaningful string to identify this effect; may be embedded |
| 29 | in generated shader code. */ |
| 30 | virtual const char* name() const = 0; |
| 31 | |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 32 | /** If given an input texture that is/is not opaque, is this |
| 33 | stage guaranteed to produce an opaque output? */ |
| 34 | virtual bool isOpaque(bool inputTextureIsOpaque) const; |
| 35 | |
bsalomon@google.com | ae4f96a | 2012-05-18 19:54:48 +0000 | [diff] [blame^] | 36 | /** This object, besides creating back-end-specific helper |
| 37 | objects, is used for run-time-type-identification. The factory should be |
| 38 | an instance of templated class, GrTProgramStageFactory. It is templated |
| 39 | on the subclass of GrCustomStage. The subclass must have a nested type |
| 40 | (or typedef) named GLProgramStage which will be the subclass of |
| 41 | GrGLProgramStage created by the factory. |
| 42 | |
| 43 | Example: |
| 44 | class MyCustomStage : public GrCustomStage { |
| 45 | ... |
| 46 | virtual const GrProgramStageFactory& getFactory() const |
| 47 | SK_OVERRIDE { |
| 48 | return GrTProgramStageFactory<MyCustomStage>::getInstance(); |
| 49 | } |
| 50 | ... |
| 51 | }; |
| 52 | */ |
| 53 | virtual const GrProgramStageFactory& getFactory() const = 0; |
tomhudson@google.com | b88bbd2 | 2012-05-01 12:48:07 +0000 | [diff] [blame] | 54 | |
| 55 | /** Returns true if the other custom stage will generate |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 56 | equal output. |
| 57 | Must only be called if the two are already known to be of the |
| 58 | same type (i.e. they return the same value from getFactory()). |
| 59 | For equivalence (that they will generate the same |
| 60 | shader, but perhaps have different uniforms), check equality |
| 61 | of the stageKey produced by the GrProgramStageFactory. */ |
| 62 | virtual bool isEqual(const GrCustomStage *) const = 0; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 63 | |
tomhudson@google.com | d8f856c | 2012-05-10 12:13:36 +0000 | [diff] [blame] | 64 | private: |
| 65 | |
| 66 | typedef GrRefCnt INHERITED; |
tomhudson@google.com | 168e634 | 2012-04-18 17:49:20 +0000 | [diff] [blame] | 67 | }; |
| 68 | |
| 69 | #endif |