blob: 5306a0fb4c17961bb7e78e368df622904af2e8e6 [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
joshualitt8072caa2015-02-12 14:20:52 -080011#include "GrPrimitiveProcessor.h"
joshualitt9b989322014-12-15 14:16:27 -080012
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 */
20class GrGeometryProcessor : public GrPrimitiveProcessor {
21public:
Ethan Nicholasabff9562017-10-09 10:54:08 -040022 GrGeometryProcessor(ClassID classID)
23 : INHERITED(classID)
24 , fWillUseGeoShader(false)
ethannicholas28ef4452016-03-25 09:26:03 -070025 , fSampleShading(0.0) {}
joshualitt9b989322014-12-15 14:16:27 -080026
Brian Salomon7f235432017-08-16 09:41:48 -040027 bool willUseGeoShader() const final { return fWillUseGeoShader; }
joshualitt74077b92014-10-24 11:26:03 -070028
ethannicholas28ef4452016-03-25 09:26:03 -070029 /**
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 Salomon7f235432017-08-16 09:41:48 -040034 float getSampleShading() const final { return fSampleShading; }
ethannicholas28ef4452016-03-25 09:26:03 -070035
joshualittb0a8a372014-09-23 09:50:21 -070036protected:
joshualitt74077b92014-10-24 11:26:03 -070037 void setWillUseGeoShader() { fWillUseGeoShader = true; }
ethannicholas28ef4452016-03-25 09:26:03 -070038 void setSampleShading(float sampleShading) {
39 fSampleShading = sampleShading;
40 }
41
Brian Salomon92be2f72018-06-19 14:33:47 -040042 /**
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
joshualittb0a8a372014-09-23 09:50:21 -070072private:
joshualitt74077b92014-10-24 11:26:03 -070073 bool fWillUseGeoShader;
ethannicholas28ef4452016-03-25 09:26:03 -070074 float fSampleShading;
joshualittb0a8a372014-09-23 09:50:21 -070075
joshualitt290c09b2014-12-19 13:45:20 -080076 typedef GrPrimitiveProcessor INHERITED;
joshualittb0a8a372014-09-23 09:50:21 -070077};
joshualitt56995b52014-12-11 15:44:02 -080078
joshualittb0a8a372014-09-23 09:50:21 -070079#endif