blob: 687fc708daab98cc619903c1c6646c7238a6364c [file] [log] [blame]
joshualittb0a8a372014-09-23 09:50:21 -07001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050011#include "src/gpu/GrPrimitiveProcessor.h"
joshualitt9b989322014-12-15 14:16:27 -080012
13/**
14 * A GrGeometryProcessor is a flexible method for rendering a primitive. The GrGeometryProcessor
Robert Phillips7cd0bfe2019-11-20 16:08:10 -050015 * has complete control over vertex attributes and uniforms (aside from the render target) but it
joshualitt9b989322014-12-15 14:16:27 -080016 * 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 Phillips7cd0bfe2019-11-20 16:08:10 -050019 *
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).
joshualitt9b989322014-12-15 14:16:27 -080026 */
27class GrGeometryProcessor : public GrPrimitiveProcessor {
28public:
Ethan Nicholasabff9562017-10-09 10:54:08 -040029 GrGeometryProcessor(ClassID classID)
30 : INHERITED(classID)
Brian Osmana63593a2018-12-06 15:54:53 -050031 , fWillUseGeoShader(false) {}
joshualitt9b989322014-12-15 14:16:27 -080032
Brian Salomon7f235432017-08-16 09:41:48 -040033 bool willUseGeoShader() const final { return fWillUseGeoShader; }
joshualitt74077b92014-10-24 11:26:03 -070034
joshualittb0a8a372014-09-23 09:50:21 -070035protected:
joshualitt74077b92014-10-24 11:26:03 -070036 void setWillUseGeoShader() { fWillUseGeoShader = true; }
ethannicholas28ef4452016-03-25 09:26:03 -070037
Brian Osman2715bf52019-12-06 14:38:47 -050038 // GPs that need to use either float or ubyte colors can just call this to get a correctly
Brian Osmanc906d252018-12-04 11:17:46 -050039 // configured Attribute struct
40 static Attribute MakeColorAttribute(const char* name, bool wideColor) {
41 return { name,
Brian Osman2715bf52019-12-06 14:38:47 -050042 wideColor ? kFloat4_GrVertexAttribType : kUByte4_norm_GrVertexAttribType,
Brian Osmanc906d252018-12-04 11:17:46 -050043 kHalf4_GrSLType };
44 }
45
joshualittb0a8a372014-09-23 09:50:21 -070046private:
joshualitt74077b92014-10-24 11:26:03 -070047 bool fWillUseGeoShader;
joshualittb0a8a372014-09-23 09:50:21 -070048
joshualitt290c09b2014-12-19 13:45:20 -080049 typedef GrPrimitiveProcessor INHERITED;
joshualittb0a8a372014-09-23 09:50:21 -070050};
joshualitt56995b52014-12-11 15:44:02 -080051
joshualittb0a8a372014-09-23 09:50:21 -070052#endif