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 | , fLocalCoordsType(kUnused_LocalCoordsType) |
| 26 | , fSampleShading(0.0) {} |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 27 | |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 28 | bool willUseGeoShader() const final { return fWillUseGeoShader; } |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 29 | |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 30 | bool hasExplicitLocalCoords() const final { |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 31 | return kHasExplicit_LocalCoordsType == fLocalCoordsType; |
| 32 | } |
| 33 | |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 34 | /** |
| 35 | * Returns the minimum fraction of samples for which the fragment shader will be run. For |
| 36 | * instance, if sampleShading is 0.5 in MSAA16 mode, the fragment shader will run a minimum of |
| 37 | * 8 times per pixel. The default value is zero. |
| 38 | */ |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 39 | float getSampleShading() const final { return fSampleShading; } |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 40 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 41 | protected: |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 42 | void setWillUseGeoShader() { fWillUseGeoShader = true; } |
| 43 | |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 44 | /** |
| 45 | * If a GrFragmentProcessor in the GrPipeline needs localCoods, we will provide them in one of |
| 46 | * three ways |
| 47 | * 1) LocalCoordTransform * Position - in Shader |
| 48 | * 2) LocalCoordTransform * ExplicitLocalCoords- in Shader |
| 49 | * 3) A transformation on the CPU uploaded via vertex attribute |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 50 | */ |
| 51 | enum LocalCoordsType { |
| 52 | kUnused_LocalCoordsType, |
| 53 | kHasExplicit_LocalCoordsType, |
| 54 | kHasTransformed_LocalCoordsType |
| 55 | }; |
| 56 | |
| 57 | void setHasExplicitLocalCoords() { |
| 58 | SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType); |
| 59 | fLocalCoordsType = kHasExplicit_LocalCoordsType; |
| 60 | } |
| 61 | void setHasTransformedLocalCoords() { |
| 62 | SkASSERT(kUnused_LocalCoordsType == fLocalCoordsType); |
| 63 | fLocalCoordsType = kHasTransformed_LocalCoordsType; |
| 64 | } |
joshualitt | 2dd1ae0 | 2014-12-03 06:24:10 -0800 | [diff] [blame] | 65 | |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 66 | void setSampleShading(float sampleShading) { |
| 67 | fSampleShading = sampleShading; |
| 68 | } |
| 69 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 70 | private: |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 71 | bool fWillUseGeoShader; |
joshualitt | b2aa7cb | 2015-08-05 11:05:22 -0700 | [diff] [blame] | 72 | LocalCoordsType fLocalCoordsType; |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 73 | float fSampleShading; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 74 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 75 | typedef GrPrimitiveProcessor INHERITED; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 76 | }; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 77 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 78 | #endif |