blob: 086d9baa5349ba2421a41d46d86a9abdb06f2c06 [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:
joshualitte3ababe2015-05-15 07:56:07 -070022 GrGeometryProcessor()
ethannicholas22793252016-01-30 09:59:10 -080023 : fWillUseGeoShader(false)
ethannicholas28ef4452016-03-25 09:26:03 -070024 , fLocalCoordsType(kUnused_LocalCoordsType)
25 , fSampleShading(0.0) {}
joshualitt9b989322014-12-15 14:16:27 -080026
mtkleinf0599002015-07-13 06:18:39 -070027 bool willUseGeoShader() const override { return fWillUseGeoShader; }
joshualitt74077b92014-10-24 11:26:03 -070028
joshualittb2aa7cb2015-08-05 11:05:22 -070029 bool hasExplicitLocalCoords() const override {
30 return kHasExplicit_LocalCoordsType == fLocalCoordsType;
31 }
32
ethannicholas28ef4452016-03-25 09:26:03 -070033 /**
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
joshualittb0a8a372014-09-23 09:50:21 -070042protected:
joshualitt74077b92014-10-24 11:26:03 -070043 void setWillUseGeoShader() { fWillUseGeoShader = true; }
44
joshualittb2aa7cb2015-08-05 11:05:22 -070045 /**
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
joshualittb2aa7cb2015-08-05 11:05:22 -070051 */
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 }
joshualitt2dd1ae02014-12-03 06:24:10 -080066
ethannicholas28ef4452016-03-25 09:26:03 -070067 void setSampleShading(float sampleShading) {
68 fSampleShading = sampleShading;
69 }
70
joshualittb0a8a372014-09-23 09:50:21 -070071private:
joshualitt74077b92014-10-24 11:26:03 -070072 bool fWillUseGeoShader;
joshualittb2aa7cb2015-08-05 11:05:22 -070073 LocalCoordsType fLocalCoordsType;
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