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