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 | |
joshualitt | 8072caa | 2015-02-12 14:20:52 -0800 | [diff] [blame] | 11 | #include "GrPrimitiveProcessor.h" |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * A GrGeometryProcessor is a flexible method for rendering a primitive. The GrGeometryProcessor |
| 15 | * has complete control over vertex attributes and uniforms(aside from the render target) but it |
| 16 | * must obey the same contract as any GrPrimitiveProcessor, specifically it must emit a color and |
| 17 | * coverage into the fragment shader. Where this color and coverage come from is completely the |
| 18 | * responsibility of the GrGeometryProcessor. |
| 19 | */ |
| 20 | class GrGeometryProcessor : public GrPrimitiveProcessor { |
| 21 | public: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 22 | GrGeometryProcessor(ClassID classID) |
| 23 | : INHERITED(classID) |
| 24 | , fWillUseGeoShader(false) |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 25 | , fSampleShading(0.0) {} |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 26 | |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 27 | bool willUseGeoShader() const final { return fWillUseGeoShader; } |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 28 | |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 29 | /** |
| 30 | * Returns the minimum fraction of samples for which the fragment shader will be run. For |
| 31 | * instance, if sampleShading is 0.5 in MSAA16 mode, the fragment shader will run a minimum of |
| 32 | * 8 times per pixel. The default value is zero. |
| 33 | */ |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 34 | float getSampleShading() const final { return fSampleShading; } |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 35 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 36 | protected: |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 37 | void setWillUseGeoShader() { fWillUseGeoShader = true; } |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 38 | void setSampleShading(float sampleShading) { |
| 39 | fSampleShading = sampleShading; |
| 40 | } |
| 41 | |
Brian Salomon | 92be2f7 | 2018-06-19 14:33:47 -0400 | [diff] [blame] | 42 | /** |
| 43 | * Recursive helpers for implementing onVertexAttribute or onInstanceAttribute. |
| 44 | */ |
| 45 | |
| 46 | template <typename... Args> |
| 47 | static const Attribute& IthAttribute(int i, const Attribute& attr0, const Args&... attrs) { |
| 48 | SkASSERT(attr0.isInitialized()); |
| 49 | return (0 == i) ? attr0 : IthAttribute(i - 1, attrs...); |
| 50 | } |
| 51 | |
| 52 | static const Attribute& IthAttribute(int i) { |
| 53 | SK_ABORT("Illegal attribute Index"); |
| 54 | static constexpr Attribute kBogus; |
| 55 | return kBogus; |
| 56 | } |
| 57 | |
| 58 | template <typename... Args> |
| 59 | static const Attribute& IthInitializedAttribute(int i, const Attribute& attr0, |
| 60 | const Args&... attrs) { |
| 61 | if (attr0.isInitialized()) { |
| 62 | if (0 == i) { |
| 63 | return attr0; |
| 64 | } |
| 65 | i -= 1; |
| 66 | } |
| 67 | return IthInitializedAttribute(i, attrs...); |
| 68 | } |
| 69 | |
| 70 | static const Attribute& IthInitializedAttribute(int i) { return IthAttribute(i); } |
| 71 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 72 | private: |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 73 | bool fWillUseGeoShader; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 74 | float fSampleShading; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 75 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 76 | typedef GrPrimitiveProcessor INHERITED; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 77 | }; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 78 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 79 | #endif |