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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "src/gpu/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 |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 15 | * has complete control over vertex attributes and uniforms (aside from the render target) but it |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 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. |
Robert Phillips | 7cd0bfe | 2019-11-20 16:08:10 -0500 | [diff] [blame] | 19 | * |
| 20 | * Note that all derived classes should hide their constructors and provide a Make factory |
| 21 | * function that takes an arena (except for CCPR-specific classes). This is because |
| 22 | * GrGeometryProcessor's are not ref-counted to must have some other mechanism for managing |
| 23 | * their lifetime. In particular, geometry processors can be created in either the |
| 24 | * record-time or flush-time arenas which defined their lifetimes (i.e., a DDLs life time in |
| 25 | * the first case and a single flush in the second case). |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 26 | */ |
| 27 | class GrGeometryProcessor : public GrPrimitiveProcessor { |
| 28 | public: |
Ethan Nicholas | abff956 | 2017-10-09 10:54:08 -0400 | [diff] [blame] | 29 | GrGeometryProcessor(ClassID classID) |
| 30 | : INHERITED(classID) |
Brian Osman | a63593a | 2018-12-06 15:54:53 -0500 | [diff] [blame] | 31 | , fWillUseGeoShader(false) {} |
joshualitt | 9b98932 | 2014-12-15 14:16:27 -0800 | [diff] [blame] | 32 | |
Brian Salomon | 7f23543 | 2017-08-16 09:41:48 -0400 | [diff] [blame] | 33 | bool willUseGeoShader() const final { return fWillUseGeoShader; } |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 34 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 35 | protected: |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 36 | void setWillUseGeoShader() { fWillUseGeoShader = true; } |
ethannicholas | 28ef445 | 2016-03-25 09:26:03 -0700 | [diff] [blame] | 37 | |
Brian Osman | 2715bf5 | 2019-12-06 14:38:47 -0500 | [diff] [blame^] | 38 | // GPs that need to use either float or ubyte colors can just call this to get a correctly |
Brian Osman | c906d25 | 2018-12-04 11:17:46 -0500 | [diff] [blame] | 39 | // configured Attribute struct |
| 40 | static Attribute MakeColorAttribute(const char* name, bool wideColor) { |
| 41 | return { name, |
Brian Osman | 2715bf5 | 2019-12-06 14:38:47 -0500 | [diff] [blame^] | 42 | wideColor ? kFloat4_GrVertexAttribType : kUByte4_norm_GrVertexAttribType, |
Brian Osman | c906d25 | 2018-12-04 11:17:46 -0500 | [diff] [blame] | 43 | kHalf4_GrSLType }; |
| 44 | } |
| 45 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 46 | private: |
joshualitt | 74077b9 | 2014-10-24 11:26:03 -0700 | [diff] [blame] | 47 | bool fWillUseGeoShader; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 48 | |
joshualitt | 290c09b | 2014-12-19 13:45:20 -0800 | [diff] [blame] | 49 | typedef GrPrimitiveProcessor INHERITED; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 50 | }; |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 51 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 52 | #endif |