blob: acd122eef51a8c201c111b1830234f3727c515d7 [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 , fLocalCoordsType(kUnused_LocalCoordsType)
26 , fSampleShading(0.0) {}
joshualitt9b989322014-12-15 14:16:27 -080027
Brian Salomon7f235432017-08-16 09:41:48 -040028 bool willUseGeoShader() const final { return fWillUseGeoShader; }
joshualitt74077b92014-10-24 11:26:03 -070029
Brian Salomon7f235432017-08-16 09:41:48 -040030 bool hasExplicitLocalCoords() const final {
joshualittb2aa7cb2015-08-05 11:05:22 -070031 return kHasExplicit_LocalCoordsType == fLocalCoordsType;
32 }
33
ethannicholas28ef4452016-03-25 09:26:03 -070034 /**
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 Salomon7f235432017-08-16 09:41:48 -040039 float getSampleShading() const final { return fSampleShading; }
ethannicholas28ef4452016-03-25 09:26:03 -070040
joshualittb0a8a372014-09-23 09:50:21 -070041protected:
joshualitt74077b92014-10-24 11:26:03 -070042 void setWillUseGeoShader() { fWillUseGeoShader = true; }
43
joshualittb2aa7cb2015-08-05 11:05:22 -070044 /**
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
joshualittb2aa7cb2015-08-05 11:05:22 -070050 */
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 }
joshualitt2dd1ae02014-12-03 06:24:10 -080065
ethannicholas28ef4452016-03-25 09:26:03 -070066 void setSampleShading(float sampleShading) {
67 fSampleShading = sampleShading;
68 }
69
joshualittb0a8a372014-09-23 09:50:21 -070070private:
joshualitt74077b92014-10-24 11:26:03 -070071 bool fWillUseGeoShader;
joshualittb2aa7cb2015-08-05 11:05:22 -070072 LocalCoordsType fLocalCoordsType;
ethannicholas28ef4452016-03-25 09:26:03 -070073 float fSampleShading;
joshualittb0a8a372014-09-23 09:50:21 -070074
joshualitt290c09b2014-12-19 13:45:20 -080075 typedef GrPrimitiveProcessor INHERITED;
joshualittb0a8a372014-09-23 09:50:21 -070076};
joshualitt56995b52014-12-11 15:44:02 -080077
joshualittb0a8a372014-09-23 09:50:21 -070078#endif