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